For comparison, the original version of the weight chart program from the previous two posts resulted in this
Obviously, I didn't fuss with the x-axis enough. It was fine early on, but as time went on it clearly needed adjustment. This is why I want sensible guesses at axis ranges and labels; I can't be trusted to do it myself. Anyway, here is the code
#!/usr/bin/env perl use v5.12; use autodie; use warnings; use Chart::Clicker; use Chart::Clicker::Data::Range; use File::Slurp qw(slurp); use List::Util qw(max min); use Method::Signatures; use Number::Format; my $ofile = shift // 'weight_chart.png'; my $ifile = shift // \*DATA; my %data = eval slurp($ifile); my $cc = Chart::Clicker->new; $cc->add_data('Weight (lbs)', \%data); my $dc = $cc->get_context('default'); format_axis( axis => $dc->domain_axis, min => 0, max => int( 5 + max keys %data), mod => 7, ); format_axis( axis => $dc->range_axis, min => int(-5 + min values %data), max => int( 5 + max values %data), mod => 5, ); $cc->write_output($ofile); system("xdg-open $ofile") == 0 or warn "eog $ofile\n"; # Format the given axis for display. # func format_axis (:$axis!, :$min=0, :$max!, :$mod=10) { $axis->tick_values([ grep {!($_ % $mod)} $min..$max ]); $axis->range(Chart::Clicker::Data::Range->new({ lower => $min, upper => $max, })); $axis->format(sub {Number::Format->new->round(shift, 0)}); } __END__ 1 => 180.2, 8 => 173.8, 15 => 172.2, 22 => 171.2, 29 => 170.2, 36 => 168.2, 43 => 166.6, 50 => 168.2, 57 => 165.6, 64 => 165.4, 71 => 165.0, 78 => 163.6, 85 => 163.2, 92 => 161.8, 99 => 160.6, 106 => 162.4, 113 => 164.3, 120 => 162.6, 134 => 161.8, 141 => 158.8, 148 => 160.6, 155 => 158.2, 162 => 161.8, 169 => 162.4, 176 => 159.8, 183 => 162.6, 190 => 160.6, 197 => 160.8, 204 => 159.6, 211 => 159.8, 218 => 158.8,
Recent Comments