SVG-TT-Graph-0.21/0000755000175000017500000000000011756545130013706 5ustar flofloooflofloooSVG-TT-Graph-0.21/lib/0000755000175000017500000000000011756545130014454 5ustar flofloooflofloooSVG-TT-Graph-0.21/lib/SVG/0000755000175000017500000000000011756545130015113 5ustar flofloooflofloooSVG-TT-Graph-0.21/lib/SVG/TT/0000755000175000017500000000000011756545130015442 5ustar flofloooflofloooSVG-TT-Graph-0.21/lib/SVG/TT/Graph/0000755000175000017500000000000011756545130016503 5ustar flofloooflofloooSVG-TT-Graph-0.21/lib/SVG/TT/Graph/Pie.pm0000755000175000017500000005441511756370174017576 0ustar floflooofloflooopackage SVG::TT::Graph::Pie; use strict; use Carp; use SVG::TT::Graph; use base qw(SVG::TT::Graph); use vars qw($VERSION $TEMPLATE_FH); $VERSION = $SVG::TT::Graph::VERSION; $TEMPLATE_FH = \*DATA; =head1 NAME SVG::TT::Graph::Pie - Create presentation quality SVG pie graphs easily =head1 SYNOPSIS use SVG::TT::Graph::Pie; my @fields = qw(Jan Feb Mar); my @data_sales_02 = qw(12 45 21); my $graph = SVG::TT::Graph::Pie->new({ 'height' => '500', 'width' => '300', 'fields' => \@fields, }); $graph->add_data({ 'data' => \@data_sales_02, 'title' => 'Sales 2002', }); print "Content-type: image/svg+xml\n\n"; print $graph->burn(); =head1 DESCRIPTION This object aims to allow you to easily create high quality SVG pie graphs. You can either use the default style sheet or supply your own. Either way there are many options which can be configured to give you control over how the graph is generated - with or without a key, display percent on pie chart, title, subtitle etc. =head1 METHODS =head2 new() use SVG::TT::Graph::Pie; # Field names along the X axis my @fields = qw(Jan Feb Mar); my $graph = SVG::TT::Graph::Pie->new({ # Required 'fields' => \@fields, # Optional - defaults shown 'height' => '500', 'width' => '300', 'show_graph_title' => 0, 'graph_title' => 'Graph Title', 'show_graph_subtitle' => 0, 'graph_subtitle' => 'Graph Sub Title', 'show_shadow' => 1, 'shadow_size' => 1, 'shadow_offset' => 15, 'key_placement' => 'R', # data by pie chart wedges: 'show_data_labels' => 0, 'show_actual_values' => 0, 'show_percent' => 1, 'rollover_values' => 0, # data on key: 'show_key_data_labels' => 1, 'show_key_actual_values' => 1, 'show_key_percent' => 0, 'expanded' => 0, 'expand_greatest' => 0, # Stylesheet defaults 'style_sheet' => '/includes/graph.css', # internal stylesheet 'style_sheet_field_names' => 0, 'random_colors' => 0, }); The constructor takes a hash reference, fields (the name for each slice on the pie) MUST be set, all other values are defaulted to those shown above - with the exception of style_sheet which defaults to using the internal style sheet. =head2 add_data() my @data_sales_02 = qw(12 45 21); $graph->add_data({ 'data' => \@data_sales_02, 'title' => 'Sales 2002', }); This method allows you to add data to the graph object, only the first data set added will be used! =head2 clear_data() my $graph->clear_data(); This method removes all data from the object so that you can reuse it to create a new graph but with the same config options. =head2 burn() print $graph->burn(); This method processes the template with the data and config which has been set and returns the resulting SVG. This method will croak unless at least one data set has been added to the graph object. =head2 config methods my $value = $graph->method(); my $confirmed_new_value = $graph->method($value); The following is a list of the methods which are available to change the config of the graph object after it has been created. =over 4 =item height() Set the height of the graph box, this is the total height of the SVG box created - not the graph it self which auto scales to fix the space. =item width() Set the width of the graph box, this is the total width of the SVG box created - not the graph it self which auto scales to fix the space. =item compress() Whether or not to compress the content of the SVG file (Compress::Zlib required). =item tidy() Whether or not to tidy the content of the SVG file (XML::Tidy required). =item style_sheet() Set the path to an external stylesheet, set to '' if you want to revert back to using the defaut internal version. The default stylesheet handles up to 12 data sets. All data series over the 12th will have no style and be in black. If you have over 12 data sets you can assign them all random colors (see the random_color() method) or create your own stylesheet and add the additional settings for the extra data sets. To create an external stylesheet create a graph using the default internal version and copy the stylesheet section to an external file and edit from there. =item random_colors() Use random colors in the internal stylesheet =item style_sheet_field_names() If you use the style_sheet_field_names() option then you can use the field names within your stylesheet. This allows consistent use of styles. The names should be: =over 4 =item _dataPoint =item _key =back =item show_graph_title() Whether to show a title on the graph, default is '0'. =item graph_title() What the title on the graph should be. =item show_graph_subtitle() Whether to show a subtitle on the graph, default is '0'. =item graph_subtitle() What the subtitle on the graph should be. =item show_shadow() Turn the shadow on and off, default to '1', set to '0' if you don't want it. It is automatically turned off if you extract one section of the pie. =item shadow_size() Size of the shadow if shown, measured as percentage of pie chart radius, default of 1 being the same size as the pie. =item shadow_offset() Offset (in pixels) of shadow to bottom-right in relation to the center of the pie chart. =item key() Whether to show a key, defaults to 0, set to '1' if you want to show it. =item key_placement() Defaults to 'R' - right, can be 'R', 'L', 'T' or 'B'. =item show_data_labels() Show label on pie chart, defaults to '0', can be set to '1'. =item show_actual_values() Show values on pie chart, defaults to '0', can be set to '1'. =item show_percent() Show percent (rounded) on the pie chart, defaults to '1', can be set to '0'. =item rollover_values() Shows data field and value when the mouse is over a piechart wedge. =item show_key_data_labels() Show label on the key, defaults to '1', can be set to '0'. =item show_key_actual_values() Show value on the key, defaults to '1', can be set to '0'. =item show_key_percent() Show percent (rounded) on the key, defaults to '0', can be set to '1'. =item expanded() All slices of pie are exploded out, defaults to '0'. Do not set to '1' if you are going to use expanded_greatest(). =item expand_greatest() The largest slice of pie is exploded out from the pie, defaults to '0'. Useful if you are only showing the percentages (which are rounded) but still want to visually show which slice was largest. Do not set to '1' if you are going to use expanded(). =back =head1 EXAMPLES For examples look at the project home page http://leo.cuckoo.org/projects/SVG-TT-Graph/ =head1 EXPORT None by default. =head1 ACKNOWLEDGEMENTS Thanks to Foxtons for letting us put this on CPAN, Todd Caine for heads up on reparsing the template (but not using atm), David Meibusch for TimeSeries and a load of other ideas, Stephen Morgan for creating the TT template and SVG, and thanks for all the patches by Andrew Ruthven and others. =head1 AUTHOR Leo Lapworth =head1 MAINTAINER Florent Angly =head1 COPYRIGHT AND LICENSE Copyright (C) 2003, Leo Lapworth This module is free software; you can redistribute it or modify it under the same terms as Perl itself. =head1 BUGS Please report any bugs or feature requests to bug-graph-svg-tt@rt.cpan.org, or through the web interface at http://rt.cpan.org. The Graph::SVG::TT development repository is located on GitHub at L. Get the latest development version using: git clone git://github.com/ranguard/svg-tt-graph.git =head1 SEE ALSO L, L, L, L, L, L, L, L, L =cut sub _init { my $self = shift; croak "fields was not supplied or is empty" unless defined $self->{'config'}->{fields} && ref($self->{'config'}->{fields}) eq 'ARRAY' && scalar(@{$self->{'config'}->{fields}}) > 0; } sub _set_defaults { my $self = shift; my %default = ( 'width' => '500', 'height' => '300', 'style_sheet' => '', 'style_sheet_field_names' => 0, 'random_colors' => 0, 'show_graph_title' => 0, 'graph_title' => 'Graph Title', 'show_graph_subtitle' => 0, 'graph_subtitle' => 'Graph Sub Title', 'show_shadow' => 1, 'shadow_size' => 1, 'shadow_offset' => 15, 'key_placement' => 'R', 'show_data_labels' => 0, 'show_actual_values' => 0, 'show_percent' => 1, 'rollover_values' => 0, 'key' => 0, 'show_key_data_labels' => 1, 'show_key_actual_values' => 1, 'show_key_percent' => 0, 'expanded' => 0, 'expand_greatest' => 0, ); while( my ($key,$value) = each %default ) { $self->{config}->{$key} = $value; } } 1; __DATA__ [% stylesheet = 'included' %] [% IF config.style_sheet && config.style_sheet != '' %] [% ELSE %] [% stylesheet = 'excluded' %] [% END %] [% IF stylesheet == 'excluded' %] [% END %] [% IF config.rollover_values %] [% END %] [% w = config.width %] [% h = config.height %] [% Pi = 3.14159 %] [% total = 0 %] [% count = 0 %] [% min_value = 99999999999 %] [% max_value = 0 %] [% FOREACH field = config.fields %] [% total = total + data.0.data.$field %] [% count = count + 1 %] [% IF min_value > data.0.data.$field && data.0.data.$field != '' %] [% min_value = data.0.data.$field %] [% END %] [% IF max_value < data.0.data.$field && data.0.data.$field != '' %] [% max_value = data.0.data.$field %] [% END %] [% END %] [% IF config.show_graph_title %][% h = h - 25 %][% END %] [% IF config.show_graph_subtitle %][% y = y + 10 %][% END %] [% IF config.show_graph_subtitle %][% y = y + 10 %][% END %] [% x = w / 2 %] [% y = h / 2 %] [% IF config.show_graph_title %][% y = y + 15 %][% END %] [% IF config.show_graph_subtitle %][% y = y + 10 %][% END %] [% padding = 30 %] [% IF w >= h %] [% r = (h / 2) - padding %] [% IF config.key %] [% key_position = 'h' %] [% x_key_start = 30 %] [% IF config.key_placement == 'R' %] [% x = x - r / 3 %] [% IF x < r %] [% r = r - (w / 8) %] [% END %] [% ELSE %] [% x = x + r / 3 %] [% IF r > (w - x) && x > (w / 2) %] [% r = r - (w / 8) %] [% END %] [% END %] [% END %] [% ELSE %] [% r = (w / 2) - padding %] [% IF config.key %] [% key_position = 'v' %] [% y_key_start = 40 %] [% IF config.key_placement == 'B' %] [% y = y - (r / 2) %] [% IF y < r %] [% r = r - (h / 8) %] [% END %] [% ELSE %] [% y = y + (r / 2) %] [% IF r > (h - y) && y > (h / 2) %] [% r = r - (h / 8) %] [% END %] [% END %] [% END %] [% END %] [% IF config.expanded OR config.expand_greatest %] [% e = 10 %] [% ELSE %] [% e = 0 %] [% END %] [% IF config.show_shadow %] [% IF config.shadow_size && config.shadow_size != '' %] [% shadow_size = r + ((r / 100) * config.shadow_size) %] [% ELSE %] [% shadow_size = r %] [% END %] [% IF !config.expanded && !config.expand_greatest %] [% END %] [% END %] [% px_start = x + r %] [% pmin_scale_value = y %] [% values = 0 %] [% values_half = 0 %] [% last_value_half = 0 %] [% IF config.show_percent && config.show_data_labels %] [% wedge_text_pad = 20 %] [% ELSE %] [% wedge_text_pad = 5 %] [% END %] [% count = 1 %] [% FOREACH field = config.fields %] [% FOREACH dataset = data %] [% value = data.0.data.$field %] [% value_half = data.0.data.$field / 2 %] [% percent = (100 / total) * value FILTER format('%2.0f')%] [% values = values + value %] [% IF count == 1 %] [% values_half = values_half + value_half %] [% ELSE %] [% values_half = values_half + last_value_half + value_half %] [% END %] [% degrees = (values / total) * 360 %] [% degrees_half = (values_half / total) * 360 %] [% radians = degrees * (Pi / 180) %] [% radians_half = degrees_half * (Pi / 180) %] [% px_end = r * cos(radians) FILTER format('%02.10f') %] [% py_end = r * sin(radians) FILTER format('%02.10f') %] [% px_mid = r * cos(radians_half) FILTER format('%02.10f') %] [% py_mid = r * sin(radians_half) FILTER format('%02.10f') %] [% IF config.expanded && !config.expand_greatest %] [% re = r / e %] [% xe = re * cos(radians_half) FILTER format('%02.10f') %] [% ye = re * sin(radians_half) FILTER format('%02.10f') %] [% ELSIF !config.expanded && config.expand_greatest %] [% IF data.0.data.$field == max_value %] [% re = r / e %] [% xe = re * cos(radians_half) FILTER format('%02.10f') %] [% ye = re * sin(radians_half) FILTER format('%02.10f') %] [% ELSE %] [% END %] [% ELSE %] [% END %] [% text_x_offset = 0 %] [% text_y_offset = 0 %] [% IF px_mid >= x && px_mid <= y %] [% text_x_offset = wedge_text_pad %] [% text_y_offset = wedge_text_pad %] [% ELSIF px_mid <= x && py_mid <= y %] [% text_x_offset = 0-wedge_text_pad %] [% text_y_offset = wedge_text_pad %] [% ELSIF px_mid <= x && py_mid >= y %] [% text_x_offset = wedge_text_pad %] [% text_y_offset = 0-wedge_text_pad %] [% ELSE %] [% text_x_offset = 0-wedge_text_pad %] [% text_y_offset = 0-wedge_text_pad %] [% END %] [% IF config.show_data_labels %][% field %][% END %][% IF config.show_actual_values %][[% data.0.data.$field %]][% END %][% IF config.show_percent %][% percent %]%[% END %] [% IF config.rollover_values %] [% field %] [% END %] [% px_start = x + px_end %] [% pmin_scale_value = y + py_end %] [% last_value_half = value_half %] [% count = count + 1 %] [% END %] [% END %] [% IF config.key %] [% key_box_size = 12 %] [% key_count = 1 %] [% key_padding = 5 %] [% x_off = 0 %] [% y_off = 0 %] [% IF key_position == 'h' %] [% IF config.key_placement == 'R' %] [% x_off = x + r + x_key_start %] [% y_off = (y - r) %] [% ELSE %] [% x_off = x_key_start %] [% y_off = (y - r) %] [% END %] [% ELSIF key_position == 'v' %] [% IF w < h && config.key_placement == 'R' OR config.key_placement == 'L' %] [% config.key_placement = 'T' %] [% END %] [% y_key = padding %] [% x_key = padding %] [% IF key_count == 7 || key_count == 13 %] [% x_key = x_key + (w / 3) %] [% y_key = y_key - (key_box_size * 8) - 6 %] [% END %] [% IF config.key_placement == 'T' %] [% x_off = x_key %] [% y_off = y_key %] [% ELSE %] [% x_off = x_key %] [% y_off = (r * 2) + (padding * 2) + y_key %] [% END %] [% END %] [% FOREACH field = config.fields %] [% percent = (100 / total) * data.0.data.$field FILTER format('%2.0f')%] [% 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 %] [% key_count = key_count + 1 %] [% END %] [% END %] [% IF config.show_graph_title %] [% config.graph_title %] [% END %] [% IF config.show_graph_subtitle %] [% IF config.show_graph_title %] [% y_subtitle = 30 %] [% ELSE %] [% y_subtitle = 15 %] [% END %] [% config.graph_subtitle %] [% END %] SVG-TT-Graph-0.21/lib/SVG/TT/Graph/Bar.pm0000755000175000017500000006266711756370226017573 0ustar floflooofloflooopackage SVG::TT::Graph::Bar; use strict; use Carp; use SVG::TT::Graph; use base qw(SVG::TT::Graph); use vars qw($VERSION $TEMPLATE_FH); $VERSION = $SVG::TT::Graph::VERSION; $TEMPLATE_FH = \*DATA; =head1 NAME SVG::TT::Graph::Bar - Create presentation quality SVG bar graphs easily =head1 SYNOPSIS use SVG::TT::Graph::Bar; my @fields = qw(Jan Feb Mar); my @data_sales_02 = qw(12 45 21); my $graph = SVG::TT::Graph::Bar->new({ 'height' => '500', 'width' => '300', 'fields' => \@fields, }); $graph->add_data({ 'data' => \@data_sales_02, 'title' => 'Sales 2002', }); print "Content-type: image/svg+xml\n\n"; print $graph->burn(); =head1 DESCRIPTION This object aims to allow you to easily create high quality SVG bar graphs. You can either use the default style sheet or supply your own. Either way there are many options which can be configured to give you control over how the graph is generated - with or without a key, data elements at each point, title, subtitle etc. =head1 METHODS =head2 new() use SVG::TT::Graph::Bar; # Field names along the X axis my @fields = qw(Jan Feb Mar); my $graph = SVG::TT::Graph::Bar->new({ # Required 'fields' => \@fields, # Optional - defaults shown 'height' => '500', 'width' => '300', 'show_data_values' => 1, 'min_scale_value' => '0', 'max_scale_value' => undef, 'stagger_x_labels' => 0, 'rotate_x_labels' => 0, 'bar_gap' => 1, 'show_x_labels' => 1, 'show_y_labels' => 1, 'scale_integers' => 0, 'scale_divisions' => '', 'y_label_formatter' => sub { return @_ }, 'x_label_formatter' => sub { return @_ }, 'show_x_title' => 0, 'x_title' => 'X Field names', 'show_y_title' => 0, 'y_title_text_direction' => 'bt', 'y_title' => 'Y Scale', 'show_graph_title' => 0, 'graph_title' => 'Graph Title', 'show_graph_subtitle' => 0, 'graph_subtitle' => 'Graph Sub Title', 'key' => 0, 'key_position' => 'right', # Stylesheet defaults 'style_sheet' => '/includes/graph.css', # internal stylesheet 'random_colors' => 0, }); The constructor takes a hash reference, fields (the names for each field on the X axis) MUST be set, all other values are defaulted to those shown above - with the exception of style_sheet which defaults to using the internal style sheet. =head2 add_data() my @data_sales_02 = qw(12 45 21); $graph->add_data({ 'data' => \@data_sales_02, 'title' => 'Sales 2002', }); This method allows you to add data to the graph object. It can be called several times to add more data sets in, but the likelihood is you should be using SVG::TT::Graph::Line as it won't look great! =head2 clear_data() my $graph->clear_data(); This method removes all data from the object so that you can reuse it to create a new graph but with the same config options. =head2 burn() print $graph->burn(); This method processes the template with the data and config which has been set and returns the resulting SVG. This method will croak unless at least one data set has been added to the graph object. =head2 config methods my $value = $graph->method(); my $confirmed_new_value = $graph->method($value); The following is a list of the methods which are available to change the config of the graph object after it has been created. =over 4 =item height() Set the height of the graph box, this is the total height of the SVG box created - not the graph it self which auto scales to fix the space. =item width() Set the width of the graph box, this is the total width of the SVG box created - not the graph it self which auto scales to fix the space. =item compress() Whether or not to compress the content of the SVG file (Compress::Zlib required). =item tidy() Whether or not to tidy the content of the SVG file (XML::Tidy required). =item style_sheet() Set the path to an external stylesheet, set to '' if you want to revert back to using the defaut internal version. The default stylesheet handles up to 12 data sets. All data series over the 12th will have no style and be in black. If you have over 12 data sets you can assign them all random colors (see the random_color() method) or create your own stylesheet and add the additional settings for the extra data sets. To create an external stylesheet create a graph using the default internal version and copy the stylesheet section to an external file and edit from there. =item random_colors() Use random colors in the internal stylesheet =item show_data_values() Show the value of each element of data on the graph =item bar_gap() Whether to have a gap between the bars or not, default is '1', set to '0' if you don't want gaps. =item min_scale_value() The point at which the Y axis starts, defaults to '0', if set to '' it will default to the minimum data value. =item max_scale_value() The maximum value for the Y axis. If set to '', it will default to the maximum data value. =item show_x_labels() Whether to show labels on the X axis or not, defaults to 1, set to '0' if you want to turn them off. =item stagger_x_labels() This puts the labels at alternative levels so if they are long field names they will not overlap so easily. Default it '0', to turn on set to '1'. =item rotate_x_labels() This turns the X axis labels by 90 degrees. Default it '0', to turn on set to '1'. =item show_y_labels() Whether to show labels on the Y axis or not, defaults to 1, set to '0' if you want to turn them off. =item scale_integers() Ensures only whole numbers are used as the scale divisions. Default it '0', to turn on set to '1'. This has no effect if scale divisions are less than 1. =item scale_divisions() This defines the gap between markers on the Y axis, default is a 10th of the max_value, e.g. you will have 10 markers on the Y axis. NOTE: do not set this too low - you are limited to 999 markers, after that the graph won't generate. =item show_x_title() Whether to show the title under the X axis labels, default is 0, set to '1' to show. =item x_title() What the title under X axis should be, e.g. 'Months'. =item show_y_title() Whether to show the title under the Y axis labels, default is 0, set to '1' to show. =item y_title_text_direction() Aligns writing mode for Y axis label. Defaults to 'bt' (Bottom to Top). Change to 'tb' (Top to Bottom) to reverse. =item y_title() What the title under Y axis should be, e.g. 'Sales in thousands'. =item show_graph_title() Whether to show a title on the graph, defaults to 0, set to '1' to show. =item graph_title() What the title on the graph should be. =item show_graph_subtitle() Whether to show a subtitle on the graph, defaults to 0, set to '1' to show. =item graph_subtitle() What the subtitle on the graph should be. =item key() Whether to show a key, defaults to 0, set to '1' if you want to show it. =item key_position() Where the key should be positioned, defaults to 'right', set to 'bottom' if you want to move it. =item x_label_formatter () A callback subroutine which will format a label on the x axis. For example: $graph->x_label_formatter( sub { return '$' . $_[0] } ); =item y_label_formatter() A callback subroutine which will format a label on the y axis. For example: $graph->y_label_formatter( sub { return '$' . $_[0] } ); =back =head1 EXAMPLES For examples look at the project home page http://leo.cuckoo.org/projects/SVG-TT-Graph/ =head1 EXPORT None by default. =head1 ACKNOWLEDGEMENTS Thanks to Foxtons for letting us put this on CPAN, Todd Caine for heads up on reparsing the template (but not using atm), David Meibusch for TimeSeries and a load of other ideas, Stephen Morgan for creating the TT template and SVG, and thanks for all the patches by Andrew Ruthven and others. =head1 AUTHOR Leo Lapworth (LLAP@cuckoo.org) =head1 MAINTAINER Florent Angly =head1 COPYRIGHT AND LICENSE Copyright (C) 2003, Leo Lapworth This module is free software; you can redistribute it or modify it under the same terms as Perl itself. =head1 BUGS Please report any bugs or feature requests to bug-graph-svg-tt@rt.cpan.org, or through the web interface at http://rt.cpan.org. The Graph::SVG::TT development repository is located on GitHub at L. Get the latest development version using: git clone git://github.com/ranguard/svg-tt-graph.git =head1 SEE ALSO L, L, L, L, L, L, L, L, L =cut sub _init { my $self = shift; croak "fields was not supplied or is empty" unless defined $self->{'config'}->{fields} && ref($self->{'config'}->{fields}) eq 'ARRAY' && scalar(@{$self->{'config'}->{fields}}) > 0; } sub _set_defaults { my $self = shift; my %default = ( 'width' => '500', 'height' => '300', 'style_sheet' => '', 'random_colors' => 0, 'show_data_values' => 1, 'min_scale_value' => '0', 'max_scale_value' => '', 'scale_divisions' => '', 'bar_gap' => 1, 'show_x_labels' => 1, 'stagger_x_labels' => 0, 'rotate_x_labels' => 0, 'x_label_formatter' => sub { return @_ }, 'y_label_formatter' => sub { return @_ }, 'show_y_labels' => 1, 'scale_integers' => 0, 'show_x_title' => 0, 'x_title' => 'X Field names', 'show_y_title' => 0, 'y_title_text_direction' => 'bt', 'y_title' => 'Y Scale', 'show_graph_title' => 0, 'graph_title' => 'Graph Title', 'show_graph_subtitle' => 0, 'graph_subtitle' => 'Graph Sub Title', 'key' => 0, 'key_position' => 'right', # bottom or right ); while( my ($key,$value) = each %default ) { $self->{config}->{$key} = $value; } } 1; __DATA__ [% stylesheet = 'included' %] [% IF config.style_sheet && config.style_sheet != '' %] [% ELSE %] [% stylesheet = 'excluded' %] [% END %] [% IF stylesheet == 'excluded' %] [% END %] [% w = config.width %] [% h = config.height %] [% x = 0 %] [% y = 0 %] [% char_width = 9 %] [% half_char_height = 2.5 %] [% min_value = 99999999999 %] [% max_value = 0 %] [% max_key_size = 0 %] [% max_x_label_size = 0 %] [% FOREACH field = config.fields %] [% IF max_x_label_size < field.length %] [% max_x_label_size = field.length %] [% END %] [% max_y_value = 0 %] [% FOREACH dataset = data %] [% IF dataset.data.$field != '' %] [% max_y_value = max_y_value + dataset.data.$field %] [% END %] [% IF dataset.title %] [% IF max_key_size < dataset.title.length %] [% max_key_size = dataset.title.length %] [% END %] [% END %] [% END %] [% IF min_value > max_y_value %] [% min_value = max_y_value %] [% END %] [% IF max_value < max_y_value %] [% max_value = max_y_value %] [% END %] [% END %] [% IF config.show_x_labels %][% h = h - 20 %][% END %] [% max_x_label_length = 0 %] [% IF config.rotate_x_labels %] [% max_x_label_length = max_x_label_size * char_width %] [% h = h - max_x_label_length %] [% END %] [% stagger = 0 %] [% IF config.stagger_x_labels %] [% stagger = 17 %] [% h = h - stagger %] [% END %] [% IF config.show_x_title %][% h = h - 25 - stagger %][% END %] [% IF config.show_y_labels %][% h = h - 10 %][% y = y + 10 %][% END %] [% IF config.show_graph_title %][% h = h - 25 %][% y = y + 25 %][% END %] [% IF config.show_graph_subtitle %][% h = h - 10 %][% y = y + 10 %][% END %] [% key_box_size = 12 %] [% key_padding = 5 %] [% IF config.key && config.key_position == 'right' %] [% w = w - (max_key_size * (char_width - 1)) - (key_box_size * 3 ) %] [% ELSIF config.key && config.key_position == 'bottom' %] [% IF data.size < 4 %] [% h = h - ((data.size + 1) * (key_box_size + key_padding))%] [% ELSE %] [% h = h - (4 * (key_box_size + key_padding))%] [% END %] [% END %] [% IF config.min_scale_value || config.min_scale_value == '0' %] [% min_scale_value = config.min_scale_value %] [% ELSE %] [% min_scale_value = min_value %] [% END %] [% IF config.max_scale_value || config.max_scale_value == '0' %] [% max_scale_value = config.max_scale_value %] [% ELSE %] [% max_scale_value = max_value %] [% END %] [% base_line = h + y %] [% IF (max_scale_value - min_scale_value) == 0 %] [% top_pad = 10 %] [% ELSE %] [% top_pad = (max_scale_value - min_scale_value) / 20 %] [% END %] [% scale_range = (max_scale_value + top_pad) - min_scale_value %] [% IF config.scale_divisions %] [% scale_division = config.scale_divisions %] [% ELSE %] [% scale_division = scale_range / 10 FILTER format('%2.01f') %] [% END %] [% IF config.scale_integers %] [% IF scale_division < 1 %] [% scale_division = 1 %] [% ELSIF scale_division.match('.') %] [% scale_division = scale_division FILTER format('%2.0f') %] [% END %] [% END %] [% dx = config.fields.size %] [% data_widths_x = w / dx %] [% dw = data_widths_x FILTER format('%2.02f') %] [% half_label_width = (config.fields.0.length / 2) * char_width %] [% space_b4_y_axis = 0 %] [% IF half_label_width > (dw / 2) %] [% space_b4_y_axis = half_label_width - (dw / 2) %] [% IF config.key && config.key_position == 'right' %] [% w = w - space_b4_y_axis %] [% ELSE %] [% w = w - (space_b4_y_axis * 2) %] [% END %] [% x = x + space_b4_y_axis %] [% END %] [% max_value_length = max_value.length %] [% max_value_length_px = max_value_length * char_width %] [% IF config.show_y_labels && space_b4_y_axis < max_value_length_px %] [% IF max_value_length < 2 %] [% w = w - (max_value_length * (char_width * 2)) - char_width %] [% x = x + (max_value_length * (char_width * 2)) + char_width %] [% ELSE %] [% w = w - max_value_length_px + char_width %] [% x = x + max_value_length_px + char_width %] [% END %] [% END %] [% IF config.show_y_title && space_b4_y_axis < max_value_length_px %] [% w = w - 25 %] [% x = x + 25 %] [% END %] [% dx = config.fields.size %] [% data_widths_x = w / dx %] [% dw = data_widths_x.match('(\d+[\.\d\d])').0 %] [% i = dw %] [% count = 0 %] [% IF config.bar_gap %] [% bar_gap = 10 %] [% IF dw < bar_gap %] [% bar_gap = dw / 2 %] [% END %] [% ELSE %] [% bar_gap = 0 %] [% END %] [% stagger_count = 0 %] [% IF config.show_x_labels %] [% FOREACH field = config.fields %] [% field_txt = config.x_label_formatter(field) %] [% IF count == 0 %] [% field_txt %] [% i = i - dw %] [% ELSE %] [% IF stagger_count == 2 %] [% field_txt %] [% stagger_count = 0 %] [% ELSE %] [% field_txt %] [% END %] [% END %] [% i = i + dw %] [% count = count + 1 %] [% stagger_count = stagger_count + 1 %] [% END %] [% END %] [% dy = scale_range / scale_division %] [% y_marker_height = h / dy %] [% dy = y_marker_height.match('(\d+[\.\d\d])').0 %] [% count = 0 %] [% y_value = min_scale_value %] [% IF config.show_y_labels %] [% WHILE (dy * count) < h %] [% y_value_txt = config.y_label_formatter(y_value) %] [% IF count == 0 %] [% y_value_txt %] [% ELSE %] [% y_value_txt %] [% END %] [% y_value = y_value + scale_division %] [% count = count + 1 %] [% END %] [% END %] [% IF config.show_x_title %] [% IF !config.show_x_labels %] [% y_xtitle = 15 %] [% ELSE %] [% y_xtitle = 35 %] [% END %] [% config.x_title %] [% END %] [% IF config.show_y_title %] [% IF config.y_title_text_direction == 'tb' %] [% config.y_title %] [% ELSE %] [% config.y_title %] [% END %] [% END %] [% bar_width = dw - bar_gap %] [% divider = dy / scale_division %] [% xcount = 0 %] [% FOREACH field = config.fields %] [% dcount = 1 %] [% start_x = base_line %] [% FOREACH dataset = data %] [% IF config.show_data_values %] [% dataset.data.$field %] [% END %] [% start_x = start_x - (dataset.data.$field * divider) %] [% dcount = dcount + 1 %] [% END %] [% xcount = xcount + 1 %] [% END %] [% key_count = 1 %] [% key_padding = 5 %] [% IF config.key && config.key_position == 'right' %] [% FOREACH dataset = data %] [% dataset.title %] [% key_count = key_count + 1 %] [% END %] [% ELSIF config.key && config.key_position == 'bottom' %] [% y_key = base_line %] [% IF config.show_x_title %][% y_key = y_key + 25 %][% END %] [% IF config.rotate_x_labels && config.show_x_labels %] [% y_key = y_key + max_x_label_length %] [% ELSIF config.show_x_labels && stagger < 1 %] [% y_key = y_key + 20 %] [% END %] [% y_key_start = y_key %] [% x_key = x %] [% FOREACH dataset = data %] [% IF key_count == 4 || key_count == 7 || key_count == 10 %] [% x_key = x_key + 200 %] [% y_key = y_key - (key_box_size * 4) - 2 %] [% END %] [% dataset.title %] [% key_count = key_count + 1 %] [% END %] [% END %] [% IF config.show_graph_title %] [% config.graph_title %] [% END %] [% IF config.show_graph_subtitle %] [% IF config.show_graph_title %] [% y_subtitle = 30 %] [% ELSE %] [% y_subtitle = 15 %] [% END %] [% config.graph_subtitle %] [% END %] SVG-TT-Graph-0.21/lib/SVG/TT/Graph/Line.pm0000755000175000017500000006453511756370241017747 0ustar floflooofloflooopackage SVG::TT::Graph::Line; use strict; use Carp; use SVG::TT::Graph; use base qw(SVG::TT::Graph); use vars qw($VERSION $TEMPLATE_FH); $VERSION = $SVG::TT::Graph::VERSION; $TEMPLATE_FH = \*DATA; =head1 NAME SVG::TT::Graph::Line - Create presentation quality SVG line graphs easily =head1 SYNOPSIS use SVG::TT::Graph::Line; my @fields = qw(Jan Feb Mar); my @data_sales_02 = qw(12 45 21); my @data_sales_03 = qw(15 30 40); my $graph = SVG::TT::Graph::Line->new({ 'height' => '500', 'width' => '300', 'fields' => \@fields, }); $graph->add_data({ 'data' => \@data_sales_02, 'title' => 'Sales 2002', }); $graph->add_data({ 'data' => \@data_sales_03, 'title' => 'Sales 2003', }); print "Content-type: image/svg+xml\n\n"; print $graph->burn(); =head1 DESCRIPTION This object aims to allow you to easily create high quality SVG line graphs. You can either use the default style sheet or supply your own. Either way there are many options which can be configured to give you control over how the graph is generated - with or without a key, data elements at each point, title, subtitle etc. =head1 METHODS =head2 new() use SVG::TT::Graph::Line; # Field names along the X axis my @fields = qw(Jan Feb Mar); my $graph = SVG::TT::Graph::Line->new({ # Required 'fields' => \@fields, # Optional - defaults shown 'height' => '500', 'width' => '300', 'show_data_points' => 1, 'show_data_values' => 1, 'stacked' => 0, 'min_scale_value' => '0', 'max_scale_value' => undef, 'area_fill' => 0, 'show_x_labels' => 1, 'stagger_x_labels' => 0, 'rotate_x_labels' => 0, 'show_y_labels' => 1, 'scale_integers' => 0, 'scale_divisions' => '20', 'y_label_formatter' => sub { return @_ }, 'x_label_formatter' => sub { return @_ }, 'show_x_title' => 0, 'x_title' => 'X Field names', 'show_y_title' => 0, 'y_title_text_direction' => 'bt', 'y_title' => 'Y Scale', 'show_graph_title' => 0, 'graph_title' => 'Graph Title', 'show_graph_subtitle' => 0, 'graph_subtitle' => 'Graph Sub Title', 'key' => 0, 'key_position' => 'right', # Stylesheet defaults 'style_sheet' => '/includes/graph.css', # internal stylesheet 'random_colors' => 0, }); The constructor takes a hash reference, fields (the names for each field on the X axis) MUST be set, all other values are defaulted to those shown above - with the exception of style_sheet which defaults to using the internal style sheet. =head2 add_data() my @data_sales_02 = qw(12 45 21); $graph->add_data({ 'data' => \@data_sales_02, 'title' => 'Sales 2002', }); This method allows you to add data to the graph object. It can be called several times to add more data sets in. =head2 clear_data() my $graph->clear_data(); This method removes all data from the object so that you can reuse it to create a new graph but with the same config options. =head2 burn() print $graph->burn(); This method processes the template with the data and config which has been set and returns the resulting SVG. This method will croak unless at least one data set has been added to the graph object. =head2 config methods my $value = $graph->method(); my $confirmed_new_value = $graph->method($value); The following is a list of the methods which are available to change the config of the graph object after it has been created. =over 4 =item height() Set the height of the graph box, this is the total height of the SVG box created - not the graph it self which auto scales to fix the space. =item width() Set the width of the graph box, this is the total height of the SVG box created - not the graph it self which auto scales to fix the space. =item compress() Whether or not to compress the content of the SVG file (Compress::Zlib required). =item tidy() Whether or not to tidy the content of the SVG file (XML::Tidy required). =item style_sheet() Set the path to an external stylesheet, set to '' if you want to revert back to using the defaut internal version. The default stylesheet handles up to 12 data sets. All data series over the 12th will have no style and be in black. If you have over 12 data sets you can assign them all random colors (see the random_color() method) or create your own stylesheet and add the additional settings for the extra data sets. To create an external stylesheet create a graph using the default internal version and copy the stylesheet section to an external file and edit from there. =item random_colors() Use random colors in the internal stylesheet =item show_data_values() Show the value of each element of data on the graph =item show_data_points() Show a small circle on the graph where the line goes from one point to the next. =item stacked() Accumulates each data set. (i.e. Each point increased by sum of all previous series at same point). Default is 0, set to '1' to show. =item min_scale_value() The point at which the Y axis starts, defaults to '0', if set to '' it will default to the minimum data value. =item max_scale_value() The maximum value for the Y axis. If set to '', it will default to the maximum data value. =item show_x_labels() Whether to show labels on the X axis or not, defaults to 1, set to '0' if you want to turn them off. =item show_y_labels() Whether to show labels on the Y axis or not, defaults to 1, set to '0' if you want to turn them off. =item scale_integers() Ensures only whole numbers are used as the scale divisions. Default it '0', to turn on set to '1'. This has no effect if scale divisions are less than 1. =item scale_divisions() This defines the gap between markers on the Y axis, default is a 10th of the max_value, e.g. you will have 10 markers on the Y axis. NOTE: do not set this too low - you are limited to 999 markers, after that the graph won't generate. =item stagger_x_labels() This puts the labels at alternative levels so if they are long field names they will not overlap so easily. Default it '0', to turn on set to '1'. =item rotate_x_labels() This turns the X axis labels by 90 degrees. Default it '0', to turn on set to '1'. =item show_x_title() Whether to show the title under the X axis labels, default is 0, set to '1' to show. =item x_title() What the title under X axis should be, e.g. 'Months'. =item show_y_title() Whether to show the title under the Y axis labels, default is 0, set to '1' to show. =item y_title_text_direction() Aligns writing mode for Y axis label. Defaults to 'bt' (Bottom to Top). Change to 'tb' (Top to Bottom) to reverse. =item y_title() What the title under Y axis should be, e.g. 'Sales in thousands'. =item show_graph_title() Whether to show a title on the graph, default is 0, set to '1' to show. =item graph_title() What the title on the graph should be. =item show_graph_subtitle() Whether to show a subtitle on the graph, default is 0, set to '1' to show. =item graph_subtitle() What the subtitle on the graph should be. =item key() Whether to show a key, defaults to 0, set to '1' if you want to show it. =item key_position() Where the key should be positioned, defaults to 'right', set to 'bottom' if you want to move it. =item x_label_formatter () A callback subroutine which will format a label on the x axis. For example: $graph->x_label_formatter( sub { return '$' . $_[0] } ); =item y_label_formatter() A callback subroutine which will format a label on the y axis. For example: $graph->y_label_formatter( sub { return '$' . $_[0] } ); =back =head1 EXAMPLES For examples look at the project home page http://leo.cuckoo.org/projects/SVG-TT-Graph/ =head1 EXPORT None by default. =head1 ACKNOWLEDGEMENTS Thanks to Foxtons for letting us put this on CPAN, Todd Caine for heads up on reparsing the template (but not using atm), David Meibusch for TimeSeries and a load of other ideas, Stephen Morgan for creating the TT template and SVG, and thanks for all the patches by Andrew Ruthven and others. =head1 AUTHOR Leo Lapworth =head1 MAINTAINER Florent Angly =head1 COPYRIGHT AND LICENSE Copyright (C) 2003, Leo Lapworth This module is free software; you can redistribute it or modify it under the same terms as Perl itself. =head1 BUGS Please report any bugs or feature requests to bug-graph-svg-tt@rt.cpan.org, or through the web interface at http://rt.cpan.org. The Graph::SVG::TT development repository is located on GitHub at L. Get the latest development version using: git clone git://github.com/ranguard/svg-tt-graph.git =head1 SEE ALSO L, L, L, L, L, L, L, L, L =cut sub _init { my $self = shift; croak "fields was not supplied or is empty" unless defined $self->{'config'}->{fields} && ref($self->{'config'}->{fields}) eq 'ARRAY' && scalar(@{$self->{'config'}->{fields}}) > 0; } sub _set_defaults { my $self = shift; my %default = ( 'width' => '500', 'height' => '300', 'style_sheet' => '', 'random_colors' => 0, 'show_data_points' => 1, 'show_data_values' => 1, 'stacked' => 0, 'min_scale_value' => '0', 'max_scale_value' => '', 'area_fill' => 0, 'show_x_labels' => 1, 'stagger_x_labels' => 0, 'rotate_x_labels' => 0, 'show_y_labels' => 1, 'scale_integers' => 0, 'scale_divisions' => '', 'x_label_formatter' => sub { return @_ }, 'y_label_formatter' => sub { return @_ }, 'show_x_title' => 0, 'x_title' => 'X Field names', 'show_y_title' => 0, 'y_title_text_direction' => 'bt', 'y_title' => 'Y Scale', 'show_graph_title' => 0, 'graph_title' => 'Graph Title', 'show_graph_subtitle' => 0, 'graph_subtitle' => 'Graph Sub Title', 'key' => 0, 'key_position' => 'right', # bottom or right ); while( my ($key,$value) = each %default ) { $self->{config}->{$key} = $value; } } 1; __DATA__ [% stylesheet = 'included' %] [% IF config.style_sheet && config.style_sheet != '' %] [% ELSE %] [% stylesheet = 'excluded' %] [% END %] [% IF stylesheet == 'excluded' %] [% END %] [% w = config.width %] [% h = config.height %] [% x = 0 %] [% y = 0 %] [% char_width = 9 %] [% half_char_height = 2.5 %] [% IF config.stacked %] [% FOREACH field = config.fields %] [% cumulative = 0 %] [% FOREACH dataset = data %] [% IF dataset.data.$field != '' %] [% cumulative = cumulative + dataset.data.$field %] [% END %] [% dataset.data.$field = cumulative %] [% END %] [% END %] [% END %] [% min_value = 99999999999 %] [% max_value = 0 %] [% max_key_size = 0 %] [% max_x_label_size = 0 %] [% FOREACH field = config.fields %] [% IF max_x_label_size < field.length %] [% max_x_label_size = field.length %] [% END %] [% FOREACH dataset = data %] [% IF min_value > dataset.data.$field && dataset.data.$field != '' %] [% min_value = dataset.data.$field %] [% END %] [% IF max_value < dataset.data.$field && dataset.data.$field != '' %] [% max_value = dataset.data.$field %] [% END %] [% IF dataset.title %] [% IF max_key_size < dataset.title.length %] [% max_key_size = dataset.title.length %] [% END %] [% END %] [% END %] [% END %] [% IF config.show_x_labels %][% h = h - 20 %][% END %] [% max_x_label_length = 0 %] [% IF config.rotate_x_labels %] [% max_x_label_length = max_x_label_size * char_width %] [% h = h - max_x_label_length %] [% END %] [% stagger = 0 %] [% IF config.show_x_labels && config.stagger_x_labels %] [% stagger = 17 %] [% h = h - stagger %] [% END %] [% IF config.show_x_title %][% h = h - 25 - stagger %][% END %] [% IF config.show_y_labels %][% h = h - 10 %][% y = y + 10 %][% END %] [% IF config.show_graph_title %][% h = h - 25 %][% y = y + 25 %][% END %] [% IF config.show_graph_subtitle %][% h = h - 10 %][% y = y + 10 %][% END %] [% key_box_size = 12 %] [% key_padding = 5 %] [% IF config.key && config.key_position == 'right' %] [% w = w - (max_key_size * (char_width - 1)) - (key_box_size * 3 ) %] [% ELSIF config.key && config.key_position == 'bottom' %] [% IF data.size < 4 %] [% h = h - ((data.size + 1) * (key_box_size + key_padding))%] [% ELSE %] [% h = h - (4 * (key_box_size + key_padding))%] [% END %] [% END %] [% IF config.min_scale_value || config.min_scale_value == '0' %] [% min_scale_value = config.min_scale_value %] [% ELSE %] [% min_scale_value = min_value %] [% END %] [% IF config.max_scale_value || config.max_scale_value == '0' %] [% max_scale_value = config.max_scale_value %] [% ELSE %] [% max_scale_value = max_value %] [% END %] [% base_line = h + y %] [% IF (max_scale_value - min_scale_value) == 0 %] [% top_pad = 10 %] [% ELSE %] [% top_pad = (max_scale_value - min_scale_value) / 20 %] [% END %] [% scale_range = (max_scale_value + top_pad) - min_scale_value %] [% IF config.scale_divisions %] [% scale_division = config.scale_divisions %] [% ELSE %] [% scale_division = scale_range / 10 FILTER format('%2.01f') %] [% END %] [% IF config.scale_integers %] [% IF scale_division < 1 %] [% scale_division = 1 %] [% ELSIF scale_division.match('.') %] [% scale_division = scale_division FILTER format('%2.0f') %] [% END %] [% END %] [% max_value_length = max_value.length %] [% max_value_length_px = max_value_length * char_width %] [% space_b4_y_axis = (config.fields.0.length / 2) * char_width %] [% IF config.show_x_labels %] [% IF config.key && config.key_position == 'right' %] [% w = w - space_b4_y_axis %] [% ELSE %] [% w = w - (space_b4_y_axis * 2) %] [% END %] [% x = x + space_b4_y_axis %] [% ELSIF config.show_data_values %] [% w = w - (max_value_length_px * 2) %] [% x = x + max_value_length_px %] [% END %] [% IF config.show_y_labels && space_b4_y_axis < max_value_length_px %] [% IF max_value_length < 2 %] [% w = w - (max_value_length * (char_width * 2)) %] [% x = x + (max_value_length * (char_width * 2)) %] [% ELSE %] [% w = w - max_value_length_px %] [% x = x + max_value_length_px %] [% END %] [% ELSIF config.show_y_labels && !config.show_x_labels %] [% w = w - max_value_length_px %] [% x = x + max_value_length_px %] [% END %] [% IF config.show_y_title %] [% w = w - 25 %] [% x = x + 25 %] [% END %] [% dx = config.fields.size %] [% dx = dx - 1 %] [% data_widths_x = w / dx %] [% dw = data_widths_x FILTER format('%2.02f') %] [% i = dw %] [% count = 0 %] [% stagger_count = 0 %] [% IF config.show_x_labels %] [% FOREACH field = config.fields %] [% field_txt = config.x_label_formatter(field) %] [% IF count == 0 %] [% field_txt %] [% i = i - dw %] [% ELSE %] [% IF stagger_count == 2 %] [% field_txt %] [% stagger_count = 0 %] [% ELSE %] [% field_txt %] [% END %] [% END %] [% i = i + dw %] [% count = count + 1 %] [% stagger_count = stagger_count + 1 %] [% END %] [% END %] [% dy = scale_range / scale_division %] [% y_marker_height = h / dy %] [% dy = y_marker_height.match('(\d+[\.\d\d])').0 %] [% count = 0 %] [% y_value = min_scale_value %] [% IF config.show_y_labels %] [% WHILE (dy * count) < h %] [% y_value_txt = config.y_label_formatter(y_value) %] [% IF count == 0 %] [% y_value_txt %] [% ELSE %] [% y_value_txt %] [% END %] [% y_value = y_value + scale_division %] [% count = count + 1 %] [% END %] [% END %] [% IF config.show_x_title %] [% IF !config.show_x_labels %] [% y_xtitle = 15 %] [% ELSE %] [% y_xtitle = 35 %] [% END %] [% config.x_title %] [% END %] [% IF config.show_y_title %] [% IF config.y_title_text_direction == 'tb' %] [% config.y_title %] [% ELSE %] [% config.y_title %] [% END %] [% END %] [% divider = dy / scale_division %] [% line = data.size %] [% FOREACH dataset = data.reverse %] [% IF config.area_fill %] [% END %] [% IF config.show_data_points || config.show_data_values%] [% xcount = 0 %] [% FOREACH field = config.fields %] [% IF config.show_data_points %] [% END %] [% IF config.show_data_values %] [% dataset.data.$field %] [% END %] [% xcount = xcount + 1 %] [% END %] [% END %] [% line = line - 1 %] [% END %] [% key_count = 1 %] [% IF config.key && config.key_position == 'right' %] [% FOREACH dataset = data %] [% dataset.title %] [% key_count = key_count + 1 %] [% END %] [% ELSIF config.key && config.key_position == 'bottom' %] [% y_key = base_line %] [% IF config.show_x_title %] [% y_key = y_key + 25 %] [% END %] [% IF config.rotate_x_labels && config.show_x_labels %] [% y_key = y_key + max_x_label_length %] [% ELSIF config.show_x_labels && stagger < 1 %] [% y_key = y_key + 20 %] [% END %] [% y_key_start = y_key %] [% x_key = x %] [% FOREACH dataset = data %] [% IF key_count == 4 || key_count == 7 || key_count == 10 %] [% x_key = x_key + 200 %] [% y_key = y_key - (key_box_size * 4) - 2 %] [% END %] [% dataset.title %] [% key_count = key_count + 1 %] [% END %] [% END %] [% IF config.show_graph_title %] [% config.graph_title %] [% END %] [% IF config.show_graph_subtitle %] [% IF config.show_graph_title %] [% y_subtitle = 30 %] [% ELSE %] [% y_subtitle = 15 %] [% END %] [% config.graph_subtitle %] [% END %] SVG-TT-Graph-0.21/lib/SVG/TT/Graph/TimeSeries.pm0000755000175000017500000011242111756370256021123 0ustar floflooofloflooopackage SVG::TT::Graph::TimeSeries; use strict; use Carp; use SVG::TT::Graph; use base qw(SVG::TT::Graph); use vars qw($VERSION $TEMPLATE_FH); $VERSION = $SVG::TT::Graph::VERSION; $TEMPLATE_FH = \*DATA; use Data::Dumper; use HTTP::Date; use DateTime; use POSIX; =head1 NAME SVG::TT::Graph::TimeSeries - Create presentation quality SVG line graphs of time series easily =head1 SYNOPSIS use SVG::TT::Graph::TimeSeries; my @data_cpu = ('2003-09-03 09:30:00',23,'2003-09-03 09:45:00',54,'2003-09-03 10:00:00',67,'2003-09-03 10:15:00',12); my @data_disk = ('2003-09-03 09:00:00',12,'2003-09-03 10:00:00',26,'2003-09-03 11:00:00',23); my $graph = SVG::TT::Graph::TimeSeries->new({ 'height' => '500', 'width' => '300', }); $graph->add_data({ 'data' => \@data_cpu, 'title' => 'CPU', }); $graph->add_data({ 'data' => \@data_disk, 'title' => 'Disk', }); print "Content-type: image/svg+xml\n\n"; print $graph->burn(); =head1 DESCRIPTION This object aims to allow you to easily create high quality SVG line graphs of time series. You can either use the default style sheet or supply your own. Either way there are many options which can be configured to give you control over how the graph is generated - with or without a key, data elements at each point, title, subtitle etc. All times must be given a format parseable by L. The L module is used for all date/time calculations. Note that the module is currently limited to the Unix-style epoch-based date range limited by 32 bit signed integers (around 1902 to 2038). =head1 METHODS =head2 new() use SVG::TT::Graph::TimeSeries; my $graph = SVG::TT::Graph::TimeSeries->new({ # Optional - defaults shown 'height' => 500, 'width' => 300, 'show_y_labels' => 1, 'scale_divisions' => '', 'min_scale_value' => 0, 'max_scale_value' => '', 'show_x_labels' => 1, 'timescale_divisions' => '', 'min_timescale_value' => '', 'max_timescale_value' => '', 'x_label_format' => '%Y-%m-%d %H:%M:%S', 'stagger_x_labels' => 0, 'rotate_x_labels' => 0, 'y_label_formatter' => sub { return @_ }, 'x_label_formatter' => sub { return @_ }, 'show_data_points' => 1, 'show_data_values' => 1, 'rollover_values' => 0, 'area_fill' => 0, 'show_x_title' => 0, 'x_title' => 'X Field names', 'show_y_title' => 0, 'y_title' => 'Y Scale', 'show_graph_title' => 0, 'graph_title' => 'Graph Title', 'show_graph_subtitle' => 0, 'graph_subtitle' => 'Graph Sub Title', 'key' => 0, 'key_position' => 'right', # Stylesheet defaults 'style_sheet' => '/includes/graph.css', # internal stylesheet 'random_colors' => 0, }); The constructor takes a hash reference with values defaulted to those shown above - with the exception of style_sheet which defaults to using the internal style sheet. =head2 add_data() my @data_cpu = ('2003-09-03 09:30:00',23,'2003-09-03 09:45:00',54,'2003-09-03 10:00:00',67,'2003-09-03 10:15:00',12); or my @data_cpu = (['2003-09-03 09:30:00',23],['2003-09-03 09:45:00',54],['2003-09-03 10:00:00',67],['2003-09-03 10:15:00',12]); $graph->add_data({ 'data' => \@data_cpu, 'title' => 'CPU', }); This method allows you to add data to the graph object. The data is expected to be a list of time, value pairs. It can be called several times to add more data sets in. =head2 clear_data() my $graph->clear_data(); This method removes all data from the object so that you can reuse it to create a new graph but with the same config options. =head2 burn() print $graph->burn(); This method processes the template with the data and config which has been set and returns the resulting SVG. This method will croak unless at least one data set has been added to the graph object. =head2 config methods my $value = $graph->method(); my $confirmed_new_value = $graph->method($value); The following is a list of the methods which are available to change the config of the graph object after it has been created. =over 4 =item height() Set the height of the graph box, this is the total height of the SVG box created - not the graph it self which auto scales to fix the space. =item width() Set the width of the graph box, this is the total width of the SVG box created - not the graph it self which auto scales to fix the space. =item compress() Whether or not to compress the content of the SVG file (Compress::Zlib required). =item tidy() Whether or not to tidy the content of the SVG file (XML::Tidy required). =item style_sheet() Set the path to an external stylesheet, set to '' if you want to revert back to using the defaut internal version. The default stylesheet handles up to 12 data sets. All data series over the 12th will have no style and be in black. If you have over 12 data sets you can assign them all random colors (see the random_color() method) or create your own stylesheet and add the additional settings for the extra data sets. To create an external stylesheet create a graph using the default internal version and copy the stylesheet section to an external file and edit from there. =item random_colors() Use random colors in the internal stylesheet. =item show_data_values() Show the value of each element of data on the graph. =item show_data_points() Show a small circle on the graph where the line goes from one point to the next. =item rollover_values() Shows data values and data points when the mouse is over the point. Used in combination with show_data_values and/or show_data_points. =item data_value_format() Format specifier to for data values (as per printf). =item max_time_span() Maximum timespan for a line between data points. If this span is exceeded, the points are not connected. This is useful for skipping missing data sections. The expected form is: ' [years | months | days | hours | minutes | seconds]' =item stacked() Accumulates each data set. (i.e. Each point increased by sum of all previous series at same time). Default is 0, set to '1' to show. All data series have the same number of points and must have the same sequence of time values for this option. =item min_scale_value() The point at which the Y axis starts, defaults to '0', if set to '' it will default to the minimum data value. =item max_scale_value() The point at which the Y axis ends, if set to '' it will default to the maximum data value. =item scale_divisions() This defines the gap between markers on the Y axis, default is a 10th of the range, e.g. you will have 10 markers on the Y axis. NOTE: do not set this too low - you are limited to 999 markers, after that the graph won't generate. =item show_x_labels() Whether to show labels on the X axis or not, defaults to 1, set to '0' if you want to turn them off. =item x_label_format() Format string for presenting the X axis labels. The POSIX strftime() function is used for formatting (see strftime man pages and LC_TIME locale information). =item show_y_labels() Whether to show labels on the Y axis or not, defaults to 1, set to '0' if you want to turn them off. =item y_label_format() Format string for presenting the Y axis labels (as per printf). =item timescale_divisions() This defines the gap between markers on the X axis. Default is the entire range (only start and end axis labels). The expected form is: ' [years | months | days | hours | minutes | seconds]' The default time period if not provided is 'days'. These time periods are used by the L methods. =item stagger_x_labels() This puts the labels at alternative levels so if they are long field names they will not overlap so easily. Default it '0', to turn on set to '1'. =item rotate_x_labels() This turns the X axis labels by 90 degrees. Default it '0', to turn on set to '1'. =item min_timescale_value() This sets the minimum timescale value (X axis). Any data points before this time will not be shown. The date/time is expected in ISO format: YYYY-MM-DD hh:mm:ss. =item max_timescale_value() This sets the maximum timescale value (X axis). Any data points after this time will not be shown. The date/time is expected in ISO format: YYYY-MM-DD hh:mm:ss. =item show_x_title() Whether to show the title under the X axis labels, default is 0, set to '1' to show. =item x_title() What the title under X axis should be, e.g. 'Months'. =item show_y_title() Whether to show the title under the Y axis labels, default is 0, set to '1' to show. =item y_title() What the title under Y axis should be, e.g. 'Sales in thousands'. =item show_graph_title() Whether to show a title on the graph, default is 0, set to '1' to show. =item graph_title() What the title on the graph should be. =item show_graph_subtitle() Whether to show a subtitle on the graph, default is 0, set to '1' to show. =item graph_subtitle() What the subtitle on the graph should be. =item key() Whether to show a key, defaults to 0, set to '1' if you want to show it. =item key_position() Where the key should be positioned, defaults to 'right', set to 'bottom' if you want to move it. =item x_label_formatter () A callback subroutine which will format a label on the x axis. For example: $graph->x_label_formatter( sub { return '$' . $_[0] } ); =item y_label_formatter() A callback subroutine which will format a label on the y axis. For example: $graph->y_label_formatter( sub { return '$' . $_[0] } ); =back =head1 EXAMPLES For examples look at the project home page http://leo.cuckoo.org/projects/SVG-TT-Graph/ =head1 EXPORT None by default. =head1 ACKNOWLEDGEMENTS Thanks to Foxtons for letting us put this on CPAN, Todd Caine for heads up on reparsing the template (but not using atm), David Meibusch for TimeSeries and a load of other ideas, Stephen Morgan for creating the TT template and SVG, and thanks for all the patches by Andrew Ruthven and others. =head1 AUTHOR David Meibusch =head1 MAINTAINER Florent Angly =head1 COPYRIGHT AND LICENSE Copyright (C) 2003, Leo Lapworth This module is free software; you can redistribute it or modify it under the same terms as Perl itself. =head1 BUGS Please report any bugs or feature requests to bug-graph-svg-tt@rt.cpan.org, or through the web interface at http://rt.cpan.org. The Graph::SVG::TT development repository is located on GitHub at L. Get the latest development version using: git clone git://github.com/ranguard/svg-tt-graph.git =head1 SEE ALSO L, L, L, L, L, L, L, L, L =cut sub _init { my $self = shift; } sub _set_defaults { my $self = shift; my @fields = (); my %default = ( 'fields' => \@fields, 'width' => '500', 'height' => '300', 'style_sheet' => '', 'random_colors' => 0, 'show_data_points' => 1, 'show_data_values' => 1, 'rollover_values' => 0, 'max_time_span' => '', 'area_fill' => 0, 'show_y_labels' => 1, 'scale_divisions' => '', 'min_scale_value' => '0', 'stacked' => 0, 'show_x_labels' => 1, 'stagger_x_labels' => 0, 'rotate_x_labels' => 0, 'timescale_divisions' => '', 'x_label_format' => '%Y-%m-%d %H:%M:%S', 'x_label_formatter' => sub { return @_ }, 'y_label_formatter' => sub { return @_ }, 'show_x_title' => 0, 'x_title' => 'X Field names', 'show_y_title' => 0, 'y_title' => 'Y Scale', 'show_graph_title' => 0, 'graph_title' => 'Graph Title', 'show_graph_subtitle' => 0, 'graph_subtitle' => 'Graph Sub Title', 'key' => 0, 'key_position' => 'right', # bottom or right 'dateadd' => \&dateadd, ); while( my ($key,$value) = each %default ) { $self->{config}->{$key} = $value; } } # override this so we can pre-manipulate the data sub add_data { my ($self, $conf) = @_; croak 'no data provided' unless (defined $conf->{'data'} && ref($conf->{'data'}) eq 'ARRAY'); # create an array unless(defined $self->{'data'}) { my @data; $self->{'data'} = \@data; } # convert to sorted (by ascending time) array of [ time, value ] my @new_data = (); my ($i,$time,@pair); $i = 0; while ($i < @{$conf->{'data'}}) { @pair = (); if (ref($conf->{'data'}->[$i]) eq 'ARRAY') { push @pair,@{$conf->{'data'}->[$i]}; $i++; } else { $pair[0] = $conf->{'data'}->[$i++]; $pair[1] = $conf->{'data'}->[$i++]; } $time = str2time($pair[0]); # special case for time-only values if ((!defined $time) && ($pair[0] =~ m/^\w*(\d+:\d+:\d+)|(\d+:\d+)\w*$/)) { $time = str2time('1970-1-1 '.$pair[0]); } croak sprintf("Series %d contains an illegal datetime value %s at sample %d.", scalar(@{$self->{'data'}}), $pair[0], $i / 2) unless (defined $time); $pair[0] = $time; push @new_data, [ @pair ]; } my @sorted = sort {@{$a}[0] <=> @{$b}[0]} @new_data; # if stacked, we accumulate the if (($self->{config}->{stacked}) && (@{$self->{'data'}})) { my $prev = $self->{'data'}->[@{$self->{'data'}} - 1]->{pairs}; # check our length matches previous croak sprintf("Series %d can not be stacked on previous series. Mismatched length.", scalar(@{$self->{'data'}})) unless (scalar(@sorted) == scalar(@$prev)); for (my $i = 0; $i < @sorted; $i++) { # check the time value matches croak sprintf("Series %d can not be stacked on previous series. Mismatched timestamp at sample %d (time %s).", scalar(@{$self->{'data'}}), $i, HTTP::Date::time2iso($sorted[$i][0])) unless ($sorted[$i][0] == $prev->[$i][0]); $sorted[$i][1] += $prev->[$i][1]; } } my %store = ( 'pairs' => \@sorted, ); $store{'title'} = $conf->{'title'} if defined $conf->{'title'}; push (@{$self->{'data'}},\%store); return 1; } # Helper function for doing date/time calculations # Current implementations of DateTime can be slow :-( sub dateadd { my ($epoch,$value,$unit) = @_; my $dt = DateTime->from_epoch(epoch => $epoch); $dt->add( $unit => $value ); return $dt->epoch(); } # override calculations to set a few calculated values, mainly for scaling sub calculations { my $self = shift; # run through the data and calculate maximum and minimum values my ($max_key_size,$max_time,$min_time,$max_value,$min_value,$max_x_label_length,$x_label); foreach my $dataset (@{$self->{data}}) { $max_key_size = length($dataset->{title}) if ((!defined $max_key_size) || ($max_key_size < length($dataset->{title}))); foreach my $pair (@{$dataset->{pairs}}) { $max_time = $pair->[0] if ((!defined $max_time) || ($max_time < $pair->[0])); $min_time = $pair->[0] if ((!defined $min_time) || ($min_time > $pair->[0])); $max_value = $pair->[1] if (($pair->[1] ne '') && ((!defined $max_value) || ($max_value < $pair->[1]))); $min_value = $pair->[1] if (($pair->[1] ne '') && ((!defined $min_value) || ($min_value > $pair->[1]))); $x_label = strftime($self->{config}->{x_label_format},localtime($pair->[0])); $max_x_label_length = length($x_label) if ((!defined $max_x_label_length) || ($max_x_label_length < length($x_label))); } } $self->{calc}->{max_key_size} = $max_key_size; $self->{calc}->{max_time} = $max_time; $self->{calc}->{min_time} = $min_time; $self->{calc}->{max_value} = $max_value; $self->{calc}->{min_value} = $min_value; $self->{calc}->{max_x_label_length} = $max_x_label_length; # Calc the x axis scale values $self->{calc}->{min_timescale_value} = ($self->_is_valid_config('min_timescale_value')) ? str2time($self->{config}->{min_timescale_value}) : $min_time; $self->{calc}->{max_timescale_value} = ($self->_is_valid_config('max_timescale_value')) ? str2time($self->{config}->{max_timescale_value}) : $max_time; $self->{calc}->{timescale_range} = $self->{calc}->{max_timescale_value} - $self->{calc}->{min_timescale_value}; # Calc the y axis scale values $self->{calc}->{min_scale_value} = ($self->_is_valid_config('min_scale_value')) ? $self->{config}->{min_scale_value} : $min_value; $self->{calc}->{max_scale_value} = ($self->_is_valid_config('max_scale_value')) ? $self->{config}->{max_scale_value} : $max_value; $self->{calc}->{scale_range} = $self->{calc}->{max_scale_value} - $self->{calc}->{min_scale_value}; my ($range,$division,$precision); if ($self->_is_valid_config('scale_divisions')) { $division = $self->{config}->{scale_divisions}; if ($division >= 1) { $precision = 0; } else { $precision = length($division) - 2; } } else { # Find divisions, format and range ($range,$division,$precision) = $self->_range_calc($self->{calc}->{scale_range}); # If a max value hasn't been set we can set a revised range and max value if (! $self->_is_valid_config('max_scale_value')) { $self->{calc}->{max_scale_value} = $self->{calc}->{min_scale_value} + $range; $self->{calc}->{scale_range} = $self->{calc}->{max_scale_value} - $self->{calc}->{min_scale_value}; } } $self->{calc}->{scale_division} = $division; $self->{calc}->{y_label_format} = ($self->_is_valid_config('y_label_format')) ? $self->{config}->{y_label_format} : "%.${precision}f"; $self->{calc}->{data_value_format} = ($self->_is_valid_config('data_value_format')) ? $self->{config}->{data_value_format} : "%.${precision}f"; } 1; __DATA__ [% USE date %] [% stylesheet = 'included' %] [% IF config.style_sheet && config.style_sheet != '' %] [% ELSE %] [% stylesheet = 'excluded' %] [% END %] [% IF stylesheet == 'excluded' %] [%# include default stylesheet if none specified %] [% END %] [% IF config.key %] [% END %] [%# get dimensions of actual graph area (NOT SVG area) %] [% w = config.width %] [% h = config.height %] [%# set start/default coords of graph %] [% x = 0 %] [% y = 0 %] [% char_width = 8 %] [% half_char_height = 2.5 %] [%# reduce height of graph area if there is labelling on x axis %] [% IF config.show_x_labels %][% h = h - 20 %][% END %] [%# reduce height if x labels are rotated %] [% x_label_allowance = 0 %] [% IF config.rotate_x_labels %] [% x_label_allowance = (calc.max_x_label_length * char_width) - 20 %] [% h = h - x_label_allowance %] [% END %] [%# stagger x labels if overlapping occurs %] [% stagger = 0 %] [% IF config.show_x_labels && config.stagger_x_labels %] [% stagger = 17 %] [% h = h - stagger %] [% END %] [% IF config.show_x_title %][% h = h - 25 - stagger %][% END %] [%# pad top of graph if y axis has data labels so labels do not get chopped off %] [% IF config.show_y_labels %][% h = h - 10 %][% y = y + 10 %][% END %] [%# reduce height if graph has title or subtitle %] [% IF config.show_graph_title %][% h = h - 25 %][% y = y + 25 %][% END %] [% IF config.show_graph_subtitle %][% h = h - 10 %][% y = y + 10 %][% END %] [%# reduce graph dimensions if there is a KEY %] [% key_box_size = 12 %] [% key_padding = 5 %] [% IF config.key && config.key_position == 'right' %] [% w = w - (calc.max_key_size * (char_width - 1)) - (key_box_size * 3 ) %] [% ELSIF config.key && config.key_position == 'bottom' %] [% IF data.size < 4 %] [% h = h - ((data.size + 1) * (key_box_size + key_padding))%] [% ELSE %] [% h = h - (4 * (key_box_size + key_padding))%] [% END %] [% END %] [%# base line %] [% base_line = h + y %] [%# find the string length of max value %] [% max_value_length = calc.max_scale_value.length %] [%# label width in pixels %] [% max_value_length_px = max_value_length * char_width %] [%# If the y labels are shown but the size of the x labels are small, pad for y labels %] [%# reduce width of graph area if there is large labelling on x axis %] [% space_b4_y_axis = (date.format(calc.min_timescale_value,config.x_label_format).length / 2) * char_width %] [% IF config.show_x_labels %] [% IF config.key && config.key_position == 'right' %] [% w = w - space_b4_y_axis %] [% ELSE %] [% w = w - (space_b4_y_axis * 2) %] [% END %] [% x = x + space_b4_y_axis %] [% ELSIF config.show_data_values %] [% w = w - (max_value_length_px * 2) %] [% x = x + max_value_length_px %] [% END %] [% IF config.show_y_labels && space_b4_y_axis < max_value_length_px %] [% IF max_value_length < 2 %] [% w = w - (max_value_length * (char_width * 2)) %] [% x = x + (max_value_length * (char_width * 2)) %] [% ELSE %] [% w = w - max_value_length_px %] [% x = x + max_value_length_px %] [% END %] [% ELSIF config.show_y_labels && !config.show_x_labels %] [% w = w - max_value_length_px %] [% x = x + max_value_length_px %] [% END %] [% IF config.show_y_title %] [% w = w - 25 %] [% x = x + 25 %] [% END %] [%# Missing data spans %] [% max_time_span = 0 %] [% IF (matches = config.max_time_span.match('(\d+) ?(\w+)?')) %] [% max_time_span = matches.0 %] [% IF (matches.1) %] [% max_time_span_units = matches.1 %] [% ELSE %] [% max_time_span_units = 'days' %] [% END %] [% END %] [%# graph bg and clipping regions for lines/fill and clip extended to included data labels %] [% dx = calc.timescale_range %] [% dw = w / dx %] [% IF config.show_x_labels %] [% x_value_txt = config.x_label_formatter(date.format(calc.min_timescale_value,config.x_label_format)) %] [% x_value_txt %] [% last_label = date.format(calc.min_timescale_value,config.x_label_format) %] [% IF config.timescale_divisions %] [% IF (matches = config.timescale_divisions.match('(\d+) ?(\w+)?')) %] [% timescale_division = matches.0 %] [% IF (matches.1) %] [% timescale_division_units = matches.1 %] [% ELSE %] [% timescale_division_units = 'days' %] [% END %] [% x_value = config.dateadd(calc.min_timescale_value,timescale_division,timescale_division_units) %] [% count = 0 %] [% WHILE ((x_value > calc.min_timescale_value) && ((x_value < calc.max_timescale_value))) %] [% x_value_txt = config.x_label_formatter(date.format(x_value,config.x_label_format)) %] [% xpos = (dw * (x_value - calc.min_timescale_value)) + x %] [% IF (config.stagger_x_labels && ((count % 2) == 0)) %] [% x_value_txt %] [% ELSE %] [% x_value_txt %] [% END %] [% last_label = date.format(x_value,config.x_label_format) %] [% x_value = config.dateadd(x_value,timescale_division,timescale_division_units) %] [% count = count + 1 %] [% LAST IF (count >= 999) %] [% END %] [% END %] [% END %] [% IF date.format(calc.max_timescale_value,config.x_label_format) != last_label %] [% x_value_txt = config.x_label_formatter(date.format(calc.max_timescale_value,config.x_label_format)) %] [% IF (config.stagger_x_labels && ((count % 2) == 0)) %] [% x_value_txt %] [% ELSE %] [% x_value_txt %] [% END %] [% END %] [% END %] [%# how much padding between largest bar and top of graph %] [% top_pad = h / 40 %] [% dy = calc.scale_range %] [% dh = (h - top_pad) / dy %] [% count = 0 %] [% y_value = calc.min_scale_value %] [% IF config.show_y_labels %] [% WHILE ((y_value == calc.min_scale_value) || (y_value == calc.max_scale_value) || ((y_value > calc.min_scale_value) && (y_value < calc.max_scale_value))) %] [%- next_label = y_value FILTER format(calc.y_label_format) -%] [%- next_label = config.y_label_formatter(next_label) -%] [%- IF count == 0 -%] [%# no stroke for first line %] [% next_label %] [%- ELSE -%] [% IF next_label != last_label %] [% next_label %] [% END %] [%- END -%] [%- y_value = y_value + calc.scale_division -%] [%- last_label = next_label -%] [%- count = count + 1 -%] [%- LAST IF (count >= 999) -%] [% END %] [% END %] [% IF config.show_x_title %] [% IF !config.show_x_labels %] [% y_xtitle = 15 %] [% ELSE %] [% y_xtitle = 35 %] [% END %] [% config.x_title %] [% END %] [% IF config.show_y_title %] [% config.y_title %] [% END %] [% line = data.size %] [% FOREACH dataset = data.reverse %] [% IF config.area_fill %] [%# create alternate fill first (so line can overwrite if necessary) %] [% xcount = 0 %] [% FOREACH pair = dataset.pairs %] [%- IF ((pair.0 >= calc.min_timescale_value) && (pair.0 <= calc.max_timescale_value)) -%] [%- IF xcount == 0 -%][% lasttime = pair.0 %] [% END %] [% END %] [% xcount = 0 %] [% FOREACH pair = dataset.pairs %] [% IF ((pair.0 >= calc.min_timescale_value) && (pair.0 <= calc.max_timescale_value)) %] [%- IF xcount == 0 -%][%- lasttime = pair.0 -%] [% END %] [% IF config.show_data_points || config.show_data_values %] [% FOREACH pair = dataset.pairs %] [% IF ((pair.0 >= calc.min_timescale_value) && (pair.0 <= calc.max_timescale_value)) %] [% IF config.show_data_points %] [% END %] [% IF config.show_data_values %] [%# datavalue shown %] [% IF (pair.2.defined) && (pair.2 != '') %][% point_label = pair.2 %][% ELSE %][% point_label = pair.1 FILTER format(calc.data_value_format) %][% END %] [% point_label %] [% END %] [% END %] [% END %] [% END %] [% line = line - 1 %] [% END %] [% key_count = 1 %] [% IF config.key && config.key_position == 'right' %] [% FOREACH dataset = data %] [% dataset.title %] [% key_count = key_count + 1 %] [% END %] [% ELSIF config.key && config.key_position == 'bottom' %] [%# calc y position of start of key %] [% y_key = base_line %] [%# consider x title %] [% IF config.show_x_title %][% y_key = base_line + 25 %][% END %] [%# consider x label rotation and stagger %] [% IF config.rotate_x_labels && config.show_x_labels %] [% y_key = y_key + x_label_allowance %] [% ELSIF config.show_x_labels && stagger < 1 %] [% y_key = y_key + 20 %] [% END %] [% y_key_start = y_key %] [% x_key = x %] [% FOREACH dataset = data %] [% IF key_count == 4 || key_count == 7 || key_count == 10 %] [%# wrap key every 3 entries %] [% x_key = x_key + 200 %] [% y_key = y_key - (key_box_size * 4) - 2 %] [% END %] [% dataset.title %] [% key_count = key_count + 1 %] [% END %] [% END %] [% IF config.show_graph_title %] [% config.graph_title %] [% END %] [% IF config.show_graph_subtitle %] [% IF config.show_graph_title %] [% y_subtitle = 30 %] [% ELSE %] [% y_subtitle = 15 %] [% END %] [% config.graph_subtitle %] [% END %] SVG-TT-Graph-0.21/lib/SVG/TT/Graph/BarHorizontal.pm0000755000175000017500000005725411756370217021641 0ustar floflooofloflooopackage SVG::TT::Graph::BarHorizontal; use strict; use Carp; use SVG::TT::Graph; use base qw(SVG::TT::Graph); use vars qw($VERSION $TEMPLATE_FH); $VERSION = $SVG::TT::Graph::VERSION; $TEMPLATE_FH = \*DATA; =head1 NAME SVG::TT::Graph::BarHorizontal - Create presentation quality SVG horizontal bar graphs easily =head1 SYNOPSIS use SVG::TT::Graph::BarHorizontal; my @fields = qw(Jan Feb Mar); my @data_sales_02 = qw(12 45 21); my $graph = SVG::TT::Graph::BarHorizontal->new({ 'height' => '500', 'width' => '300', 'fields' => \@fields, }); $graph->add_data({ 'data' => \@data_sales_02, 'title' => 'Sales 2002', }); print "Content-type: image/svg+xml\n\n"; print $graph->burn(); =head1 DESCRIPTION This object aims to allow you to easily create high quality SVG horitonzal bar graphs. You can either use the default style sheet or supply your own. Either way there are many options which can be configured to give you control over how the graph is generated - with or without a key, data elements at each point, title, subtitle etc. =head1 METHODS =head2 new() use SVG::TT::Graph::BarHorizontal; # Field names along the X axis my @fields = qw(Jan Feb Mar); my $graph = SVG::TT::Graph::BarHorizontal->new({ # Required 'fields' => \@fields, # Optional - defaults shown 'height' => '500', 'width' => '300', 'show_data_values' => 1, 'scale_divisions' => '', 'min_scale_value' => '0', 'bar_gap' => 1, 'show_x_labels' => 1, 'stagger_x_labels' => 0, 'show_y_labels' => 1, 'scale_integers' => 0, 'y_label_formatter' => sub { return @_ }, 'x_label_formatter' => sub { return @_ }, 'show_x_title' => 0, 'x_title' => 'X Field names', 'show_y_title' => 0, 'y_title_text_direction' => 'bt', 'y_title' => 'Y Scale', 'show_graph_title' => 0, 'graph_title' => 'Graph Title', 'show_graph_subtitle' => 0, 'graph_subtitle' => 'Graph Sub Title', 'key' => 0, 'key_position' => 'right', # Stylesheet defaults 'style_sheet' => '/includes/graph.css', # internal stylesheet 'random_colors' => 0, }); The constructor takes a hash reference, only fields (the names for each field on the X axis) MUST be set, all other values are defaulted to those shown above - with the exception of style_sheet which defaults to using the internal style sheet. =head2 add_data() my @data_sales_02 = qw(12 45 21); $graph->add_data({ 'data' => \@data_sales_02, 'title' => 'Sales 2002', }); This method allows you to add data to the graph object. It can be called several times to add more data sets in, but the likelihood is you should be using SVG::TT::Graph::Line as it won't look great! =head2 clear_data() my $graph->clear_data(); This method removes all data from the object so that you can reuse it to create a new graph but with the same config options. =head2 burn() print $graph->burn(); This method processes the template with the data and config which has been set and returns the resulting SVG. This method will croak unless at least one data set has been added to the graph object. =head2 config methods my $value = $graph->method(); my $confirmed_new_value = $graph->method($value); The following is a list of the methods which are available to change the config of the graph object after it has been created. =over 4 =item height() Set the height of the graph box, this is the total height of the SVG box created - not the graph it self which auto scales to fix the space. =item width() Set the width of the graph box, this is the total width of the SVG box created - not the graph it self which auto scales to fix the space. =item compress() Whether or not to compress the content of the SVG file (Compress::Zlib required). =item tidy() Whether or not to tidy the content of the SVG file (XML::Tidy required). =item style_sheet() Set the path to an external stylesheet, set to '' if you want to revert back to using the defaut internal version. The default stylesheet handles up to 12 data sets. All data series over the 12th will have no style and be in black. If you have over 12 data sets you can assign them all random colors (see the random_color() method) or create your own stylesheet and add the additional settings for the extra data sets. To create an external stylesheet create a graph using the default internal version and copy the stylesheet section to an external file and edit from there. =item random_colors() Use random colors in the internal stylesheet =item show_data_values() Show the value of each element of data on the graph =item bar_gap() Whether to have a gap between the bars or not, default is '1', set to '0' if you don't want gaps. =item min_scale_value() The point at which the Y axis starts, defaults to '0', if set to '' it will default to the minimum data value. =item show_x_labels() Whether to show labels on the X axis or not, defaults to 1, set to '0' if you want to turn them off. =item stagger_x_labels() This puts the labels at alternative levels so if they are long field names they will not overlap so easily. Default it '0', to turn on set to '1'. =item show_y_labels() Whether to show labels on the Y axis or not, defaults to 1, set to '0' if you want to turn them off. =item scale_integers() Ensures only whole numbers are used as the scale divisions. Default it '0', to turn on set to '1'. This has no effect if scale divisions are less than 1. =item scale_divisions() This defines the gap between markers on the X axis, default is a 10th of the max_value, e.g. you will have 10 markers on the X axis. NOTE: do not set this too low - you are limited to 999 markers, after that the graph won't generate. =item show_x_title() Whether to show the title under the X axis labels, default is 0, set to '1' to show. =item x_title() What the title under X axis should be, e.g. 'Months'. =item show_y_title() Whether to show the title under the Y axis labels, default is 0, set to '1' to show. =item y_title_text_direction() Aligns writing mode for Y axis label. Defaults to 'bt' (Bottom to Top). Change to 'tb' (Top to Bottom) to reverse. =item y_title() What the title under Y axis should be, e.g. 'Sales in thousands'. =item show_graph_title() Whether to show a title on the graph, default is 0, set to '1' to show. =item graph_title() What the title on the graph should be. =item show_graph_subtitle() Whether to show a subtitle on the graph, default is 0, set to '1' to show. =item graph_subtitle() What the subtitle on the graph should be. =item key() Whether to show a key, defaults to 0, set to '1' if you want to show it. =item key_position() Where the key should be positioned, defaults to 'right', set to 'bottom' if you want to move it. =item x_label_formatter () A callback subroutine which will format a label on the x axis. For example: $graph->x_label_formatter( sub { return '$' . $_[0] } ); =item y_label_formatter() A callback subroutine which will format a label on the y axis. For example: $graph->y_label_formatter( sub { return '$' . $_[0] } ); =back =head1 EXAMPLES For examples look at the project home page http://leo.cuckoo.org/projects/SVG-TT-Graph/ =head1 EXPORT None by default. =head1 ACKNOWLEDGEMENTS Thanks to Foxtons for letting us put this on CPAN, Todd Caine for heads up on reparsing the template (but not using atm), David Meibusch for TimeSeries and a load of other ideas, Stephen Morgan for creating the TT template and SVG, and thanks for all the patches by Andrew Ruthven and others. =head1 AUTHOR Leo Lapworth =head1 MAINTAINER Florent Angly =head1 COPYRIGHT AND LICENSE Copyright (C) 2003, Leo Lapworth This module is free software; you can redistribute it or modify it under the same terms as Perl itself. =head1 BUGS Please report any bugs or feature requests to bug-graph-svg-tt@rt.cpan.org, or through the web interface at http://rt.cpan.org. The Graph::SVG::TT development repository is located on GitHub at L. Get the latest development version using: git clone git://github.com/ranguard/svg-tt-graph.git =head1 SEE ALSO L, L, L, L, L, L, L, L, L =cut sub _init { my $self = shift; croak "fields was not supplied or is empty" unless defined $self->{'config'}->{fields} && ref($self->{'config'}->{fields}) eq 'ARRAY' && scalar(@{$self->{'config'}->{fields}}) > 0; } sub _set_defaults { my $self = shift; my %default = ( 'width' => '500', 'height' => '300', 'random_colors' => 0, 'style_sheet' => '', 'show_data_values' => 1, 'min_scale_value' => '0', 'scale_divisions' => '', 'bar_gap' => 1, 'show_x_labels' => 1, 'stagger_x_labels' => 0, 'show_y_labels' => 1, 'scale_integers' => 0, 'x_label_formatter' => sub { return @_ }, 'y_label_formatter' => sub { return @_ }, 'show_x_title' => 0, 'x_title' => 'X Field names', 'show_y_title' => 0, 'y_title_text_direction' => 'bt', 'y_title' => 'Y Scale', 'show_graph_title' => 0, 'graph_title' => 'Graph Title', 'show_graph_subtitle' => 0, 'graph_subtitle' => 'Graph Sub Title', 'key' => 0, 'key_position' => 'right', # bottom or right ); while( my ($key,$value) = each %default ) { $self->{config}->{$key} = $value; } } 1; __DATA__ [% stylesheet = 'included' %] [% IF config.style_sheet && config.style_sheet != '' %] [% ELSE %] [% stylesheet = 'excluded' %] [% END %] [% IF stylesheet == 'excluded' %] [% END %] [% w = config.width %] [% h = config.height %] [% x = 0 %] [% y = 0 %] [% char_width = 7 %] [% IF config.show_y_title %][% w = w - 20 %][% x = x + 20 %][% END %] [% IF config.show_y_labels %] [% max_ylabel_length = 0 %] [% FOREACH y_label = config.fields %] [% IF max_ylabel_length < y_label.length %] [% max_ylabel_length = y_label.length %] [% END %] [% END %] [% space_b4_axis = char_width * max_ylabel_length %] [% w = w - space_b4_axis %] [% x = x + space_b4_axis %] [% END %] [% IF max_ylabel_length == 1 %] [% w = w - 5 %] [% x = x + 5 %] [% END %] [% IF config.show_x_labels %] [% w = w - 20 %] [% IF !config.show_y_labels && !config.show_y_title %] [% w = w - 10 %] [% x = x + 10 %] [% END %] [% IF config.min_scale_value.length > 1 %] [% padding_for_labels = char_width * config.min_scale_value.length %] [% w = w - (padding_for_labels / 2) %] [% x = x + (padding_for_labels / 2) %] [% END %] [% END %] [% IF config.show_x_labels %][% h = h - 20 %][% END %] [% stagger = 0 %] [% IF config.stagger_x_labels %] [% stagger = 17 %] [% h = h - stagger %] [% END %] [% IF config.show_x_title %][% h = h - 25 - stagger %][% END %] [% IF config.show_y_labels %][% h = h - 10 %][% y = y + 10 %][% END %] [% IF config.show_graph_title %][% h = h - 25 %][% y = y + 25 %][% END %] [% IF config.show_graph_subtitle %][% h = h - 10 %][% y = y + 10 %][% END %] [% max_key_size = 0 %] [% FOREACH y_label = config.fields %] [% IF max_key_size < data.0.title.length %] [% max_key_size = data.0.title.length %] [% END %] [% END %] [% key_box_size = 12 %] [% IF config.key && config.key_position == 'right' %] [% w = w - (max_key_size * (char_width - 1)) - (key_box_size * 3 ) %] [% ELSIF config.key && config.key_position == 'bottom' %] [% IF data.size < 4 %] [% h = h - ((data.size + 1) * (key_box_size + key_padding))%] [% ELSE %] [% h = h - (4 * (key_box_size + key_padding))%] [% END %] [% END %] [% min_value = 99999999999 %] [% max_value = 0 %] [% FOREACH field = config.fields %] [% FOREACH dataset = data %] [% IF min_value > dataset.data.$field && dataset.data.$field != '' %] [% min_value = dataset.data.$field %] [% END %] [% IF max_value < dataset.data.$field && dataset.data.$field != '' %] [% max_value = dataset.data.$field %] [% END %] [% END %] [% END %] [% IF config.min_scale_value || config.min_scale_value == '0' %] [% min_scale_value = config.min_scale_value %] [% ELSE %] [% min_scale_value = min_value %] [% END %] [% base_line = h + y %] [% IF (max_value - min_scale_value) == 0 %] [% top_pad = 10 %] [% ELSE %] [% top_pad = (max_value - min_scale_value) / 20 %] [% END %] [% scale_range = (max_value + top_pad) - min_scale_value %] [% IF config.scale_divisions %] [% scale_division = config.scale_divisions %] [% ELSE %] [% scale_division = scale_range / 10 %] [% END %] [% IF config.scale_integers %] [% IF scale_division < 1 %] [% scale_division = 1 %] [% ELSIF scale_division.match('.') %] [% scale_division = scale_division FILTER format('%2.0f') %] [% END %] [% END %] [% dy = config.fields.size %] [% data_widths_y = h / dy %] [% dh = data_widths_y.match('(\d+[\.\d\d])').0 %] [% i = dh %] [% count = 0 %] [% IF config.show_y_labels %] [% FOREACH field = config.fields %] [% field_txt = config.y_label_formatter(field) %] [% IF count == 0 %] [% field_txt %] [% i = i - dh %] [% ELSE %] [% field_txt %] [% END %] [% i = i + dh %] [% count = count + 1 %] [% END %] [% END %] [% dx = scale_range / scale_division %] [% scale_division_height = w / dx %] [% dx = scale_division_height.match('(\d+[\.\d\d])').0 %] [% count = 0 %] [% y_value = min_scale_value %] [% stagger_count = 0 %] [% IF config.show_x_labels %] [% WHILE (dx * count) < w %] [% IF count == 0 %] [% y_value_txt = y_value FILTER format('%2.0f') %] [% y_value_txt = config.y_label_formatter(y_value_txt) %] [% y_value_txt %] [% ELSE %] [% IF stagger_count == 2 %] [% y_value_txt = y_value FILTER format('%2.01f') %] [% y_value_txt = config.y_label_formatter(y_value_txt) %] [% y_value_txt %] [% stagger_count = 0 %] [% ELSE %] [% y_value_txt = y_value FILTER format('%2.01f') %] [% y_value_txt = config.y_label_formatter(y_value_txt) %] [% y_value_txt %] [% END %] [% END %] [% y_value = y_value + scale_division %] [% count = count + 1 %] [% stagger_count = stagger_count + 1 %] [% END %] [% END %] [% IF config.show_x_title %] [% IF !config.show_x_labels %] [% y_xtitle = 15 %] [% ELSE %] [% y_xtitle = 35 %] [% END %] [% config.x_title %] [% END %] [% IF config.show_y_title %] [% IF config.y_title_text_direction == 'tb' %] [% config.y_title %] [% ELSE %] [% config.y_title %] [% END %] [% END %] [% IF config.bar_gap %] [% bar_gap = 10 %] [% ELSE %] [% bar_gap = 0 %] [% END %] [% bar_width = dh - bar_gap %] [% divider = dx / scale_division %] [% xcount = 0 %] [% FOREACH field = config.fields %] [% dcount = 1 %] [% FOREACH dataset = data %] [% IF config.show_data_values %] [% dataset.data.$field %] [% END %] [% dcount = dcount + 1 %] [% END %] [% xcount = xcount + 1 %] [% END %] [% key_box_size = 12 %] [% key_count = 1 %] [% key_padding = 5 %] [% IF config.key && config.key_position == 'right' %] [% FOREACH dataset = data %] [% dataset.title %] [% key_count = key_count + 1 %] [% END %] [% ELSIF config.key && config.key_position == 'bottom' %] [% y_key = base_line %] [% IF config.show_x_labels %][% y_key = base_line + 20 %][% END %] [% IF config.show_x_title %][% y_key = base_line + 25 %][% END %] [% y_key_start = y_key %] [% x_key = x %] [% FOREACH dataset = data %] [% IF key_count == 4 || key_count == 7 || key_count == 10 %] [% x_key = x_key + 200 %] [% y_key = y_key - (key_box_size * 4) - 2 %] [% END %] [% dataset.title %] [% key_count = key_count + 1 %] [% END %] [% END %] [% IF config.show_graph_title %] [% config.graph_title %] [% END %] [% IF config.show_graph_subtitle %] [% IF config.show_graph_title %] [% y_subtitle = 30 %] [% ELSE %] [% y_subtitle = 15 %] [% END %] [% config.graph_subtitle %] [% END %] SVG-TT-Graph-0.21/lib/SVG/TT/Graph/BarLine.pm0000755000175000017500000007464711756370206020402 0ustar floflooofloflooopackage SVG::TT::Graph::BarLine; use strict; use Carp; use SVG::TT::Graph; use base qw(SVG::TT::Graph); use vars qw($VERSION $TEMPLATE_FH); $VERSION = $SVG::TT::Graph::VERSION; $TEMPLATE_FH = \*DATA; =head1 NAME SVG::TT::Graph::BarLine - Create presentation quality SVG bar-line graphs easily =head1 SYNOPSIS use SVG::TT::Graph::BarLine; my @fields = qw(Jan Feb Mar); my @data_sales_02 = qw(12 45 21); my @data_sales_03 = (24, 55, 61); my $graph = SVG::TT::Graph::BarLine->new({ 'height' => '500', 'width' => '300', 'fields' => \@fields, }); $graph->add_data({ 'data' => \@data_sales_02, 'title' => 'Sales 2002', }); $graph->add_data({ 'data' => \@data_sales_03, 'title' => 'Sales 2003', }); print "Content-type: image/svg+xml\n\n"; print $graph->burn(); =head1 DESCRIPTION This object aims to allow you to easily create high quality SVG bar graphs. You can either use the default style sheet or supply your own. Either way there are many options which can be configured to give you control over how the graph is generated - with or without a key, data elements at each point, title, subtitle etc. =head1 METHODS =head2 new() use SVG::TT::Graph::BarLine; # Field names along the X axis my @fields = qw(Jan Feb Mar); my $graph = SVG::TT::Graph::BarLine->new({ # Required 'fields' => \@fields, # Optional - defaults shown 'height' => '500', 'width' => '300', 'show_data_values' => 1, 'scale_divisions' => '', 'min_scale_value' => '0', 'bar_gap' => 1, 'show_x_labels' => 1, 'stagger_x_labels' => 0, 'rotate_x_labels' => 0, 'show_y_labels' => 1, 'scale_integers' => 0, 'show_secondary_y_labels' => 1, 'y_label_formatter' => sub { return @_ }, 'x_label_formatter' => sub { return @_ }, 'show_x_title' => 0, 'x_title' => 'X Field names', 'show_y_title' => 0, 'show_secondary_y_title' => 0, 'y_title_text_direction' => 'bt', 'secondary_y_title_text_direction' => 'bt', 'y_title' => 'Y Scale', 'secondary_y_title' => 'Y Scale 2', 'show_graph_title' => 0, 'graph_title' => 'Graph Title', 'show_graph_subtitle' => 0, 'graph_subtitle' => 'Graph Sub Title', 'key' => 0, 'key_position' => 'right', # Stylesheet defaults 'style_sheet' => '/includes/graph.css', # internal stylesheet 'random_colors' => 0, }); The constructor takes a hash reference, fields (the names for each field on the X axis) MUST be set, all other values are defaulted to those shown above - with the exception of style_sheet which defaults to using the internal style sheet. =head2 add_data() my @data_sales_02 = qw(12 45 21); $graph->add_data({ 'data' => \@data_sales_02, 'title' => 'Sales 2002', }); This method allows you to add data to the graph object. It can be called several times to add more data sets in, but the likelihood is you should be using SVG::TT::Graph::Line as it won't look great! =head2 clear_data() my $graph->clear_data(); This method removes all data from the object so that you can reuse it to create a new graph but with the same config options. =head2 burn() print $graph->burn(); This method processes the template with the data and config which has been set and returns the resulting SVG. This method will croak unless at least one data set has been added to the graph object. =head2 config methods my $value = $graph->method(); my $confirmed_new_value = $graph->method($value); The following is a list of the methods which are available to change the config of the graph object after it has been created. =over 4 =item height() Set the height of the graph box, this is the total height of the SVG box created - not the graph it self which auto scales to fix the space. =item width() Set the width of the graph box, this is the total width of the SVG box created - not the graph it self which auto scales to fix the space. =item compress() Whether or not to compress the content of the SVG file (Compress::Zlib required). =item tidy() Whether or not to tidy the content of the SVG file (XML::Tidy required). =item style_sheet() =item style_sheet() Set the path to an external stylesheet, set to '' if you want to revert back to using the defaut internal version. The default stylesheet handles up to 12 data sets. All data series over the 12th will have no style and be in black. If you have over 12 data sets you can assign them all random colors (see the random_color() method) or create your own stylesheet and add the additional settings for the extra data sets. To create an external stylesheet create a graph using the default internal version and copy the stylesheet section to an external file and edit from there. =item random_colors() Use random colors in the internal stylesheet =item show_data_values() Show the value of each element of data on the graph =item bar_gap() Whether to have a gap between the bars or not, default is '1', set to '0' if you don't want gaps. =item show_x_labels() Whether to show labels on the X axis or not, defaults to 1, set to '0' if you want to turn them off. =item stagger_x_labels() This puts the labels at alternative levels so if they are long field names they will not overlap so easily. Default it '0', to turn on set to '1'. =item rotate_x_labels() This turns the X axis labels by 90 degrees. Default it '0', to turn on set to '1'. =item show_y_labels() Whether to show labels on the Y axis or not, defaults to 1, set to '0' if you want to turn them off. =item scale_integers() Ensures only whole numbers are used as the scale divisions. Default it '0', to turn on set to '1'. This has no effect if scale divisions are less than 1. =item show_secondary_y_labels() Whether to show labels on the right hand side Y axis or not, defaults to 1, set to '0' if you want to turn them off. =item min_scale_value() The point at which the Y axis starts, defaults to '0', if set to '' it will default to the minimum data value. =item scale_divisions() This defines the gap between markers on the Y axis, default is a 10th of the max_value, e.g. you will have 10 markers on the Y axis. NOTE: do not set this too low - you are limited to 999 markers, after that the graph won't generate. =item show_x_title() Whether to show the title under the X axis labels, default is 0, set to '1' to show. =item x_title() What the title under X axis should be, e.g. 'Months'. =item show_y_title() Whether to show the title on the left hand side Y axis, default is 0, set to '1' to show. =item show_secondary_y_title() Whether to show the title on the right hand side Y axis, default is 0, set to '1' to show. =item y_title_text_direction() Aligns writing mode for Y axis label. Defaults to 'bt' (Bottom to Top). Change to 'tb' (Top to Bottom) to reverse. =item secondary_y_title_text_direction() Aligns writing mode for right hand Y axis label. Defaults to 'bt' (Bottom to Top). Change to 'tb' (Top to Bottom) to reverse. =item y_title() What the title under Y axis should be, e.g. 'Sales in thousands'. =item secondary_y_title() What the title on the right hand side Y axis should be, e.g. 'Number of deals'. =item show_graph_title() Whether to show a title on the graph, defaults to 0, set to '1' to show. =item graph_title() What the title on the graph should be. =item show_graph_subtitle() Whether to show a subtitle on the graph, defaults to 0, set to '1' to show. =item graph_subtitle() What the subtitle on the graph should be. =item key() Whether to show a key, defaults to 0, set to '1' if you want to show it. =item key_position() Where the key should be positioned, defaults to 'right', set to 'bottom' if you want to move it. =item x_label_formatter () A callback subroutine which will format a label on the x axis. For example: $graph->x_label_formatter( sub { return '$' . $_[0] } ); =item y_label_formatter() A callback subroutine which will format a label on the y axis. For example: $graph->y_label_formatter( sub { return '$' . $_[0] } ); =back =head1 EXAMPLES For examples look at the project home page http://leo.cuckoo.org/projects/SVG-TT-Graph/ =head1 EXPORT None by default. =head1 ACKNOWLEDGEMENTS Thanks to Foxtons for letting us put this on CPAN, Todd Caine for heads up on reparsing the template (but not using atm), David Meibusch for TimeSeries and a load of other ideas, Stephen Morgan for creating the TT template and SVG, and thanks for all the patches by Andrew Ruthven and others. =head1 AUTHOR Leo Lapworth =head1 MAINTAINER Florent Angly =head1 COPYRIGHT AND LICENSE Copyright (C) 2003, Leo Lapworth This module is free software; you can redistribute it or modify it under the same terms as Perl itself. =head1 BUGS Please report any bugs or feature requests to bug-graph-svg-tt@rt.cpan.org, or through the web interface at http://rt.cpan.org. The Graph::SVG::TT development repository is located on GitHub at L. Get the latest development version using: git clone git://github.com/ranguard/svg-tt-graph.git =head1 SEE ALSO L, L, L, L, L, L, L, L, L =cut sub _init { my $self = shift; croak "fields was not supplied or is empty" unless defined $self->{'config'}->{fields} && ref($self->{'config'}->{fields}) eq 'ARRAY' && scalar(@{$self->{'config'}->{fields}}) > 0; } sub _set_defaults { my $self = shift; my %default = ( 'width' => '500', 'height' => '300', 'style_sheet' => '', 'random_colors' => 0, 'show_data_values' => 1, 'min_scale_value' => '0', 'scale_divisions' => '', 'bar_gap' => 1, 'show_x_labels' => 1, 'rotate_x_labels' => 0, 'stagger_x_labels' => 0, 'show_y_labels' => 1, 'scale_integers' => 0, 'show_secondary_y_labels' => 1, 'x_label_formatter' => sub { return @_ }, 'y_label_formatter' => sub { return @_ }, 'show_x_title' => 0, 'x_title' => 'X Field names', 'show_y_title' => 0, 'show_secondary_y_title' => 0, 'y_title_text_direction' => 'bt', 'secondary_y_title_text_direction' => 'bt', 'y_title' => 'Y Scale', 'secondary_y_title' => 'Y Scale 2', 'show_graph_title' => 0, 'graph_title' => 'Graph Title', 'show_graph_subtitle' => 0, 'graph_subtitle' => 'Graph Sub Title', 'key' => 0, 'key_position' => 'right', # bottom or right ); while( my ($key,$value) = each %default ) { $self->{config}->{$key} = $value; } } 1; __DATA__ [% stylesheet = 'included' %] [% IF config.style_sheet && config.style_sheet != '' %] [% ELSE %] [% stylesheet = 'excluded' %] [% END %] [% IF stylesheet == 'excluded' %] [% END %] [% w = config.width %] [% h = config.height %] [% x = 0 %] [% y = 0 %] [% char_width = 9 %] [% half_char_height = 2.5 %] [% title_height = 25 %] [% min_value = 99999999999 %] [% max_value = 0 %] [% secondary_max_value = 0 %] [% secondary_max_y_label_length = 0 %] [% secondary_max_y_label_size = 0 %] [% max_key_size = 0 %] [% max_x_label_size = 0 %] [% FOREACH field = config.fields %] [% IF max_x_label_size < field.length %] [% max_x_label_size = field.length %] [% END %] [% IF min_value > data.0.data.$field && data.0.data.$field != '' %] [% min_value = data.0.data.$field %] [% END %] [% IF max_value < data.0.data.$field && data.0.data.$field != '' %] [% max_value = data.0.data.$field %] [% END %] [% IF secondary_max_value < data.1.data.$field && data.1.data.$field != '' %] [% secondary_max_value = data.1.data.$field %] [% END %] [% IF secondary_max_y_label_size < data.1.data.$field.length %] [% secondary_max_y_label_size = data.1.data.$field.length %] [% END %] [% IF max_key_size < data.0.title.length %] [% max_key_size = data.0.title.length %] [% END %] [% END %] [% secondary_max_y_label_length = secondary_max_y_label_size * char_width %] [% IF config.show_x_labels %][% h = h - 20 %][% END %] [% max_x_label_length = 0 %] [% IF config.rotate_x_labels %] [% max_x_label_length = max_x_label_size * char_width %] [% h = h - max_x_label_length %] [% END %] [% stagger = 0 %] [% IF config.stagger_x_labels %] [% stagger = 17 %] [% h = h - stagger %] [% END %] [% IF config.show_x_title %][% h = h - title_height - stagger %][% END %] [% IF config.show_y_labels %][% h = h - 10 %][% y = y + 10 %][% END %] [% IF config.show_graph_title %][% h = h - title_height %][% y = y + title_height %][% END %] [% IF config.show_graph_subtitle %][% h = h - 10 %][% y = y + 10 %][% END %] [% key_box_size = 12 %] [% IF config.key && config.key_position == 'right' %] [% IF config.show_secondary_y_title %] [% w = w - (max_key_size * (char_width - 1)) - (key_box_size * 3 ) %] [% ELSE %] [% w = w - (max_key_size * (char_width - 1)) - (key_box_size * 3 ) - title_height %] [% END %] [% ELSIF config.key && config.key_position == 'bottom' %] [% IF data.size < 4 %] [% h = h - ((data.size + 1) * (key_box_size + key_padding))%] [% ELSE %] [% h = h - (4 * (key_box_size + key_padding))%] [% END %] [% END %] [% IF config.min_scale_value || config.min_scale_value == '0' %] [% min_scale_value = config.min_scale_value %] [% ELSE %] [% min_scale_value = min_value %] [% END %] [% base_line = h + y %] [% IF (max_value - min_scale_value) == 0 %] [% top_pad = 10 %] [% ELSE %] [% top_pad = (max_value - min_scale_value) / 20 %] [% END %] [% IF (secondary_max_value - min_scale_value) == 0 %] [% secondary_top_pad = 10 %] [% ELSE %] [% secondary_top_pad = (secondary_max_value - min_scale_value) / 20 %] [% END %] [% scale_range = (max_value + top_pad) - min_scale_value %] [% secondary_scale_range = (secondary_max_value + secondary_top_pad) - min_scale_value %] [% IF config.scale_divisions %] [% scale_division = config.scale_divisions %] [% ELSE %] [% scale_division = scale_range / 10 FILTER format('%2.01f') %] [% END %] [% IF config.scale_divisions %] [% secondary_scale_division = config.scale_divisions %] [% ELSE %] [% secondary_scale_division = secondary_scale_range / 10 FILTER format('%2.01f') %] [% END %] [% IF config.scale_integers %] [% IF scale_division < 1 %] [% scale_division = 1 %] [% ELSIF scale_division.match('.') %] [% scale_division = scale_division FILTER format('%2.0f') %] [% END %] [% END %] [% dx = config.fields.size %] [% secondary_title_padding = 0 %] [% IF config.show_secondary_y_labels %] [% w = w - secondary_max_y_label_length - title_height %] [% secondary_title_padding = secondary_title_padding + secondary_max_y_label_length + 10 %] [% END %] [% IF config.show_secondary_y_title %] [% w = w - title_height - char_width %] [% secondary_title_padding = secondary_title_padding + title_height %] [% END %] [% data_widths_x = w / dx %] [% dw = data_widths_x FILTER format('%2.02f') %] [% half_label_width = (config.fields.0.length / 2) * char_width %] [% space_b4_y_axis = 0 %] [% IF half_label_width > (dw / 2) %] [% space_b4_y_axis = half_label_width - (dw / 2) %] [% IF config.key && config.key_position == 'right' %] [% w = w - space_b4_y_axis %] [% ELSE %] [% w = w - (space_b4_y_axis * 2) %] [% END %] [% x = x + space_b4_y_axis %] [% END %] [% max_value_length = max_value.length %] [% max_value_length_px = max_value_length * char_width %] [% IF config.show_y_labels && space_b4_y_axis < max_value_length_px %] [% IF max_value_length < 2 %] [% w = w - (max_value_length * (char_width * 2)) %] [% x = x + (max_value_length * (char_width * 2)) %] [% ELSE %] [% w = w - max_value_length_px %] [% x = x + max_value_length_px %] [% END %] [% END %] [% IF config.show_y_title && space_b4_y_axis < max_value_length_px %] [% w = w - title_height %] [% x = x + title_height %] [% END %] [% dx = config.fields.size %] [% data_widths_x = w / dx %] [%# dw = data_widths_x.match('(\d+[\.\d\d])').0 %] [% dw = data_widths_x %] [% IF config.bar_gap %] [% bar_gap = 10 %] [% IF dw < bar_gap %] [% bar_gap = dw / 2 %] [% END %] [% ELSE %] [% bar_gap = 0 %] [% END %] [% i = dw %] [% count = 0 %] [% stagger_count = 0 %] [% IF config.show_x_labels %] [% FOREACH field = config.fields %] [% field_txt = config.x_label_formatter(field) %] [% IF count == 0 %] [% field %] [% i = i - dw %] [% ELSE %] [% IF stagger_count == 2 %] [% field_txt %] [% stagger_count = 0 %] [% ELSE %] [% field_txt %] [% END %] [% END %] [% i = i + dw %] [% count = count + 1 %] [% stagger_count = stagger_count + 1 %] [% END %] [% END %] [% dy = scale_range / scale_division %] [% y_marker_height = h / dy %] [% dy = y_marker_height.match('(\d+[\.\d\d])').0 %] [% count = 0 %] [% y_value = min_scale_value %] [% IF config.show_y_labels %] [% WHILE (dy * count) < h %] [% y_value_txt = config.y_label_formatter(y_value) %] [% IF count == 0 %] [% y_value_txt %] [% ELSE %] [% y_value_txt %] [% END %] [% y_value = y_value + scale_division %] [% count = count + 1 %] [% END %] [% END %] [% secondary_y_marker_height = h / dy %] [% s_count = 0 %] [% secondary_y_value = min_scale_value %] [% IF config.show_secondary_y_labels %] [% WHILE (dy * s_count) < h %] [% secondary_y_value %] [% secondary_y_value = secondary_y_value + secondary_scale_division %] [% s_count = s_count + 1 %] [% END %] [% END %] [% IF config.show_x_title %] [% IF !config.show_x_labels %] [% y_xtitle = 15 %] [% ELSE %] [% y_xtitle = 35 %] [% END %] [% config.x_title %] [% END %] [% IF config.show_y_title %] [% IF config.y_title_text_direction == 'tb' %] [% config.y_title %] [% ELSE %] [% config.y_title %] [% END %] [% END %] [% IF config.show_secondary_y_title %] [% IF config.secondary_y_title_text_direction == 'tb' %] [% config.secondary_y_title %] [% ELSE %] [% config.secondary_y_title %] [% END %] [% END %] [% bar_width = dw - bar_gap %] [% divider = dy / scale_division %] [% secondary_divider = dy / secondary_scale_division %] [% xcount = 0 %] [% line = data.size %] [% FOREACH field = config.fields %] [% dcount = 1 %] [% IF config.show_data_values %] [% data.0.data.$field %] [% END %] [% dcount = dcount + 1 %] [% xcount = xcount + 1 %] [% END %] [% xcount = 0 %] [% FOREACH field = config.fields %] [% IF config.show_data_points %] [% END %] [% IF config.show_data_values %] [% data.1.data.$field %] [% END %] [% xcount = xcount + 1 %] [% END %] [% key_count = 1 %] [% key_padding = 5 %] [% IF config.key && config.key_position == 'right' %] [% FOREACH dataset = data %] [% dataset.title %] [% key_count = key_count + 1 %] [% END %] [% ELSIF config.key && config.key_position == 'bottom' %] [% y_key = base_line %] [% IF config.show_x_title %][% y_key = y_key + title_height %][% END %] [% IF config.rotate_x_labels && config.show_x_labels %] [% y_key = y_key + max_x_label_length %] [% ELSIF config.show_x_labels && stagger < 1 %] [% y_key = y_key + 20 %] [% END %] [% y_key_start = y_key %] [% x_key = x %] [% FOREACH dataset = data %] [% IF key_count == 4 || key_count == 7 || key_count == 10 %] [% x_key = x_key + 200 %] [% y_key = y_key - (key_box_size * 4) - 2 %] [% END %] [% dataset.title %] [% key_count = key_count + 1 %] [% END %] [% END %] [% IF config.show_graph_title %] [% config.graph_title %] [% END %] [% IF config.show_graph_subtitle %] [% IF config.show_graph_title %] [% y_subtitle = 30 %] [% ELSE %] [% y_subtitle = 15 %] [% END %] [% config.graph_subtitle %] [% END %] SVG-TT-Graph-0.21/lib/SVG/TT/Graph/XY.pm0000644000175000017500000010326211756374376017421 0ustar floflooofloflooopackage SVG::TT::Graph::XY; use strict; use Carp; use SVG::TT::Graph; use base qw(SVG::TT::Graph); use vars qw($VERSION $TEMPLATE_FH); $VERSION = $SVG::TT::Graph::VERSION; $TEMPLATE_FH = \*DATA; =head1 NAME SVG::TT::Graph::XY - Create presentation quality SVG line graphs of XY data points easily =head1 SYNOPSIS use SVG::TT::Graph::XY; my @data_cpu = (0.3, 23, 0.5, 54, 1.0, 67, 1.8, 12); my @data_disk = (0.45, 12, 0.51, 26, 0.53, 23); my $graph = SVG::TT::Graph::XY->new({ 'height' => '500', 'width' => '300', }); $graph->add_data({ 'data' => \@data_cpu, 'title' => 'CPU', }); $graph->add_data({ 'data' => \@data_disk, 'title' => 'Disk', }); print "Content-type: image/svg+xml\n\n"; print $graph->burn(); =head1 DESCRIPTION This object aims to allow you to easily create high quality SVG line graphs of XY data. You can either use the default style sheet or supply your own. Either way there are many options which can be configured to give you control over how the graph is generated - with or without a key, data elements at each point, title, subtitle etc. =head1 METHODS =head2 new() use SVG::TT::Graph::XY; my $graph = SVG::TT::Graph::XY->new({ # Optional - defaults shown 'height' => 500, 'width' => 300, 'show_y_labels' => 1, 'yscale_divisions' => '', 'min_yscale_value' => 0, 'max_yscale_value' => '', 'show_x_labels' => 1, 'xscale_divisions' => '', 'min_xscale_value' => '', 'max_xscale_value' => '', 'stagger_x_labels' => 0, 'rotate_x_labels' => 0, 'y_label_formatter' => sub { return @_ }, 'x_label_formatter' => sub { return @_ }, 'show_data_points' => 1, 'show_data_values' => 1, 'rollover_values' => 0, 'area_fill' => 0, 'show_x_title' => 0, 'x_title' => 'X Field names', 'show_y_title' => 0, 'y_title' => 'Y Scale', 'show_graph_title' => 0, 'graph_title' => 'Graph Title', 'show_graph_subtitle' => 0, 'graph_subtitle' => 'Graph Sub Title', 'key' => 0, 'key_position' => 'right', # Stylesheet defaults 'style_sheet' => '/includes/graph.css', # internal stylesheet 'random_colors' => 0, }); The constructor takes a hash reference with values defaulted to those shown above - with the exception of style_sheet which defaults to using the internal style sheet. =head2 add_data() my @data_cpu = (0.3, 23, 0.5, 54, 1.0, 67, 1.8, 12); or my @data_cpu = ([0.3,23], [0.5,54], [1.0,67], [1.8,12]); $graph->add_data({ 'data' => \@data_cpu, 'title' => 'CPU', }); This method allows you to add data to the graph object. The data is expected to be a list of pairs of numbers. It can be called several times to add more data sets in. =head2 clear_data() my $graph->clear_data(); This method removes all data from the object so that you can reuse it to create a new graph but with the same config options. =head2 burn() print $graph->burn(); This method processes the template with the data and config which has been set and returns the resulting SVG. This method will croak unless at least one data set has been added to the graph object. =head2 config methods my $value = $graph->method(); my $confirmed_new_value = $graph->method($value); The following is a list of the methods which are available to change the config of the graph object after it has been created. =over 4 =item height() Set the height of the graph box, this is the total height of the SVG box created - not the graph it self which auto scales to fix the space. =item width() Set the width of the graph box, this is the total width of the SVG box created - not the graph it self which auto scales to fix the space. =item compress() Whether or not to compress the content of the SVG file (Compress::Zlib required). =item tidy() Whether or not to tidy the content of the SVG file (XML::Tidy required). =item style_sheet() Set the path to an external stylesheet, set to '' if you want to revert back to using the defaut internal version. The default stylesheet handles up to 12 data sets. All data series over the 12th will have no style and be in black. If you have over 12 data sets you can assign them all random colors (see the random_color() method) or create your own stylesheet and add the additional settings for the extra data sets. To create an external stylesheet create a graph using the default internal version and copy the stylesheet section to an external file and edit from there. =item random_colors() Use random colors in the internal stylesheet. =item show_data_values() Show the value of each element of data on the graph. =item show_data_points() Show a small circle on the graph where the line goes from one point to the next. =item rollover_values() Shows data values and data points when the mouse is over the point. Used in combination with show_data_values and/or show_data_points. =item data_value_format() Format specifier to for data values (as per printf). =item max_x_span() Maximum span for a line between data points on the X-axis. If this span is exceeded, the points are not connected. This is useful for skipping missing data sections. If you set this value to something smaller than 0 (e.g. -1), you will get an XY scatter plot with no line joining the data points. =item stacked() Accumulates each data set. (i.e. Each point increased by sum of all previous series at same point). Default is 0, set to '1' to show. =item min_yscale_value() The point at which the Y axis starts, defaults to '0', if set to '' it will default to the minimum data value. =item max_yscale_value() The point at which the Y axis ends, if set to '' it will default to the maximum data value. =item yscale_divisions() This defines the gap between markers on the Y axis, default is a 10th of the range, e.g. you will have 10 markers on the Y axis. NOTE: do not set this too low - you are limited to 999 markers, after that the graph won't generate. =item show_x_labels() Whether to show labels on the X axis or not, defaults to 1, set to '0' if you want to turn them off. =item show_y_labels() Whether to show labels on the Y axis or not, defaults to 1, set to '0' if you want to turn them off. =item y_label_format() Format string for presenting the Y axis labels (as per printf). =item xscale_divisions() This defines the gap between markers on the X axis. Default is the entire range (only start and end axis labels). =item stagger_x_labels() This puts the labels at alternative levels so if they are long field names they will not overlap so easily. Default it '0', to turn on set to '1'. =item rotate_x_labels() This turns the X axis labels by 90 degrees. Default it '0', to turn on set to '1'. =item min_xscale_value() This sets the minimum X value. Any data points before this value will not be shown. =item max_xscale_value() This sets the maximum X value. Any data points after this value will not be shown. =item show_x_title() Whether to show the title under the X axis labels, default is 0, set to '1' to show. =item x_title() What the title under X axis should be, e.g. 'Parameter X'. =item show_y_title() Whether to show the title under the Y axis labels, default is 0, set to '1' to show. =item y_title() What the title under Y axis should be, e.g. 'Sales in thousands'. =item show_graph_title() Whether to show a title on the graph, default is 0, set to '1' to show. =item graph_title() What the title on the graph should be. =item show_graph_subtitle() Whether to show a subtitle on the graph, default is 0, set to '1' to show. =item graph_subtitle() What the subtitle on the graph should be. =item key() Whether to show a key, defaults to 0, set to '1' if you want to show it. =item key_position() Where the key should be positioned, defaults to 'right', set to 'bottom' if you want to move it. =item x_label_formatter () A callback subroutine which will format a label on the x axis. For example: $graph->x_label_formatter( sub { return '$' . $_[0] } ); =item y_label_formatter() A callback subroutine which will format a label on the y axis. For example: $graph->y_label_formatter( sub { return '$' . $_[0] } ); =back =head1 EXAMPLES For examples look at the project home page http://leo.cuckoo.org/projects/SVG-TT-Graph/ =head1 EXPORT None by default. =head1 ACKNOWLEDGEMENTS This module was largely based on SVG::TT::Graph::TimeSeries by David Meibusch. =head1 AUTHOR Florent Angly =head1 MAINTAINER Florent Angly =head1 COPYRIGHT AND LICENSE Copyright (C) 2003, Leo Lapworth This module is free software; you can redistribute it or modify it under the same terms as Perl itself. =head1 BUGS Please report any bugs or feature requests to bug-graph-svg-tt@rt.cpan.org, or through the web interface at http://rt.cpan.org. The Graph::SVG::TT development repository is located on GitHub at L. Get the latest development version using: git clone git://github.com/ranguard/svg-tt-graph.git =head1 SEE ALSO L, L, L, L, L, L, L, L =cut sub _init { my $self = shift; } sub _set_defaults { my $self = shift; my @fields = (); my %default = ( 'fields' => \@fields, 'width' => '500', 'height' => '300', 'style_sheet' => '', 'random_colors' => 0, 'show_data_points' => 1, 'show_data_values' => 1, 'rollover_values' => 0, 'max_x_span' => '', 'area_fill' => 0, 'show_y_labels' => 1, 'yscale_divisions' => '', 'min_yscale_value' => '0', 'stacked' => 0, 'show_x_labels' => 1, 'stagger_x_labels' => 0, 'rotate_x_labels' => 0, 'xscale_divisions' => '', 'x_label_formatter' => sub { return @_ }, 'y_label_formatter' => sub { return @_ }, 'show_x_title' => 0, 'x_title' => 'X Field names', 'show_y_title' => 0, 'y_title' => 'Y Scale', 'show_graph_title' => 0, 'graph_title' => 'Graph Title', 'show_graph_subtitle' => 0, 'graph_subtitle' => 'Graph Sub Title', 'key' => 0, 'key_position' => 'right', # bottom or right ); while( my ($key,$value) = each %default ) { $self->{config}->{$key} = $value; } } # override this so we can pre-manipulate the data sub add_data { my ($self, $conf) = @_; croak 'no data provided' unless (defined $conf->{'data'} && ref($conf->{'data'}) eq 'ARRAY'); # create an array unless(defined $self->{'data'}) { my @data; $self->{'data'} = \@data; } # convert to sorted (by ascending numeric value) array of [ x, y ] my @new_data = (); my ($i,$x,@pair); $i = 0; while ($i < @{$conf->{'data'}}) { @pair = (); if (ref($conf->{'data'}->[$i]) eq 'ARRAY') { push @pair,@{$conf->{'data'}->[$i]}; $i++; } else { $pair[0] = $conf->{'data'}->[$i++]; $pair[1] = $conf->{'data'}->[$i++]; } push @new_data, [ @pair ]; } my @sorted = sort {@{$a}[0] <=> @{$b}[0]} @new_data; # if stacked, we accumulate the if (($self->{config}->{stacked}) && (@{$self->{'data'}})) { my $prev = $self->{'data'}->[@{$self->{'data'}} - 1]->{pairs}; # check our length matches previous croak sprintf("Series %d can not be stacked on previous series. Mismatched length.", scalar(@{$self->{'data'}})) unless (scalar(@sorted) == scalar(@$prev)); for (my $i = 0; $i < @sorted; $i++) { # check the x value matches croak sprintf("Series %d can not be stacked on previous series. Mismatched x value at sample %d (x %s).", scalar(@{$self->{'data'}}), $i, $sorted[$i][0]) unless ($sorted[$i][0] == $prev->[$i][0]); $sorted[$i][1] += $prev->[$i][1]; } } my %store = ( 'pairs' => \@sorted, ); $store{'title'} = $conf->{'title'} if defined $conf->{'title'}; push (@{$self->{'data'}},\%store); return 1; } # override calculations to set a few calculated values, mainly for scaling sub calculations { my $self = shift; # run through the data and calculate maximum and minimum values my ($max_key_size, $max_x, $min_x, $max_y, $min_y, $max_x_label_length, $x_label); foreach my $dataset (@{$self->{data}}) { $max_key_size = length($dataset->{title}) if ((!defined $max_key_size) || ($max_key_size < length($dataset->{title}))); foreach my $pair (@{$dataset->{pairs}}) { $max_x = $pair->[0] if ((!defined $max_x) || ($max_x < $pair->[0])); $min_x = $pair->[0] if ((!defined $min_x) || ($min_x > $pair->[0])); $max_y = $pair->[1] if (($pair->[1] ne '') && ((!defined $max_y) || ($max_y < $pair->[1]))); $min_y = $pair->[1] if (($pair->[1] ne '') && ((!defined $min_y) || ($min_y > $pair->[1]))); $x_label = $pair->[0]; $max_x_label_length = length($x_label) if ((!defined $max_x_label_length) || ($max_x_label_length < length($x_label))); } } $self->{calc}->{max_key_size} = $max_key_size; $self->{calc}->{max_x} = $max_x; $self->{calc}->{min_x} = $min_x; $self->{calc}->{max_y} = $max_y; $self->{calc}->{min_y} = $min_y; $self->{calc}->{max_x_label_length} = $max_x_label_length; # Calc the x axis scale values $self->{calc}->{min_xscale_value} = ($self->_is_valid_config('min_xscale_value')) ? $self->{config}->{min_xscale_value} : $min_x; $self->{calc}->{max_xscale_value} = ($self->_is_valid_config('max_xscale_value')) ? $self->{config}->{max_xscale_value} : $max_x; $self->{calc}->{xscale_range} = $self->{calc}->{max_xscale_value} - $self->{calc}->{min_xscale_value}; # Calc the y axis scale values $self->{calc}->{min_yscale_value} = ($self->_is_valid_config('min_yscale_value')) ? $self->{config}->{min_yscale_value} : $min_y; $self->{calc}->{max_yscale_value} = ($self->_is_valid_config('max_yscale_value')) ? $self->{config}->{max_yscale_value} : $max_y; $self->{calc}->{yscale_range} = $self->{calc}->{max_yscale_value} - $self->{calc}->{min_yscale_value}; my ($range,$division,$precision); if ($self->_is_valid_config('yscale_divisions')) { $division = $self->{config}->{yscale_divisions}; if ($division >= 1) { $precision = 0; } else { $precision = length($division) - 2; } } else { # Find divisions, format and range ($range, $division, $precision) = $self->_range_calc($self->{calc}->{yscale_range}); # If a max value hasn't been set we can set a revised range and max value if (! $self->_is_valid_config('max_yscale_value')) { $self->{calc}->{max_yscale_value} = $self->{calc}->{min_yscale_value} + $range; $self->{calc}->{yscale_range} = $self->{calc}->{max_yscale_value} - $self->{calc}->{min_yscale_value}; } } $self->{calc}->{yscale_division} = $division; $self->{calc}->{y_label_format} = ($self->_is_valid_config('y_label_format')) ? $self->{config}->{y_label_format} : "%.${precision}f"; $self->{calc}->{data_value_format} = ($self->_is_valid_config('data_value_format')) ? $self->{config}->{data_value_format} : "%.${precision}f"; } 1; __DATA__ [% stylesheet = 'included' %] [% IF config.style_sheet && config.style_sheet != '' %] [% ELSE %] [% stylesheet = 'excluded' %] [% END %] [% IF stylesheet == 'excluded' %] [%# include default stylesheet if none specified %] [% END %] [% IF config.key %] [% END %] [%# get dimensions of actual graph area (NOT SVG area) %] [% w = config.width %] [% h = config.height %] [%# set start/default coords of graph %] [% x = 0 %] [% y = 0 %] [% char_width = 8 %] [% half_char_height = 2.5 %] [%# reduce height of graph area if there is labelling on x axis %] [% IF config.show_x_labels %][% h = h - 20 %][% END %] [%# reduce height if x labels are rotated %] [% x_label_allowance = 0 %] [% IF config.rotate_x_labels %] [% x_label_allowance = (calc.max_x_label_length * char_width) - 20 %] [% h = h - x_label_allowance %] [% END %] [%# stagger x labels if overlapping occurs %] [% stagger = 0 %] [% IF config.show_x_labels && config.stagger_x_labels %] [% stagger = 17 %] [% h = h - stagger %] [% END %] [% IF config.show_x_title %][% h = h - 25 - stagger %][% END %] [%# pad top of graph if y axis has data labels so labels do not get chopped off %] [% IF config.show_y_labels %][% h = h - 10 %][% y = y + 10 %][% END %] [%# reduce height if graph has title or subtitle %] [% IF config.show_graph_title %][% h = h - 25 %][% y = y + 25 %][% END %] [% IF config.show_graph_subtitle %][% h = h - 10 %][% y = y + 10 %][% END %] [%# reduce graph dimensions if there is a KEY %] [% key_box_size = 12 %] [% key_padding = 5 %] [% IF config.key && config.key_position == 'right' %] [% w = w - (calc.max_key_size * (char_width - 1)) - (key_box_size * 3 ) %] [% ELSIF config.key && config.key_position == 'bottom' %] [% IF data.size < 4 %] [% h = h - ((data.size + 1) * (key_box_size + key_padding))%] [% ELSE %] [% h = h - (4 * (key_box_size + key_padding))%] [% END %] [% END %] [%# base line %] [% base_line = h + y %] [%# find the string length of max value %] [% max_y_length = calc.max_yscale_value.length %] [%# label width in pixels %] [% max_y_length_px = max_y_length * char_width %] [%# If the y labels are shown but the size of the x labels are small, pad for y labels %] [%# reduce width of graph area if there is large labelling on x axis %] [% space_b4_y_axis = (calc.min_xscale_value.length / 2) * char_width %] [% IF config.show_x_labels %] [% IF config.key && config.key_position == 'right' %] [% w = w - space_b4_y_axis %] [% ELSE %] [% w = w - (space_b4_y_axis * 2) %] [% END %] [% x = x + space_b4_y_axis %] [% ELSIF config.show_data_values %] [% w = w - (max_y_length_px * 2) %] [% x = x + max_y_length_px %] [% END %] [% IF config.show_y_labels && space_b4_y_axis < max_y_length_px %] [% IF max_y_length < 2 %] [% w = w - (max_y_length * (char_width * 2)) %] [% x = x + (max_y_length * (char_width * 2)) %] [% ELSE %] [% w = w - max_y_length_px %] [% x = x + max_y_length_px %] [% END %] [% ELSIF config.show_y_labels && !config.show_x_labels %] [% w = w - max_y_length_px %] [% x = x + max_y_length_px %] [% END %] [% IF config.show_y_title %] [% w = w - 25 %] [% x = x + 25 %] [% END %] [%# Missing data spans %] [% max_x_span = 0 %] [% IF config.max_x_span %] [% max_x_span = config.max_x_span %] [% END %] [%# graph bg and clipping regions for lines/fill and clip extended to included data labels %] [% dx = calc.xscale_range %] [% dw = w / dx %] [% IF config.show_x_labels %] [% x_value_txt = config.x_label_formatter(calc.min_xscale_value) %] [% x_value_txt %] [% last_label = calc.min_xscale_value %] [% IF config.xscale_divisions %] [% xscale_division = config.xscale_divisions %] [% x_value = calc.min_xscale_value + xscale_division %] [% count = 0 %] [% WHILE ((x_value > calc.min_xscale_value) && ((x_value < calc.max_xscale_value))) %] [% x_value_txt = config.x_label_formatter(x_value) %] [% xpos = (dw * (x_value - calc.min_xscale_value)) + x %] [% IF (config.stagger_x_labels && ((count % 2) == 0)) %] [% x_value_txt %] [% ELSE %] [% x_value_txt %] [% END %] [% last_label = x_value %] [% x_value = x_value + xscale_division %] [% count = count + 1 %] [% LAST IF (count >= 999) %] [% END %] [% END %] [% IF calc.max_xscale_value != last_label %] [% x_value_txt = config.x_label_formatter(calc.max_xscale_value) %] [% IF (config.stagger_x_labels && ((count % 2) == 0)) %] [% x_value_txt %] [% ELSE %] [% x_value_txt %] [% END %] [% END %] [% END %] [%# how much padding between largest bar and top of graph %] [% top_pad = h / 40 %] [% dy = calc.yscale_range %] [% dh = (h - top_pad) / dy %] [% count = 0 %] [% y_value = calc.min_yscale_value %] [% IF config.show_y_labels %] [% WHILE ((y_value == calc.min_yscale_value) || (y_value == calc.max_yscale_value) || ((y_value > calc.min_yscale_value) && (y_value < calc.max_yscale_value))) %] [%- next_label = y_value FILTER format(calc.y_label_format) -%] [%- next_label = config.y_label_formatter(next_label) -%] [%- IF count == 0 -%] [%# no stroke for first line %] [% next_label %] [%- ELSE -%] [% IF next_label != last_label %] [% next_label %] [% END %] [%- END -%] [%- y_value = y_value + calc.yscale_division -%] [%- last_label = next_label -%] [%- count = count + 1 -%] [%- LAST IF (count >= 999) -%] [% END %] [% END %] [% IF config.show_x_title %] [% IF !config.show_x_labels %] [% y_xtitle = 15 %] [% ELSE %] [% y_xtitle = 35 %] [% END %] [% config.x_title %] [% END %] [% IF config.show_y_title %] [% config.y_title %] [% END %] [% line = data.size %] [% FOREACH dataset = data.reverse %] [% IF config.area_fill %] [%# create alternate fill first (so line can overwrite if necessary) %] [% xcount = 0 %] [% FOREACH pair = dataset.pairs %] [%- IF ((pair.0 >= calc.min_xscale_value) && (pair.0 <= calc.max_xscale_value)) -%] [%- IF xcount == 0 -%][% lastx = pair.0 %] [% END %] [% END %] [% xcount = 0 %] [% FOREACH pair = dataset.pairs %] [% IF ((pair.0 >= calc.min_xscale_value) && (pair.0 <= calc.max_xscale_value)) %] [%- IF xcount == 0 -%][%- lastx = pair.0 -%] [% END %] [% IF config.show_data_points || config.show_data_values %] [% FOREACH pair = dataset.pairs %] [% IF ((pair.0 >= calc.min_xscale_value) && (pair.0 <= calc.max_xscale_value)) %] [% IF config.show_data_points %] [% END %] [% IF config.show_data_values %] [%# datavalue shown %] [% IF (pair.2.defined) && (pair.2 != '') %][% point_label = pair.2 %][% ELSE %][% point_label = pair.1 FILTER format(calc.data_value_format) %][% END %] [% point_label %] [% END %] [% END %] [% END %] [% END %] [% line = line - 1 %] [% END %] [% key_count = 1 %] [% IF config.key && config.key_position == 'right' %] [% FOREACH dataset = data %] [% dataset.title %] [% key_count = key_count + 1 %] [% END %] [% ELSIF config.key && config.key_position == 'bottom' %] [%# calc y position of start of key %] [% y_key = base_line %] [%# consider x title %] [% IF config.show_x_title %][% y_key = base_line + 25 %][% END %] [%# consider x label rotation and stagger %] [% IF config.rotate_x_labels && config.show_x_labels %] [% y_key = y_key + x_label_allowance %] [% ELSIF config.show_x_labels && stagger < 1 %] [% y_key = y_key + 20 %] [% END %] [% y_key_start = y_key %] [% x_key = x %] [% FOREACH dataset = data %] [% IF key_count == 4 || key_count == 7 || key_count == 10 %] [%# wrap key every 3 entries %] [% x_key = x_key + 200 %] [% y_key = y_key - (key_box_size * 4) - 2 %] [% END %] [% dataset.title %] [% key_count = key_count + 1 %] [% END %] [% END %] [% IF config.show_graph_title %] [% config.graph_title %] [% END %] [% IF config.show_graph_subtitle %] [% IF config.show_graph_title %] [% y_subtitle = 30 %] [% ELSE %] [% y_subtitle = 15 %] [% END %] [% config.graph_subtitle %] [% END %] SVG-TT-Graph-0.21/lib/SVG/TT/Graph.pm0000755000175000017500000003060011756545003017042 0ustar floflooofloflooopackage SVG::TT::Graph; use strict; use Carp; use vars qw($VERSION $AUTOLOAD $TEMPLATE_FH); use Template; use POSIX; require 5.6.1; $VERSION = '0.21'; =head1 NAME SVG::TT::Graph - Base module for generating SVG graphics =head1 SYNOPSIS package SVG::TT::Graph::GRAPH_TYPE; use SVG::TT::Graph; use base qw(SVG::TT::Graph); use vars qw($VERSION); $VERSION = $SVG::TT::Graph::VERSION; $TEMPLATE_FH = \*DATA; sub _set_defaults { my $self = shift; my %default = ( 'keys' => 'value', ); while( my ($key,$value) = each %default ) { $self->{config}->{$key} = $value; } } # optional - called when object is created sub _init { my $self = shift; # any testing you want to do. } ... 1; __DATA__ In your script: use SVG::TT::Graph::GRAPH_TYPE; my $width = '500', my $heigh = '300', my @fields = qw(field_1 field_2 field_3); my $graph = SVG::TT::Graph::GRAPH_TYPE->new({ # Required for some graph types 'fields' => \@fields, # .. other config options 'height' => '500', }); my @data = qw(23 56 32); $graph->add_data({ 'data' => \@data, 'title' => 'Sales 2002', }); # find a config options value my $config_value = $graph->config_option(); # set a config option value $graph->config_option($config_value); # All graphs support SVGZ (compressed SVG) if # Compress::Zlib is available. Use either the # 'compress' => 1 config option, or: $graph->compress(1); # All graph SVGs can be tidied if XML::Tidy # is installed. Use either the 'tidy' => 1 # config option, or: $graph->tidy(1); print "Content-type: image/svg+xml\n\n"; print $graph->burn(); =head1 DESCRIPTION This package is a base module for creating graphs in Scalable Vector Format (SVG). Do not use this module directly. Instead, use one of the following modules to create the plot of your choice: =over =item L =item L =item L =item L =item L =item L =item L =back If XML::Tidy is installed, the SVG files generated can be tidied. If Compress::Zlib is available, the SVG files can also be compressed to SVGZ. =cut sub new { my ($proto,$conf) = @_; my $class = ref($proto) || $proto; my $self = {}; bless($self, $class); if($self->can('_set_defaults')) { # Populate with local defaults $self->_set_defaults(); } else { croak "$class should have a _set_defaults method"; } # overwrite defaults with user options while( my ($key,$value) = each %{$conf} ) { $self->{config}->{$key} = $value; } # Allow the inheriting modules to do checks if($self->can('_init')) { $self->_init(); } return $self; } =head1 METHODS =head2 add_data() my @data_sales_02 = qw(12 45 21); $graph->add_data({ 'data' => \@data_sales_02, 'title' => 'Sales 2002', }); This method allows you do add data to the graph object. It can be called several times to add more data sets in. =cut sub add_data { my ($self, $conf) = @_; # create an array unless(defined $self->{'data'}) { my @data; $self->{'data'} = \@data; } croak 'no fields array ref' unless defined $self->{'config'}->{'fields'} && ref($self->{'config'}->{'fields'}) eq 'ARRAY'; if(defined $conf->{'data'} && ref($conf->{'data'}) eq 'ARRAY') { my %new_data; @new_data{ map { s/&/&/; $_ } @{$self->{'config'}->{'fields'}}} = @{$conf->{'data'}}; my %store = ( 'data' => \%new_data, ); $store{'title'} = $conf->{'title'} if defined $conf->{'title'}; push (@{$self->{'data'}},\%store); return 1; } return undef; } =head2 clear_data() my $graph->clear_data(); This method removes all data from the object so that you can reuse it to create a new graph but with the same config options. =cut sub clear_data { my $self = shift; my @data; $self->{'data'} = \@data; } =head2 get_template() print $graph->get_template(); This method returns the TT template used for making the graph. =cut sub get_template { my $self = shift; # Template filehandle my $class = ref($self); my $template_fh = eval('$'.$class.'::TEMPLATE_FH'); croak $class . ' must have a template' if not $template_fh; # Read in TT template my $start = tell $template_fh; my $template = ''; while(<$template_fh>) { chomp; $template .= $_ . "\n"; } # This method may be used again, so return to start of filehandle seek $template_fh, $start, 0; return $template; } =head2 burn() print $graph->burn(); This method processes the template with the data and config which has been set and returns the resulting SVG. This method will croak unless at least one data set has been added to the graph object. =cut sub burn { my $self = shift; # Check we have at least one data value croak "No data available" unless scalar(@{$self->{'data'}}) > 0; # perform any calculations prior to burn $self->calculations() if $self->can('calculations'); my $template = $self->get_template(); my %vals = ( 'data' => $self->{'data'}, # the data 'config' => $self->{'config'}, # the configuration 'calc' => $self->{'calc'}, # the calculated values 'sin' => \&_sin_it, 'cos' => \&_cos_it, 'predefined_color' => \&_predefined_color, 'random_color' => \&_random_color, ); # euu - hack!! - maybe should just be a method $self->{sin} = \&_sin_it; $self->{cos} = \&_cos_it; # set up TT object my %config = ( POST_CHOMP => 1, INCLUDE_PATH => '/', #STRICT => 1, # we should probably enable this for strict checking #DEBUG => 'undef', # TT warnings on, useful for debugging, finding undef values ); my $tt = Template->new( \%config ); my $file; my $template_response = $tt->process( \$template, \%vals, \$file ); if($tt->error()) { croak "Template error: " . $tt->error . "\n" if $tt->error; } # tidy SVG if required if ($self->tidy()) { if (eval "require XML::Tidy") { # remove the doctype tag temporarily because it seems to cause trouble $file =~ s/()//si; my $doctype = $1; # tidy my $tidy_obj = XML::Tidy->new( 'xml' => $file ); $tidy_obj->tidy(); $file = $tidy_obj->toString(); # re-add the doctype if (defined $doctype) { $file =~ s/(<\?xml.+?\?>)/$1\n$doctype/si; } # even more tidy $file = $self->_tidy_more($file); } else { croak "Error tidying the SVG file: XML::Tidy does not seem to be installed properly"; } } # compress SVG if required if ($self->compress()) { if (eval "require Compress::Zlib") { $file = Compress::Zlib::memGzip($file); } else { croak "Error compressing the SVG file: Compress::Zlib does not seem to be installed properly"; } } return $file; } sub _sin_it { return sin(shift); } sub _cos_it { return cos(shift); } =head2 compress() $graph->compress(1); If Compress::Zlib is installed, the content of the SVG file can be compressed. This get/set method controls whether or not to compress. The default is 0 (off). =cut sub compress { my ($self, $val) = @_; # set the default compress value if (not defined $self->{config}->{compress}) { $self->{config}->{compress} = 0; } # set the user-defined compress value if (defined $val) { $self->{config}->{compress} = $val; } # get the compress value return $self->{config}->{compress}; } =head2 tidy() $graph->tidy(1); If XML::Tidy is installed, the content of the SVG file can be formatted in a prettier way. This get/set method controls whether or not to tidy. The default is 0 (off). The limitations of tidy are described at this URL: L =cut sub tidy { my ($self, $val) = @_; # set the default tidy value if (not defined $self->{config}->{tidy}) { $self->{config}->{tidy} = 0; } # set the user-defined tidy value if (defined $val) { $self->{config}->{tidy} = $val; } # get the tidy value return $self->{config}->{tidy}; } sub _tidy_more { # Remove extra spaces in the SVG tag my ($self, $svg_string) = @_; while ($svg_string =~ s/()/$1$2/mgi) {}; return $svg_string; } sub _random_color { # Generate the rgb code for a randomly selected color my $rgb = 'rgb('.int(rand(256)).','.int(rand(256)).','.int(rand(256)).')'; return $rgb; } sub _predefined_color { # Get the hexadecimal code for one of 12 predefined colors my ($num) = shift; my @colors = ("#ff0000", "#0000ff", "#00ff00", "#ffcc00", "#00ccff", "#ff00ff", "#00ffff", "#ffff00", "#cc6666", "#663399", "#339900", "#9966FF"); my $hex; if ($num-1 < scalar @colors) { $hex = $colors[$num-1]; } return $hex; } # Calculate a scaling range and divisions to be aesthetically pleasing # Parameters: # value range # Returns # (revised range, division size, division precision) sub _range_calc () { my ($self, $range) = @_; my ($max,$division); my $count = 0; my $value = $range; if ($value == 0) { # Can't do much really $division = 0.2; $max = 1; return ($max,$division,1); } if ($value < 1) { while ($value < 1) { $value *= 10; $count++; } $division = 1; while ($count--) { $division /= 10; } $max = ceil($range / $division) * $division; } else { while ($value > 10) { $value /= 10; $count++; } $division = 1; while ($count--) { $division *= 10; } $max = ceil($range / $division) * $division; } if (int($max / $division) <= 2) { $division /= 5; $max = ceil($range / $division) * $division; } elsif (int($max / $division) <= 5) { $division /= 2; $max = ceil($range / $division) * $division; } if ($division >= 1) { $count = 0; } else { $count = length($division) - 2; } return ($max,$division,$count); } # Returns true if config value exists, is defined and not '' sub _is_valid_config() { my ($self,$name) = @_; return ((exists $self->{config}->{$name}) && (defined $self->{config}->{$name}) && ($self->{config}->{$name} ne '')); } =head2 config methods my $value = $graph->method(); $graph->method($value); This object provides autoload methods for all config options defined in the _set_default method within the inheriting object. See the SVG::TT::Graph::GRAPH_TYPE documentation for a list. =cut ## AUTOLOAD FOR CONFIG editing sub AUTOLOAD { my $name = $AUTOLOAD; $name =~ s/.*://; croak "No object supplied" unless $_[0]; if(defined $_[0]->{'config'}->{$name}) { if(defined $_[1]) { # set the value $_[0]->{'config'}->{$name} = $_[1]; } return $_[0]->{'config'}->{$name} if defined $_[0]->{'config'}->{$name}; return undef; } else { croak "Method: $name can not be used with " . ref($_[0]); } } # As we have AUTOLOAD we need this sub DESTROY { } 1; __END__ =head1 EXAMPLES For examples look at the project home page http://leo.cuckoo.org/projects/SVG-TT-Graph/ =head1 EXPORT None by default. =head1 ACKNOWLEDGEMENTS Thanks to Foxtons for letting us put this on CPAN, Todd Caine for heads up on reparsing the template (but not using atm), David Meibusch for TimeSeries and a load of other ideas, Stephen Morgan for creating the TT template and SVG, and thanks for all the patches by Andrew Ruthven and others. =head1 AUTHOR Leo Lapworth =head1 MAINTAINER Florent Angly =head1 COPYRIGHT AND LICENSE Copyright (C) 2003, Leo Lapworth This module is free software; you can redistribute it or modify it under the same terms as Perl itself. =head1 BUGS Please report any bugs or feature requests to bug-graph-svg-tt@rt.cpan.org, or through the web interface at http://rt.cpan.org. The Graph::SVG::TT development repository is located on GitHub at L. Get the latest development version using: git clone git://github.com/ranguard/svg-tt-graph.git =head1 SEE ALSO L, L, L, L, L, L, L, L, L =cut SVG-TT-Graph-0.21/Changes0000755000175000017500000001217111756543605015213 0ustar flofloooflofloooRevision history for Perl extension SVG::TT::Graph. 0.21 - New type of graph available: XY (written by Florent Angly, but largely based on the TimeSeries module by David Meibusch) 0.20 - Fixed wrong formatting of Y labels in SVG::TT:Graph::BarHorizontal (patch by Erin Schönhals) - Fixed wrong formatting of Y labels in SVG::TT::Graph::Bar 0.19 - Fixed warning messages with missing data title (#69691, reported by dean@fragfest.com.au, patch by Florent Angly) 0.18 - Thu 5 Jan 2012 - Added format_x_axis, format_y_axis callback options (Eric Johnson) 0.17 - Wed Jul 20 2011 - By default, do not compress() or tidy() the SVG - Line and Timeseries graphs now have points styled as '.dataPointNN', consistently with BarLine graphs (patch from Henrik Pauli, #67834) - Added a max_scale_value option to set the maximum value for the Y axis of Bar and Line graphs (patch by Bryce and Henrik Pauli, #20475) - Repackaged module without extra files (#56718) 0.16 - Sun Apr 18 2010 - Javascript code in the piechart and timeseries put into a CDATA tag 0.15 - Sat Apr 17 2010 - Method get_template() moved from SVG::TT::Graph::* to SVG::TT::Graph to avoid redundancy - Fixed bug in get_template(). The DATA filehandle is now read from the beginning at each get_template call - Makefile.PL does not use autoinstall aymore (not a good practice for CPAN modules) - Rollover improvements in piechart 0.14 - Mon Apr 05 2010 - Fixed some unit tests and the URL of the repository 0.13 - Sat Apr 03 2010 - Revised TT templates warnings due to undef values (bug # 44115) - Fixed the "used only once" warnings (bug # 43854, thank you Ia Hun) - Introduced a new method to use random colors instead of the 12 predefined colors. Along with the dynamic allocation of the number of style elements, this allows an unlimited number of dataseries - Added Javascript code to display field name when the mouse rolls over a piechart wedge - Implemented an optional new method to tidy the formatting of the SVG files (using XML::Tidy) - Replaced carriage returns by line feeds because it is more portable (http://www.webmasterworld.com/forum13/4067.htm) - Did documentation, unit testing and packaging revisions - Misc little code touch ups 0.12 - Mon Feb 16 12:00:00 EST 2009 - Missed updating the versions for some of the sub libraries. 0.11 - Sun Feb 15 22:54:00 EST 2009 - Applied patches: http://rt.cpan.org/Ticket/Display.html?id=38441 - Ampersands in Fields cause XML error http://rt.cpan.org/Ticket/Display.html?id=43326 - Multiple data sets in Bar.pm will now show stacked graphs http://rt.cpan.org/Ticket/Display.html?id=43325 - Allow toggling the display of data on TimeSeries 0.10 - Mon Apr 28 21:07:30 BST 2008 - Applied patches: http://rt.cpan.org/Ticket/Display.html?id=34491 http://rt.cpan.org/Ticket/Display.html?id=22896 http://rt.cpan.org/Ticket/Display.html?id=20828 http://rt.cpan.org/Ticket/Display.html?id=20475 0.09 - Applied path patch for Firefox from Pat Ekman for Pie - patched other modules so Firefox works (doesn't like comma's in a path) 0.08 - Fix stylesheet for Pie 0.07 Help from Yanick with the following: - Bug fixes: #7342 (bad default stylesheet class) #8680 (Typo in defaut Stylesheet for SVG::TT::Graph::TimeSeries) #7541 (BarHorizontal) #7549 (Character width setting in BarHorizontal) 0.06 - Put in comment so people know where to copy the style sheet from (e.g. not including the