1SVG::Graph(3) User Contributed Perl Documentation SVG::Graph(3)
2
3
4
6 SVG::Graph
7
9 use SVG::Graph;
10 use SVG::Graph::Data;
11 use SVG::Graph::Data::Datum;
12
13 #create a new SVG document to plot in...
14 my $graph = SVG::Graph->new(width=>600,height=>600,margin=>30);
15
16 #and create a frame to hold the data/glyphs
17 my $frame = $graph->add_frame;
18
19 #let's plot y = x^2
20 my @data = map {SVG::Graph::Data::Datum->new(x=>$_,y=>$_^2)}
21 (1,2,3,4,5);
22 my $data = SVG::Graph::Data->new(data => \@data);
23
24 #put the xy data into the frame
25 $frame->add_data($data);
26
27 #add some glyphs to apply to the data in the frame
28 $frame->add_glyph('axis', #add an axis glyph
29 'x_absolute_ticks' => 1, #with ticks every one
30 #unit on the x axis
31 'y_absolute_ticks' => 1, #and ticks every one
32 #unit on the y axis
33
34 'stroke' => 'black', #draw the axis black
35 'stroke-width' => 2, #and 2px thick
36 );
37
38 $frame->add_glyph('scatter', #add a scatterplot glyph
39 'stroke' => 'red', #the dots will be outlined
40 #in red,
41 'fill' => 'red', #filled red,
42 'fill-opacity' => 0.5, #and 50% opaque
43 );
44
45 #print the graphic
46 print $graph->draw;
47
49 SVG::Graph is a suite of perl modules for plotting data. SVG::Graph
50 currently supports plots of one-, two- and three-dimensional data, as
51 well as N-ary rooted trees. Data may be represented as:
52
53 Glyph Name Dimensionality supported
54 1d 2d 3d tree
55 --------------------------------------------------------
56 Axis x
57 Bar Graph x
58 Bubble Plot x
59 Heatmap Graph x
60 Line Graph x
61 Pie Graph x
62 Scatter Plot x
63 Spline Graph x
64 Tree x
65
66 SVG::Graph 0.02 is a pre-alpha release. Keep in mind that many of the
67 glyphs are not very robust.
68
70 SVG::Graph - Visualize your data in Scalable Vector Graphics (SVG)
71 format.
72
74 You need to create a SVG::Graph::Frame instance from the parent
75 SVG::Graph instance for each set of data to be plotted. Datasets can
76 be hierarchical, and to represent this, SVG::Graph::Frame instances can
77 themselves contain subframes. SVG::Graph::Frame can contain:
78
79 - multiple subframes as instances of SVG::Graph::Frame
80 - a single SVG::Graph::Data instance
81 - multiple SVG::Graph::Glyph instances with which to render
82 the attached SVG::Graph::Data instance, and all SVG::Graph::Data
83 instances attached to SVG::Graph::Frame subinstances
84
85 See SVG::Graph::Frame and SVG::Graph::Glyph for details.
86
87 ONE DATA SET
88 1. create an SVG::Graph instance
89 2. create an SVG::Graph::Frame instance by calling
90 SVG::Graph::add_frame();
91 3. create an SVG::Graph::Data instance, containing
92 an SVG::Graph::Data::Datum instance for each data point.
93 4. Attach the SVG::Graph::Data instance to your SVG::Graph::Frame
94 using SVG::Graph::Frame::add_data();
95 5. Attach glyphs to the SVG::Graph::Frame instance using
96 SVG::Graph::Frame::add_glyph();
97 6. Call SVG::Graph::draw();
98
99 MULTIPLE DATA SETS
100 1. create an SVG::Graph instance
101 2. create an SVG::Graph::Frame instance by calling
102 SVG::Graph::add_frame();
103 3. create an SVG::Graph::Data instance, containing
104 an SVG::Graph::Data::Datum instance for each data point.
105 4. Attach the SVG::Graph::Data instance to your SVG::Graph::Frame
106 using SVG::Graph::Frame::add_data();
107 5. Attach glyphs to the SVG::Graph::Frame instance using
108 SVG::Graph::Frame::add_glyph();
109 6. repeat [2-5] for each additional data set to be added.
110 add_frame() can be called on SVG::Graph to add top-level data
111 sets, or SVG::Graph::Frame to add hierarchical data sets.
112 7. Call SVG::Graph::draw();
113
115 Send an email to the svg-graph-developers list. For more info, visit
116 the project page at http://www.sf.net/projects/svg-graph
117
119 Allen Day, <allenday@ucla.edu>
120 Chris To, <crsto@ucla.edu>
121
123 James Chen, <chenj@seas.ucla.edu>
124 Brian O'Connor, <boconnor@ucla.edu>
125 Chris Fields, cjfields at bioperl dot org
126
128 SVG
129
130 new
131 Title : new
132 Usage : my $graph = SVG::Graph->new(width=>600,
133 height=>600,
134 margin=>20);
135 Function: creates a new SVG::Graph object
136 Returns : a SVG::Graph object
137 Args : width => the width of the SVG
138 height => the height of the SVG
139 margin => margin for the root frame
140
141 init
142 Title : init
143 Usage :
144 Function:
145 Example :
146 Returns :
147 Args :
148
149 width
150 Title : width
151 Usage : $obj->width($newval)
152 Function:
153 Example :
154 Returns : value of width (a scalar)
155 Args : on set, new value (a scalar or undef, optional)
156
157 height
158 Title : height
159 Usage : $obj->height($newval)
160 Function:
161 Example :
162 Returns : value of height (a scalar)
163 Args : on set, new value (a scalar or undef, optional)
164
165 margin
166 Title : margin
167 Usage : $obj->margin($newval)
168 Function:
169 Example :
170 Returns : value of margin (a scalar)
171 Args : on set, new value (a scalar or undef, optional)
172
173 svg
174 Title : svg
175 Usage : $obj->svg($newval)
176 Function:
177 Example :
178 Returns : value of svg (a scalar)
179 Args : on set, new value (a scalar or undef, optional)
180
181 add_frame
182 Title : add_frame
183 Usage : my $frame = $graph->add_frame
184 Function: adds a Frame to the current Graph
185 Returns : a SVG::Graph::Frame object
186 Args : a hash. usable keys:
187 frame_transform (optional)
188 'top' default orientation
189 'bottom' rotates graph 180 deg (about the center)
190 'right' points top position towards right
191 'left' points top position towards left
192
193 frames
194 Title : frames
195 Usage : get/set
196 Function:
197 Example :
198 Returns :
199 Args :
200
201 xoffset
202 Title : xoffset
203 Usage : $obj->xoffset($newval)
204 Function:
205 Example :
206 Returns : value of xoffset (a scalar)
207 Args : on set, new value (a scalar or undef, optional)
208
209 yoffset
210 Title : yoffset
211 Usage : $obj->yoffset($newval)
212 Function:
213 Example :
214 Returns : value of yoffset (a scalar)
215 Args : on set, new value (a scalar or undef, optional)
216
217 draw
218 Title : draw
219 Usage : $graph=>draw
220 Function: depends on child glyph implementations
221 Returns : xmlifyied SVG object
222 Args : none
223
225 Chris Fields <cjfields@bioperl.org>
226
228 This software is Copyright (c) 2012 by Chris Fields.
229
230 This is free software, licensed under:
231
232 The Artistic License 2.0 (GPL Compatible)
233
234
235
236perl v5.34.0 2021-07-22 SVG::Graph(3)