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