svg-graph 1.0.1 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data.tar.gz.sig +0 -0
  2. data/History.txt +7 -5
  3. data/Manifest.txt +53 -17
  4. data/README.markdown +14 -0
  5. data/README.txt +10 -3
  6. data/Rakefile +6 -0
  7. data/build.xml +143 -0
  8. data/dist.xml.in +46 -0
  9. data/images/bar.png +0 -0
  10. data/images/bar.svg +76 -0
  11. data/images/bar.svgz +0 -0
  12. data/images/barhorizontal.png +0 -0
  13. data/images/barhorizontal.svg +76 -0
  14. data/images/barhorizontal.svgz +0 -0
  15. data/images/line.png +0 -0
  16. data/images/line.svg +80 -0
  17. data/images/line.svgz +0 -0
  18. data/images/pie.png +0 -0
  19. data/images/pie.svg +70 -0
  20. data/images/pie.svgz +0 -0
  21. data/images/plot.png +0 -0
  22. data/images/plot.svg +131 -0
  23. data/images/plot.svgz +0 -0
  24. data/images/schedule.png +0 -0
  25. data/images/schedule.svg +67 -0
  26. data/images/timeseries.png +0 -0
  27. data/images/timeseries.svg +179 -0
  28. data/images/timeseries.svgz +0 -0
  29. data/index.xml +281 -0
  30. data/install.rb +161 -0
  31. data/lib/SVG/Graph/Bar.rb +1 -1
  32. data/lib/SVG/Graph/Graph.rb +11 -9
  33. data/lib/SVG/Graph/Line.rb +1 -0
  34. data/lib/SVG/Graph/Pie.rb +3 -3
  35. data/lib/SVG/Graph/Plot.rb +69 -20
  36. data/lib/SVG/Graph/Schedule.rb +19 -5
  37. data/lib/SVG/Graph/TimeSeries.rb +62 -45
  38. data/lib/svggraph.rb +1 -2
  39. data/screenshots.xml +148 -0
  40. data/style/common.xsl +37 -0
  41. data/style/release_html.xsl +169 -0
  42. data/style/release_txt.xsl +25 -0
  43. data/svg-graph.gemspec +59 -0
  44. data/test/data.txt +4 -0
  45. data/test/plot.rb +51 -0
  46. data/test/schedule.rb +43 -0
  47. data/test/single.rb +33 -0
  48. data/test/test.rb +54 -0
  49. data/test/test_plot.rb +170 -0
  50. data/test/test_svg_graph.rb +24 -55
  51. data/test/timeseries.rb +58 -0
  52. metadata +79 -14
  53. metadata.gz.sig +2 -1
