Graph/TimeSeries.pm

filter: Statementstmt 23.8% 30 / 126 Branchbran 0.0% 0 / 58 Conditioncond 0.0% 0 / 33 MC/DCmcdc 0.0% 0 / 20 Subroutinesub 60.0% 9 / 15 Podpod 25.0% 1 / 4 totaltotal 15.6% 40 / 256 CC 43 SCAR 59.5
CC
43
Cov
14%
calculations
702.0
add_data
240.0
get_template
12.0
CRAP 384.4
↑ Summary Graph.pm »
1 package SVG::TT::Graph::TimeSeries;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 $VERSION = '0.11';
7  
8 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use HTTP::Date;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use POSIX;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 ▶use SVG::TT::Graph;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use base qw(SVG::TT::Graph);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 my $template;
17  
18 =head1 NAME
19  
20 SVG::TT::Graph::TimeSeries - Create presentation quality SVG line graphs of time series easily
21  
22 =head1 SYNOPSIS
23  
24 use SVG::TT::Graph::TimeSeries;
25  
26 my @data_cpu = ('2003-09-03 09:30:00',23,'2003-09-03 09:45:00',54,'2003-09-03 10:00:00',67,'2003-09-03 10:15:00',12);
27 my @data_disk = ('2003-09-03 09:00:00',12,'2003-09-03 10:00:00',26,'2003-09-03 11:00:00',23);
28
29 my $graph = SVG::TT::Graph::TimeSeries->new({
30 'height' => '500',
31 'width' => '300',
32 });
33
34 $graph->add_data({
35 'data' => \@data_cpu,
36 'title' => 'CPU',
37 });
38  
39 $graph->add_data({
40 'data' => \@data_disk,
41 'title' => 'Disk',
42 });
43
44 print "Content-type: image/svg+xml\r\n\r\n";
45 print $graph->burn();
46  
47 =head1 DESCRIPTION
48  
49 This object aims to allow you to easily create high quality
50 SVG line graphs of time series. You can either use the default style sheet
51 or supply your own. Either way there are many options which can
52 be configured to give you control over how the graph is
53 generated - with or without a key, data elements at each point,
54 title, subtitle etc.
55 All times must be given a format parseable by L<HTTP::Date>.
56 The L<DateTime> module is used for all date/time calculations.
57  
58 Note that the module is currently limited to the Unix-style epoch-based
59 date range limited by 32 bit signed integers (around 1902 to 2038).
60  
61 =head1 METHODS
62  
63 =head2 new()
64  
65 use SVG::TT::Graph::TimeSeries;
66
67 my $graph = SVG::TT::Graph::TimeSeries->new({
68
69 # Optional - defaults shown
70 'height' => 500,
71 'width' => 300,
72  
73 'show_y_labels' => 1,
74 'scale_divisions' => '',
75 'min_scale_value' => 0,
76 'max_scale_value' => '',
77  
78 'show_x_labels' => 1,
79 'timescale_divisions' => '',
80 'min_timescale_value' => '',
81 'max_timescale_value' => '',
82 'x_label_format' => '%Y-%m-%d %H:%M:%S',
83 'stagger_x_labels' => 0,
84 'rotate_x_labels' => 0,
85
86 'show_data_points' => 1,
87 'show_data_values' => 1,
88 'rollover_values' => 0,
89
90 'area_fill' => 0,
91  
92 'show_x_title' => 0,
93 'x_title' => 'X Field names',
94  
95 'show_y_title' => 0,
96 'y_title' => 'Y Scale',
97  
98 'show_graph_title' => 0,
99 'graph_title' => 'Graph Title',
100 'show_graph_subtitle' => 0,
101 'graph_subtitle' => 'Graph Sub Title',
102 'key' => 0,
103 'key_position' => 'right',
104  
105 # Optional - defaults to using internal stylesheet
106 'style_sheet' => '/includes/graph.css',
107 });
108  
109 The constructor takes a hash reference with values defaulted to those
110 shown above - with the exception of style_sheet which defaults
111 to using the internal style sheet.
112  
113 =head2 add_data()
114  
115 my @data_cpu = ('2003-09-03 09:30:00',23,'2003-09-03 09:45:00',54,'2003-09-03 10:00:00',67,'2003-09-03 10:15:00',12);
116 or
117 my @data_cpu = (['2003-09-03 09:30:00',23],['2003-09-03 09:45:00',54],['2003-09-03 10:00:00',67],['2003-09-03 10:15:00',12]);
118  
119 $graph->add_data({
120 'data' => \@data_cpu,
121 'title' => 'CPU',
122 });
123  
124 This method allows you to add data to the graph object.
125 The data is expected to be a list of time, value pairs.
126 It can be called several times to add more data sets in.
127  
128 =head2 clear_data()
129  
130 my $graph->clear_data();
131  
132 This method removes all data from the object so that you can
133 reuse it to create a new graph but with the same config options.
134  
135 =head2 burn()
136  
137 print $graph->burn();
138  
139 This method processes the template with the data and
140 config which has been set and returns the resulting SVG.
141  
142 This method will croak unless at least one data set has
143 been added to the graph object.
144  
145 =head2 config methods
146  
147 my $value = $graph->method();
148 my $confirmed_new_value = $graph->method($value);
149
150 The following is a list of the methods which are available
151 to change the config of the graph object after it has been
152 created.
153  
154 =over 4
155  
156 =item height()
157  
158 Set the height of the graph box, this is the total height
159 of the SVG box created - not the graph it self which auto
160 scales to fix the space.
161  
162 =item width()
163  
164 Set the width of the graph box, this is the total width
165 of the SVG box created - not the graph it self which auto
166 scales to fix the space.
167  
168 =item style_sheet()
169  
170 Set the path to an external stylesheet, set to '' if
171 you want to revert back to using the defaut internal version.
172  
173 To create an external stylesheet create a graph using the
174 default internal version and copy the stylesheet section to
175 an external file and edit from there.
176  
177 =item show_data_values()
178  
179 Show the value of each element of data on the graph.
180  
181 =item rollover_values()
182  
183 Shows data values and data points when the mouse is over the point.
184 Used in combination with show_data_values and/or show_data_points.
185  
186 =item data_value_format()
187  
188 Format specifier to for data values (as per printf).
189  
190 =item show_data_points()
191  
192 Show a small circle on the graph where the line
193 goes from one point to the next.
194  
195 =item max_time_span()
196  
197 Maximum timespan for a line between data points. If this span is exceeded, the points are not connected.
198 This is useful for skipping missing data sections.
199 The expected form is:
200 '<integer> [years | months | days | hours | minutes | seconds]'
201  
202 =item stacked()
203  
204 Accumulates each data set. (i.e. Each point increased by sum of all previous series at same time). Default is 0, set to '1' to show.
205 All data series have the same number of points and must have the same sequence of time values
206 for this option.
207  
208 =item min_scale_value()
209  
210 The point at which the Y axis starts, defaults to '0',
211 if set to '' it will default to the minimum data value.
212  
213 =item max_scale_value()
214  
215 The point at which the Y axis ends,
216 if set to '' it will default to the maximum data value.
217  
218 =item scale_divisions()
219  
220 This defines the gap between markers on the Y axis,
221 default is a 10th of the range, e.g. you will have
222 10 markers on the Y axis. NOTE: do not set this too
223 low - you are limited to 999 markers, after that the
224 graph won't generate.
225  
226 =item show_x_labels()
227  
228 Whether to show labels on the X axis or not, defaults
229 to 1, set to '0' if you want to turn them off.
230  
231 =item x_label_format()
232  
233 Format string for presenting the X axis labels.
234 The POSIX strftime() function is used for formatting
235 (see strftime man pages and LC_TIME locale information).
236  
237 =item show_y_labels()
238  
239 Whether to show labels on the Y axis or not, defaults
240 to 1, set to '0' if you want to turn them off.
241  
242 =item y_label_format()
243  
244 Format string for presenting the Y axis labels (as per printf).
245  
246 =item timescale_divisions()
247  
248 This defines the gap between markers on the X axis.
249 Default is the entire range (only start and end axis
250 labels).
251 The expected form is:
252 '<integer> [years | months | days | hours | minutes | seconds]'
253 The default time period if not provided is 'days'.
254 These time periods are used by the L<DateTime::Duration> methods.
255  
256 =item stagger_x_labels()
257  
258 This puts the labels at alternative levels so if they
259 are long field names they will not overlap so easily.
260 Default it '0', to turn on set to '1'.
261  
262 =item rotate_x_labels()
263  
264 This turns the X axis labels by 90 degrees.
265 Default it '0', to turn on set to '1'.
266  
267 =item min_timescale_value()
268  
269 This sets the minimum timescale value (X axis).
270 Any data points before this time will not be shown.
271 The date/time is expected in ISO format: YYYY-MM-DD hh:mm:ss.
272  
273 =item max_timescale_value()
274  
275 This sets the maximum timescale value (X axis).
276 Any data points after this time will not be shown.
277 The date/time is expected in ISO format: YYYY-MM-DD hh:mm:ss.
278  
279 =item show_x_title()
280  
281 Whether to show the title under the X axis labels,
282 default is 0, set to '1' to show.
283  
284 =item x_title()
285  
286 What the title under X axis should be, e.g. 'Months'.
287  
288 =item show_y_title()
289  
290 Whether to show the title under the Y axis labels,
291 default is 0, set to '1' to show.
292  
293 =item y_title()
294  
295 What the title under Y axis should be, e.g. 'Sales in thousands'.
296  
297 =item show_graph_title()
298  
299 Whether to show a title on the graph,
300 default is 0, set to '1' to show.
301  
302 =item graph_title()
303  
304 What the title on the graph should be.
305  
306 =item show_graph_subtitle()
307  
308 Whether to show a subtitle on the graph,
309 default is 0, set to '1' to show.
310  
311 =item graph_subtitle()
312  
313 What the subtitle on the graph should be.
314  
315 =item key()
316  
317 Whether to show a key, defaults to 0, set to
318 '1' if you want to show it.
319  
320 =item key_position()
321  
322 Where the key should be positioned, defaults to
323 'right', set to 'bottom' if you want to move it.
324  
325 =back
326  
327 =head1 NOTES
328  
329 The default stylesheet handles upto 12 data sets, if you
330 use more you must create your own stylesheet and add the
331 additional settings for the extra data sets. You will know
332 if you go over 12 data sets as they will have no style and
333 be in black.
334  
335 =head1 EXAMPLES
336  
337 For examples look at the project home page
338 http://leo.cuckoo.org/projects/SVG-TT-Graph/
339  
340 =head1 EXPORT
341  
342 None by default.
343  
344 =head1 ACKNOWLEDGEMENTS
345  
346 Leo Lapworth for SVG-TT-Graph.
347 Stephen Morgan for creating the TT template and SVG.
348  
349 =head1 AUTHOR
350  
351 David Meibusch (David.Meibusch@adc.com)
352  
353 =head1 SEE ALSO
354  
355 L<SVG::TT::Graph>,
356 L<SVG::TT::Graph::Line>,
357 L<SVG::TT::Graph::Bar>,
358 L<SVG::TT::Graph::BarHorizontal>,
359 L<SVG::TT::Graph::BarLine>,
360 L<SVG::TT::Graph::Pie>
361  
362 =cut
363  
364 sub get_template {
365 0 ▶ my $self = shift;
Subroutine get_template: not called CC=3 SCAR=24.8
Pod undocumented
366 # read in template
367 0 ▶ return $template if $template;
Branch: 1 branch
BranchTrueFalseTotal
if $template 0 0 0
368 0 ▶ while(<DATA>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline DATA)) 0 0 0
369 0 $template .= $_ . "\r\n";
370 }
371 0 return $template;
372 }
373  
374 sub _init {
375 0 ▶ my $self = shift;
Subroutine _init: not called CC=1 SCAR=6.9
376 }
377  
378 sub _set_defaults {
379 0 ▶ my $self = shift;
Subroutine _set_defaults: not called CC=2 SCAR=17.9
380
381 0 my @fields = ();
382  
383 0 my %default = (
384 'fields' => \@fields,
385
386 'width' => '500',
387 'height' => '300',
388
389 'style_sheet' => '',
390 'show_data_points' => 1,
391 'show_data_values' => 1,
392 'max_time_span' => '',
393
394 'area_fill' => 0,
395
396 'show_y_labels' => 1,
397 'scale_divisions' => '',
398 'min_scale_value' => '0',
399
400 'stacked' => 0,
401  
402 'show_x_labels' => 1,
403 'stagger_x_labels' => 0,
404 'rotate_x_labels' => 0,
405 'timescale_divisions' => '',
406 'x_label_format' => '%Y-%m-%d %H:%M:%S',
407
408 'show_x_title' => 0,
409 'x_title' => 'X Field names',
410
411 'show_y_title' => 0,
412 'y_title' => 'Y Scale',
413
414 'show_graph_title' => 0,
415 'graph_title' => 'Graph Title',
416 'show_graph_subtitle' => 0,
417 'graph_subtitle' => 'Graph Sub Title',
418 'key' => 0,
419 'key_position' => 'right', # bottom or right
420
421 'dateadd' => \&dateadd,
422 );
423
424 0 ▶ while( my ($key,$value) = each %default ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %default) 0 0 0
425 0 $self->{config}->{$key} = $value;
426 }
427 }
428  
429 # override this so we can pre-manipulate the data
430 sub add_data {
431 0 ▶ my ($self, $conf) = @_;
Subroutine add_data: not called CC=15 SCAR=54.8
Pod documented
432  
433 croak 'no data provided'
434 0 ▶ unless (defined $conf->{'data'} && ref($conf->{'data'}) eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
unless defined $conf->{"data"} and ref $conf->{"data"} eq "ARRAY" 0 0 0
Condition0%0/3
defined $conf->{"data"} and ref $conf->{"data"} eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $conf->{"data"} and ref $conf->{"data"} eq "ARRAY"
defined $conf->{"data"} ref $conf->{"data"} eq "ARRAY"
Truth table0%0/3
A and B
A= defined $conf->{"data"}B= ref $conf->{"data"} eq "ARRAY"
ABresult
0X0
100
111
435  
436 # create an array
437 0 ▶ unless(defined $self->{'data'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"data"}) 0 0 0
438 0 my @data;
439 0 $self->{'data'} = \@data;
440 }
441  
442 # convert to sorted (by ascending time) array of [ time, value ]
443 0 my @new_data = ();
444 0 my ($i,$time,@pair);
445  
446 0 $i = 0;
447 0 ▶ while ($i < @{$conf->{'data'}}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @{$conf->{"data"};}) 0 0 0
448 0 @pair = ();
449 0 ▶ if (ref($conf->{'data'}->[$i]) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $conf->{'data'}[$i] eq 'ARRAY') { } 0 0 0
450 0 push @pair,@{$conf->{'data'}->[$i]};
451 0 $i++;
452 }
453 else {
454 0 $pair[0] = $conf->{'data'}->[$i++];
455 0 $pair[1] = $conf->{'data'}->[$i++];
456 }
457
458 0 $time = str2time($pair[0]);
459 # special case for time-only values
460 0 ▶ if ((!defined $time) && ($pair[0] =~ m/^\w*(\d+:\d+:\d+)|(\d+:\d+)\w*$/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $time and $pair[0] =~ /^\w*(\d+:\d+:\d+)|(\d+:\d+)\w*$/) 0 0 0
Condition0%0/3
not defined $time and $pair[0] =~ /^\w*(\d+:\d+:\d+)|(\d+:\d+)\w*$/
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $time and $pair[0] =~ /^\w*(\d+:\d+:\d+)|(\d+:\d+)\w*$/
not defined $time $pair[0] =~ /^\w*(\d+:\d+:\d+)|(\d+:\d+)\w*$/
Truth table0%0/3
not(A) and B
A= not defined $timeB= $pair[0] =~ /^\w*(\d+:\d+:\d+)|(\d+:\d+)\w*$/
ABresult
0X0
100
111
461 0 $time = str2time('1970-1-1 '.$pair[0]);
462 }
463
464 croak sprintf("Series %d contains an illegal datetime value %s at sample %d.",
465 0 ▶ scalar(@{$self->{'data'}}),
Branch: 1 branch
BranchTrueFalseTotal
unless defined $time 0 0 0
466 $pair[0],
467 $i / 2)
468 unless (defined $time);
469
470 0 $pair[0] = $time;
471 0 push @new_data, [ @pair ];
472 }
473
474 0 my @sorted = sort {@{$a}[0] <=> @{$b}[0]} @new_data;
475
476 # if stacked, we accumulate the
477 0 ▶ if (($self->{config}->{stacked}) && (@{$self->{'data'}})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"config"}{"stacked"} and @{$self->{"data"};}) 0 0 0
Condition0%0/3
$self->{"config"}{"stacked"} and @{$self->{"data"};}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"config"}{"stacked"} and @{$self->{"data"};}
$self->{"config"}{"stacked"} @{$self->{"data"};}
Truth table0%0/3
A and B
A= $self->{"config"}{"stacked"}B= @{$self->{"data"};}
ABresult
0X0
100
111
478 0 my $prev = $self->{'data'}->[@{$self->{'data'}} - 1]->{pairs};
479
480 # check our length matches previous
481 croak sprintf("Series %d can not be stacked on previous series. Mismatched length.",
482 0 ▶ scalar(@{$self->{'data'}}))
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @sorted == scalar @$prev 0 0 0
483 unless (scalar(@sorted) == scalar(@$prev));
484
485 0 ▶ for (my $i = 0; $i < @sorted; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @sorted) 0 0 0
486 # check the time value matches
487 croak sprintf("Series %d can not be stacked on previous series. Mismatched timestamp at sample %d (time %s).",
488 0 ▶ scalar(@{$self->{'data'}}),
Branch: 1 branch
BranchTrueFalseTotal
unless $sorted[$i][0] == $prev->[$i][0] 0 0 0
489 $i,
490 HTTP::Date::time2iso($sorted[$i][0]))
491 unless ($sorted[$i][0] == $prev->[$i][0]);
492
493 0 $sorted[$i][1] += $prev->[$i][1];
494 }
495 }
496
497 0 my %store = (
498 'pairs' => \@sorted,
499 );
500
501 0 ▶ $store{'title'} = $conf->{'title'} if defined $conf->{'title'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $conf->{"title"} 0 0 0
502 0 push (@{$self->{'data'}},\%store);
503  
504 0 return 1;
505 }
506  
507 # Helper function for doing date/time calculations
508 # Current implementations of DateTime can be slow :-(
509 sub dateadd {
510 0 ▶ my ($epoch,$value,$unit) = @_;
Subroutine dateadd: not called CC=1 SCAR=6.9
Pod undocumented
511 0 my $dt = DateTime->from_epoch(epoch => $epoch);
512 0 $dt->add( $unit => $value );
513 0 return $dt->epoch();
514 }
515  
516 # override calculations to set a few calculated values, mainly for scaling
517 sub calculations {
518 0 ▶ my $self = shift;
Subroutine calculations: not called CC=26 SCAR=65.5
Pod undocumented
519
520 # run through the data and calculate maximum and minimum values
521 0 my ($max_key_size,$max_time,$min_time,$max_value,$min_value,$max_x_label_length,$x_label);
522
523 0 foreach my $dataset (@{$self->{data}}) {
524 0 ▶ $max_key_size = length($dataset->{title}) if ((!defined $max_key_size) || ($max_key_size < length($dataset->{title})));
Branch: 1 branch
BranchTrueFalseTotal
if not defined $max_key_size or $max_key_size < length $dataset->{"title"} 0 0 0
Condition0%0/3
not defined $max_key_size or $max_key_size < length $dataset->{"title"}
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $max_key_size or $max_key_size < length $dataset->{"title"}
not defined $max_key_size $max_key_size < length $dataset->{"title"}
Truth table0%0/3
not(A) or B
A= not defined $max_key_sizeB= $max_key_size < length $dataset->{"title"}
ABresult
1X1
011
000
525
526 0 foreach my $pair (@{$dataset->{pairs}}) {
527 0 ▶ $max_time = $pair->[0] if ((!defined $max_time) || ($max_time < $pair->[0]));
Branch: 1 branch
BranchTrueFalseTotal
if not defined $max_time or $max_time < $pair->[0] 0 0 0
Condition0%0/3
not defined $max_time or $max_time < $pair->[0]
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $max_time or $max_time < $pair->[0]
not defined $max_time $max_time < $pair->[0]
Truth table0%0/3
not(A) or B
A= not defined $max_timeB= $max_time < $pair->[0]
ABresult
1X1
011
000
528 0 ▶ $min_time = $pair->[0] if ((!defined $min_time) || ($min_time > $pair->[0]));
Branch: 1 branch
BranchTrueFalseTotal
if not defined $min_time or $min_time > $pair->[0] 0 0 0
Condition0%0/3
not defined $min_time or $min_time > $pair->[0]
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $min_time or $min_time > $pair->[0]
not defined $min_time $min_time > $pair->[0]
Truth table0%0/3
not(A) or B
A= not defined $min_timeB= $min_time > $pair->[0]
ABresult
1X1
011
000
529 0 ▶ $max_value = $pair->[1] if (($pair->[1] ne '') && ((!defined $max_value) || ($max_value < $pair->[1])));
Branch: 1 branch
BranchTrueFalseTotal
if $pair->[1] ne "" and !defined($max_value) || $max_value < $pair->[1] 0 0 0
Condition0%0/6
$pair->[1] ne "" and !defined($max_value) || $max_value < $pair->[1]
!ll&&!rl&&r
000
not defined $max_value or $max_value < $pair->[1]
l!l&&r!l&&!r
000
MC/DC0%0/3
$pair->[1] ne "" and !defined($max_value) || $max_value < $pair->[1]
$pair->[1] ne "" not defined $max_value $max_value < $pair->[1]
Truth table0%0/4
A and not(B) or C
A= $pair->[1] ne ""B= not defined $max_valueC= $max_value < $pair->[1]
ABCresult
0XX0
1000
11X1
1011
530 0 ▶ $min_value = $pair->[1] if (($pair->[1] ne '') && ((!defined $min_value) || ($min_value > $pair->[1])));
Branch: 1 branch
BranchTrueFalseTotal
if $pair->[1] ne "" and !defined($min_value) || $min_value > $pair->[1] 0 0 0
Condition0%0/6
$pair->[1] ne "" and !defined($min_value) || $min_value > $pair->[1]
!ll&&!rl&&r
000
not defined $min_value or $min_value > $pair->[1]
l!l&&r!l&&!r
000
MC/DC0%0/3
$pair->[1] ne "" and !defined($min_value) || $min_value > $pair->[1]
$pair->[1] ne "" not defined $min_value $min_value > $pair->[1]
Truth table0%0/4
A and not(B) or C
A= $pair->[1] ne ""B= not defined $min_valueC= $min_value > $pair->[1]
ABCresult
0XX0
1000
11X1
1011
531
532 0 $x_label = strftime($self->{config}->{x_label_format},localtime($pair->[0]));
533 0 ▶ $max_x_label_length = length($x_label) if ((!defined $max_x_label_length) || ($max_x_label_length < length($x_label)));
Branch: 1 branch
BranchTrueFalseTotal
if not defined $max_x_label_length or $max_x_label_length < length $x_label 0 0 0
Condition0%0/3
not defined $max_x_label_length or $max_x_label_length < length $x_label
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $max_x_label_length or $max_x_label_length < length $x_label
not defined $max_x_label_length $max_x_label_length < length $x_label
Truth table0%0/3
not(A) or B
A= not defined $max_x_label_lengthB= $max_x_label_length < length $x_label
ABresult
1X1
011
000
534 }
535 }
536 0 $self->{calc}->{max_key_size} = $max_key_size;
537 0 $self->{calc}->{max_time} = $max_time;
538 0 $self->{calc}->{min_time} = $min_time;
539 0 $self->{calc}->{max_value} = $max_value;
540 0 $self->{calc}->{min_value} = $min_value;
541 0 $self->{calc}->{max_x_label_length} = $max_x_label_length;
542  
543 # Calc the x axis scale values
544 0 ▶ $self->{calc}->{min_timescale_value} = ($self->_is_valid_config('min_timescale_value')) ? str2time($self->{config}->{min_timescale_value}) : $min_time;
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_valid_config('min_timescale_value') ? : 0 0 0
545 0 ▶ $self->{calc}->{max_timescale_value} = ($self->_is_valid_config('max_timescale_value')) ? str2time($self->{config}->{max_timescale_value}) : $max_time;
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_valid_config('max_timescale_value') ? : 0 0 0
546 0 $self->{calc}->{timescale_range} = $self->{calc}->{max_timescale_value} - $self->{calc}->{min_timescale_value};
547  
548 # Calc the y axis scale values
549 0 ▶ $self->{calc}->{min_scale_value} = ($self->_is_valid_config('min_scale_value')) ? $self->{config}->{min_scale_value} : $min_value;
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_valid_config('min_scale_value') ? : 0 0 0
550 0 ▶ $self->{calc}->{max_scale_value} = ($self->_is_valid_config('max_scale_value')) ? $self->{config}->{max_scale_value} : $max_value;
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_valid_config('max_scale_value') ? : 0 0 0
551 0 $self->{calc}->{scale_range} = $self->{calc}->{max_scale_value} - $self->{calc}->{min_scale_value};
552
553 0 my ($range,$division,$precision);
554
555 0 ▶ if ($self->_is_valid_config('scale_divisions')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_valid_config('scale_divisions')) { } 0 0 0
556 0 $division = $self->{config}->{scale_divisions};
557  
558 0 ▶ if ($division >= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($division >= 1) { } 0 0 0
559 0 $precision = 0;
560 }
561 else {
562 0 $precision = length($division) - 2;
563 }
564 }
565 else {
566 # Find divisions, format and range
567 0 ($range,$division,$precision) = $self->_range_calc($self->{calc}->{scale_range});
568  
569 # If a max value hasn't been set we can set a revised range and max value
570 0 ▶ if (! $self->_is_valid_config('max_scale_value')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_valid_config("max_scale_value")) 0 0 0
571 0 $self->{calc}->{max_scale_value} = $self->{calc}->{min_scale_value} + $range;
572 0 $self->{calc}->{scale_range} = $self->{calc}->{max_scale_value} - $self->{calc}->{min_scale_value};
573 }
574 }
575 0 $self->{calc}->{scale_division} = $division;
576
577 0 ▶ $self->{calc}->{y_label_format} = ($self->_is_valid_config('y_label_format')) ? $self->{config}->{y_label_format} : "%.${precision}f";
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_valid_config('y_label_format') ? : 0 0 0
578 0 ▶ $self->{calc}->{data_value_format} = ($self->_is_valid_config('data_value_format')) ? $self->{config}->{data_value_format} : "%.${precision}f";
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_valid_config('data_value_format') ? : 0 0 0
579 }
580  
581 1 1;
582 __DATA__
583 <?xml version="1.0"?>
584 <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
585 "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
586  
587 [% USE date %]
588 [% stylesheet = 'included' %]
589  
590 [% IF config.style_sheet && config.style_sheet != '' %]
591 <?xml-stylesheet href="[% config.style_sheet %]" type="text/css"?>
592 [% ELSE %]
593 [% stylesheet = 'excluded' %]
594 [% END %]
595  
596 <svg width="[% config.width %]" height="[% config.height %]" viewBox="0 0 [% config.width %] [% config.height %]" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
597  
598 <!-- \\\\\\\\\\\\\\\\\\\\\\\\\\\\ -->
599 <!-- Created with SVG::TT::Graph -->
600 <!-- Dave Meibusch -->
601 <!-- //////////////////////////// -->
602  
603 [% IF stylesheet == 'excluded' %]
604 [%# include default stylesheet if none specified %]
605 <defs>
606 <style type="text/css">
607 <![CDATA[
608 /* Copy from here for external style sheet */
609 .svgBackground{
610 fill:#ffffff;
611 }
612 .graphBackground{
613 fill:#f0f0f0;
614 }
615  
616 /* graphs titles */
617 .mainTitle{
618 text-anchor: middle;
619 fill: #000000;
620 font-size: 14px;
621 font-family: "Arial", sans-serif;
622 font-weight: normal;
623 }
624 .subTitle{
625 text-anchor: middle;
626 fill: #999999;
627 font-size: 12px;
628 font-family: "Arial", sans-serif;
629 font-weight: normal;
630 }
631  
632 .axis{
633 stroke: #000000;
634 stroke-width: 1px;
635 }
636  
637 .guideLines{
638 stroke: #666666;
639 stroke-width: 1px;
640 stroke-dasharray: 5 5;
641 }
642  
643 .xAxisLabels{
644 text-anchor: middle;
645 fill: #000000;
646 font-size: 12px;
647 font-family: "Arial", sans-serif;
648 font-weight: normal;
649 }
650  
651 .yAxisLabels{
652 text-anchor: end;
653 fill: #000000;
654 font-size: 12px;
655 font-family: "Arial", sans-serif;
656 font-weight: normal;
657 }
658  
659 .xAxisTitle{
660 text-anchor: middle;
661 fill: #ff0000;
662 font-size: 14px;
663 font-family: "Arial", sans-serif;
664 font-weight: normal;
665 }
666  
667 .yAxisTitle{
668 fill: #ff0000;
669 text-anchor: middle;
670 font-size: 14px;
671 font-family: "Arial", sans-serif;
672 font-weight: normal;
673 }
674  
675 .dataPointLabel{
676 fill: #000000;
677 text-anchor:middle;
678 font-size: 10px;
679 font-family: "Arial", sans-serif;
680 font-weight: normal;
681 }
682 .staggerGuideLine{
683 fill: none;
684 stroke: #000000;
685 stroke-width: 0.5px;
686 }
687 /* default fill styles */
688 .fill1{
689 fill: #cc0000;
690 fill-opacity: 0.2;
691 stroke: none;
692 }
693 .fill2{
694 fill: #0000cc;
695 fill-opacity: 0.2;
696 stroke: none;
697 }
698 .fill3{
699 fill: #00cc00;
700 fill-opacity: 0.2;
701 stroke: none;
702 }
703 .fill4{
704 fill: #ffcc00;
705 fill-opacity: 0.2;
706 stroke: none;
707 }
708 .fill5{
709 fill: #00ccff;
710 fill-opacity: 0.2;
711 stroke: none;
712 }
713 .fill6{
714 fill: #ff00ff;
715 fill-opacity: 0.2;
716 stroke: none;
717 }
718 .fill7{
719 fill: #00ffff;
720 fill-opacity: 0.2;
721 stroke: none;
722 }
723 .fill8{
724 fill: #ffff00;
725 fill-opacity: 0.2;
726 stroke: none;
727 }
728 .fill9{
729 fill: #cc6666;
730 fill-opacity: 0.2;
731 stroke: none;
732 }
733 .fill10{
734 fill: #663399;
735 fill-opacity: 0.2;
736 stroke: none;
737 }
738 .fill11{
739 fill: #339900;
740 fill-opacity: 0.2;
741 stroke: none;
742 }
743 .fill12{
744 fill: #9966FF;
745 fill-opacity: 0.2;
746 stroke: none;
747 }
748  
749 /* default line styles */
750 .line1{
751 fill: none;
752 stroke: #ff0000;
753 stroke-width: 1px;
754 }
755 .line2{
756 fill: none;
757 stroke: #0000ff;
758 stroke-width: 1px;
759 }
760 .line3{
761 fill: none;
762 stroke: #00ff00;
763 stroke-width: 1px;
764 }
765 .line4{
766 fill: none;
767 stroke: #ffcc00;
768 stroke-width: 1px;
769 }
770 .line5{
771 fill: none;
772 stroke: #00ccff;
773 stroke-width: 1px;
774 }
775 .line6{
776 fill: none;
777 stroke: #ff00ff;
778 stroke-width: 1px;
779 }
780 .line7{
781 fill: none;
782 stroke: #00ffff;
783 stroke-width: 1px;
784 }
785 .line8{
786 fill: none;
787 stroke: #ffff00;
788 stroke-width: 1px;
789 }
790 .line9{
791 fill: none;
792 stroke: #cc6666;
793 stroke-width: 1px;
794 }
795 .line10{
796 fill: none;
797 stroke: #663399;
798 stroke-width: 1px;
799 }
800 .line11{
801 fill: none;
802 stroke: #339900;
803 stroke-width: 1px;
804 }
805 .line12{
806 fill: none;
807 stroke: #9966FF;
808 stroke-width: 1px;
809 }
810  
811 /* default line styles */
812 .key1,.fill1{
813 fill: #ff0000;
814 stroke: none;
815 stroke-width: 1px;
816 }
817 .key2,.fill2{
818 fill: #0000ff;
819 stroke: none;
820 stroke-width: 1px;
821 }
822 .key3,.fill3{
823 fill: #00ff00;
824 stroke: none;
825 stroke-width: 1px;
826 }
827 .key4,.fill4{
828 fill: #ffcc00;
829 stroke: none;
830 stroke-width: 1px;
831 }
832 .key5,.fill5{
833 fill: #00ccff;
834 stroke: none;
835 stroke-width: 1px;
836 }
837 .key6,.fill6{
838 fill: #ff00ff;
839 stroke: none;
840 stroke-width: 1px;
841 }
842 .key7,.fill7{
843 fill: #00ffff;
844 stroke: none;
845 stroke-width: 1px;
846 }
847 .key8,.fill8{
848 fill: #ffff00;
849 stroke: none;
850 stroke-width: 1px;
851 }
852 .key9,.fill9{
853 fill: #cc6666;
854 stroke: none;
855 stroke-width: 1px;
856 }
857 .key10,.fill10{
858 fill: #663399;
859 stroke: none;
860 stroke-width: 1px;
861 }
862 .key11,.fill11{
863 fill: #339900;
864 stroke: none;
865 stroke-width: 1px;
866 }
867 .key12,.fill12{
868 fill: #9966FF;
869 stroke: none;
870 stroke-width: 1px;
871 }
872 .keyText{
873 fill: #000000;
874 text-anchor:start;
875 font-size: 10px;
876 font-family: "Arial", sans-serif;
877 font-weight: normal;
878 }
879 /* End copy for external style sheet */
880 ]]>
881 </style>
882 </defs>
883 [% END %]
884  
885 <!-- Script to toggle paths when their key is clicked on -->
886 <script language="JavaScript">
887 function togglePath( series ) {
888 var path = document.getElementById('groupDataSeries' + series)
889 var points = document.getElementById('groupDataLabels' + series)
890 var current = path.getAttribute('opacity');
891 if ( path.getAttribute('opacity') == 0 ) {
892 path.setAttribute('opacity',1)
893 points.setAttribute('opacity',1)
894 } else {
895 path.setAttribute('opacity',0)
896 points.setAttribute('opacity',0)
897 }
898 }
899 </script>
900  
901 <!-- svg bg -->
902 <rect x="0" y="0" width="[% config.width %]" height="[% config.height %]" class="svgBackground"/>
903  
904 <!-- ///////////////// CALCULATE GRAPH AREA AND BOUNDARIES //////////////// -->
905 [%# get dimensions of actual graph area (NOT SVG area) %]
906 [% w = config.width %]
907 [% h = config.height %]
908  
909 [%# set start/default coords of graph %]
910 [% x = 0 %]
911 [% y = 0 %]
912  
913 [% char_width = 8 %]
914 [% half_char_height = 2.5 %]
915  
916 <!-- min_value [% calc.min_value %] max_value [% calc.max_value %] min_time [% calc.min_time %] max_time [% calc.max_time %] -->
917  
918 <!-- CALC HEIGHT AND Y COORD DIMENSIONS -->
919 [%# reduce height of graph area if there is labelling on x axis %]
920 [% IF config.show_x_labels %][% h = h - 20 %][% END %]
921
922 [%# reduce height if x labels are rotated %]
923 [% x_label_allowance = 0 %]
924 [% IF config.rotate_x_labels %]
925 [% x_label_allowance = (calc.max_x_label_length * char_width) - 20 %]
926 [% h = h - x_label_allowance %]
927 [% END %]
928  
929 [%# stagger x labels if overlapping occurs %]
930 [% stagger = 0 %]
931 [% IF config.show_x_labels && config.stagger_x_labels %]
932 [% stagger = 17 %]
933 [% h = h - stagger %]
934 [% END %]
935  
936 [% IF config.show_x_title %][% h = h - 25 - stagger %][% END %]
937  
938 [%# pad top of graph if y axis has data labels so labels do not get chopped off %]
939 [% IF config.show_y_labels %][% h = h - 10 %][% y = y + 10 %][% END %]
940  
941 [%# reduce height if graph has title or subtitle %]
942 [% IF config.show_graph_title %][% h = h - 25 %][% y = y + 25 %][% END %]
943 [% IF config.show_graph_subtitle %][% h = h - 10 %][% y = y + 10 %][% END %]
944  
945 [%# reduce graph dimensions if there is a KEY %]
946 [% key_box_size = 12 %]
947 [% key_padding = 5 %]
948  
949 [% IF config.key && config.key_position == 'right' %][% w = w - (calc.max_key_size * (char_width - 1)) - (key_box_size * 3 ) %]
950 [% ELSIF config.key && config.key_position == 'bottom' %]
951 [% IF data.size < 4 %]
952 [% h = h - ((data.size + 1) * (key_box_size + key_padding))%]
953 [% ELSE %]
954 [% h = h - (4 * (key_box_size + key_padding))%]
955 [% END %]
956 [% END %]
957  
958 <!-- min_scale_value [% calc.min_scale_value %] max_scale_value [% calc.max_scale_value %] -->
959  
960 [%# base line %]
961 [% base_line = h + y %]
962  
963 [%# find the string length of max value %]
964 [% max_value_length = calc.max_scale_value.length %]
965  
966 [%# label width in pixels %]
967 [% max_value_length_px = max_value_length * char_width %]
968 [%# If the y labels are shown but the size of the x labels are small, pad for y labels %]
969
970 <!-- CALC WIDTH AND X COORD DIMENSIONS -->
971 [%# reduce width of graph area if there is large labelling on x axis %]
972 [% space_b4_y_axis = (date.format(calc.min_timescale_value,config.x_label_format).length / 2) * char_width %]
973  
974 [% IF config.show_x_labels %]
975 [% IF config.key && config.key_position == 'right' %]
976 [% w = w - space_b4_y_axis %]
977 [% ELSE %]
978 <!-- pad both sides -->
979 [% w = w - (space_b4_y_axis * 2) %]
980 [% END %]
981 [% x = x + space_b4_y_axis %]
982 [% ELSIF config.show_data_values %]
983 [% w = w - (max_value_length_px * 2) %]
984 [% x = x + max_value_length_px %]
985 [% END %]
986  
987 [% IF config.show_y_labels && space_b4_y_axis < max_value_length_px %]
988 <!-- allow slightly more padding if small labels -->
989 [% IF max_value_length < 2 %]
990 [% w = w - (max_value_length * (char_width * 2)) %]
991 [% x = x + (max_value_length * (char_width * 2)) %]
992 [% ELSE %]
993 [% w = w - max_value_length_px %]
994 [% x = x + max_value_length_px %]
995 [% END %]
996 [% ELSIF config.show_y_labels && !config.show_x_labels %]
997 [% w = w - max_value_length_px %]
998 [% x = x + max_value_length_px %]
999 [% END %]
1000  
1001 [% IF config.show_y_title %]
1002 [% w = w - 25 %]
1003 [% x = x + 25 %]
1004 [% END %]
1005  
1006 <!-- min_timescale_value [% calc.min_timescale_value %] max_timescale_value [% calc.max_timescale_value %] -->
1007  
1008 [%# Missing data spans %]
1009 [% max_time_span = 0 %]
1010 [% IF (matches = config.max_time_span.match('(\d+) ?(\w+)?')) %]
1011 [% max_time_span = matches.0 %]
1012 [% IF (matches.1) %]
1013 [% max_time_span_units = matches.1 %]
1014 [% ELSE %]
1015 [% max_time_span_units = 'days' %]
1016 [% END %]
1017 <!-- max_time_span [% max_time_span %] max_time_span_units [% max_time_span_units %]-->
1018 [% END %]
1019  
1020 <!-- ////////////////////////////// BUILD GRAPH AREA ////////////////////////////// -->
1021 [%# graph bg and clipping regions for lines/fill and clip extended to included data labels %]
1022 <rect x="[% x %]" y="[% y %]" width="[% w %]" height="[% h %]" class="graphBackground"/>
1023 <clipPath id="clipGraphArea">
1024 <rect x="[% x %]" y="[% y %]" width="[% w %]" height="[% h %]"/>
1025 </clipPath>
1026  
1027 <!-- axis -->
1028 <path d="M[% x %] [% y %] v[% h %]" class="axis" id="xAxis"/>
1029 <path d="M[% x %] [% base_line %] h[% w %]" class="axis" id="yAxis"/>
1030  
1031 <!-- ////////////////////////////// AXIS DISTRIBUTIONS //////////////////////////// -->
1032 <!-- x axis scaling -->
1033 [% dx = calc.timescale_range %]
1034 [% dw = w / dx %]
1035 <!-- dx [% dx %] dw [% dw %] -->
1036  
1037 <!-- x axis labels -->
1038 [% IF config.show_x_labels %]
1039 <text x="[% x %]" y="[% base_line + 15 %]" [% IF config.rotate_x_labels %] transform="rotate(90 [% x - half_char_height %] [% base_line + 15 %]) translate(-10,0)" style="text-anchor: start" [% END %] class="xAxisLabels">[% date.format(calc.min_timescale_value,config.x_label_format) %]</text>
1040 [% last_label = date.format(calc.min_timescale_value,config.x_label_format) %]
1041 [% IF config.timescale_divisions %]
1042 [% IF (matches = config.timescale_divisions.match('(\d+) ?(\w+)?')) %]
1043 [% timescale_division = matches.0 %]
1044 [% IF (matches.1) %]
1045 [% timescale_division_units = matches.1 %]
1046 [% ELSE %]
1047 [% timescale_division_units = 'days' %]
1048 [% END %]
1049 <!-- timescale_division [% timescale_division %] timescale_division_units [% timescale_division_units %]-->
1050 [% x_value = config.dateadd(calc.min_timescale_value,timescale_division,timescale_division_units) %]
1051 [% count = 0 %]
1052 [% WHILE ((x_value > calc.min_timescale_value) && ((x_value < calc.max_timescale_value))) %]
1053 [% xpos = (dw * (x_value - calc.min_timescale_value)) + x %]
1054 [% IF (config.stagger_x_labels && ((count % 2) == 0)) %]
1055 <path d="M[% xpos %] [% base_line %] v[% stagger %]" class="staggerGuideLine" />
1056 <text x="[% xpos %]" y="[% base_line + 15 + stagger %]" [% IF config.rotate_x_labels %] transform="rotate(90 [% xpos - half_char_height %] [% base_line + 15 + stagger %]) translate(-10,0)" style="text-anchor: start" [% END %] class="xAxisLabels">[% date.format(x_value,config.x_label_format) %]</text>
1057 [% ELSE %]
1058 <text x="[% xpos %]" y="[% base_line + 15 %]" [% IF config.rotate_x_labels %] transform="rotate(90 [% xpos - half_char_height %] [% base_line + 15 %]) translate(-10,0)" style="text-anchor: start" [% END %] class="xAxisLabels">[% date.format(x_value,config.x_label_format) %]</text>
1059 [% END %]
1060 [% last_label = date.format(x_value,config.x_label_format) %]
1061 [% x_value = config.dateadd(x_value,timescale_division,timescale_division_units) %]
1062 [% count = count + 1 %]
1063 [% LAST IF (count >= 999) %]
1064 [% END %]
1065 [% END %]
1066 [% END %]
1067 [% IF date.format(calc.max_timescale_value,config.x_label_format) != last_label %]
1068 [% IF (config.stagger_x_labels && ((count % 2) == 0)) %]
1069 <path d="M[% x + w %] [% base_line %] v[% stagger %]" class="staggerGuideLine" />
1070 <text x="[% x + w %]" y="[% base_line + 15 + stagger %]" [% IF config.rotate_x_labels %] transform="rotate(90 [% x + w - half_char_height %] [% base_line + 15 + stagger %]) translate(-10,0)" style="text-anchor: start" [% END %] class="xAxisLabels">[% date.format(calc.max_timescale_value,config.x_label_format) %]</text>
1071 [% ELSE %]
1072 <text x="[% x + w %]" y="[% base_line + 15 %]" [% IF config.rotate_x_labels %] transform="rotate(90 [% x + w - half_char_height %] [% base_line + 15 %]) translate(-10,0)" style="text-anchor: start" [% END %] class="xAxisLabels">[% date.format(calc.max_timescale_value,config.x_label_format) %]</text>
1073 [% END %]
1074 [% END %]
1075 [% END %]
1076  
1077 <!-- y axis scaling -->
1078 [%# how much padding between largest bar and top of graph %]
1079 [% top_pad = h / 40 %]
1080  
1081 [% dy = calc.scale_range %]
1082 [% dh = (h - top_pad) / dy %]
1083 <!-- dy [% dy %] dh [% dh %] scale_division [% calc.scale_division %] max_scale_value [% calc.max_scale_value %]-->
1084  
1085 [% count = 0 %]
1086 [% y_value = calc.min_scale_value %]
1087 [% IF config.show_y_labels %]
1088 [% WHILE ((y_value == calc.min_scale_value) || (y_value == calc.max_scale_value) || ((y_value > calc.min_scale_value) && (y_value < calc.max_scale_value))) %]
1089 [%- next_label = y_value FILTER format(calc.y_label_format) -%]
1090 [%- IF count == 0 -%]
1091 [%# no stroke for first line %]
1092 <text x="[% x - 5 %]" y="[% base_line - (dh * (y_value - calc.min_scale_value)) %]" class="yAxisLabels">[% next_label %]</text>
1093 [%- ELSE -%]
1094 [% IF next_label != last_label %]
1095 <text x="[% x - 5 %]" y="[% base_line - (dh * (y_value - calc.min_scale_value)) %]" class="yAxisLabels">[% next_label %]</text>
1096 <path d="M[% x %] [% base_line - (dh * (y_value - calc.min_scale_value)) %] h[% w %]" class="guideLines"/>
1097 [% END %]
1098 [%- END -%]
1099 [%- y_value = y_value + calc.scale_division -%]
1100 [%- last_label = next_label -%]
1101 [%- count = count + 1 -%]
1102 [%- LAST IF (count >= 999) -%]
1103 [% END %]
1104 [% END %]
1105  
1106 <!-- ////////////////////////////// AXIS TITLES ////////////////////////////// -->
1107 <!-- x axis title -->
1108 [% IF config.show_x_title %]
1109 [% IF !config.show_x_labels %]
1110 [% y_xtitle = 15 %]
1111 [% ELSE %]
1112 [% y_xtitle = 35 %]
1113 [% END %]
1114 <text x="[% (w / 2) + x %]" y="[% h + y + y_xtitle + stagger + x_label_allowance %]" class="xAxisTitle">[% config.x_title %]</text>
1115 [% END %]
1116  
1117 <!-- y axis title -->
1118 [% IF config.show_y_title %]
1119 <text x="10" y="[% (h / 2) + y %]" transform="rotate(270,10,[% (h / 2) + y %])" class="yAxisTitle">[% config.y_title %]</text>
1120 [% END %]
1121  
1122 <!-- ////////////////////////////// SHOW DATA ////////////////////////////// -->
1123 [% line = data.size %]
1124 <g id="groupData" class="data">
1125 [% FOREACH dataset = data.reverse %]
1126 <g id="groupDataSeries[% line %]" class="dataSeries[% line %]" clip-path="url(#clipGraphArea)">
1127 [% IF config.area_fill %]
1128 [%# create alternate fill first (so line can overwrite if necessary) %]
1129 [% xcount = 0 %]
1130 [% FOREACH pair = dataset.pairs %]
1131 [%- IF ((pair.0 >= calc.min_timescale_value) && (pair.0 <= calc.max_timescale_value)) -%]
1132 [%- IF xcount == 0 -%][% lasttime = pair.0 %]<path d="M[% (dw * (pair.0 - calc.min_timescale_value)) + x %] [% base_line %][%- END -%]
1133 [%- IF ((max_time_span) && (pair.0 > config.dateadd(lasttime,max_time_span,max_time_span_units))) -%]
1134 V [% base_line %] H [% (dw * (pair.0 - calc.min_timescale_value)) + x %] V [% base_line - (dh * (pair.1 - calc.min_scale_value)) %]
1135 [%- ELSE -%]
1136 L [% (dw * (pair.0 - calc.min_timescale_value)) + x %] [% base_line - (dh * (pair.1 - calc.min_scale_value)) %]
1137 [%- END -%]
1138 [%- lasttime = pair.0 -%][%- xcount = xcount + 1 -%]
1139 [%- END -%]
1140 [% END %]
1141 [% IF xcount > 0 %] V [% base_line %] Z" class="fill[% line %]"/> [% END %]
1142 [% END %]
1143  
1144 <!--- create line [% dataset.title %]-->
1145 [% xcount = 0 %]
1146 [% FOREACH pair = dataset.pairs %]
1147 [% IF ((pair.0 >= calc.min_timescale_value) && (pair.0 <= calc.max_timescale_value)) %]
1148 [%- IF xcount == 0 -%][%- lasttime = pair.0 -%]<path d="M
1149 [% (dw * (pair.0 - calc.min_timescale_value)) + x %] [% base_line - (dh * (pair.1 - calc.min_scale_value)) %]
1150 [%- ELSE -%]
1151 [%- IF ((max_time_span) && (pair.0 > config.dateadd(lasttime,max_time_span,max_time_span_units))) -%]
1152 M [% (dw * (pair.0 - calc.min_timescale_value)) + x %] [% base_line - (dh * (pair.1 - calc.min_scale_value)) %]
1153 [%- ELSE -%]
1154 L [% (dw * (pair.0 - calc.min_timescale_value)) + x %] [% base_line - (dh * (pair.1 - calc.min_scale_value)) %]
1155 [%- END -%]
1156 [%- END -%]
1157 [%- lasttime = pair.0 -%][%- xcount = xcount + 1 -%]
1158 [%- END -%]
1159 [% END %]
1160 [% IF xcount > 0 %] " class="line[% line %]"/> [% END %]
1161 </g>
1162 <g id="groupDataLabels[% line %]" class="dataLabels[% line %]">
1163 [% IF config.show_data_points || config.show_data_values %]
1164 [% FOREACH pair = dataset.pairs %]
1165 [% IF ((pair.0 >= calc.min_timescale_value) && (pair.0 <= calc.max_timescale_value)) %]
1166 <g class="dataLabel[% line %]" [% IF config.rollover_values %] opacity="0" [% END %]>
1167 [% IF config.show_data_points %]
1168 <circle cx="[% (dw * (pair.0 - calc.min_timescale_value)) + x %]" cy="[% base_line - (dh * (pair.1 - calc.min_scale_value)) %]" r="2.5" class="fill[% line %]"
1169 [% IF config.rollover_values %]
1170 onmouseover="evt.target.parentNode.setAttribute('opacity',1);"
1171 onmouseout="evt.target.parentNode.setAttribute('opacity',0);"
1172 [% END %]
1173 [% IF pair.3.defined %]
1174 onclick="[% pair.3 %]"
1175 [% END %]
1176 ></circle>
1177 [% END %]
1178 [% IF config.show_data_values %]
1179 [%# datavalue shown %]
1180 [% IF (pair.2.defined) && (pair.2 != '') %][% point_label = pair.2 %][% ELSE %][% point_label = pair.1 FILTER format(calc.data_value_format) %][% END %]
1181 <text x="[% (dw * (pair.0 - calc.min_timescale_value)) + x %]" y="[% base_line - (dh * (pair.1 - calc.min_scale_value)) - 6 %]" class="dataPointLabel[% line %]"
1182 [% IF config.rollover_values %]
1183 onmouseover="evt.target.parentNode.setAttribute('opacity',1);"
1184 onmouseout="evt.target.parentNode.setAttribute('opacity',0);"
1185 [% END %]
1186 >[% point_label %]</text>
1187 [% END %]
1188 </g>
1189 [% END %]
1190 [% END %]
1191 [% END %]
1192 </g>
1193 [% line = line - 1 %]
1194 [% END %]
1195 </g>
1196  
1197 <!-- //////////////////////////////// KEY /////// ////////////////////////// -->
1198 [% key_count = 1 %]
1199 [% IF config.key && config.key_position == 'right' %]
1200 [% FOREACH dataset = data %]
1201 <rect x="[% x + w + 20 %]" y="[% y + (key_box_size * key_count) + (key_count * key_padding) %]" width="[% key_box_size %]" height="[% key_box_size %]" class="key[% key_count %]" onclick="togglePath([% key_count %]);"/>
1202 <text x="[% x + w + 20 + key_box_size + key_padding %]" y="[% y + (key_box_size * key_count) + (key_count * key_padding) + key_box_size %]" class="keyText">[% dataset.title %]</text>
1203 [% key_count = key_count + 1 %]
1204 [% END %]
1205 [% ELSIF config.key && config.key_position == 'bottom' %]
1206 [%# calc y position of start of key %]
1207 [% y_key = base_line %]
1208 [%# consider x title %]
1209 [% IF config.show_x_title %][% y_key = base_line + 25 %][% END %]
1210 [%# consider x label rotation and stagger %]
1211 [% IF config.rotate_x_labels && config.show_x_labels %]
1212 [% y_key = y_key + x_label_allowance %]
1213 [% ELSIF config.show_x_labels && stagger < 1 %]
1214 [% y_key = y_key + 20 %]
1215 [% END %]
1216
1217 [% y_key_start = y_key %]
1218 [% x_key = x %]
1219 [% FOREACH dataset = data %]
1220 [% IF key_count == 4 || key_count == 7 || key_count == 10 %]
1221 [%# wrap key every 3 entries %]
1222 [% x_key = x_key + 200 %]
1223 [% y_key = y_key - (key_box_size * 4) - 2 %]
1224 [% END %]
1225 <rect x="[% x_key %]" y="[% y_key + (key_box_size * key_count) + (key_count * key_padding) + stagger %]" width="[% key_box_size %]" height="[% key_box_size %]" class="key[% key_count %]" onclick="togglePath([% key_count %]);"/>
1226 <text x="[% x_key + key_box_size + key_padding %]" y="[% y_key + (key_box_size * key_count) + (key_count * key_padding) + key_box_size + stagger %]" class="keyText">[% dataset.title %]</text>
1227 [% key_count = key_count + 1 %]
1228 [% END %]
1229
1230 [% END %]
1231
1232 <!-- //////////////////////////////// MAIN TITLES ////////////////////////// -->
1233 <!-- main graph title -->
1234 [% IF config.show_graph_title %]
1235 <text x="[% config.width / 2 %]" y="15" class="mainTitle">[% config.graph_title %]</text>
1236 [% END %]
1237  
1238 <!-- graph sub title -->
1239 [% IF config.show_graph_subtitle %]
1240 [% IF config.show_graph_title %]
1241 [% y_subtitle = 30 %]
1242 [% ELSE %]
1243 [% y_subtitle = 15 %]
1244 [% END %]
1245 <text x="[% config.width / 2 %]" y="[% y_subtitle %]" class="subTitle">[% config.graph_subtitle %]</text>
1246 [% END %]
1247 </svg>
↑ Summary Graph.pm »