17 $area{fieldxsize} = $area{fieldxmax} - $area{fieldxmin};
18 $area{fieldysize} = $area{fieldymax} - $area{fieldymin};
25 for my $input (@ARGV) {
26 open my $datafile, '<', $input or next;
29 while (defined ($_ = readline $datafile)) {
30 my ($frame, $time, @vars) = split /\t/, $_;
31 $frame =~ /^\d+:$/ or next;
32 if ($time !~ /^\d+$/) {
33 defined $lasttime or next;
34 $time = $lasttime + 1;
39 /^\d+$/ or $_ = undef for @vars;
40 push @{$data[$time]} => \@vars;
41 defined $vars[$_] and $vars[$_] > $max[$_] and $max[$_] = $vars[$_]
44 $maxtime = $#data if $#data > $maxtime;
47 for my $time (0 .. $#data) {
48 my $vals = $data[$time];
49 for my $subtime (0 .. $#$vals) {
50 defined $vals->[$subtime]->[$_] and push @{$lines[$_][$player]} => [
51 ($time + $subtime/@$vals), # x
52 $vals->[$subtime]->[$_] # y
58 my $line = $lines[$_][$player];
61 for (my $i = 1; $i <= $#$line; $i++) {
62 defined $line->[$i] or next;
63 if ($line->[$i][1] == $line->[$i - 1][1]) {
64 $start = $i unless defined $start;
65 } elsif (defined $start) {
66 delete @$line[$start .. $i-2];
70 delete @$line[$start .. $#$line-2] if defined $start; # or -1
76 my @norm = ((map {$area{fieldysize} / $_} @max), $area{fieldxsize} / $maxtime);
79 my $xstep = $maxtime / $xsteps;
80 my @xaxis = map [$area{fieldxmin} + $_ * $norm[4], sprintf '%d:%02d', $_/3600, $_/60%60],
81 map $_*$xstep, 0 .. $xsteps-1;
86 my $ystep = $max[$i] / $ysteps;
87 $ystep = 10 ** int (log($ystep * 4) / log(10));
88 $ystep /= 2 while $ystep * $ysteps > $max[$i];
90 map [$area{fieldymax} - $_ * $norm[$i], $_],
91 map $_*$ystep, 0 .. int $max[$i] / $ystep
96 my $svg = Template->new({POST_CHOMP => 1, BLOCKS => {timeline => readline DATA}});
98 for ([0 => "min", "Minerals"], [1 => "gas", "Gas"], [2 => "unit", "Units"]) {
99 my ($line, $filename, $title) = @$_;
100 open my $output, '>', "$filename.svg";
101 $svg->process('timeline', {
102 title => "$title timeline for /replay/20080201md4x4",
104 map { "\n\tM " . join "\tL ", map sprintf("%s %s\n",
105 $area{fieldxmin} + $_->[0] * $norm[4],
106 $area{fieldymax} - $_->[1] * $norm[$line]
107 ), grep defined, @$_ } @{$lines[$line]}
110 yaxis => $yaxis[$line],
112 }, $output) or die $svg->error;
116 <?xml version="1.0"?>
117 <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
118 "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
120 <?xml-stylesheet href="http://sc.shiar.net/apm.css" type="text/css"?>
122 <svg width="100%" height="100%" viewBox="0 0 [% area.xmax %] [% area.ymax %]"
123 xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
124 <title>[% title %]</title>
126 <rect x="0" y="0" width="[% area.xmax %]" height="[% area.ymax %]" class="svgBackground" />
127 <rect x="[% area.fieldxmin %]" y="[% area.fieldymin %]" width="[% area.fieldxsize %]" height="[% area.fieldysize %]" class="graphBackground" />
129 <path d="M[% area.fieldxmin %] [% area.fieldymin %] v[% area.fieldysize %]" class="axis" id="xAxis"/>
130 [% FOREACH entry = xaxis %]
131 <text x="[% entry.0 %]" y="[% area.fieldymax + 15 %]" class="xAxisLabels"> [% entry.1 %]</text>
134 <path d="M[% area.fieldxmin %] [% area.fieldymax %] h[% area.fieldxsize %]" class="axis" id="yAxis"/>
135 [% FOREACH entry = yaxis %]
136 <path d="M[% area.fieldxmin %] [% entry.0 %] h[% area.fieldxsize %]" class="guideLines" />
137 <text x="[% area.fieldxmin - 5 %]" y="[% entry.0 %]" class="yAxisLabels">[% entry.1 %]</text>
142 [% FOREACH path = paths %][% count = count + 1 %]
143 <path d="[% path %]" class="line[% count %]" />