Binary file
data/index.xml ADDED
@@ -0,0 +1,281 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
3
+ "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
4
+ <article>
5
+ <title>SVG::Graph</title>
6
+
7
+ <subtitle>@ANT_VERSION@</subtitle>
8
+
9
+ <articleinfo>
10
+ <date>@ANT_DATE@</date>
11
+
12
+ <author>
13
+ <firstname>Sean</firstname>
14
+
15
+ <surname>Russell</surname>
16
+
17
+ <email>serATgermaneHYPHENsoftwareDOTcom</email>
18
+ </author>
19
+ </articleinfo>
20
+
21
+ <sect1>
22
+ <title>What is it?</title>
23
+
24
+ <para>SVG:::Graph is a pure Ruby library for generating charts, which are
25
+ a type of graph where the values of one axis are not scalar. SVG::Graph
26
+ has a verry similar API to the Perl library SVG::TT::Graph, and the
27
+ resulting charts also look the same. This isn't surprising, because
28
+ SVG::Graph started as a loose port of SVG::TT::Graph, although the
29
+ internal code no longer resembles the Perl original at all.</para>
30
+
31
+ <para>SVG::Graph isn't only for charts. With version 0.4.0, support for
32
+ Plot charts was added, so scalar data may now be charted.</para>
33
+ </sect1>
34
+
35
+ <sect1>
36
+ <title>What's new?</title>
37
+ <para>You can find that out in the <ulink
38
+ url='changelog.html'>change log.</ulink></para>
39
+ </sect1>
40
+
41
+ <sect1>
42
+ <title>Screenshot</title>
43
+
44
+ <para>Gotta have one.</para>
45
+
46
+ <mediaobject>
47
+ <imageobject>
48
+ <imagedata fileref="images/pie.svg" format="SVG" />
49
+ </imageobject>
50
+ </mediaobject>
51
+
52
+ <para>Here's a PNG version of the above image for the
53
+ SVG-challenged:</para>
54
+
55
+ <mediaobject>
56
+ <imageobject>
57
+ <imagedata fileref="images/pie.png" format="PNG" />
58
+ </imageobject>
59
+ </mediaobject>
60
+
61
+ <para>The SVG version is <emphasis>much</emphasis> cooler. <ulink
62
+ url="screenshots.html">More screenshots are available</ulink>.</para>
63
+ </sect1>
64
+
65
+ <sect1>
66
+ <title>Why use it?</title>
67
+
68
+ <para>If you're a Ruby programmer, you can't use SVG::TT::Graph directly.
69
+ This package is for you.</para>
70
+
71
+ <para>If you want one of the features that this package has that the Perl
72
+ version doesn't, and you don't mind doing your graph code in Ruby, then
73
+ this package is for you.</para>
74
+
75
+ <para>If you want to generate SVGs that aren't CSS styled (and work with
76
+ more SVG renderers), use this package.</para>
77
+
78
+ <para>If you're a Perl wienie or you have something against Ruby, use
79
+ SVG::TT::Graph. If it doesn't provide you with the features you want, hack
80
+ it yourself.</para>
81
+ </sect1>
82
+
83
+ <sect1>
84
+ <title>Getting it</title>
85
+
86
+ <para>The source archives contain the example script(s) and an install
87
+ script. Documentation must be downloaded separately.<itemizedlist>
88
+ <listitem>
89
+ <para><ulink
90
+ url="http://www.germane-software.com/archives/svg_graph_@ANT_VERSION@.tgz">Gzipped
91
+ sources</ulink></para>
92
+ </listitem>
93
+
94
+ <listitem>
95
+ <para><ulink
96
+ url="http://www.germane-software.com/archives/svg_graph_api_@ANT_VERSION@.tgz">Gzipped
97
+ documentation</ulink></para>
98
+ </listitem>
99
+
100
+ <listitem>
101
+ <para><ulink
102
+ url="http://www.germane-software.com/archives/svg_graph_@ANT_VERSION@.zip">Zipped
103
+ sources</ulink></para>
104
+ </listitem>
105
+
106
+ <listitem>
107
+ <para><ulink
108
+ url="http://www.germane-software.com/archives/svg_graph_api_@ANT_VERSION@.zip">Zipped
109
+ documentation</ulink></para>
110
+ </listitem>
111
+ </itemizedlist></para>
112
+ </sect1>
113
+
114
+ <sect1>
115
+ <title>Why?</title>
116
+
117
+ <para>The SVG::TT:Graph package is just fine. It lacked a couple of
118
+ features that I wanted, and it was in Perl<footnote>
119
+ <para>Perl is from Hell. The language is bad enough, but working with
120
+ the package system -- CPAN, etc. -- is an exercize in masochism. I'd
121
+ rather chew on glass.</para>
122
+ </footnote>, so I re-implemented it.</para>
123
+
124
+ <para>SVG::Graph is not a straight port of SVG::TT::Graph, because the
125
+ Perl version uses templates, and I don't believe that this is a job for
126
+ templates. Templates are great when you have lots of context containing a
127
+ little bit of evaluated code, but the Graph classes are mostly code with a
128
+ little SVG; therefore, it makes more sense (and is a hell of a lot more
129
+ readable) to have the SVG embedded in the code rather than vice versa.
130
+ However, some of the logic was directly cut and paste out of
131
+ SVG::TT::Graph, as was the entire CSS code and chunks of the
132
+ documentation, and the part of the API that the user sees is almost
133
+ identical to the original.</para>
134
+
135
+ <para>In version 0.2.0 I completely refactored the code to make it more
136
+ modular. As a result, the core Graph class contains most of the graph
137
+ drawing primatives, and the specializations (Bar, BarHorizontal, Line,
138
+ Pie, etc.) only draw the plot itself. This results in many fewer lines of
139
+ code, and that code is more robust. SVG::TT::Graph re-implemented most of
140
+ the code for every plot type, whereas SVG::Graph reuses most of the
141
+ code.</para>
142
+
143
+ <para>I intend SVG::Graph to have more features than SVG::TT::Graph, which
144
+ is the main reason for the re-implementation. One such feature is the
145
+ ability to change the stacking of the data sets. For instance, SVG::Graph
146
+ allows you to place the data bars from multiple data sets on the same
147
+ graph side-by-side, rather than overlapping.</para>
148
+
149
+ <para>SVG::Graph also has an option to disable CSS styling of the graphs.
150
+ This has a number of consequences, both positive and negative. The SVGs
151
+ generated can be larger without CSS, and they are harder to dynamically
152
+ style (you can't use your own styles with CSS disabled). However, a number
153
+ of SVG renderers do not support or do not fully support CSS in SVG (KSVG
154
+ in Konqueror and librsvg, for instance). Adobe and Batik both support CSS,
155
+ so if those are your targets, you can use CSS. For maximum compatability,
156
+ disable CSS with the :no_css attriibute.</para>
157
+
158
+ <para>The currently supported graph types are:</para>
159
+
160
+ <itemizedlist>
161
+ <listitem>
162
+ <para>Bar</para>
163
+ </listitem>
164
+
165
+ <listitem>
166
+ <para>BarHorizontal</para>
167
+ </listitem>
168
+
169
+ <listitem>
170
+ <para>Line</para>
171
+ </listitem>
172
+
173
+ <listitem>
174
+ <para>Pie</para>
175
+ </listitem>
176
+
177
+ <listitem>
178
+ <para>Plot (this is scalar data)</para>
179
+ </listitem>
180
+
181
+ <listitem>
182
+ <para>TimeSeries (also scalar data, with one axis being dates)</para>
183
+ </listitem>
184
+
185
+ <listitem>
186
+ <para>Schedule (scalar time range data, with non-scalar Y axis)</para>
187
+ </listitem>
188
+ </itemizedlist>
189
+ </sect1>
190
+
191
+ <sect1>
192
+ <title>Dependancies</title>
193
+
194
+ <para>REXML 3.0+, or Ruby 1.8+. If you want to use the SVG compression
195
+ feature, which generates zlib compressed SVGs, you must also have the Ruby
196
+ zlib library installed.</para>
197
+ </sect1>
198
+
199
+ <sect1>
200
+ <title>Usage</title>
201
+
202
+ <para>There's API documentation available, either <ulink
203
+ url="http://www.germane-software.com/software/SVG/SVG::Graph/doc">online</ulink>
204
+ or for <ulink
205
+ url="http://www.germane-software.com/archive/svg_graph_api_@ANT_VERSION@.tgz">download</ulink>.
206
+ Or, you can use rdoc to generate it yourself. The API documentation is
207
+ pretty comprehensive (Leo Lapworth did a really good job on the docs, and
208
+ I stole most of them), and there's an example application in the main
209
+ directory.</para>
210
+ </sect1>
211
+
212
+ <sect1>
213
+ <title>Notes</title>
214
+
215
+ <sect2>
216
+ <title>SVG feature support</title>
217
+
218
+ <para>Some SVG renderers (librsvg) do not understand CSS. This is a
219
+ problem with Perl's SVG::TT::Graph, because <emphasis>all</emphasis> of
220
+ the styling of the charts it generates is done with CSS. SVG::Graph is
221
+ able to inline the styles, rendering graphs that are compatible with
222
+ more viewers.</para>
223
+
224
+ <para>The Pie chart uses the feGaussianBlur filter to generate the
225
+ shadow, whiich is also unsupperted by some renderers (librsvg). The
226
+ shadow will not look as smooth on those displays, although it will
227
+ render.</para>
228
+ </sect2>
229
+
230
+ <sect2>
231
+ <title>Sizes</title>
232
+
233
+ <para>The bar charts PNGs tend to be smaller than the uncompressed SVGs.
234
+ In the best case (for PNG), the PNG is 66% of the size of the
235
+ uncompressed SVG.</para>
236
+
237
+ <para>For line and pie charts, which are a little more visually complex,
238
+ the SVGs are smaller than the PNGs. In the best case, the PNG is 130%
239
+ the size of the SVG. In the worst case, the PNG is 220% the size of the
240
+ uncompressed SVG.</para>
241
+
242
+ <para>The compressed SVGs are always much smaller than the PNGs. In the
243
+ best case (a vertical bar chart), the PNG is 4.4 times the size of the
244
+ compressed SVG, and in the worst case (for a pie chart), it is over 12
245
+ times the size of the compressed SVG.</para>
246
+
247
+ <para>These values were measured with inline styled SVGs, and the PNGs
248
+ were reduced to 8-bit, indexed images, and were crushed with
249
+ pngcrush.</para>
250
+ </sect2>
251
+ </sect1>
252
+
253
+ <sect1>
254
+ <title>Bugs</title>
255
+
256
+ <para>SVG::Graph probably contains bugs. In fact, it is probably mostly
257
+ bugs, held together with some working code around them. In particular,
258
+ SVG::Graph is probably really intolerant of *your* bugs, and is likely
259
+ entirely unhelpful in helping you track down problems. We can only pray
260
+ that this situation improves<footnote>
261
+ <para>Prayer is much more effective when accompanied by sums of cash
262
+ sent to the author.</para>
263
+ </footnote>.</para>
264
+
265
+ <para>There is a <ulink
266
+ url="http://www.germane-software.com/cgi-bin/roundup/svg-graph">bug and
267
+ feature request database</ulink>; use this, and please create a user
268
+ account if you don't have one, so that I can email you if I have
269
+ questions. Alternatively, post anonymously, and check the database
270
+ often.</para>
271
+ </sect1>
272
+
273
+ <sect1>
274
+ <title>Repository</title>
275
+
276
+ <para>The sourcecode repository is a <ulink
277
+ url="http://subversion.tigris.org">Subversion</ulink> repository, located
278
+ <ulink
279
+ url="http://www.germane-software.com/repositories/public/SVG">here</ulink>.</para>
280
+ </sect1>
281
+ </article>
data/install.rb ADDED
@@ -0,0 +1,161 @@
1
+ #! /usr/bin/env ruby
2
+ ################################################################################
3
+ # #
4
+ # Name: install.rb #
5
+ # Author: Sean E Russell <ser@germane-software.com> #
6
+ # Version: $Id: $
7
+ # Date: *2002-174 #
8
+ # Description: #
9
+ # This is a generic installation script for pure ruby sources. Features #
10
+ # include: #
11
+ # * Clean uninstall #
12
+ # * Installation into an absolute path #
13
+ # * Installation into a temp path (useful for systems like Portage) #
14
+ # * Noop mode, for testing #
15
+ # To set for a different system, change the SRC directory to point to the #
16
+ # package name / source directory for the project. #
17
+ # #
18
+ ################################################################################
19
+
20
+ # CHANGE THIS
21
+ SRC = ['SVG' ]
22
+ STRIP = ''
23
+ SETVERSION = 'SVG'
24
+ SRCVERSION = '@ANT_VERSION@'
25
+ DATE = '@ANT_DATE@'
26
+
27
+ ################################################################################
28
+ # CHANGE NOTHING BELOW THIS LINE
29
+
30
+ Dir.chdir ".." if Dir.pwd =~ /bin.?$/
31
+
32
+ require 'getoptlong'
33
+ require 'rbconfig'
34
+ require 'ftools'
35
+ require 'find'
36
+
37
+ opts = GetoptLong.new( [ '--uninstall', '-u', GetoptLong::NO_ARGUMENT],
38
+ [ '--destdir', '-d', GetoptLong::REQUIRED_ARGUMENT ],
39
+ [ '--target', '-t', GetoptLong::REQUIRED_ARGUMENT ],
40
+ [ '--concurrent', '-c', GetoptLong::NO_ARGUMENT],
41
+ [ '--help', '-h', GetoptLong::NO_ARGUMENT],
42
+ [ '--noop', '-n', GetoptLong::NO_ARGUMENT])
43
+
44
+
45
+ destdir = File.join(Config::CONFIG['sitedir'],
46
+ "#{Config::CONFIG['MAJOR']}.#{Config::CONFIG['MINOR']}")
47
+
48
+ uninstall = false
49
+ prepend = nil
50
+ help = false
51
+ opts.each do |opt,arg|
52
+ case opt
53
+ when '--concurrent'
54
+ CONCURRENT = true
55
+ when '--destdir'
56
+ prepend = arg
57
+ when '--uninstall'
58
+ uninstall = true
59
+ when '--target'
60
+ destdir = arg
61
+ when '--help'
62
+ help = true
63
+ when '--noop'
64
+ NOOP = true
65
+ end
66
+ end
67
+
68
+ destdir = File.join prepend, destdir if prepend
69
+
70
+ def transmogrify( dir )
71
+ dir = dir.sub( /^#{STRIP}\//, '' )
72
+ if defined? CONCURRENT
73
+ dir.sub( /#{SETVERSION}/, "#{SETVERSION}-#{SRCVERSION}")
74
+ else
75
+ dir
76
+ end
77
+ end
78
+
79
+ if help
80
+ puts "Installs #{SRC.inspect}.\nUsage: #$0 [[-u] [-n] [-c] [-t <dir>|-d <dir>]|-h]"
81
+ puts " -u --uninstall\n Uninstalls the package"
82
+ puts " -c --concurrent\n Install concurrently, IE, into"
83
+ for d in SRC
84
+ puts " #{destdir}/#{transmogrify( d )}"
85
+ end
86
+ puts " The default behavior is to upgrade the current installation,"
87
+ puts " by installing into"
88
+ for d in SRC
89
+ puts " #{destdir}/#{transmogrify( d )}"
90
+ end
91
+ puts " -t --target\n Installs the software at an absolute location, EG:"
92
+ puts " #$0 -t /usr/local/lib/ruby"
93
+ puts " will put the software directly underneath /usr/local/lib/ruby;"
94
+ for d in SRC
95
+ puts " /usr/local/lib/ruby/#{transmogrify( d )}"
96
+ end
97
+ puts " -d --destdir\n Installs the software at a relative location, EG:"
98
+ puts " #$0 -d /tmp"
99
+ puts " will put the software under tmp, using your ruby environment."
100
+ for d in SRC
101
+ puts " /tmp#{destdir}/#{transmogrify( d )}"
102
+ end
103
+ puts " -n --noop\n Don't actually do anything; just print out what it"
104
+ puts " would do."
105
+ exit 0
106
+ end
107
+
108
+ def install destdir
109
+ puts "Installing in #{destdir}"
110
+ begin
111
+ for src in SRC
112
+ Find.find(src) { |file|
113
+ dstfile = transmogrify( file )
114
+ next if file =~ /CVS|\.svn/
115
+ dst = File.join( destdir, dstfile )
116
+ if defined? NOOP
117
+ puts ">> #{dst}" if file =~ /\.rb$/
118
+ else
119
+ File.makedirs( File.dirname(dst) )
120
+ File.install(file, dst, 0644, true) if file =~ /\.rb$/
121
+ end
122
+ }
123
+ end
124
+ rescue
125
+ puts $!
126
+ end
127
+ end
128
+
129
+ def uninstall destdir
130
+ puts "Uninstalling in #{destdir}"
131
+ begin
132
+ puts "Deleting:"
133
+ dirs = []
134
+ Find.find(File.join(destdir,SRC)) do |file|
135
+ file.sub!( /#{SRC}/, "#{SRC}-#{SRCVERSION}") if defined? CONCURRENT
136
+ if defined? NOOP
137
+ puts "-- #{file}" if File.file? file
138
+ else
139
+ File.rm_f file,true if File.file? file
140
+ end
141
+ dirs << file if File.directory? file
142
+ end
143
+ dirs.sort { |x,y|
144
+ y.length <=> x.length
145
+ }.each { |d|
146
+ if defined? NOOP
147
+ puts "-- #{d}"
148
+ else
149
+ puts d
150
+ Dir.delete d
151
+ end
152
+ }
153
+ rescue
154
+ end
155
+ end
156
+
157
+ if uninstall
158
+ uninstall destdir
159
+ else
160
+ install destdir
161
+ end
data/lib/SVG/Graph/Bar.rb CHANGED
@@ -105,7 +105,7 @@ module SVG
105
105
 
106
106
  bar_width = fieldwidth - bargap
107
107
  bar_width /= @data.length if stack == :side
108
- x_mod = (@graph_width-bargap)/2 - (stack==:side ? bar_width/2 : 0)
108
+ #x_mod = (@graph_width-bargap)/2 - (stack==:side ? bar_width/2 : 0)
109
109
 
110
110
  bottom = @graph_height
111
111