Graph/Pie.pm

filter: Statementstmt 80.7% 21 / 26 Branchbran 50.0% 4 / 8 Conditioncond 66.6% 4 / 6 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 85.7% 6 / 7 Podpod 0.0% 0 / 1 totaltotal 70.5% 36 / 51 CC 7 SCAR 15.4
CC
7
Cov
72%
get_template
12.0
_init
4.1
_set_defaults
2.0
CRAP 4.6
« Graph/Line.pm ↑ Summary Graph/Bar.pm »
1 package SVG::TT::Graph::Pie;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use SVG::TT::Graph;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use base qw(SVG::TT::Graph);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 my $template;
10  
11 =head1 NAME
12  
13 SVG::TT::Graph::Pie - Create presentation quality SVG pie graphs easily
14  
15 =head1 SYNOPSIS
16  
17 use SVG::TT::Graph::Pie;
18  
19 my @fields = qw(Jan Feb Mar);
20 my @data_sales_02 = qw(12 45 21);
21
22 my $graph = SVG::TT::Graph::Pie->new({
23 'height' => '500',
24 'width' => '300',
25 'fields' => \@fields,
26 });
27
28 $graph->add_data({
29 'data' => \@data_sales_02,
30 'title' => 'Sales 2002',
31 });
32
33 print "Content-type: image/svg+xml\r\n\r\n";
34 print $graph->burn();
35  
36 =head1 DESCRIPTION
37  
38 This object aims to allow you to easily create high quality
39 SVG pie graphs. You can either use the default style sheet
40 or supply your own. Either way there are many options which can
41 be configured to give you control over how the graph is
42 generated - with or without a key, display percent on pie chart,
43 title, subtitle etc.
44  
45 =head1 METHODS
46  
47 =head2 new()
48  
49 use SVG::TT::Graph::Pie;
50
51 # Field names along the X axis
52 my @fields = qw(Jan Feb Mar);
53
54 my $graph = SVG::TT::Graph::Pie->new({
55 # Required
56 'fields' => \@fields,
57  
58 # Optional - defaults shown
59 'height' => '500',
60 'width' => '300',
61  
62 'show_graph_title' => 0,
63 'graph_title' => 'Graph Title',
64 'show_graph_subtitle' => 0,
65 'graph_subtitle' => 'Graph Sub Title',
66  
67 'show_shadow' => 1,
68 'shadow_size' => 1,
69 'shadow_offset' => 15,
70  
71 'key_placement' => 'R',
72  
73 # data by pie chart wedges:
74 'show_data_labels' => 0,
75 'show_actual_values'=> 0,
76 'show_percent' => 1,
77  
78 # data on key:
79 'show_key_data_labels' => 1,
80 'show_key_actual_values'=> 1,
81 'show_key_percent' => 0,
82  
83 'expanded' => 0,
84 'expand_greatest' => 0,
85  
86 # Optional - defaults to using internal stylesheet
87 'style_sheet' => '/includes/graph.css',
88  
89 # Use field names for in the stylesheet
90 'style_sheet_field_names' => 0,
91  
92 });
93  
94 The constructor takes a hash reference, fields (the name for each
95 slice on the pie) MUST be set, all other values are defaulted to those
96 shown above - with the exception of style_sheet which defaults
97 to using the internal style sheet.
98  
99 =head2 add_data()
100  
101 my @data_sales_02 = qw(12 45 21);
102  
103 $graph->add_data({
104 'data' => \@data_sales_02,
105 'title' => 'Sales 2002',
106 });
107  
108 This method allows you to add data to the graph object, only
109 the first data set added will be used!
110  
111 =head2 clear_data()
112  
113 my $graph->clear_data();
114  
115 This method removes all data from the object so that you can
116 reuse it to create a new graph but with the same config options.
117  
118 =head2 burn()
119  
120 print $graph->burn();
121  
122 This method processes the template with the data and
123 config which has been set and returns the resulting SVG.
124  
125 This method will croak unless at least one data set has
126 been added to the graph object.
127  
128 =head2 config methods
129  
130 my $value = $graph->method();
131 my $confirmed_new_value = $graph->method($value);
132
133 The following is a list of the methods which are available
134 to change the config of the graph object after it has been
135 created.
136  
137 =over 4
138  
139 =item height()
140  
141 Set the height of the graph box, this is the total height
142 of the SVG box created - not the graph it self which auto
143 scales to fix the space.
144  
145 =item width()
146  
147 Set the width of the graph box, this is the total width
148 of the SVG box created - not the graph it self which auto
149 scales to fix the space.
150  
151 =item style_sheet()
152  
153 Set the path to an external stylesheet, set to '' if
154 you want to revert back to using the defaut internal version.
155  
156 To create an external stylesheet create a graph using the
157 default internal version and copy the stylesheet section to
158 an external file and edit from there.
159  
160 If you use the style_sheet_field_names() option then you can
161 use the field names within your stylesheet. This allows
162 consistent use of styles. The names should be:
163  
164 =over 4
165  
166 =item <field>_dataPoint
167  
168 =item <field>_key
169  
170 =back
171  
172 =item show_graph_title()
173  
174 Whether to show a title on the graph, default is '0'.
175  
176 =item graph_title()
177  
178 What the title on the graph should be.
179  
180 =item show_graph_subtitle()
181  
182 Whether to show a subtitle on the graph, default is '0'.
183  
184 =item graph_subtitle()
185  
186 What the subtitle on the graph should be.
187  
188 =item show_shadow()
189  
190 Turn the shadow on and off, default to '1', set
191 to '0' if you don't want it. It is automatically
192 turned off if you extract one section of the pie.
193  
194 =item shadow_size()
195  
196 Size of the shadow if shown, measured as
197 percentage of pie chart radius, default of 1
198 being the same size as the pie.
199  
200 =item shadow_offset()
201  
202 Offset (in pixels) of shadow to bottom-right
203 in relation to the center of the pie chart.
204  
205 =item key()
206  
207 Whether to show a key, defaults to 0, set to
208 '1' if you want to show it.
209  
210 =item key_placement()
211  
212 Defaults to 'R' - right, can be
213 'R', 'L', 'T' or 'B'.
214  
215 =item show_data_labels()
216  
217 Show label on pie chart, defaults
218 to '0', can be set to '1'.
219  
220 =item show_actual_values()
221  
222 Show values on pie chart, defaults
223 to '0', can be set to '1'.
224  
225 =item show_percent()
226  
227 Show percent (rounded) on the pie chart, defaults
228 to '1', can be set to '0'.
229  
230 =item show_key_data_labels()
231  
232 Show label on the key, defaults
233 to '1', can be set to '0'.
234  
235 =item show_key_actual_values()
236  
237 Show value on the key, defaults
238 to '1', can be set to '0'.
239  
240 =item show_key_percent()
241  
242 Show percent (rounded) on the key, defaults
243 to '0', can be set to '1'.
244  
245 =item expanded()
246  
247 All slices of pie are exploded out, defaults
248 to '0'. Do not set to '1' if you are going to
249 use expanded_greatest().
250  
251 =item expand_greatest()
252  
253 The largest slice of pie is exploded out
254 from the pie, defaults to '0'. Useful if you are
255 only showing the percentages (which are rounded) but
256 still want to visually show which slice was largest.
257  
258 Do not set to '1' if you are going to
259 use expanded().
260  
261 =back
262  
263 =head1 NOTES
264  
265 The default stylesheet handles upto 12 fields, if you
266 use more you must create your own stylesheet and add the
267 additional settings for the extra fields. You will know
268 if you go over 12 fields as they will have no style and
269 be in black.
270  
271 =head1 EXAMPLES
272  
273 For examples look at the project home page
274 http://leo.cuckoo.org/projects/SVG-TT-Graph/
275  
276 =head1 EXPORT
277  
278 None by default.
279  
280 =head1 ACKNOWLEDGEMENTS
281  
282 Stephen Morgan for creating the TT template and SVG.
283  
284 =head1 AUTHOR
285  
286 Leo Lapworth (LLAP@cuckoo.org)
287  
288 =head1 SEE ALSO
289  
290 L<SVG::TT::Graph>,
291 L<SVG::TT::Graph::Line>,
292 L<SVG::TT::Graph::Bar>,
293 L<SVG::TT::Graph::BarHorizontal>,
294 L<SVG::TT::Graph::BarLine>,
295 L<SVG::TT::Graph::TimeSeries>
296  
297 =cut
298  
299 sub get_template {
300 0 ▶ my $self = shift;
Subroutine get_template: not called CC=3 SCAR=24.8
Pod undocumented
301 # read in template
302 0 ▶ return $template if $template;
Branch: 1 branch
BranchTrueFalseTotal
if $template 0 0 0
303 0 ▶ while(<DATA>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline DATA)) 0 0 0
304 0 $template .= $_ . "\r\n";
305 }
306 0 return $template;
307 }
308  
309 sub _init {
310 2 ▶ my $self = shift;
Subroutine _init: called CC=4 SCAR=14.1
311 croak "fields was not supplied or is empty"
312 unless defined $self->{'config'}->{fields}
313 && ref($self->{'config'}->{fields}) eq 'ARRAY'
314 2 ▶ && scalar(@{$self->{'config'}->{fields}}) > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"config"}{"fields"} and ref $self->{"config"}{"fields"} eq "ARRAY" and scalar @{$self->{"config"}{"fields"};} > 0 1 1 2
Condition66%4/6
defined $self->{"config"}{"fields"} and ref $self->{"config"}{"fields"} eq "ARRAY" and scalar @{$self->{"config"}{"fields"};} > 0
!ll&&!rl&&r
101
defined $self->{"config"}{"fields"} and ref $self->{"config"}{"fields"} eq "ARRAY"
!ll&&!rl&&r
101
MC/DC33%1/3
defined $self->{"config"}{"fields"} and ref $self->{"config"}{"fields"} eq "ARRAY" and scalar @{$self->{"config"}{"fields"};} > 0
defined $self->{"config"}{"fields"} ref $self->{"config"}{"fields"} eq "ARRAY" scalar @{$self->{"config"}{"fields"};} > 0
Truth table50%2/4
A and B and C
A= defined $self->{"config"}{"fields"}B= ref $self->{"config"}{"fields"} eq "ARRAY"C= scalar @{$self->{"config"}{"fields"};} > 0
ABCresult
0XX0
10X0
1100
1111
315 }
316  
317 sub _set_defaults {
318 2 ▶ my $self = shift;
Subroutine _set_defaults: called CC=2 SCAR=6.9
319
320 2 my %default = (
321 'width' => '500',
322 'height' => '300',
323 'style_sheet' => '',
324 'style_sheet_field_names' => 0,
325  
326 'show_graph_title' => 0,
327 'graph_title' => 'Graph Title',
328 'show_graph_subtitle' => 0,
329 'graph_subtitle' => 'Graph Sub Title',
330
331 'show_shadow' => 1,
332 'shadow_size' => 1,
333 'shadow_offset' => 15,
334
335 'key_placement' => 'R',
336
337 'show_data_labels' => 0,
338 'show_actual_values'=> 0,
339 'show_percent' => 1,
340  
341 'key' => 0,
342 'show_key_data_labels' => 1,
343 'show_key_actual_values'=> 1,
344 'show_key_percent' => 0,
345
346 'expanded' => 0,
347 'expand_greatest' => 0,
348
349 );
350
351 2 ▶ while( my ($key,$value) = each %default ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %default) 42 2 44
352 42 $self->{config}->{$key} = $value;
353 }
354 }
355  
356 2 1;
357 __DATA__
358 <?xml version="1.0"?>
359 <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
360 "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
361 [% stylesheet = 'included' %]
362  
363 [% IF config.style_sheet && config.style_sheet != '' %]
364 <?xml-stylesheet href="[% config.style_sheet %]" type="text/css"?>
365 [% ELSE %]
366 [% stylesheet = 'excluded' %]
367 [% END %]
368  
369 <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">
370  
371 <!-- \\\\\\\\\\\\\\\\\\\\\\\\\\\\ -->
372 <!-- Created with SVG::TT::Graph -->
373 <!-- Stephen Morgan / Leo Lapworth -->
374 <!-- //////////////////////////// -->
375 <defs>
376 <radialGradient id="shadow">
377 <stop offset="85%" style="stop-color: #ccc;"/>
378 <stop offset="100%" style="stop-color: #ccc;stop-opacity: 0"/>
379 </radialGradient>
380  
381 [% IF stylesheet == 'excluded' %]
382 <!-- include default stylesheet if none specified -->
383 <style type="text/css">
384 <![CDATA[
385 /* Copy from here for external style sheet */
386 .svgBackground{
387 fill:none;
388 }
389 .graphBackground{
390 fill:#f0f0f0;
391 }
392  
393 /* graphs titles */
394 .mainTitle{
395 text-anchor: middle;
396 fill: #000000;
397 font-size: 14px;
398 font-family: "Arial", sans-serif;
399 font-weight: normal;
400 }
401 .subTitle{
402 text-anchor: middle;
403 fill: #999999;
404 font-size: 12px;
405 font-family: "Arial", sans-serif;
406 font-weight: normal;
407 }
408  
409 .dataPointLabel{
410 fill: #000000;
411 text-anchor:middle;
412 font-size: 10px;
413 font-family: "Arial", sans-serif;
414 font-weight: normal;
415 }
416  
417  
418 /* key - MUST match fill styles */
419 .key1,.dataPoint1{
420 fill: #ff0000;
421 fill-opacity: 0.5;
422 stroke: none;
423 stroke-width: 1px;
424 }
425 .key2,.dataPoint2{
426 fill: #0000ff;
427 fill-opacity: 0.5;
428 stroke: none;
429 stroke-width: 1px;
430 }
431 .key3,.dataPoint3{
432 fill-opacity: 0.5;
433 fill: #00ff00;
434 stroke: none;
435 stroke-width: 1px;
436 }
437 .key4,.dataPoint4{
438 fill-opacity: 0.5;
439 fill: #ffcc00;
440 stroke: none;
441 stroke-width: 1px;
442 }
443 .key5,.dataPoint5{
444 fill-opacity: 0.5;
445 fill: #00ccff;
446 stroke: none;
447 stroke-width: 1px;
448 }
449 .key6,.dataPoint6{
450 fill-opacity: 0.5;
451 fill: #ff00ff;
452 stroke: none;
453 stroke-width: 1px;
454 }
455 .key7,.dataPoint7{
456 fill-opacity: 0.5;
457 fill: #00ff99;
458 stroke: none;
459 stroke-width: 1px;
460 }
461 .key8,.dataPoint8{
462 fill-opacity: 0.5;
463 fill: #ffff00;
464 stroke: none;
465 stroke-width: 1px;
466 }
467 .key9,.dataPoint9{
468 fill-opacity: 0.5;
469 fill: #cc6666;
470 stroke: none;
471 stroke-width: 1px;
472 }
473 .key10,.dataPoint10{
474 fill-opacity: 0.5;
475 fill: #663399;
476 stroke: none;
477 stroke-width: 1px;
478 }
479 .key11,.dataPoint11{
480 fill-opacity: 0.5;
481 fill: #339900;
482 stroke: none;
483 stroke-width: 1px;
484 }
485 .key12,.dataPoint12{
486 fill-opacity: 0.5;
487 fill: #9966FF;
488 stroke: none;
489 stroke-width: 1px;
490 }
491 .keyText{
492 fill: #000000;
493 text-anchor:start;
494 font-size: 10px;
495 font-family: "Arial", sans-serif;
496 font-weight: normal;
497 }
498 /* End copy for external style sheet */
499 ]]>
500 </style>
501 [% END %]
502 </defs>
503  
504  
505 <!-- svg bg -->
506 <rect x="0" y="0" width="[% config.width %]" height="[% config.height %]" class="svgBackground"/>
507
508 <!-- ///////////////// CALCULATE GRAPH AREA AND BOUNDARIES //////////////// -->
509 <!-- get dimensions of actual graph area (NOT SVG area) -->
510 [% w = config.width %]
511 [% h = config.height %]
512 [% Pi = 3.14159 %]
513  
514 <!-- calc min and max values -->
515 [% count = 0 %]
516 [% min_value = 99999999999 %]
517 [% max_value = 0 %]
518 [% max_key_size = 0 %]
519 [% FOREACH field = config.fields %]
520 [% total = total + data.0.data.$field %]
521 [% count = count + 1 %]
522 [% IF min_value > data.0.data.$field && data.0.data.$field != '' %]
523 [% min_value = data.0.data.$field %]
524 [% END %]
525 [% IF max_value < data.0.data.$field && data.0.data.$field != '' %]
526 [% max_value = data.0.data.$field %]
527 [% END %]
528 <!-- find largest dataset title for Key size -->
529 [% IF max_key_size < dataset.title.length %]
530 [% max_key_size = dataset.title.length %]
531 [% END %]
532 [% END %]
533
534 <!-- reduce height if graph has title or subtitle -->
535 [% IF config.show_graph_title %][% h = h - 25 %][% END %]
536 [% IF config.show_graph_subtitle %][% h = h - 10 %][% END %]
537
538 <!-- set start/default coords of graph -->
539 [% x = w / 2 %]
540 [% y = h / 2 %]
541
542 <!-- move centre of pie chart if title present -->
543 [% IF config.show_graph_title %][% y = y + 15 %][% END %]
544 [% IF config.show_graph_subtitle %][% y = y + 10 %][% END %]
545  
546 [% padding = 30 %]
547
548 <!-- calc radius and check whether KEY will affect this -->
549 [% IF w >= h %]
550 [% r = (h / 2) - padding %]
551
552 [% IF config.key %]
553 [% key_position = 'h' %]
554 [% x_key_start = 30 %]
555 [% IF config.key_placement == 'R' %]
556 <!-- if there is a key, move the pie chart -->
557 [% x = x - r / 3 %]
558 <!-- if the radius is too big, shrink it -->
559 [% IF x < r %]
560 [% r = r - (w / 8) %]
561 [% END %]
562 [% ELSE %]
563 <!-- if there is a key, move the pie chart -->
564 [% x = x + r / 3 %]
565 <!-- if the radius is too big, shrink it -->
566 [% IF r > (w - x) && x > (w / 2) %]
567 [% r = r - (w / 8) %]
568 [% END %]
569 [% END %]
570 [% END %]
571
572
573 [% ELSE %]
574 [% r = (w / 2) - padding %]
575
576 [% IF config.key %]
577 [% key_position = 'v' %]
578 [% y_key_start = 40 %]
579 [% IF config.key_placement == 'B' %]
580 <!-- if there is a key, move the pie chart -->
581 [% y = y - (r / 2) %]
582 <!-- if the radius is too big, shrink it -->
583 [% IF y < r %]
584 [% r = r - (h / 8) %]
585 [% END %]
586 [% ELSE %]
587 <!-- if there is a key, move the pie chart -->
588 [% y = y + (r / 2) %]
589 <!-- if the radius is too big, shrink it -->
590 [% IF r > (h - y) && y > (h / 2) %]
591 [% r = r - (h / 8) %]
592 [% END %]
593 [% END %]
594 [% END %]
595  
596 [% END %]
597
598  
599 <!-- if chart expanded -->
600 [% IF config.expanded OR config.expand_greatest %]
601 [% e = 10 %]
602 [% ELSE %]
603 [% e = 0 %]
604 [% END %]
605  
606  
607 [% IF config.show_shadow %]
608 <!-- check if a shadow size has been entered -->
609 [% IF config.shadow_size && config.shadow_size != '' %]
610 [% shadow_size = r + ((r / 100) * config.shadow_size) %]
611 [% ELSE %]
612 [% shadow_size = r %]
613 [% END %]
614
615 [% IF !config.expanded && !config.expand_greatest %]
616 <!-- only show shadow if not expanded -->
617 <circle cx="[% x + config.shadow_offset %]" cy="[% y + config.shadow_offset %]" r="[% shadow_size + e %]" style="fill: url(#shadow); stroke: none;"/>
618 [% END %]
619
620 [% END %]
621  
622 <circle cx="[% x %]" cy="[% y %]" r="[% r + e %]" fill="#ffffff"/>
623  
624 [% px_start = x + r %]
625 [% pmin_scale_value = y %]
626  
627 [% values = 0 %]
628 <!-- half values used to show values next to wedges -->
629 [% values_half = 0 %]
630 [% last_value_half = 0 %]
631  
632 [% IF config.show_percent && config.show_data_labels %]
633 [% wedge_text_pad = 20 %]
634 [% ELSE %]
635 [% wedge_text_pad = 5 %]
636 [% END %]
637  
638
639 [% count = 1 %]
640 [% FOREACH field = config.fields %]
641 [% FOREACH dataset = data %]
642  
643 [% value = data.0.data.$field %]
644 [% value_half = data.0.data.$field / 2 %]
645
646 <!-- calc percentage -->
647 [% percent = (100 / total) * value FILTER format('%2.0f')%]
648
649
650 [% values = values + value %]
651
652 [% IF count == 1 %]
653 <!-- offset values at start to get mid point -->
654 [% values_half = values_half + value_half %]
655 [% ELSE %]
656 [% values_half = values_half + last_value_half + value_half %]
657 [% END %]
658  
659 [% degrees = (values / total) * 360 %]
660 [% degrees_half = (values_half / total) * 360 %]
661
662 [% radians = degrees * (Pi / 180) %]
663 [% radians_half = degrees_half * (Pi / 180) %]
664  
665 [% px_end = r * cos(radians) FILTER format('%02.10f') %]
666 [% py_end = r * sin(radians) FILTER format('%02.10f') %]
667
668 [% px_mid = r * cos(radians_half) FILTER format('%02.10f') %]
669 [% py_mid = r * sin(radians_half) FILTER format('%02.10f') %]
670
671  
672  
673 <!-- segments displayed clockwise from ' 3 o'clock ' -->
674 [% IF config.expanded && !config.expand_greatest %]
675 [% re = r / e %]
676 [% xe = re * cos(radians_half) FILTER format('%02.10f') %]
677 [% ye = re * sin(radians_half) FILTER format('%02.10f') %]
678  
679 <path d="M[% px_start + xe %] [% pmin_scale_value + ye %] A[% r %] [% r %] 0
680 [% IF percent >= 50 %]1[% ELSE %]0[% END %] 1 [% x + px_end + xe %] [% y + py_end + ye %] L[% x + xe %] [% y + ye %] Z" class="[% IF config.style_sheet_field_names %][% field %]_dataPoint[% ELSE %]dataPoint[% count %][% END %]"/>
681
682 [% ELSIF !config.expanded && config.expand_greatest %]
683 [% IF data.0.data.$field == max_value %]
684 [% re = r / e %]
685 [% xe = re * cos(radians_half) FILTER format('%02.10f') %]
686 [% ye = re * sin(radians_half) FILTER format('%02.10f') %]
687 <path d="M[% px_start + xe %] [% pmin_scale_value + ye %] A[% r %] [% r %] 0
688 [% IF percent >= 50 %]1[% ELSE %]0[% END %] 1 [% x + px_end + xe %] [% y + py_end + ye %] L[% x + xe %] [% y + ye %] Z" class="[% IF config.style_sheet_field_names %][% field %]_dataPoint[% ELSE %]dataPoint[% count %][% END %]"/>
689 [% ELSE %]
690 <path d="M[% px_start %] [% pmin_scale_value %] A[% r %] [% r %] 0
691 [% IF percent >= 50 %]1[% ELSE %]0[% END %] 1 [% x + px_end %] [% y + py_end %] L[% x %] [% y %] Z" class="[% IF config.style_sheet_field_names %][% field %]_dataPoint[% ELSE %]dataPoint[% count %][% END %]"/>
692 [% END %]
693
694 [% ELSE %]
695 <path d="M[% px_start %] [% pmin_scale_value %] A[% r %] [% r %] 0
696 [% IF percent >= 50 %]1[% ELSE %]0[% END %] 1 [% x + px_end %] [% y + py_end %] L[% x %] [% y %] Z" class="[% IF config.style_sheet_field_names %][% field %]_dataPoint[% ELSE %]dataPoint[% count %][% END %]"/>
697 [% END %]
698
699
700 <!-- show values next to wedges -->
701 [% IF px_mid >= x && px_mid <= y %]
702 <text x="[% x + px_mid + wedge_text_pad %]" y="[% y + py_mid + wedge_text_pad %]">[% IF config.show_data_labels %][% field %][% END %] [% IF config.show_actual_values %][[% data.0.data.$field %]][% END %] [% IF config.show_percent %][% percent %]%[% END %]</text>
703 [% ELSIF px_mid <= x && py_mid <= y %]
704 <text x="[% x + px_mid - wedge_text_pad %]" y="[% y + py_mid + wedge_text_pad %]">[% IF config.show_data_labels %][% field %][% END %] [% IF config.show_actual_values %][[% data.0.data.$field %]][% END %] [% IF config.show_percent %][% percent %]%[% END %]</text>
705 [% ELSIF px_mid <= x && py_mid >= y %]
706 <text x="[% x + px_mid - wedge_text_pad %]" y="[% y + py_mid - wedge_text_pad %]">[% IF config.show_data_labels %][% field %][% END %] [% IF config.show_actual_values %][[% data.0.data.$field %]][% END %] [% IF config.show_percent %][% percent %]%[% END %]</text>
707 [% ELSE %]
708 <text x="[% x + px_mid + wedge_text_pad %]" y="[% y + py_mid - wedge_text_pad %]">[% IF config.show_data_labels %][% field %][% END %] [% IF config.show_actual_values %][[% data.0.data.$field %]][% END %] [% IF config.show_percent %][% percent %]%[% END %]</text>
709 [% END %]
710
711 [% px_start = x + px_end %]
712 [% pmin_scale_value = y + py_end %]
713 [% last_value_half = value_half %]
714 [% count = count + 1 %]
715 [% END %]
716 [% END %]
717  
718  
719  
720  
721 <!-- //////////////////////////////// KEY /////// ////////////////////////// -->
722 [% key_box_size = 12 %]
723 [% key_count = 1 %]
724 [% key_padding = 5 %]
725  
726 [% IF config.key && key_position == 'h' %]
727
728 [% FOREACH field = config.fields %]
729
730 [% percent = (100 / total) * data.0.data.$field FILTER format('%2.0f')%]
731 <!-- position key left or right -->
732 [% IF config.key_placement == 'R' %]
733 <rect x="[% x + r + x_key_start %]" y="[% (y - r) + (key_box_size * key_count) + (key_count * key_padding) %]" width="[% key_box_size %]" height="[% key_box_size %]" class="[% IF config.style_sheet_field_names %][% field %]_key[% ELSE %]key[% key_count %][% END %]"/>
734 <text x="[% x + r + x_key_start + key_box_size + key_padding %]" y="[% (y - r) + (key_box_size * key_count) + (key_count * key_padding) + key_box_size %]" class="keyText">[% IF config.show_key_data_labels %][% field %][% END %] [% IF config.show_key_actual_values %][[% data.0.data.$field %]][% END %] [% IF config.show_key_percent %][% percent %]%[% END %]</text>
735 [% ELSE %]
736 <rect x="[% x_key_start %]" y="[% (y - r) + (key_box_size * key_count) + (key_count * key_padding) %]" width="[% key_box_size %]" height="[% key_box_size %]" class="[% IF config.style_sheet_field_names %][% field %]_key[% ELSE %]key[% key_count %][% END %]"/>
737 <text x="[% x_key_start + key_box_size + key_padding %]" y="[% (y - r) + (key_box_size * key_count) + (key_count * key_padding) + key_box_size %]" class="keyText" style="text-anchor: start">[% IF config.show_key_data_labels %][% field %][% END %] [% IF config.show_key_actual_values %][[% data.0.data.$field %]][% END %] [% IF config.show_key_percent %][% percent %]%[% END %]</text>
738 [% END %]
739 [% key_count = key_count + 1 %]
740 [% END %]
741  
742 [% ELSIF config.key && key_position == 'v' %]
743 <!-- only allow key under or over chart if the height dimensions are greatest -->
744 [% IF w < h && config.key_placement == 'R' OR config.key_placement == 'L' %]
745 [% config.key_placement = 'T' %]
746 [% END %]
747
748 <!-- calc y position of start of key -->
749 [% y_key = padding %]
750 [%# y_key_start = y_key %]
751 [% x_key = padding %]
752
753 [% FOREACH field = config.fields %]
754
755 [% percent = (100 / total) * data.0.data.$field FILTER format('%2.0f')%]
756
757 [% IF key_count == 7 || key_count == 13 %]
758 <!-- wrap key every 3 entries -->
759 [% x_key = x_key + (w / 3) %]
760 [% y_key = y_key - (key_box_size * 8) - 6 %]
761 [% END %]
762
763 [% IF config.key_placement == 'T' %]
764 <rect x="[% x_key %]" y="[% y_key + (key_box_size * key_count) + (key_count * key_padding) %]" width="[% key_box_size %]" height="[% key_box_size %]" class="[% IF config.style_sheet_field_names %][% field %]_key[% ELSE %]key[% key_count %][% END %]"/>
765  
766 <text x="[% x_key + key_box_size + key_padding %]" y="[% y_key + (key_box_size * key_count) + (key_count * key_padding) + key_box_size %]" class="keyText">[% IF config.show_key_data_labels %][% field %][% END %] [% IF config.show_key_actual_values %][[% data.0.data.$field %]][% END %] [% IF config.show_key_percent %][% percent %]%[% END %]</text>
767 [% ELSE %]
768 <rect x="[% x_key %]" y="[% (r * 2) + (padding * 2) + y_key + (key_box_size * key_count) + (key_count * key_padding) %]" width="[% key_box_size %]" height="[% key_box_size %]" class="[% IF config.style_sheet_field_names %][% field %]_key[% ELSE %]key[% key_count %][% END %]"/>
769  
770 <text x="[% x_key + key_box_size + key_padding %]" y="[% (r * 2) + (padding * 2) + y_key + (key_box_size * key_count) + (key_count * key_padding) + key_box_size %]" class="keyText">[% IF config.show_key_data_labels %][% field %][% END %] [% IF config.show_key_actual_values %][[% data.0.data.$field %]][% END %] [% IF config.show_key_percent %][% percent %]%[% END %]</text>
771
772 [% END %]
773 [% key_count = key_count + 1 %]
774 [% END %]
775 [% END %]
776
777  
778  
779 <!-- //////////////////////////////// MAIN TITLES ////////////////////////// -->
780  
781 <!-- main graph title -->
782 [% IF config.show_graph_title %]
783 <text x="[% x %]" y="15" class="mainTitle">[% config.graph_title %]</text>
784 [% END %]
785  
786 <!-- graph sub title -->
787 [% IF config.show_graph_subtitle %]
788 [% IF config.show_graph_title %]
789 [% y_subtitle = 30 %]
790 [% ELSE %]
791 [% y_subtitle = 15 %]
792 [% END %]
793 <text x="[% x %]" y="[% y_subtitle %]" class="subTitle">[% config.graph_subtitle %]</text>
794 [% END %]
795  
796 </svg>
« Graph/Line.pm ↑ Summary Graph/Bar.pm »