You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Dec 22, 2023. It is now read-only.
By default Chart::Clicker chooses non-optimal values for tick marks (such as 0.30, 1.40, 2.50, 3.60, 4.70, 5.80).
I created a subroutine getrange() which creates tick marks to produce a chart which is easier to read.
In the example above, if getrange() is given a min of 0.30 and a max of 5.80, the tick marks returned will be [0, 1, 2, 3, 4, 5, 6]
my $Yrange = getrange( $min, $max, { integer => 1 } );
$ctx->range_axis->tick_values($Yrange);
sub getrange {
my ( $min, $max, $options ) = @_;
# $min and $max are the minimum and maximum values of the input data
return if not defined $min or not defined $max;
my $span = $max - $min;
my $n = substr( sprintf( "%.6e", $span ), 0, 8 ); # First few number 1.000000 to 9.999999
my $e = substr( sprintf( "%.6e", $span ), 9, 11 ); # exponent with sign such as +01
my $step;
if ( $n > 5 ) {
$step = 1 * 10**($e); # 5.01 to 9.99
} elsif ( $n > 2 ) {
$step = 5 * 10**( $e - 1 ); # 2.01 to 3.00
} else {
$step = 2 * 10**( $e - 1 ); # 1.00 to 2.00
}
if ( $options->{integer} ) {
# This forces steps to be integers. If max is 2.2, then step is 1 (not 0.5)
use POSIX;
$step = ceil($step);
}
my $range;
if ( $max/$step == int($max/$step) ) {
$range = [ map { $_ * $step } int( $min / $step ) .. int( $max / $step ) ];
} else {
$range = [ map { $_ * $step } int( $min / $step ) .. int( $max / $step ) + 1 ];
}
return $range;
}
sub test_getrange {
my @minmax = ( 0.30, 5.80, 0, 0.85, 0, 1.1, 0, 2.2, 0, 5.8, 0, 8, 0, 15, 0, 28, 0, 44, 0, 58, 0, 88, 0, 100, 0, 102, 0, 1020, -7, 21, 18, 45, 18, 49 );
while (@minmax) {
my $min = shift @minmax;
my $max = shift @minmax;
my $range = getrange( $min, $max, { integer => 1 } );
say "\n$min $max\n " . join ' ', @{$range};
}
exit 0;
}
The text was updated successfully, but these errors were encountered:
By default Chart::Clicker chooses non-optimal values for tick marks (such as 0.30, 1.40, 2.50, 3.60, 4.70, 5.80).
I created a subroutine getrange() which creates tick marks to produce a chart which is easier to read.
In the example above, if getrange() is given a min of 0.30 and a max of 5.80, the tick marks returned will be [0, 1, 2, 3, 4, 5, 6]
The text was updated successfully, but these errors were encountered: