| 1 | package SVG::TT::Graph::BarHorizontal; | ||||||||||||||||||||||||||||||||||||||||||
| 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::BarHorizontal - Create presentation quality SVG horitonzal bar graphs easily | ||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | use SVG::TT::Graph::BarHorizontal; | ||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | my @fields = qw(Jan Feb Mar); | ||||||||||||||||||||||||||||||||||||||||||
| 20 | my @data_sales_02 = qw(12 45 21); | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | my $graph = SVG::TT::Graph::BarHorizontal->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 horitonzal bar 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, data elements at each point, | ||||||||||||||||||||||||||||||||||||||||||
| 43 | title, subtitle etc. | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | =head2 new() | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | use SVG::TT::Graph::BarHorizontal; | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | # Field names along the X axis | ||||||||||||||||||||||||||||||||||||||||||
| 52 | my @fields = qw(Jan Feb Mar); | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | my $graph = SVG::TT::Graph::BarHorizontal->new({ | ||||||||||||||||||||||||||||||||||||||||||
| 55 | # Required | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 'fields' => \@fields, | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | # Optional - defaults shown | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 'height' => '500', | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 'width' => '300', | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 'show_data_values' => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | 'scale_divisions' => '', | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 'min_scale_value' => '0', | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 'bar_gap' => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 'show_x_labels' => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 'stagger_x_labels' => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 'show_y_labels' => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 'scale_integers' => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 'show_x_title' => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 'x_title' => 'X Field names', | ||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 'show_y_title' => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 'y_title_text_direction' => 'bt', | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 'y_title' => 'Y Scale', | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | 'show_graph_title' => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 'graph_title' => 'Graph Title', | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 'show_graph_subtitle' => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 'graph_subtitle' => 'Graph Sub Title', | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 'key' => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 'key_position' => 'right', | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | # Optional - defaults to using internal stylesheet | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 'style_sheet' => '/includes/graph.css', | ||||||||||||||||||||||||||||||||||||||||||
| 89 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | The constructor takes a hash reference, only fields (the names for each | ||||||||||||||||||||||||||||||||||||||||||
| 92 | field on the X axis) MUST be set, all other values are defaulted to those | ||||||||||||||||||||||||||||||||||||||||||
| 93 | shown above - with the exception of style_sheet which defaults | ||||||||||||||||||||||||||||||||||||||||||
| 94 | to using the internal style sheet. | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | =head2 add_data() | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | my @data_sales_02 = qw(12 45 21); | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | $graph->add_data({ | ||||||||||||||||||||||||||||||||||||||||||
| 101 | 'data' => \@data_sales_02, | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 'title' => 'Sales 2002', | ||||||||||||||||||||||||||||||||||||||||||
| 103 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | This method allows you to add data to the graph object. | ||||||||||||||||||||||||||||||||||||||||||
| 106 | It can be called several times to add more data sets in, | ||||||||||||||||||||||||||||||||||||||||||
| 107 | but the likely hood is you should be using SVG::TT::Graph::Line | ||||||||||||||||||||||||||||||||||||||||||
| 108 | as it won't look great! | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | =head2 clear_data() | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | my $graph->clear_data(); | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | This method removes all data from the object so that you can | ||||||||||||||||||||||||||||||||||||||||||
| 115 | reuse it to create a new graph but with the same config options. | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | =head2 burn() | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | print $graph->burn(); | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | This method processes the template with the data and | ||||||||||||||||||||||||||||||||||||||||||
| 122 | config which has been set and returns the resulting SVG. | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | This method will croak unless at least one data set has | ||||||||||||||||||||||||||||||||||||||||||
| 125 | been added to the graph object. | ||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | =head2 config methods | ||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | my $value = $graph->method(); | ||||||||||||||||||||||||||||||||||||||||||
| 130 | my $confirmed_new_value = $graph->method($value); | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | The following is a list of the methods which are available | ||||||||||||||||||||||||||||||||||||||||||
| 133 | to change the config of the graph object after it has been | ||||||||||||||||||||||||||||||||||||||||||
| 134 | created. | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | =item height() | ||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | Set the height of the graph box, this is the total height | ||||||||||||||||||||||||||||||||||||||||||
| 141 | of the SVG box created - not the graph it self which auto | ||||||||||||||||||||||||||||||||||||||||||
| 142 | scales to fix the space. | ||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | =item width() | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | Set the width of the graph box, this is the total width | ||||||||||||||||||||||||||||||||||||||||||
| 147 | of the SVG box created - not the graph it self which auto | ||||||||||||||||||||||||||||||||||||||||||
| 148 | scales to fix the space. | ||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | =item style_sheet() | ||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | Set the path to an external stylesheet, set to '' if | ||||||||||||||||||||||||||||||||||||||||||
| 153 | you want to revert back to using the defaut internal version. | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | To create an external stylesheet create a graph using the | ||||||||||||||||||||||||||||||||||||||||||
| 156 | default internal version and copy the stylesheet section to | ||||||||||||||||||||||||||||||||||||||||||
| 157 | an external file and edit from there. | ||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | =item show_data_values() | ||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | Show the value of each element of data on the graph | ||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | =item bar_gap() | ||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | Whether to have a gap between the bars or not, default | ||||||||||||||||||||||||||||||||||||||||||
| 166 | is '1', set to '0' if you don't want gaps. | ||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | =item min_scale_value() | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | The point at which the Y axis starts, defaults to '0', | ||||||||||||||||||||||||||||||||||||||||||
| 171 | if set to '' it will default to the minimum data value. | ||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | =item show_x_labels() | ||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||
| 175 | Whether to show labels on the X axis or not, defaults | ||||||||||||||||||||||||||||||||||||||||||
| 176 | to 1, set to '0' if you want to turn them off. | ||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | =item stagger_x_labels() | ||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | This puts the labels at alternative levels so if they | ||||||||||||||||||||||||||||||||||||||||||
| 181 | are long field names they will not overlap so easily. | ||||||||||||||||||||||||||||||||||||||||||
| 182 | Default it '0', to turn on set to '1'. | ||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | =item show_y_labels() | ||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | Whether to show labels on the Y axis or not, defaults | ||||||||||||||||||||||||||||||||||||||||||
| 187 | to 1, set to '0' if you want to turn them off. | ||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | =item scale_integers() | ||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | Ensures only whole numbers are used as the scale divisions. | ||||||||||||||||||||||||||||||||||||||||||
| 192 | Default it '0', to turn on set to '1'. This has no effect if | ||||||||||||||||||||||||||||||||||||||||||
| 193 | scale divisions are less than 1. | ||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | =item scale_divisions() | ||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||
| 197 | This defines the gap between markers on the X axis, | ||||||||||||||||||||||||||||||||||||||||||
| 198 | default is a 10th of the max_value, e.g. you will have | ||||||||||||||||||||||||||||||||||||||||||
| 199 | 10 markers on the X axis. NOTE: do not set this too | ||||||||||||||||||||||||||||||||||||||||||
| 200 | low - you are limited to 999 markers, after that the | ||||||||||||||||||||||||||||||||||||||||||
| 201 | graph won't generate. | ||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | =item show_x_title() | ||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||
| 205 | Whether to show the title under the X axis labels, | ||||||||||||||||||||||||||||||||||||||||||
| 206 | default is 0, set to '1' to show. | ||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||
| 208 | =item x_title() | ||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | What the title under X axis should be, e.g. 'Months'. | ||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||
| 212 | =item show_y_title() | ||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||
| 214 | Whether to show the title under the Y axis labels, | ||||||||||||||||||||||||||||||||||||||||||
| 215 | default is 0, set to '1' to show. | ||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | =item y_title_text_direction() | ||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | Aligns writing mode for Y axis label. Defaults to 'bt' (Bottom to Top). | ||||||||||||||||||||||||||||||||||||||||||
| 220 | Change to 'tb' (Top to Bottom) to reverse. | ||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | =item y_title() | ||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | What the title under Y axis should be, e.g. 'Sales in thousands'. | ||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | =item show_graph_title() | ||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||
| 228 | Whether to show a title on the graph, | ||||||||||||||||||||||||||||||||||||||||||
| 229 | default is 0, set to '1' to show. | ||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | =item graph_title() | ||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | What the title on the graph should be. | ||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||
| 235 | =item show_graph_subtitle() | ||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | Whether to show a subtitle on the graph, | ||||||||||||||||||||||||||||||||||||||||||
| 238 | default is 0, set to '1' to show. | ||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | =item graph_subtitle() | ||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||
| 242 | What the subtitle on the graph should be. | ||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||
| 244 | =item key() | ||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | Whether to show a key, defaults to 0, set to | ||||||||||||||||||||||||||||||||||||||||||
| 247 | '1' if you want to show it. | ||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||
| 249 | =item key_position() | ||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||
| 251 | Where the key should be positioned, defaults to | ||||||||||||||||||||||||||||||||||||||||||
| 252 | 'right', set to 'bottom' if you want to move it. | ||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||
| 254 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||
| 256 | =head1 NOTES | ||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | The default stylesheet handles upto 12 data sets, if you | ||||||||||||||||||||||||||||||||||||||||||
| 259 | use more you must create your own stylesheet and add the | ||||||||||||||||||||||||||||||||||||||||||
| 260 | additional settings for the extra data sets. You will know | ||||||||||||||||||||||||||||||||||||||||||
| 261 | if you go over 12 data sets as they will have no style and | ||||||||||||||||||||||||||||||||||||||||||
| 262 | be in black. | ||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | =head1 EXAMPLES | ||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||
| 266 | For examples look at the project home page | ||||||||||||||||||||||||||||||||||||||||||
| 267 | http://leo.cuckoo.org/projects/SVG-TT-Graph/ | ||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||
| 269 | =head1 EXPORT | ||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | None by default. | ||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||
| 273 | =head1 ACKNOWLEDGEMENTS | ||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||
| 275 | Stephen Morgan for creating the TT template and SVG. | ||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||
| 277 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||
| 279 | Leo Lapworth (LLAP@cuckoo.org) | ||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||
| 281 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||
| 283 | L<SVG::TT::Graph>, | ||||||||||||||||||||||||||||||||||||||||||
| 284 | L<SVG::TT::Graph::Line>, | ||||||||||||||||||||||||||||||||||||||||||
| 285 | L<SVG::TT::Graph::Bar>, | ||||||||||||||||||||||||||||||||||||||||||
| 286 | L<SVG::TT::Graph::BarLine>, | ||||||||||||||||||||||||||||||||||||||||||
| 287 | L<SVG::TT::Graph::Pie>, | ||||||||||||||||||||||||||||||||||||||||||
| 288 | L<SVG::TT::Graph::TimeSeries> | ||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||
| 290 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||
| 292 | sub get_template { | ||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_template: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 294 | # read in template | ||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | ▶ | return $template if $template; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | ▶ | while(<DATA>) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | $template .= $_ . "\r\n"; | |||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | return $template; | |||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||
| 302 | sub _init { | ||||||||||||||||||||||||||||||||||||||||||
| 303 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_init: called CC=4 SCAR=14.1
| |||||||||||||||||||||||||||||||||||||||||||
| 304 | croak "fields was not supplied or is empty" | ||||||||||||||||||||||||||||||||||||||||||
| 305 | unless defined $self->{'config'}->{fields} | ||||||||||||||||||||||||||||||||||||||||||
| 306 | && ref($self->{'config'}->{fields}) eq 'ARRAY' | ||||||||||||||||||||||||||||||||||||||||||
| 307 | 2 | ▶ | && scalar(@{$self->{'config'}->{fields}}) > 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
defined $self->{"config"}{"fields"} and ref $self->{"config"}{"fields"} eq "ARRAY" and scalar @{$self->{"config"}{"fields"};} > 0
defined $self->{"config"}{"fields"} and ref $self->{"config"}{"fields"} eq "ARRAY"
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
| |||||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||
| 310 | sub _set_defaults { | ||||||||||||||||||||||||||||||||||||||||||
| 311 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_defaults: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||
| 313 | 2 | my %default = ( | |||||||||||||||||||||||||||||||||||||||||
| 314 | 'width' => '500', | ||||||||||||||||||||||||||||||||||||||||||
| 315 | 'height' => '300', | ||||||||||||||||||||||||||||||||||||||||||
| 316 | 'style_sheet' => '', | ||||||||||||||||||||||||||||||||||||||||||
| 317 | 'show_data_values' => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||
| 319 | 'min_scale_value' => '0', | ||||||||||||||||||||||||||||||||||||||||||
| 320 | 'scale_divisions' => '', | ||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||
| 322 | 'bar_gap' => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||
| 324 | 'show_x_labels' => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 325 | 'stagger_x_labels' => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 326 | 'show_y_labels' => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 327 | 'scale_integers' => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||
| 329 | 'show_x_title' => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 330 | 'x_title' => 'X Field names', | ||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||
| 332 | 'show_y_title' => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 333 | 'y_title_text_direction' => 'bt', | ||||||||||||||||||||||||||||||||||||||||||
| 334 | 'y_title' => 'Y Scale', | ||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||
| 336 | 'show_graph_title' => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 337 | 'graph_title' => 'Graph Title', | ||||||||||||||||||||||||||||||||||||||||||
| 338 | 'show_graph_subtitle' => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 339 | 'graph_subtitle' => 'Graph Sub Title', | ||||||||||||||||||||||||||||||||||||||||||
| 340 | 'key' => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 341 | 'key_position' => 'right', # bottom or right | ||||||||||||||||||||||||||||||||||||||||||
| 342 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||
| 344 | 2 | ▶ | while( my ($key,$value) = each %default ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 345 | 44 | $self->{config}->{$key} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||
| 349 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 350 | __DATA__ | ||||||||||||||||||||||||||||||||||||||||||
| 351 | <?xml version="1.0"?> | ||||||||||||||||||||||||||||||||||||||||||
| 352 | <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" | ||||||||||||||||||||||||||||||||||||||||||
| 353 | "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"> | ||||||||||||||||||||||||||||||||||||||||||
| 354 | [% stylesheet = 'included' %] | ||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||
| 356 | [% IF config.style_sheet && config.style_sheet != '' %] | ||||||||||||||||||||||||||||||||||||||||||
| 357 | <?xml-stylesheet href="[% config.style_sheet %]" type="text/css"?> | ||||||||||||||||||||||||||||||||||||||||||
| 358 | [% ELSE %] | ||||||||||||||||||||||||||||||||||||||||||
| 359 | [% stylesheet = 'excluded' %] | ||||||||||||||||||||||||||||||||||||||||||
| 360 | [% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||
| 362 | <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"> | ||||||||||||||||||||||||||||||||||||||||||
| 363 | <!-- \\\\\\\\\\\\\\\\\\\\\\\\\\\\ --> | ||||||||||||||||||||||||||||||||||||||||||
| 364 | <!-- Created with SVG::TT::Graph --> | ||||||||||||||||||||||||||||||||||||||||||
| 365 | <!-- Stephen Morgan / Leo Lapworth --> | ||||||||||||||||||||||||||||||||||||||||||
| 366 | <!-- //////////////////////////// --> | ||||||||||||||||||||||||||||||||||||||||||
| 367 | [% IF stylesheet == 'excluded' %] | ||||||||||||||||||||||||||||||||||||||||||
| 368 | <!-- include default stylesheet if none specified --> | ||||||||||||||||||||||||||||||||||||||||||
| 369 | <defs> | ||||||||||||||||||||||||||||||||||||||||||
| 370 | <style type="text/css"> | ||||||||||||||||||||||||||||||||||||||||||
| 371 | <![CDATA[ | ||||||||||||||||||||||||||||||||||||||||||
| 372 | /* Copy from here for external style sheet */ | ||||||||||||||||||||||||||||||||||||||||||
| 373 | .svgBackground{ | ||||||||||||||||||||||||||||||||||||||||||
| 374 | fill:#ffffff; | ||||||||||||||||||||||||||||||||||||||||||
| 375 | /* set 'fill: none;' and then include 'wmode="transparent"' | ||||||||||||||||||||||||||||||||||||||||||
| 376 | in the HTML embed tag if you need the SVG transparent */ | ||||||||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||||||
| 378 | .graphBackground{ | ||||||||||||||||||||||||||||||||||||||||||
| 379 | fill:#f0f0f0; | ||||||||||||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||
| 382 | /* graphs titles */ | ||||||||||||||||||||||||||||||||||||||||||
| 383 | .mainTitle{ | ||||||||||||||||||||||||||||||||||||||||||
| 384 | text-anchor: middle; | ||||||||||||||||||||||||||||||||||||||||||
| 385 | fill: #000000; | ||||||||||||||||||||||||||||||||||||||||||
| 386 | font-size: 14px; | ||||||||||||||||||||||||||||||||||||||||||
| 387 | font-family: "Arial", sans-serif; | ||||||||||||||||||||||||||||||||||||||||||
| 388 | font-weight: bold; | ||||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||
| 390 | .subTitle{ | ||||||||||||||||||||||||||||||||||||||||||
| 391 | text-anchor: middle; | ||||||||||||||||||||||||||||||||||||||||||
| 392 | fill: #999999; | ||||||||||||||||||||||||||||||||||||||||||
| 393 | font-size: 12px; | ||||||||||||||||||||||||||||||||||||||||||
| 394 | font-family: "Arial", sans-serif; | ||||||||||||||||||||||||||||||||||||||||||
| 395 | font-weight: normal; | ||||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||
| 398 | .axis{ | ||||||||||||||||||||||||||||||||||||||||||
| 399 | stroke: #000000; | ||||||||||||||||||||||||||||||||||||||||||
| 400 | stroke-width: 1px; | ||||||||||||||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||
| 403 | .guideLines{ | ||||||||||||||||||||||||||||||||||||||||||
| 404 | stroke: #666666; | ||||||||||||||||||||||||||||||||||||||||||
| 405 | stroke-width: 1px; | ||||||||||||||||||||||||||||||||||||||||||
| 406 | stroke-dasharray: 5 5; | ||||||||||||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||
| 409 | .xAxisLabels{ | ||||||||||||||||||||||||||||||||||||||||||
| 410 | text-anchor: middle; | ||||||||||||||||||||||||||||||||||||||||||
| 411 | fill: #000000; | ||||||||||||||||||||||||||||||||||||||||||
| 412 | font-size: 12px; | ||||||||||||||||||||||||||||||||||||||||||
| 413 | font-family: "Arial", sans-serif; | ||||||||||||||||||||||||||||||||||||||||||
| 414 | font-weight: normal; | ||||||||||||||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||
| 417 | .yAxisLabels{ | ||||||||||||||||||||||||||||||||||||||||||
| 418 | text-anchor: end; | ||||||||||||||||||||||||||||||||||||||||||
| 419 | fill: #000000; | ||||||||||||||||||||||||||||||||||||||||||
| 420 | font-size: 12px; | ||||||||||||||||||||||||||||||||||||||||||
| 421 | font-family: "Arial", sans-serif; | ||||||||||||||||||||||||||||||||||||||||||
| 422 | font-weight: normal; | ||||||||||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||
| 425 | .xAxisTitle{ | ||||||||||||||||||||||||||||||||||||||||||
| 426 | text-anchor: middle; | ||||||||||||||||||||||||||||||||||||||||||
| 427 | fill: #ff0000; | ||||||||||||||||||||||||||||||||||||||||||
| 428 | font-size: 14px; | ||||||||||||||||||||||||||||||||||||||||||
| 429 | font-family: "Arial", sans-serif; | ||||||||||||||||||||||||||||||||||||||||||
| 430 | font-weight: normal; | ||||||||||||||||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||
| 433 | .yAxisTitle{ | ||||||||||||||||||||||||||||||||||||||||||
| 434 | fill: #ff0000; | ||||||||||||||||||||||||||||||||||||||||||
| 435 | text-anchor: middle; | ||||||||||||||||||||||||||||||||||||||||||
| 436 | font-size: 14px; | ||||||||||||||||||||||||||||||||||||||||||
| 437 | font-family: "Arial", sans-serif; | ||||||||||||||||||||||||||||||||||||||||||
| 438 | font-weight: normal; | ||||||||||||||||||||||||||||||||||||||||||
| 439 | } | ||||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||
| 441 | .dataPointLabel{ | ||||||||||||||||||||||||||||||||||||||||||
| 442 | fill: #000000; | ||||||||||||||||||||||||||||||||||||||||||
| 443 | text-anchor:middle; | ||||||||||||||||||||||||||||||||||||||||||
| 444 | font-size: 10px; | ||||||||||||||||||||||||||||||||||||||||||
| 445 | font-family: "Arial", sans-serif; | ||||||||||||||||||||||||||||||||||||||||||
| 446 | font-weight: normal; | ||||||||||||||||||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||||||||||||||||
| 448 | .staggerGuideLine{ | ||||||||||||||||||||||||||||||||||||||||||
| 449 | fill: none; | ||||||||||||||||||||||||||||||||||||||||||
| 450 | stroke: #000000; | ||||||||||||||||||||||||||||||||||||||||||
| 451 | stroke-width: 0.5px; | ||||||||||||||||||||||||||||||||||||||||||
| 452 | } | ||||||||||||||||||||||||||||||||||||||||||
| 453 | /* default fill styles for multiple datasets (probably only use a single dataset on this graph though) */ | ||||||||||||||||||||||||||||||||||||||||||
| 454 | .key1,.fill1{ | ||||||||||||||||||||||||||||||||||||||||||
| 455 | fill: #ff0000; | ||||||||||||||||||||||||||||||||||||||||||
| 456 | fill-opacity: 0.5; | ||||||||||||||||||||||||||||||||||||||||||
| 457 | stroke: none; | ||||||||||||||||||||||||||||||||||||||||||
| 458 | stroke-width: 0.5px; | ||||||||||||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||||||||||||
| 460 | .key2,.fill2{ | ||||||||||||||||||||||||||||||||||||||||||
| 461 | fill: #0000ff; | ||||||||||||||||||||||||||||||||||||||||||
| 462 | fill-opacity: 0.5; | ||||||||||||||||||||||||||||||||||||||||||
| 463 | stroke: none; | ||||||||||||||||||||||||||||||||||||||||||
| 464 | stroke-width: 1px; | ||||||||||||||||||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||||||||||||||||
| 466 | .key3,.fill3{ | ||||||||||||||||||||||||||||||||||||||||||
| 467 | fill: #00ff00; | ||||||||||||||||||||||||||||||||||||||||||
| 468 | fill-opacity: 0.5; | ||||||||||||||||||||||||||||||||||||||||||
| 469 | stroke: none; | ||||||||||||||||||||||||||||||||||||||||||
| 470 | stroke-width: 1px; | ||||||||||||||||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||||||||||||||||
| 472 | .key4,.fill4{ | ||||||||||||||||||||||||||||||||||||||||||
| 473 | fill: #ffcc00; | ||||||||||||||||||||||||||||||||||||||||||
| 474 | fill-opacity: 0.5; | ||||||||||||||||||||||||||||||||||||||||||
| 475 | stroke: none; | ||||||||||||||||||||||||||||||||||||||||||
| 476 | stroke-width: 1px; | ||||||||||||||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||||||||||||
| 478 | .key5,.fill5{ | ||||||||||||||||||||||||||||||||||||||||||
| 479 | fill: #00ccff; | ||||||||||||||||||||||||||||||||||||||||||
| 480 | fill-opacity: 0.5; | ||||||||||||||||||||||||||||||||||||||||||
| 481 | stroke: none; | ||||||||||||||||||||||||||||||||||||||||||
| 482 | stroke-width: 1px; | ||||||||||||||||||||||||||||||||||||||||||
| 483 | } | ||||||||||||||||||||||||||||||||||||||||||
| 484 | .key6,.fill6{ | ||||||||||||||||||||||||||||||||||||||||||
| 485 | fill: #ff00ff; | ||||||||||||||||||||||||||||||||||||||||||
| 486 | fill-opacity: 0.5; | ||||||||||||||||||||||||||||||||||||||||||
| 487 | stroke: none; | ||||||||||||||||||||||||||||||||||||||||||
| 488 | stroke-width: 1px; | ||||||||||||||||||||||||||||||||||||||||||
| 489 | } | ||||||||||||||||||||||||||||||||||||||||||
| 490 | .key7,.fill7{ | ||||||||||||||||||||||||||||||||||||||||||
| 491 | fill: #00ffff; | ||||||||||||||||||||||||||||||||||||||||||
| 492 | fill-opacity: 0.5; | ||||||||||||||||||||||||||||||||||||||||||
| 493 | stroke: none; | ||||||||||||||||||||||||||||||||||||||||||
| 494 | stroke-width: 1px; | ||||||||||||||||||||||||||||||||||||||||||
| 495 | } | ||||||||||||||||||||||||||||||||||||||||||
| 496 | .key8,.fill8{ | ||||||||||||||||||||||||||||||||||||||||||
| 497 | fill: #ffff00; | ||||||||||||||||||||||||||||||||||||||||||
| 498 | fill-opacity: 0.5; | ||||||||||||||||||||||||||||||||||||||||||
| 499 | stroke: none; | ||||||||||||||||||||||||||||||||||||||||||
| 500 | stroke-width: 1px; | ||||||||||||||||||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||||||||||||||||
| 502 | .key9,.fill9{ | ||||||||||||||||||||||||||||||||||||||||||
| 503 | fill: #cc6666; | ||||||||||||||||||||||||||||||||||||||||||
| 504 | fill-opacity: 0.5; | ||||||||||||||||||||||||||||||||||||||||||
| 505 | stroke: none; | ||||||||||||||||||||||||||||||||||||||||||
| 506 | stroke-width: 1px; | ||||||||||||||||||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||||||||||||||||
| 508 | .key10,.fill10{ | ||||||||||||||||||||||||||||||||||||||||||
| 509 | fill: #663399; | ||||||||||||||||||||||||||||||||||||||||||
| 510 | fill-opacity: 0.5; | ||||||||||||||||||||||||||||||||||||||||||
| 511 | stroke: none; | ||||||||||||||||||||||||||||||||||||||||||
| 512 | stroke-width: 1px; | ||||||||||||||||||||||||||||||||||||||||||
| 513 | } | ||||||||||||||||||||||||||||||||||||||||||
| 514 | .key11,.fill11{ | ||||||||||||||||||||||||||||||||||||||||||
| 515 | fill: #339900; | ||||||||||||||||||||||||||||||||||||||||||
| 516 | fill-opacity: 0.5; | ||||||||||||||||||||||||||||||||||||||||||
| 517 | stroke: none; | ||||||||||||||||||||||||||||||||||||||||||
| 518 | stroke-width: 1px; | ||||||||||||||||||||||||||||||||||||||||||
| 519 | } | ||||||||||||||||||||||||||||||||||||||||||
| 520 | .key12,.fill12{ | ||||||||||||||||||||||||||||||||||||||||||
| 521 | fill: #9966FF; | ||||||||||||||||||||||||||||||||||||||||||
| 522 | fill-opacity: 0.5; | ||||||||||||||||||||||||||||||||||||||||||
| 523 | stroke: none; | ||||||||||||||||||||||||||||||||||||||||||
| 524 | stroke-width: 1px; | ||||||||||||||||||||||||||||||||||||||||||
| 525 | } | ||||||||||||||||||||||||||||||||||||||||||
| 526 | .keyText{ | ||||||||||||||||||||||||||||||||||||||||||
| 527 | fill: #000000; | ||||||||||||||||||||||||||||||||||||||||||
| 528 | text-anchor:start; | ||||||||||||||||||||||||||||||||||||||||||
| 529 | font-size: 10px; | ||||||||||||||||||||||||||||||||||||||||||
| 530 | font-family: "Arial", sans-serif; | ||||||||||||||||||||||||||||||||||||||||||
| 531 | font-weight: normal; | ||||||||||||||||||||||||||||||||||||||||||
| 532 | } | ||||||||||||||||||||||||||||||||||||||||||
| 533 | /* End copy for external style sheet */ | ||||||||||||||||||||||||||||||||||||||||||
| 534 | ]]> | ||||||||||||||||||||||||||||||||||||||||||
| 535 | </style> | ||||||||||||||||||||||||||||||||||||||||||
| 536 | </defs> | ||||||||||||||||||||||||||||||||||||||||||
| 537 | [% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 538 | <!-- svg bg --> | ||||||||||||||||||||||||||||||||||||||||||
| 539 | <rect x="0" y="0" width="[% config.width %]" height="[% config.height %]" class="svgBackground"/> | ||||||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||||||
| 541 | <!-- ///////////////// CALCULATE GRAPH AREA AND BOUNDARIES //////////////// --> | ||||||||||||||||||||||||||||||||||||||||||
| 542 | <!-- get dimensions of actual graph area (NOT SVG area) --> | ||||||||||||||||||||||||||||||||||||||||||
| 543 | [% w = config.width %] | ||||||||||||||||||||||||||||||||||||||||||
| 544 | [% h = config.height %] | ||||||||||||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||||||||||||
| 546 | <!-- set start/default coords of graph --> | ||||||||||||||||||||||||||||||||||||||||||
| 547 | [% x = 0 %] | ||||||||||||||||||||||||||||||||||||||||||
| 548 | [% y = 0 %] | ||||||||||||||||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||||||||||||||||
| 550 | [% char_width = 7 %] | ||||||||||||||||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||||||||||||||||
| 552 | <!-- CALC WIDTH AND X COORD DIMENSIONS --> | ||||||||||||||||||||||||||||||||||||||||||
| 553 | <!-- reduce width of graph area if there is labelling on y axis --> | ||||||||||||||||||||||||||||||||||||||||||
| 554 | [% IF config.show_y_title %][% w = w - 20 %][% x = x + 20 %][% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 555 | [% IF config.show_y_labels %] | ||||||||||||||||||||||||||||||||||||||||||
| 556 | [% max_ylabel_length = 0 %] | ||||||||||||||||||||||||||||||||||||||||||
| 557 | <!-- calculate largest label width and add margin accordingly --> | ||||||||||||||||||||||||||||||||||||||||||
| 558 | [% FOREACH y_label = config.fields %] | ||||||||||||||||||||||||||||||||||||||||||
| 559 | [% IF max_ylabel_length < y_label.length %] | ||||||||||||||||||||||||||||||||||||||||||
| 560 | [% max_ylabel_length = y_label.length %] | ||||||||||||||||||||||||||||||||||||||||||
| 561 | [% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 562 | [% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||||||||||||
| 564 | [% space_b4_axis = char_width * max_ylabel_length %] | ||||||||||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||||||||||
| 566 | [% w = w - space_b4_axis %] | ||||||||||||||||||||||||||||||||||||||||||
| 567 | [% x = x + space_b4_axis %] | ||||||||||||||||||||||||||||||||||||||||||
| 568 | [% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||||||||||||||||
| 570 | <!-- corrects space around graph when very small y labels are used --> | ||||||||||||||||||||||||||||||||||||||||||
| 571 | [% IF max_ylabel_length == 1 %] | ||||||||||||||||||||||||||||||||||||||||||
| 572 | [% w = w - 5 %] | ||||||||||||||||||||||||||||||||||||||||||
| 573 | [% x = x + 5 %] | ||||||||||||||||||||||||||||||||||||||||||
| 574 | [% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||||||||||||||||
| 576 | <!-- pad ends of graph if there are x labels --> | ||||||||||||||||||||||||||||||||||||||||||
| 577 | [% IF config.show_x_labels %] | ||||||||||||||||||||||||||||||||||||||||||
| 578 | [% w = w - 20 %] | ||||||||||||||||||||||||||||||||||||||||||
| 579 | <!-- if there are no y labels or titles BUT there are x labels, then pad left --> | ||||||||||||||||||||||||||||||||||||||||||
| 580 | [% IF !config.show_y_labels && !config.show_y_title %] | ||||||||||||||||||||||||||||||||||||||||||
| 581 | [% w = w - 10 %] | ||||||||||||||||||||||||||||||||||||||||||
| 582 | [% x = x + 10 %] | ||||||||||||||||||||||||||||||||||||||||||
| 583 | [% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 584 | <!-- adjust axis start position using the first x label char lengths --> | ||||||||||||||||||||||||||||||||||||||||||
| 585 | [% IF config.min_scale_value.length > 1 %] | ||||||||||||||||||||||||||||||||||||||||||
| 586 | [% padding_for_labels = char_width * config.min_scale_value.length %] | ||||||||||||||||||||||||||||||||||||||||||
| 587 | [% w = w - (padding_for_labels / 2) %] | ||||||||||||||||||||||||||||||||||||||||||
| 588 | [% x = x + (padding_for_labels / 2) %] | ||||||||||||||||||||||||||||||||||||||||||
| 589 | [% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 590 | [% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||||||||||||||||
| 593 | <!-- CALC HEIGHT AND Y COORD DIMENSIONS --> | ||||||||||||||||||||||||||||||||||||||||||
| 594 | <!-- reduce height of graph area if there is labelling on x axis --> | ||||||||||||||||||||||||||||||||||||||||||
| 595 | [% IF config.show_x_labels %][% h = h - 20 %][% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||||||||||||||||
| 597 | <!-- stagger x labels if overlapping occurs --> | ||||||||||||||||||||||||||||||||||||||||||
| 598 | [% stagger = 0 %] | ||||||||||||||||||||||||||||||||||||||||||
| 599 | [% IF config.stagger_x_labels %] | ||||||||||||||||||||||||||||||||||||||||||
| 600 | [% stagger = 17 %] | ||||||||||||||||||||||||||||||||||||||||||
| 601 | [% h = h - stagger %] | ||||||||||||||||||||||||||||||||||||||||||
| 602 | [% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||||||||||||||||
| 604 | [% IF config.show_x_title %][% h = h - 25 - stagger %][% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||||||||||||||||
| 606 | <!-- pad top of graph if y axis has data labels so labels do not get chopped off --> | ||||||||||||||||||||||||||||||||||||||||||
| 607 | [% IF config.show_y_labels %][% h = h - 10 %][% y = y + 10 %][% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||||||||||||||||
| 609 | <!-- reduce height if graph has title or subtitle --> | ||||||||||||||||||||||||||||||||||||||||||
| 610 | [% IF config.show_graph_title %][% h = h - 25 %][% y = y + 25 %][% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 611 | [% IF config.show_graph_subtitle %][% h = h - 10 %][% y = y + 10 %][% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||||||||||||
| 613 | [% max_key_size = 0 %] | ||||||||||||||||||||||||||||||||||||||||||
| 614 | [% FOREACH y_label = config.fields %] | ||||||||||||||||||||||||||||||||||||||||||
| 615 | <!-- find largest dataset title for Key size --> | ||||||||||||||||||||||||||||||||||||||||||
| 616 | [% IF max_key_size < data.0.title.length %] | ||||||||||||||||||||||||||||||||||||||||||
| 617 | [% max_key_size = data.0.title.length %] | ||||||||||||||||||||||||||||||||||||||||||
| 618 | [% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 619 | [% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 620 | |||||||||||||||||||||||||||||||||||||||||||
| 621 | <!-- reduce graph dimensions if there is a KEY --> | ||||||||||||||||||||||||||||||||||||||||||
| 622 | [% key_box_size = 12 %] | ||||||||||||||||||||||||||||||||||||||||||
| 623 | [% IF config.key && config.key_position == 'right' %][% w = w - (max_key_size * (char_width - 1)) - (key_box_size * 3 ) %] | ||||||||||||||||||||||||||||||||||||||||||
| 624 | [% ELSIF config.key && config.key_position == 'bottom' %] | ||||||||||||||||||||||||||||||||||||||||||
| 625 | [% IF data.size < 4 %] | ||||||||||||||||||||||||||||||||||||||||||
| 626 | [% h = h - ((data.size + 1) * (key_box_size + key_padding))%] | ||||||||||||||||||||||||||||||||||||||||||
| 627 | [% ELSE %] | ||||||||||||||||||||||||||||||||||||||||||
| 628 | [% h = h - (4 * (key_box_size + key_padding))%] | ||||||||||||||||||||||||||||||||||||||||||
| 629 | [% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 630 | [% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 631 | |||||||||||||||||||||||||||||||||||||||||||
| 632 | |||||||||||||||||||||||||||||||||||||||||||
| 633 | <!-- calc min and max values --> | ||||||||||||||||||||||||||||||||||||||||||
| 634 | [% min_value = 99999999999 %] | ||||||||||||||||||||||||||||||||||||||||||
| 635 | [% max_value = 0 %] | ||||||||||||||||||||||||||||||||||||||||||
| 636 | [% FOREACH field = config.fields %] | ||||||||||||||||||||||||||||||||||||||||||
| 637 | [% FOREACH dataset = data %] | ||||||||||||||||||||||||||||||||||||||||||
| 638 | [% IF min_value > dataset.data.$field && dataset.data.$field != '' %] | ||||||||||||||||||||||||||||||||||||||||||
| 639 | [% min_value = dataset.data.$field %] | ||||||||||||||||||||||||||||||||||||||||||
| 640 | [% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 641 | [% IF max_value < dataset.data.$field && dataset.data.$field != '' %] | ||||||||||||||||||||||||||||||||||||||||||
| 642 | [% max_value = dataset.data.$field %] | ||||||||||||||||||||||||||||||||||||||||||
| 643 | [% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 644 | [% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 645 | [% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||||||||||||||||
| 647 | [% IF config.min_scale_value || config.min_scale_value == '0' %] | ||||||||||||||||||||||||||||||||||||||||||
| 648 | [% min_scale_value = config.min_scale_value %] | ||||||||||||||||||||||||||||||||||||||||||
| 649 | [% ELSE %] | ||||||||||||||||||||||||||||||||||||||||||
| 650 | <!-- setting lowest value to be min_value as no min_scale_value defined --> | ||||||||||||||||||||||||||||||||||||||||||
| 651 | [% min_scale_value = min_value %] | ||||||||||||||||||||||||||||||||||||||||||
| 652 | [% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||||||||||||||||
| 654 | <!-- base line --> | ||||||||||||||||||||||||||||||||||||||||||
| 655 | [% base_line = h + y %] | ||||||||||||||||||||||||||||||||||||||||||
| 656 | |||||||||||||||||||||||||||||||||||||||||||
| 657 | <!-- how much padding above max point on graph --> | ||||||||||||||||||||||||||||||||||||||||||
| 658 | [% IF (max_value - min_scale_value) == 0 %] | ||||||||||||||||||||||||||||||||||||||||||
| 659 | [% top_pad = 10 %] | ||||||||||||||||||||||||||||||||||||||||||
| 660 | [% ELSE %] | ||||||||||||||||||||||||||||||||||||||||||
| 661 | [% top_pad = (max_value - min_scale_value) / 20 %] | ||||||||||||||||||||||||||||||||||||||||||
| 662 | [% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 663 | |||||||||||||||||||||||||||||||||||||||||||
| 664 | [% scale_range = (max_value + top_pad) - min_scale_value %] | ||||||||||||||||||||||||||||||||||||||||||
| 665 | |||||||||||||||||||||||||||||||||||||||||||
| 666 | <!-- default to 10 scale_divisions if none have been set --> | ||||||||||||||||||||||||||||||||||||||||||
| 667 | [% IF config.scale_divisions %] | ||||||||||||||||||||||||||||||||||||||||||
| 668 | [% scale_division = config.scale_divisions %] | ||||||||||||||||||||||||||||||||||||||||||
| 669 | [% ELSE %] | ||||||||||||||||||||||||||||||||||||||||||
| 670 | [% scale_division = scale_range / 10 %] | ||||||||||||||||||||||||||||||||||||||||||
| 671 | [% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 672 | |||||||||||||||||||||||||||||||||||||||||||
| 673 | [% IF config.scale_integers %] | ||||||||||||||||||||||||||||||||||||||||||
| 674 | [% IF scale_division < 1 %] | ||||||||||||||||||||||||||||||||||||||||||
| 675 | [% scale_division = 1 %] | ||||||||||||||||||||||||||||||||||||||||||
| 676 | [% ELSIF scale_division.match('.') %] | ||||||||||||||||||||||||||||||||||||||||||
| 677 | [% scale_division = scale_division FILTER format('%2.0f') %] | ||||||||||||||||||||||||||||||||||||||||||
| 678 | [% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 679 | [% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 680 | |||||||||||||||||||||||||||||||||||||||||||
| 681 | <!-- ////////////////////////////// BUILD GRAPH AREA ////////////////////////////// --> | ||||||||||||||||||||||||||||||||||||||||||
| 682 | <!-- graph bg --> | ||||||||||||||||||||||||||||||||||||||||||
| 683 | <rect x="[% x %]" y="[% y %]" width="[% w %]" height="[% h %]" class="graphBackground"/> | ||||||||||||||||||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||||||||||||||||
| 685 | <!-- axis --> | ||||||||||||||||||||||||||||||||||||||||||
| 686 | <path d="M[% x %] [% y %] v[% h %]" class="axis" id="xAxis"/> | ||||||||||||||||||||||||||||||||||||||||||
| 687 | <path d="M[% x %] [% base_line %] h[% w %]" class="axis" id="yAxis"/> | ||||||||||||||||||||||||||||||||||||||||||
| 688 | |||||||||||||||||||||||||||||||||||||||||||
| 689 | <!-- ////////////////////////////// AXIS DISTRIBUTIONS //////////////////////////// --> | ||||||||||||||||||||||||||||||||||||||||||
| 690 | <!-- get number of data points on y scale --> | ||||||||||||||||||||||||||||||||||||||||||
| 691 | [% dy = config.fields.size %] | ||||||||||||||||||||||||||||||||||||||||||
| 692 | |||||||||||||||||||||||||||||||||||||||||||
| 693 | <!-- get distribution heights on y axis --> | ||||||||||||||||||||||||||||||||||||||||||
| 694 | [% data_widths_y = h / dy %] | ||||||||||||||||||||||||||||||||||||||||||
| 695 | [% dh = data_widths_y.match('(\d+[\.\d\d])').0 %] | ||||||||||||||||||||||||||||||||||||||||||
| 696 | |||||||||||||||||||||||||||||||||||||||||||
| 697 | [% i = dh %] | ||||||||||||||||||||||||||||||||||||||||||
| 698 | [% count = 0 %] | ||||||||||||||||||||||||||||||||||||||||||
| 699 | |||||||||||||||||||||||||||||||||||||||||||
| 700 | <!-- y axis labels --> | ||||||||||||||||||||||||||||||||||||||||||
| 701 | [% IF config.show_y_labels %] | ||||||||||||||||||||||||||||||||||||||||||
| 702 | [% FOREACH field = config.fields %] | ||||||||||||||||||||||||||||||||||||||||||
| 703 | [% IF count == 0 %] | ||||||||||||||||||||||||||||||||||||||||||
| 704 | <text x="[% x - 10 %]" y="[% base_line - (dh / 2) %]" class="yAxisLabels">[% field %]</text> | ||||||||||||||||||||||||||||||||||||||||||
| 705 | [% i = i - dh %] | ||||||||||||||||||||||||||||||||||||||||||
| 706 | [% ELSE %] | ||||||||||||||||||||||||||||||||||||||||||
| 707 | <text x="[% x - 10 %]" y="[% base_line - i - (dh / 2) %]" class="yAxisLabels">[% field %]</text> | ||||||||||||||||||||||||||||||||||||||||||
| 708 | [% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 709 | [% i = i + dh %] | ||||||||||||||||||||||||||||||||||||||||||
| 710 | [% count = count + 1 %] | ||||||||||||||||||||||||||||||||||||||||||
| 711 | [% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 712 | [% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 713 | |||||||||||||||||||||||||||||||||||||||||||
| 714 | |||||||||||||||||||||||||||||||||||||||||||
| 715 | <!-- distribute x scale --> | ||||||||||||||||||||||||||||||||||||||||||
| 716 | [% dx = scale_range / scale_division %] | ||||||||||||||||||||||||||||||||||||||||||
| 717 | <!-- ensure x_data_points butt up to edge of graph --> | ||||||||||||||||||||||||||||||||||||||||||
| 718 | [% scale_division_height = w / dx %] | ||||||||||||||||||||||||||||||||||||||||||
| 719 | [% dx = scale_division_height.match('(\d+[\.\d\d])').0 %] | ||||||||||||||||||||||||||||||||||||||||||
| 720 | [% count = 0 %] | ||||||||||||||||||||||||||||||||||||||||||
| 721 | [% y_value = min_scale_value %] | ||||||||||||||||||||||||||||||||||||||||||
| 722 | [% stagger_count = 0 %] | ||||||||||||||||||||||||||||||||||||||||||
| 723 | [% IF config.show_x_labels %] | ||||||||||||||||||||||||||||||||||||||||||
| 724 | [% WHILE (dx * count) < w %] | ||||||||||||||||||||||||||||||||||||||||||
| 725 | [% IF count == 0 %] | ||||||||||||||||||||||||||||||||||||||||||
| 726 | <!-- no stroke for first line --> | ||||||||||||||||||||||||||||||||||||||||||
| 727 | <text x="[% x + (dx * count) %]" y="[% base_line + 15 %]" class="xAxisLabels">[% y_value FILTER format('%2.0f') %]</text> | ||||||||||||||||||||||||||||||||||||||||||
| 728 | [% ELSE %] | ||||||||||||||||||||||||||||||||||||||||||
| 729 | [% IF stagger_count == 2 %] | ||||||||||||||||||||||||||||||||||||||||||
| 730 | <text x="[% x + (dx * count) %]" y="[% base_line + 15 %]" class="xAxisLabels" style="text-anchor: middle;">[% y_value FILTER format('%2.01f') %]</text> | ||||||||||||||||||||||||||||||||||||||||||
| 731 | <path d="M[% x + (dx * count) %] [% base_line %] V[% y %]" class="guideLines"/> | ||||||||||||||||||||||||||||||||||||||||||
| 732 | [% stagger_count = 0 %] | ||||||||||||||||||||||||||||||||||||||||||
| 733 | [% ELSE %] | ||||||||||||||||||||||||||||||||||||||||||
| 734 | <text x="[% x + (dx * count) %]" y="[% base_line + 15 + stagger %]" class="xAxisLabels" style="text-anchor: middle;">[% y_value FILTER format('%2.01f') %]</text> | ||||||||||||||||||||||||||||||||||||||||||
| 735 | <path d="M[% x + (dx * count) %] [% base_line %] V[% y %]" class="guideLines"/> | ||||||||||||||||||||||||||||||||||||||||||
| 736 | <path d="M[% x + (dx * count) %] [% base_line %] v[% stagger %]" class="staggerGuideLine" /> | ||||||||||||||||||||||||||||||||||||||||||
| 737 | [% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 738 | [% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 739 | [% y_value = y_value + scale_division %] | ||||||||||||||||||||||||||||||||||||||||||
| 740 | [% count = count + 1 %] | ||||||||||||||||||||||||||||||||||||||||||
| 741 | [% stagger_count = stagger_count + 1 %] | ||||||||||||||||||||||||||||||||||||||||||
| 742 | [% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 743 | [% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 744 | |||||||||||||||||||||||||||||||||||||||||||
| 745 | |||||||||||||||||||||||||||||||||||||||||||
| 746 | |||||||||||||||||||||||||||||||||||||||||||
| 747 | |||||||||||||||||||||||||||||||||||||||||||
| 748 | <!-- ////////////////////////////// AXIS TITLES ////////////////////////////// --> | ||||||||||||||||||||||||||||||||||||||||||
| 749 | |||||||||||||||||||||||||||||||||||||||||||
| 750 | <!-- x axis title --> | ||||||||||||||||||||||||||||||||||||||||||
| 751 | [% IF config.show_x_title %] | ||||||||||||||||||||||||||||||||||||||||||
| 752 | [% IF !config.show_x_labels %] | ||||||||||||||||||||||||||||||||||||||||||
| 753 | [% y_xtitle = 15 %] | ||||||||||||||||||||||||||||||||||||||||||
| 754 | [% ELSE %] | ||||||||||||||||||||||||||||||||||||||||||
| 755 | [% y_xtitle = 35 %] | ||||||||||||||||||||||||||||||||||||||||||
| 756 | [% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 757 | <text x="[% (w / 2) + x %]" y="[% h + y + y_xtitle + stagger %]" class="xAxisTitle">[% config.x_title %]</text> | ||||||||||||||||||||||||||||||||||||||||||
| 758 | [% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 759 | |||||||||||||||||||||||||||||||||||||||||||
| 760 | <!-- y axis title --> | ||||||||||||||||||||||||||||||||||||||||||
| 761 | [% IF config.show_y_title %] | ||||||||||||||||||||||||||||||||||||||||||
| 762 | [% IF config.y_title_text_direction == 'tb' %] | ||||||||||||||||||||||||||||||||||||||||||
| 763 | <text x="11" y="[% (h / 2) + y %]" class="yAxisTitle" style="writing-mode:tb;">[% config.y_title %]</text> | ||||||||||||||||||||||||||||||||||||||||||
| 764 | [% ELSE %] | ||||||||||||||||||||||||||||||||||||||||||
| 765 | <text class="yAxisTitle" transform="translate(15,[% (h / 2) + y %]) rotate(270)">[% config.y_title %]</text> | ||||||||||||||||||||||||||||||||||||||||||
| 766 | [% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 767 | [% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 768 | |||||||||||||||||||||||||||||||||||||||||||
| 769 | |||||||||||||||||||||||||||||||||||||||||||
| 770 | <!-- ////////////////////////////// SHOW DATA ////////////////////////////// --> | ||||||||||||||||||||||||||||||||||||||||||
| 771 | [% IF config.bar_gap %] | ||||||||||||||||||||||||||||||||||||||||||
| 772 | [% bar_gap = 10 %] | ||||||||||||||||||||||||||||||||||||||||||
| 773 | [% ELSE %] | ||||||||||||||||||||||||||||||||||||||||||
| 774 | [% bar_gap = 0 %] | ||||||||||||||||||||||||||||||||||||||||||
| 775 | [% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 776 | |||||||||||||||||||||||||||||||||||||||||||
| 777 | [% bar_width = dh - bar_gap %] | ||||||||||||||||||||||||||||||||||||||||||
| 778 | |||||||||||||||||||||||||||||||||||||||||||
| 779 | [% divider = dx / scale_division %] | ||||||||||||||||||||||||||||||||||||||||||
| 780 | |||||||||||||||||||||||||||||||||||||||||||
| 781 | [% xcount = 0 %] | ||||||||||||||||||||||||||||||||||||||||||
| 782 | |||||||||||||||||||||||||||||||||||||||||||
| 783 | [% FOREACH field = config.fields %] | ||||||||||||||||||||||||||||||||||||||||||
| 784 | [% dcount = 1 %] | ||||||||||||||||||||||||||||||||||||||||||
| 785 | |||||||||||||||||||||||||||||||||||||||||||
| 786 | [% FOREACH dataset = data %] | ||||||||||||||||||||||||||||||||||||||||||
| 787 | <path d="M[% x %] [% base_line - (dh * xcount) - dh %] H[% x + (dataset.data.$field * divider) %] v[% bar_width %] H[% x %] Z" class="fill[% dcount %]"/> | ||||||||||||||||||||||||||||||||||||||||||
| 788 | |||||||||||||||||||||||||||||||||||||||||||
| 789 | |||||||||||||||||||||||||||||||||||||||||||
| 790 | [% IF config.show_data_values %] | ||||||||||||||||||||||||||||||||||||||||||
| 791 | <text x="[% x + (dataset.data.$field * divider) + 5 %]" y="[% base_line - (dh * xcount) - dh + (dh / 2) %]" class="dataPointLabel" style="text-anchor: start;">[% dataset.data.$field %]</text> | ||||||||||||||||||||||||||||||||||||||||||
| 792 | [% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 793 | [% dcount = dcount + 1 %] | ||||||||||||||||||||||||||||||||||||||||||
| 794 | [% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 795 | [% xcount = xcount + 1 %] | ||||||||||||||||||||||||||||||||||||||||||
| 796 | [% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 797 | |||||||||||||||||||||||||||||||||||||||||||
| 798 | |||||||||||||||||||||||||||||||||||||||||||
| 799 | |||||||||||||||||||||||||||||||||||||||||||
| 800 | <!-- //////////////////////////////// KEY /////// ////////////////////////// --> | ||||||||||||||||||||||||||||||||||||||||||
| 801 | [% key_box_size = 12 %] | ||||||||||||||||||||||||||||||||||||||||||
| 802 | [% key_count = 1 %] | ||||||||||||||||||||||||||||||||||||||||||
| 803 | [% key_padding = 5 %] | ||||||||||||||||||||||||||||||||||||||||||
| 804 | [% IF config.key && config.key_position == 'right' %] | ||||||||||||||||||||||||||||||||||||||||||
| 805 | [% FOREACH dataset = data %] | ||||||||||||||||||||||||||||||||||||||||||
| 806 | <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 %]"/> | ||||||||||||||||||||||||||||||||||||||||||
| 807 | <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> | ||||||||||||||||||||||||||||||||||||||||||
| 808 | [% key_count = key_count + 1 %] | ||||||||||||||||||||||||||||||||||||||||||
| 809 | [% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 810 | [% ELSIF config.key && config.key_position == 'bottom' %] | ||||||||||||||||||||||||||||||||||||||||||
| 811 | <!-- calc y position of start of key --> | ||||||||||||||||||||||||||||||||||||||||||
| 812 | [% y_key = base_line %] | ||||||||||||||||||||||||||||||||||||||||||
| 813 | [% IF config.show_x_labels %][% y_key = base_line + 20 %][% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 814 | [% IF config.show_x_title %][% y_key = base_line + 25 %][% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 815 | [% y_key_start = y_key %] | ||||||||||||||||||||||||||||||||||||||||||
| 816 | [% x_key = x %] | ||||||||||||||||||||||||||||||||||||||||||
| 817 | [% FOREACH dataset = data %] | ||||||||||||||||||||||||||||||||||||||||||
| 818 | [% IF key_count == 4 || key_count == 7 || key_count == 10 %] | ||||||||||||||||||||||||||||||||||||||||||
| 819 | <!-- wrap key every 3 entries --> | ||||||||||||||||||||||||||||||||||||||||||
| 820 | [% x_key = x_key + 200 %] | ||||||||||||||||||||||||||||||||||||||||||
| 821 | [% y_key = y_key - (key_box_size * 4) - 2 %] | ||||||||||||||||||||||||||||||||||||||||||
| 822 | [% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 823 | <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 %]"/> | ||||||||||||||||||||||||||||||||||||||||||
| 824 | |||||||||||||||||||||||||||||||||||||||||||
| 825 | <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> | ||||||||||||||||||||||||||||||||||||||||||
| 826 | [% key_count = key_count + 1 %] | ||||||||||||||||||||||||||||||||||||||||||
| 827 | [% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 828 | |||||||||||||||||||||||||||||||||||||||||||
| 829 | [% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 830 | |||||||||||||||||||||||||||||||||||||||||||
| 831 | <!-- //////////////////////////////// MAIN TITLES ////////////////////////// --> | ||||||||||||||||||||||||||||||||||||||||||
| 832 | |||||||||||||||||||||||||||||||||||||||||||
| 833 | <!-- main graph title --> | ||||||||||||||||||||||||||||||||||||||||||
| 834 | [% IF config.show_graph_title %] | ||||||||||||||||||||||||||||||||||||||||||
| 835 | <text x="[% config.width / 2 %]" y="15" class="mainTitle">[% config.graph_title %]</text> | ||||||||||||||||||||||||||||||||||||||||||
| 836 | [% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 837 | |||||||||||||||||||||||||||||||||||||||||||
| 838 | <!-- graph sub title --> | ||||||||||||||||||||||||||||||||||||||||||
| 839 | [% IF config.show_graph_subtitle %] | ||||||||||||||||||||||||||||||||||||||||||
| 840 | [% IF config.show_graph_title %] | ||||||||||||||||||||||||||||||||||||||||||
| 841 | [% y_subtitle = 30 %] | ||||||||||||||||||||||||||||||||||||||||||
| 842 | [% ELSE %] | ||||||||||||||||||||||||||||||||||||||||||
| 843 | [% y_subtitle = 15 %] | ||||||||||||||||||||||||||||||||||||||||||
| 844 | [% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 845 | <text x="[% config.width / 2 %]" y="[% y_subtitle %]" class="subTitle">[% config.graph_subtitle %]</text> | ||||||||||||||||||||||||||||||||||||||||||
| 846 | [% END %] | ||||||||||||||||||||||||||||||||||||||||||
| 847 | </svg> | ||||||||||||||||||||||||||||||||||||||||||