pricecharts

track prices of consumer electronics
Log | Files | Refs | README

commit 383cfca2ef3ebebb3f17195fde67f80b8131cdb4
parent eb9cd70cc2ab8fc283f81866a00d31e343f02737
Author: Kyle Milz <kyle@getaddrinfo.net>
Date:   Sat,  4 Apr 2015 19:03:04 -0600

gen_svg: misc cleanups

- make reduced date labels work
- use full month name on chart x axis
- don't use a fill color for path

Diffstat:
Mgen_svg | 20++++++++------------
1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/gen_svg b/gen_svg @@ -90,14 +90,11 @@ while (my ($manufacturer, $part_num) = $parts_sth->fetchrow_array()) { } # make dates along the bottom - if ($domain == 0) { - $num_labels = 1; + if ($domain == 24 * 60 * 60) { + $num_labels = 2; } for (1..$num_labels) { my $step = ($_ - 1) / ($num_labels - 1); - my $time = $x_min + $domain * $step; - my $date = strftime "%b %e %Y", localtime($time); - my $x = $left + $center * $step; # make the dates not hang off the ends of the chart my $text_anchor = "middle"; @@ -105,15 +102,15 @@ while (my ($manufacturer, $part_num) = $parts_sth->fetchrow_array()) { $text_anchor = "end" if ($_ == $num_labels); # print the dates along the x axis - $svg->text( - id => "date_$_", x => $x, y => $height - 5, + my $x = $left + $center * $step; + my $time = $x_min + $domain * $step; + $svg->text(id => "date_$_", x => $x, y => $height - 5, class => "chart_date", "text-anchor" => $text_anchor - )->cdata($date); + )->cdata(strftime("%B %e, %Y", localtime($time))); # print the little tick marks down from the x axis my $x_axis = $top + $middle; - $svg->line( - id => "date_marker_$_", x1 => $x, y1 => $x_axis, + $svg->line(id => "date_marker_$_", x1 => $x, y1 => $x_axis, x2 => $x, y2 => $x_axis + 5, class => "chart_rulers", ); } @@ -143,7 +140,6 @@ while (my ($manufacturer, $part_num) = $parts_sth->fetchrow_array()) { # transform and clamp real world coordinates push @xs, sprintf "%.2f", ($date - $x_min) * $x_scale + $left; push @ys, sprintf "%.2f", $height - $bottom - ($price - $y_min) * $y_scale; - $points++; } @@ -158,7 +154,7 @@ while (my ($manufacturer, $part_num) = $parts_sth->fetchrow_array()) { # draw path first $anchor->use( -href => "#path_$retailer_id", class => "chart_series", - style => { fill => "#$color", stroke => "#$color" } + style => { stroke => "#$color" } ); # then draw individual data points