1SVG::TT::Graph(3) User Contributed Perl Documentation SVG::TT::Graph(3)
2
3
4
6 SVG::TT::Graph - Base module for generating SVG graphics
7
9 package SVG::TT::Graph::GRAPH_TYPE;
10 use SVG::TT::Graph;
11 use base qw(SVG::TT::Graph);
12 use vars qw($VERSION);
13 $VERSION = $SVG::TT::Graph::VERSION;
14 $TEMPLATE_FH = \*DATA;
15
16 sub _set_defaults {
17 my $self = shift;
18
19 my %default = (
20 'keys' => 'value',
21 );
22 while( my ($key,$value) = each %default ) {
23 $self->{config}->{$key} = $value;
24 }
25 }
26
27
28 # optional - called when object is created
29 sub _init {
30 my $self = shift;
31 # any testing you want to do.
32
33 }
34
35 ...
36
37 1;
38 __DATA__
39 <!-- SVG Template goes here -->
40
41
42 In your script:
43
44 use SVG::TT::Graph::GRAPH_TYPE;
45
46 my $width = '500',
47 my $heigh = '300',
48 my @fields = qw(field_1 field_2 field_3);
49
50 my $graph = SVG::TT::Graph::GRAPH_TYPE->new({
51 # Required for some graph types
52 'fields' => \@fields,
53 # .. other config options
54 'height' => '500',
55 });
56
57 my @data = qw(23 56 32);
58 $graph->add_data({
59 'data' => \@data,
60 'title' => 'Sales 2002',
61 });
62
63 # find a config options value
64 my $config_value = $graph->config_option();
65 # set a config option value
66 $graph->config_option($config_value);
67
68 # All graphs support SVGZ (compressed SVG) if
69 # Compress::Zlib is available. Use either the
70 # 'compress' => 1 config option, or:
71 $graph->compress(1);
72
73 # All graph SVGs can be tidied if XML::Tidy
74 # is installed. Use either the 'tidy' => 1
75 # config option, or:
76 $graph->tidy(1);
77
78 print "Content-type: image/svg+xml\n\n";
79 print $graph->burn();
80
82 This package is a base module for creating graphs in Scalable Vector
83 Format (SVG). Do not use this module directly. Instead, use one of the
84 following modules to create the plot of your choice:
85
86 SVG::TT::Graph::Line
87 SVG::TT::Graph::Bar
88 SVG::TT::Graph::BarHorizontal
89 SVG::TT::Graph::BarLine
90 SVG::TT::Graph::Pie
91 SVG::TT::Graph::TimeSeries
92 SVG::TT::Graph::XY
93
94 If XML::Tidy is installed, the SVG files generated can be tidied. If
95 Compress::Zlib is available, the SVG files can also be compressed to
96 SVGZ.
97
99 add_data()
100 my @data_sales_02 = qw(12 45 21);
101
102 $graph->add_data({
103 'data' => \@data_sales_02,
104 'title' => 'Sales 2002',
105 });
106
107 This method allows you do add data to the graph object. It can be
108 called several times to add more data sets in.
109
110 clear_data()
111 my $graph->clear_data();
112
113 This method removes all data from the object so that you can reuse it
114 to create a new graph but with the same config options.
115
116 get_template()
117 print $graph->get_template();
118
119 This method returns the TT template used for making the graph.
120
121 burn()
122 print $graph->burn();
123
124 This method processes the template with the data and config which has
125 been set and returns the resulting SVG.
126
127 This method will croak unless at least one data set has been added to
128 the graph object.
129
130 compress()
131 $graph->compress(1);
132
133 If Compress::Zlib is installed, the content of the SVG file can be
134 compressed. This get/set method controls whether or not to compress.
135 The default is 0 (off).
136
137 tidy()
138 $graph->tidy(1);
139
140 If XML::Tidy is installed, the content of the SVG file can be formatted
141 in a prettier way. This get/set method controls whether or not to tidy.
142 The default is 0 (off). The limitations of tidy are described at this
143 URL:
144 <http://search.cpan.org/~pip/XML-Tidy-1.12.B55J2qn/Tidy.pm#tidy%28%29>
145
146 config methods
147 my $value = $graph->method();
148 $graph->method($value);
149
150 This object provides autoload methods for all config options defined in
151 the _set_default method within the inheriting object.
152
153 See the SVG::TT::Graph::GRAPH_TYPE documentation for a list.
154
156 For examples look at the project home page
157 http://leo.cuckoo.org/projects/SVG-TT-Graph/
158
160 None by default.
161
163 Thanks to Foxtons for letting us put this on CPAN, Todd Caine for heads
164 up on reparsing the template (but not using atm), David Meibusch for
165 TimeSeries and a load of other ideas, Stephen Morgan for creating the
166 TT template and SVG, and thanks for all the patches by Andrew Ruthven
167 and others.
168
170 Leo Lapworth <LLAP@cuckoo.org>
171
173 Florent Angly <florent.angly@gmail.com>
174
176 Copyright (C) 2003, Leo Lapworth
177
178 This module is free software; you can redistribute it or modify it
179 under the same terms as Perl itself.
180
182 SVG::TT::Graph::Line, SVG::TT::Graph::Bar,
183 SVG::TT::Graph::BarHorizontal, SVG::TT::Graph::BarLine,
184 SVG::TT::Graph::Pie, SVG::TT::Graph::TimeSeries, SVG::TT::Graph::XY,
185 Compress::Zlib, XML::Tidy
186
187
188
189perl v5.28.1 2015-04-14 SVG::TT::Graph(3)