| 1 | package Term::Fabulous::Chart::Scale::Linear; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use v5.32; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use feature 'signatures'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | no warnings 'experimental::signatures'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | our $VERSION = '0.05'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Object::Pad 0.825; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Term::Fabulous::Chart::Scale; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | class Term::Fabulous::Chart::Scale::Linear :isa(Term::Fabulous::Chart::Scale) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use List::Util (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use POSIX qw(ceil floor); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use Term::Fabulous::Chart::Format qw(number_formatter); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use constant { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 1 | EPSILON => 1e-9, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | MOST_TICKS => 10_000, # more never fit an axis; a step that needs them is skipped | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 1 | ▶ | field $step :param :reader; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
step: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 1 | ▶ | method kind () { return 'linear' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
kind: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 67 | ▶ | method position ($value) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
position: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 67 | my ( $low, $high ) = ( $self->min, $self->max ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 67 | return ( $value - $low ) / ( $high - $low ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | ▶ | method value_at ($position) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
value_at: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | return $self->min + $position * ( $self->max - $self->min ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 1 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | # The nice steps (1, 2, 2.5 and 5 times a power of ten) between two | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # sizes. Whole-number data takes no steps below 1 and no 2.5 below 25. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 21 | ▶ | sub _nice_steps ( $smallest, $largest, $integer ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_nice_steps: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 21 | my @steps; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 21 | foreach my $exponent ( floor( log($smallest) / log(10) ) - 1 .. ceil( log($largest) / log(10) ) + 1 ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 102 | foreach my $mantissa ( 1, 2, 2.5, 5 ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 408 | my $step = $mantissa * 10**$exponent; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 408 | ▶ | next if $integer && ( $step < 1 || ( $mantissa == 2.5 && $step < 25 ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%9/9
$integer and $step < 1 || $mantissa == "2.5" && $step < 25
$step < 1 or $mantissa == "2.5" and $step < 25
$mantissa == "2.5" and $step < 25
MC/DC100%4/4
$integer and $step < 1 || $mantissa == "2.5" && $step < 25
$integer
$step < 1
$mantissa == "2.5"
$step < 25
Truth table100%5/5
A and B or C and D
A= $integerB= $step < 1C= $mantissa == "2.5"D= $step < 25
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 386 | ▶ | push @steps, $step if $step >= $smallest * ( 1 - EPSILON ) && $step <= $largest * ( 1 + EPSILON ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$step >= $smallest * "0.999999999" and $step <= $largest * "1.000000001"
MC/DC100%2/2
$step >= $smallest * "0.999999999" and $step <= $largest * "1.000000001"
$step >= $smallest * "0.999999999"
$step <= $largest * "1.000000001"
Truth table100%3/3
A and B
A= $step >= $smallest * "0.999999999"B= $step <= $largest * "1.000000001"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 21 | return @steps; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | # The multiples of $step from $low to $high; none when there would be | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | # more than MOST_TICKS. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 95 | ▶ | sub _multiples ( $low, $high, $step ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_multiples: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 95 | my $first = ceil( $low / $step - EPSILON ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 95 | ▶ | return () if floor( $high / $step + EPSILON ) - $first + 1 > MOST_TICKS; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 94 | my @values; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 94 | ▶ | for ( my $index = $first; $index * $step <= $high + $step * EPSILON; $index++ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 586 | my $value = $index * $step; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 586 | ▶ | push @values, abs($value) < $step * EPSILON ? 0 : $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 94 | return @values; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | # Fits a scale to data and to the cells of an axis. See the POD. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 27 | ▶ | method fit :common (%options) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fit: called CC=35 SCAR=35.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 27 | ▶ | my $cells = $options{cells} // croak "$class: fit needs cells"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$options{"cells"} // croak("${class}: fit needs cells")
MC/DC100%1/1
$options{"cells"} // croak("${class}: fit needs cells")
$options{"cells"}
Truth table100%2/2
A
A= $options{"cells"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 26 | ▶ | croak "$class: cells must be a positive integer, got $cells" unless $cells =~ /\A[1-9][0-9]*\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 25 | ▶ | my $vertical = ( $options{orientation} // 'vertical' ) eq 'vertical'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$options{"orientation"} // "vertical"
MC/DC100%1/1
$options{"orientation"} // "vertical"
$options{"orientation"}
Truth table100%2/2
A
A= $options{"orientation"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 25 | ▶ | my $align = $options{align} // $vertical; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$options{"align"} // $vertical
MC/DC0%0/2
$options{"align"} // $vertical
$options{"align"}
$vertical
Truth table66%2/3
A // B
A= $options{"align"}B= $vertical
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 25 | my ( $fixed_low, $fixed_high ) = @options{qw(min max)}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 25 | ▶ | croak "$class: min ($fixed_low) must be less than max ($fixed_high)" if defined $fixed_low && defined $fixed_high && $fixed_low >= $fixed_high; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
defined $fixed_low and defined $fixed_high and $fixed_low >= $fixed_high
defined $fixed_low and defined $fixed_high
MC/DC100%3/3
defined $fixed_low and defined $fixed_high and $fixed_low >= $fixed_high
defined $fixed_low
defined $fixed_high
$fixed_low >= $fixed_high
Truth table100%4/4
A and B and C
A= defined $fixed_lowB= defined $fixed_highC= $fixed_low >= $fixed_high
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 24 | ▶ | my ( $low, $high ) = $options{extent} ? $options{extent}->@* : ( 0, 1 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 24 | ▶ | ( $low, $high ) = ( List::Util::min( $low, 0 ), List::Util::max( $high, 0 ) ) if $options{zero}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 24 | ▶ | $low = $fixed_low if defined $fixed_low; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 24 | ▶ | $high = $fixed_high if defined $fixed_high; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 24 | ▶ | ( $low, $high ) = _widened( $low, $high, $fixed_low, $fixed_high ) if $high <= $low; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 24 | ▶ | my $measure = $options{measure} // sub ($label) { length $label }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.1
Condition66%2/3
$options{"measure"} // sub ($label) {
length $label;
}
MC/DC0%0/2
$options{"measure"} // sub ($label) {
length $label;
}
$options{"measure"}
sub ($label) {
length $label;
}
Truth table66%2/3
A // B
A= $options{"measure"}B= sub ($label) {
length $label;
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | my @steps | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | = defined $options{step} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | ? ( $options{step} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 24 | ▶ | : _nice_steps( ( $high - $low ) / List::Util::max( 1, $cells - 1 ), $high - $low, $options{integer} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 24 | my $wanted_ticks = $options{ticks}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 24 | my $best; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 24 | foreach my $step (@steps) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 96 | ▶ | next if ( $high - $low ) / $step > $cells; # more intervals than cells: no tick could get a cell of its own | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 95 | ▶ | my $candidate = _candidate( $low, $high, $step, $fixed_low, $fixed_high, $options{nice} // 1 ) // next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%4/4
_candidate($low, $high, $step, $fixed_low, $fixed_high, $options{"nice"} // 1) // (next)
$options{"nice"} // 1
MC/DC100%1/1
_candidate($low, $high, $step, $fixed_low, $fixed_high, $options{"nice"} // 1) // (next)
_candidate($low, $high, $step, $fixed_low, $fixed_high, $options{"nice"} // 1)
MC/DC100%1/1
$options{"nice"} // 1
$options{"nice"}
Truth table100%2/2
A
A= _candidate($low, $high, $step, $fixed_low, $fixed_high, $options{"nice"} // 1)
Truth table100%2/2
A
A= $options{"nice"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 94 | my ( $domain_low, $domain_high, $values ) = @$candidate{qw(low high values)}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 94 | my $intervals = @$values - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 94 | ▶ | next if $intervals < 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 93 | my $format = number_formatter( $options{format}, $step, List::Util::max( map { abs } @$values ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 93 | my @labels = map { $format->($_) } @$values; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 93 | my $widest = List::Util::max( map { $measure->($_) } @labels ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 93 | my ( $least, $ideal ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 93 | ▶ | if ($vertical) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 71 | ▶ | ( $least, $ideal ) = ( $cells >= 8 ? 2 : 1, $cells >= 8 ? List::Util::min( 6, List::Util::max( 3, $cells / 4 ) ) : 2 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 22 | ( $least, $ideal ) = ( $widest + 2, List::Util::max( $widest + 4, 10 ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 93 | my $headroom = ( ( $domain_high - $domain_low ) - ( $high - $low ) ) / ( $domain_high - $domain_low ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | # Evenly spaced ticks from end to end land on whole cells when the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | # axis spans a multiple of the intervals, which may leave a few | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | # cells unused. Ticks that do not span the domain (a fixed end | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | # between two of them) are placed as near as they can be. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 93 | ▶ | my $spans_domain = abs( $values->[0] - $domain_low ) < $step * EPSILON && abs( $values->[-1] - $domain_high ) < $step * EPSILON; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
abs $values->[0] - $domain_low < $step * 1e-09 && abs $values->[-1] - $domain_high < $step * 1e-09
MC/DC100%2/2
abs $values->[0] - $domain_low < $step * 1e-09 && abs $values->[-1] - $domain_high < $step * 1e-09
abs $values->[0] - $domain_low < $step * 1e-09
abs $values->[-1] - $domain_high < $step * 1e-09
Truth table100%3/3
A && B
A= abs $values->[0] - $domain_low < $step * 1e-09B= abs $values->[-1] - $domain_high < $step * 1e-09
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 93 | ▶ | my ( $per_interval, $used ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$align and $spans_domain
MC/DC100%2/2
$align and $spans_domain
$align
$spans_domain
Truth table100%3/3
A and B
A= $alignB= $spans_domain
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | = $align && $spans_domain | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | ? ( floor( ( $cells - 1 ) / $intervals ), $intervals * floor( ( $cells - 1 ) / $intervals ) + 1 ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | : ( ( $cells - 1 ) * ( $values->[-1] - $values->[0] ) / ( $domain_high - $domain_low ) / $intervals, $cells ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 93 | ▶ | next if $per_interval < 1 || ( $per_interval < $least && !defined $options{step} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$per_interval < 1 or $per_interval < $least and not defined $options{"step"}
$per_interval < $least and not defined $options{"step"}
MC/DC66%2/3
$per_interval < 1 or $per_interval < $least and not defined $options{"step"}
$per_interval < 1
$per_interval < $least
not defined $options{"step"}
Truth table75%3/4
A or B and not(C)
A= $per_interval < 1B= $per_interval < $leastC= not defined $options{"step"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 64 | my $waste = ( $cells - $used ) / $cells; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 64 | ▶ | my $density = defined $wanted_ticks ? abs( @$values - $wanted_ticks ) / $wanted_ticks : abs( log( $per_interval / $ideal ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 64 | ▶ | my $score = 3 * $waste + 3 * $headroom + $density + ( @$values < 3 && $cells >= 6 ? 0.5 : 0 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@$values < 3 and $cells >= 6
MC/DC50%1/2
@$values < 3 and $cells >= 6
@$values < 3
$cells >= 6
Truth table66%2/3
A and B
A= @$values < 3B= $cells >= 6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | $best = { score => $score, step => $step, low => $domain_low, high => $domain_high, used => $used, values => $values, labels => \@labels } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 64 | ▶ | if !defined $best || $score < $best->{score} - EPSILON; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $best or $score < $best->{"score"} - "1e-09"
MC/DC100%2/2
not defined $best or $score < $best->{"score"} - "1e-09"
not defined $best
$score < $best->{"score"} - "1e-09"
Truth table100%3/3
not(A) or B
A= not defined $bestB= $score < $best->{"score"} - "1e-09"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | # Too little room for any two ticks: the two ends. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 24 | ▶ | $best //= do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$best //= do {
my $format = number_formatter($options{"format"}, $high - $low, &List::Util::max(abs $low, abs $high));
+{"step", $high - $low, "low", $low, "high", $high, "used", $cells, "values", [$low, $high], "labels", [map({&$format($_);} $low, $high)]}
}
MC/DC0%0/2
$best //= do {
my $format = number_formatter($options{"format"}, $high - $low, &List::Util::max(abs $low, abs $high));
+{"step", $high - $low, "low", $low, "high", $high, "used", $cells, "values", [$low, $high], "labels", [map({&$format($_);} $low, $high)]}
}
$best
do {
my $format = number_formatter($options{"format"}, $high - $low, &List::Util::max(abs $low, abs $high));
+{"step", $high - $low, "low", $low, "high", $high, "used", $cells, "values", [$low, $high], "labels", [map({&$format($_);} $low, $high)]}
}
Truth table66%2/3
A //= B
A= $bestB= do {
my $format = number_formatter($options{"format"}, $high - $low, &List::Util::max(abs $low, abs $high));
+{"step", $high - $low, "low", $low, "high", $high, "used", $cells, "values", [$low, $high], "labels", [map({&$format($_);} $low, $high)]}
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 3 | my $format = number_formatter( $options{format}, $high - $low, List::Util::max( abs $low, abs $high ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 3 | { step => $high - $low, low => $low, high => $high, used => $cells, values => [ $low, $high ], labels => [ map { $format->($_) } $low, $high ] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 24 | my @ticks = map { { value => $best->{values}[$_], label => $best->{labels}[$_] } } 0 .. $best->{values}->$#*; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 24 | return $class->new( min => $best->{low}, max => $best->{high}, cells => $cells, used => $best->{used}, step => $best->{step}, ticks => \@ticks ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 1 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 1 | ▶ | sub _widened ( $low, $high, $fixed_low, $fixed_high ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_widened: called CC=5 SCAR=17.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 1 | ▶ | my $margin = $low == 0 ? 1 : abs($low) / 10; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 1 | ▶ | return ( $low, $low + $margin ) if defined $fixed_low; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 1 | ▶ | return ( $high - $margin, $high ) if defined $fixed_high; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 1 | ▶ | return $low == 0 ? ( 0, 1 ) : ( $low - $margin, $high + $margin ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 95 | ▶ | sub _candidate ( $low, $high, $step, $fixed_low, $fixed_high, $nice ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_candidate: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 95 | ▶ | my $domain_low = defined $fixed_low || !$nice ? $low : floor( $low / $step + EPSILON ) * $step; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $fixed_low or not $nice
MC/DC100%2/2
defined $fixed_low or not $nice
defined $fixed_low
not $nice
Truth table100%3/3
A or not(B)
A= defined $fixed_lowB= not $nice
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 95 | ▶ | my $domain_high = defined $fixed_high || !$nice ? $high : ceil( $high / $step - EPSILON ) * $step; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $fixed_high or not $nice
MC/DC100%2/2
defined $fixed_high or not $nice
defined $fixed_high
not $nice
Truth table100%3/3
A or not(B)
A= defined $fixed_highB= not $nice
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 95 | ▶ | $domain_high += $step if $domain_high <= $domain_low; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 95 | my @values = _multiples( $domain_low, $domain_high, $step ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 95 | ▶ | return undef unless @values; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 94 | return { low => $domain_low, high => $domain_high, values => \@values }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||