1SVG::TT::Graph(3) User Contributed Perl Documentation SVG::TT::Graph(3)
2
3
4
6 SVG::TT::Graph - Base object for generating SVG Graphs
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.
70 # either 'compress' => 1 config option, or
71 $graph->compress(1);
72
73 # All graph SVGs can be tidied if XML::Tidy
74 # Compress::Zlib is installed.
75 # either 'tidy' => 1 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 should be used as a base for creating SVG graphs. If
83 XML::Tidy is installed, the SVG files generated are tidied.
84
85 See SVG::TT::Graph::Line for an example.
86
88 add_data()
89 my @data_sales_02 = qw(12 45 21);
90
91 $graph->add_data({
92 'data' => \@data_sales_02,
93 'title' => 'Sales 2002',
94 });
95
96 This method allows you do add data to the graph object. It can be
97 called several times to add more data sets in.
98
99 clear_data()
100 my $graph->clear_data();
101
102 This method removes all data from the object so that you can reuse it
103 to create a new graph but with the same config options.
104
105 get_template()
106 print $graph->get_template();
107
108 This method returns the TT template used for making the graph.
109
110 burn()
111 print $graph->burn();
112
113 This method processes the template with the data and config which has
114 been set and returns the resulting SVG.
115
116 This method will croak unless at least one data set has been added to
117 the graph object.
118
119 compress()
120 $graph->compress(1);
121
122 If Compress::Zlib is installed, the content of the SVG file can be
123 compressed. This get/set method controls whether or not to compress.
124 The default is 1 if Compress::Zlib is available, 0 otherwise.
125
126 tidy()
127 $graph->tidy(1);
128
129 If XML::Tidy is installed, the content of the SVG file can be formatted
130 in a prettier way. This get/set method controls whether or not to tidy.
131 The default is 1 if XML::Tidy is available, 0 otherwise.
132
133 config methods
134 my $value = $graph->method();
135 $graph->method($value);
136
137 This object provides autoload methods for all config options defined in
138 the _set_default method within the inheriting object.
139
140 See the SVG::TT::Graph::GRAPH_TYPE documentation for a list.
141
143 For examples look at the project home page
144 http://leo.cuckoo.org/projects/SVG-TT-Graph/
145
147 None by default.
148
150 Thanks to Foxtons for letting us put this on CPAN. Todd Caine for
151 heads up on reparsing the template (but not using atm) David Meibusch
152 for TimeSeries and a load of other ideas Thanks for all the patches
153 supplied by Andrew Ruthven and others
154
156 Leo Lapworth (LLAP@cuckoo.org) and Stephen Morgan (TT and SVG)
157
159 SVG::TT::Graph::Line, SVG::TT::Graph::Bar,
160 SVG::TT::Graph::BarHorizontal, SVG::TT::Graph::BarLine,
161 SVG::TT::Graph::Pie, SVG::TT::Graph::TimeSeries, Compress::Zlib,
162 XML::Tidy
163
165 Copyright (C) 2003, Leo Lapworth
166
167 This module is free software; you can redistribute it or modify it
168 under the same terms as Perl itself.
169
170
171
172perl v5.12.0 2010-04-17 SVG::TT::Graph(3)