svg-graph 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
Binary file
data/History.txt CHANGED
@@ -1,9 +1,16 @@
1
- === 1.0.3 / 2011-08-04
2
- * Removed unused variables which raises warnings on ruby head
3
- * Bug fix: Test raises error on different order of xml attribute
4
- * Merge pull request #2 from liehann/master
5
- * Max values and improved Time data handling.
6
- * Merge pull request #1 from thinkingbox/master
7
- * Adding scattered plot support with :show_lines =>false Rounding values to integers in popups can be disabled with :round_popups => false Optional description gets shown in popup
8
-
9
-
1
+ === 1.0.4 / 2011-09-03
2
+ * Data point shape is configurable based on rule matches on description. It defaults to usual circle with radius 2.5. [pgbossi]
3
+ * New shapes can be specified through lambdas that accept parameters x,y (coordinates) and the dataset number.[pgbossi]
4
+ * Max x and y values & allow Time objects in TimeSeries data. [pgbossi]
5
+ * Popup hovering area is now customizable (it defaults to radius=10). [pgbossi]
6
+ * Some DataPoint shapes can be marked as overlays. [pgbossi]
7
+
8
+ === 1.0.3 / 2011-08-04
9
+ * Removed unused variables which raises warnings on ruby head
10
+ * Bug fix: Test raises error on different order of xml attribute
11
+ * Merge pull request #2 from liehann/master
12
+ * Max values and improved Time data handling.
13
+ * Merge pull request #1 from thinkingbox/master
14
+ * Adding scattered plot support with :show_lines =>false Rounding values to integers in popups can be disabled with :round_popups => false Optional description gets shown in popup
15
+
16
+
data/Manifest.txt CHANGED
@@ -32,6 +32,7 @@ install.rb
32
32
  lib/SVG/Graph/Bar.rb
33
33
  lib/SVG/Graph/BarBase.rb
34
34
  lib/SVG/Graph/BarHorizontal.rb
35
+ lib/SVG/Graph/DataPoint.rb
35
36
  lib/SVG/Graph/Graph.rb
36
37
  lib/SVG/Graph/Line.rb
37
38
  lib/SVG/Graph/Pie.rb
@@ -49,5 +50,7 @@ test/plot.rb
49
50
  test/schedule.rb
50
51
  test/single.rb
51
52
  test/test.rb
53
+ test/test_data_point.rb
54
+ test/test_plot.rb
52
55
  test/test_svg_graph.rb
53
56
  test/timeseries.rb
data/README.txt CHANGED
@@ -1,89 +1,89 @@
1
- = SVG::Graph
2
-
3
- http://www.germane-software.com/software/SVG/SVG::Graph/
4
-
5
- == AUTHOR
6
-
7
- Sean E. Russell <serATgermaneHYPHENsoftwareDOTcom>
8
- Copyright 2004 Sean E. Russell
9
- This software is available under the Ruby license[LICENSE.txt]
10
-
11
- == DEVELOPERS
12
-
13
- * Claudio Bustos <clbustos_AT_gmail_DOT_com
14
- * Liehann Loots <liehhanl_AT_gmail_DOT_com
15
- * Piergiuliano Bossi <pgbossi_AT_gmail_DOT_com
16
-
17
- == DESCRIPTION:
18
-
19
- This is a minor revision of the [SVG::Graph library](http://www.germane-software.com/software/SVG/SVG::Graph/) by Sean Russell with few minor touch-ups to make it run on Ruby 1.9.x and to have it gem-installable
20
-
21
- SVG:::Graph is a pure Ruby library for generating charts, which are a type of graph where the values of one axis are not scalar. SVG::Graph has a verry similar API to the Perl library SVG::TT::Graph, and the resulting charts also look the same. This isn't surprising, because SVG::Graph started as a loose port of SVG::TT::Graph, although the internal code no longer resembles the Perl original at all.
22
-
23
- == FEATURES
24
-
25
- * Tested for Ruby versions 1.8.6, 1.8.7 and 1.9.*
26
-
27
- We are not sure that all the parts of the original SVG library work as expected under 1.9.x too. Please notify via github messages or on the Issues section if you find any bug.
28
-
29
- == LICENSE:
30
-
31
- (The Ruby Licence)
32
-
33
- SVG::Graph is copyrighted free software by Sean Russell <ser@germane-software.com>.
34
- You can redistribute it and/or modify it under either the terms of the GPL
35
- (see GPL.txt file), or the conditions below:
36
-
37
- 1. You may make and give away verbatim copies of the source form of the
38
- software without restriction, provided that you duplicate all of the
39
- original copyright notices and associated disclaimers.
40
-
41
- 2. You may modify your copy of the software in any way, provided that
42
- you do at least ONE of the following:
43
-
44
- a) place your modifications in the Public Domain or otherwise
45
- make them Freely Available, such as by posting said
46
- modifications to Usenet or an equivalent medium, or by allowing
47
- the author to include your modifications in the software.
48
-
49
- b) use the modified software only within your corporation or
50
- organization.
51
-
52
- c) rename any non-standard executables so the names do not conflict
53
- with standard executables, which must also be provided.
54
-
55
- d) make other distribution arrangements with the author.
56
-
57
- 3. You may distribute the software in object code or executable
58
- form, provided that you do at least ONE of the following:
59
-
60
- a) distribute the executables and library files of the software,
61
- together with instructions (in the manual page or equivalent)
62
- on where to get the original distribution.
63
-
64
- b) accompany the distribution with the machine-readable source of
65
- the software.
66
-
67
- c) give non-standard executables non-standard names, with
68
- instructions on where to get the original software distribution.
69
-
70
- d) make other distribution arrangements with the author.
71
-
72
- 4. You may modify and include the part of the software into any other
73
- software (possibly commercial). But some files in the distribution
74
- are not written by the author, so that they are not under this terms.
75
-
76
- They are gc.c(partly), utils.c(partly), regex.[ch], st.[ch] and some
77
- files under the ./missing directory. See each file for the copying
78
- condition.
79
-
80
- 5. The scripts and library files supplied as input to or produced as
81
- output from the software do not automatically fall under the
82
- copyright of the software, but belong to whomever generated them,
83
- and may be sold commercially, and may be aggregated with this
84
- software.
85
-
86
- 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
87
- IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
88
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
89
- PURPOSE.
1
+ = SVG::Graph
2
+
3
+ http://www.germane-software.com/software/SVG/SVG::Graph/
4
+
5
+ == AUTHOR
6
+
7
+ Sean E. Russell <serATgermaneHYPHENsoftwareDOTcom>
8
+ Copyright 2004 Sean E. Russell
9
+ This software is available under the Ruby license[LICENSE.txt]
10
+
11
+ == DEVELOPERS
12
+
13
+ * Claudio Bustos <clbustos_AT_gmail_DOT_com
14
+ * Liehann Loots <liehhanl_AT_gmail_DOT_com
15
+ * Piergiuliano Bossi <pgbossi_AT_gmail_DOT_com
16
+
17
+ == DESCRIPTION:
18
+
19
+ This is a revision of the [SVG::Graph library](http://www.germane-software.com/software/SVG/SVG::Graph/) by Sean Russell with touch-ups to make it run on Ruby 1.9.x and be gem-installable. See History.txt for other changes
20
+
21
+ SVG:::Graph is a pure Ruby library for generating charts, which are a type of graph where the values of one axis are not scalar. SVG::Graph has a verry similar API to the Perl library SVG::TT::Graph, and the resulting charts also look the same. This isn't surprising, because SVG::Graph started as a loose port of SVG::TT::Graph, although the internal code no longer resembles the Perl original at all.
22
+
23
+ == FEATURES
24
+
25
+ * Tested for Ruby versions 1.8.6, 1.8.7 and 1.9.*
26
+
27
+ We are not sure that all the parts of the original SVG library work as expected under 1.9.x too. Please notify via github messages or on the Issues section if you find any bug.
28
+
29
+ == LICENSE:
30
+
31
+ (The Ruby Licence)
32
+
33
+ SVG::Graph is copyrighted free software by Sean Russell <ser@germane-software.com>.
34
+ You can redistribute it and/or modify it under either the terms of the GPL
35
+ (see GPL.txt file), or the conditions below:
36
+
37
+ 1. You may make and give away verbatim copies of the source form of the
38
+ software without restriction, provided that you duplicate all of the
39
+ original copyright notices and associated disclaimers.
40
+
41
+ 2. You may modify your copy of the software in any way, provided that
42
+ you do at least ONE of the following:
43
+
44
+ a) place your modifications in the Public Domain or otherwise
45
+ make them Freely Available, such as by posting said
46
+ modifications to Usenet or an equivalent medium, or by allowing
47
+ the author to include your modifications in the software.
48
+
49
+ b) use the modified software only within your corporation or
50
+ organization.
51
+
52
+ c) rename any non-standard executables so the names do not conflict
53
+ with standard executables, which must also be provided.
54
+
55
+ d) make other distribution arrangements with the author.
56
+
57
+ 3. You may distribute the software in object code or executable
58
+ form, provided that you do at least ONE of the following:
59
+
60
+ a) distribute the executables and library files of the software,
61
+ together with instructions (in the manual page or equivalent)
62
+ on where to get the original distribution.
63
+
64
+ b) accompany the distribution with the machine-readable source of
65
+ the software.
66
+
67
+ c) give non-standard executables non-standard names, with
68
+ instructions on where to get the original software distribution.
69
+
70
+ d) make other distribution arrangements with the author.
71
+
72
+ 4. You may modify and include the part of the software into any other
73
+ software (possibly commercial). But some files in the distribution
74
+ are not written by the author, so that they are not under this terms.
75
+
76
+ They are gc.c(partly), utils.c(partly), regex.[ch], st.[ch] and some
77
+ files under the ./missing directory. See each file for the copying
78
+ condition.
79
+
80
+ 5. The scripts and library files supplied as input to or produced as
81
+ output from the software do not automatically fall under the
82
+ copyright of the software, but belong to whomever generated them,
83
+ and may be sold commercially, and may be aggregated with this
84
+ software.
85
+
86
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
87
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
88
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
89
+ PURPOSE.
data/Rakefile CHANGED
@@ -1,21 +1,21 @@
1
- # -*- ruby -*-
2
- # -*- coding: utf-8 -*-
3
- $:.unshift(File.dirname(__FILE__)+"/lib/")
4
-
5
- require 'rubygems'
6
- require 'hoe'
7
-
8
- Hoe.plugin :git
9
- $:.unshift("./lib")
10
- require 'svggraph'
11
- Hoe.spec 'svg-graph' do
12
- self.version=SVG::Graph::VERSION
13
- self.developer('Sean Russell', 'ser_AT_germane-software.com')
14
- self.developer('Claudio Bustos', 'clbustos_AT_gmail.com')
15
- self.developer("Liehann Loots","liehhanl_AT_gmail.com")
16
- self.developer("Piergiuliano Bossi","pgbossi_AT_gmail.com")
17
- self.rubyforge_name = 'ruby-statsample' # if different than 'svg_graph'
18
- self.remote_rdoc_dir = 'svg-graph'
19
- end
20
-
21
- # vim: syntax=ruby
1
+ # -*- ruby -*-
2
+ # -*- coding: utf-8 -*-
3
+ $:.unshift(File.dirname(__FILE__)+"/lib/")
4
+
5
+ require 'rubygems'
6
+ require 'hoe'
7
+
8
+ Hoe.plugin :git
9
+ $:.unshift("./lib")
10
+ require 'svggraph'
11
+ Hoe.spec 'svg-graph' do
12
+ self.version=SVG::Graph::VERSION
13
+ self.developer('Sean Russell', 'ser_AT_germane-software.com')
14
+ self.developer('Claudio Bustos', 'clbustos_AT_gmail.com')
15
+ self.developer("Liehann Loots","liehhanl_AT_gmail.com")
16
+ self.developer("Piergiuliano Bossi","pgbossi_AT_gmail.com")
17
+ self.rubyforge_name = 'ruby-statsample' # if different than 'svg_graph'
18
+ self.remote_rdoc_dir = 'svg-graph'
19
+ end
20
+
21
+ # vim: syntax=ruby
@@ -0,0 +1,39 @@
1
+ class DataPoint
2
+ OVERLAY = "OVERLAY" unless defined?(OVERLAY)
3
+ DEFAULT_SHAPE = lambda{|x,y,line| ["circle", {
4
+ "cx" => x,
5
+ "cy" => y,
6
+ "r" => "2.5",
7
+ "class" => "dataPoint#{line}"
8
+ }]
9
+ } unless defined? DEFAULT_SHAPE
10
+ CRITERIA = [] unless defined? CRITERIA
11
+ def DataPoint.configure_shape_criteria(*matchers)
12
+ CRITERIA.push(*matchers)
13
+ end
14
+ def DataPoint.reset_shape_criteria
15
+ CRITERIA.clear
16
+ end
17
+
18
+ def initialize(x, y, line)
19
+ @x = x
20
+ @y = y
21
+ @line = line
22
+ end
23
+ def shape(description=nil)
24
+ shapes = CRITERIA.select {|criteria|
25
+ criteria.size == 2
26
+ }.collect {|regexp, proc|
27
+ proc.call(@x, @y, @line) if description =~ regexp
28
+ }.compact
29
+ shapes = [DEFAULT_SHAPE.call(@x, @y, @line)] if shapes.empty?
30
+
31
+ overlays = CRITERIA.select { |criteria|
32
+ criteria.last == OVERLAY
33
+ }.collect { |regexp, proc|
34
+ proc.call(@x, @y, @line) if description =~ regexp
35
+ }.compact
36
+
37
+ return shapes + overlays
38
+ end
39
+ end
@@ -341,6 +341,8 @@ module SVG
341
341
  attr_accessor :no_css
342
342
  # Add popups for the data points on some graphs
343
343
  attr_accessor :add_popups
344
+ # Customize popup radius
345
+ attr_accessor :popup_radius
344
346
 
345
347
 
346
348
  protected
@@ -355,6 +357,7 @@ module SVG
355
357
  config.each { |key, value|
356
358
  self.send( key.to_s+"=", value ) if self.respond_to? key
357
359
  }
360
+ @popup_radius ||= 10
358
361
  end
359
362
 
360
363
  attr_accessor :top_align, :top_font, :right_align, :right_font
@@ -424,7 +427,7 @@ module SVG
424
427
  @foreground.add_element( "circle", {
425
428
  "cx" => x.to_s,
426
429
  "cy" => y.to_s,
427
- "r" => "10",
430
+ "r" => "#{@popup_radius}",
428
431
  "style" => "opacity: 0",
429
432
  "onmouseover" =>
430
433
  "document.getElementById(#{t.object_id}).setAttribute('visibility', 'visible' )",
@@ -1,4 +1,5 @@
1
1
  require 'SVG/Graph/Graph'
2
+ require 'SVG/Graph/DataPoint'
2
3
 
3
4
  module SVG
4
5
  module Graph
@@ -334,12 +335,9 @@ module SVG
334
335
  x = (x_points[idx] - x_min) * x_step
335
336
  y = @graph_height - (y_points[idx] - y_min) * y_step
336
337
  if show_data_points
337
- @graph.add_element( "circle", {
338
- "cx" => x.to_s,
339
- "cy" => y.to_s,
340
- "r" => "2.5",
341
- "class" => "dataPoint#{line}"
342
- })
338
+ DataPoint.new(x, y, line).shape(data[:description][idx]).each{|s|
339
+ @graph.add_element( *s )
340
+ }
343
341
  add_popup(x, y, format( x_points[idx], y_points[idx], data[:description][idx])) if add_popups
344
342
  end
345
343
  make_datapoint_text( x, y-6, y_points[idx] ) if show_data_values
data/lib/svggraph.rb CHANGED
@@ -1,13 +1,14 @@
1
- module SVG
2
- module Graph
3
- VERSION = '1.0.3'
4
- autoload(:Bar, 'SVG/Graph/Bar')
5
- autoload(:BarBase, 'SVG/Graph/BarBase')
6
- autoload(:BarHorizontal, 'SVG/Graph/BarHorizontal')
7
- autoload(:Line, 'SVG/Graph/Line')
8
- autoload(:Pie, 'SVG/Graph/Pie')
9
- autoload(:Plot, 'SVG/Graph/Plot')
10
- autoload(:Schedule, 'SVG/Graph/Schedule')
11
- autoload(:TimeSeries, 'SVG/Graph/TimeSeries')
12
- end
13
- end
1
+ module SVG
2
+ module Graph
3
+ VERSION = '1.0.4'
4
+ autoload(:Bar, 'SVG/Graph/Bar')
5
+ autoload(:BarBase, 'SVG/Graph/BarBase')
6
+ autoload(:BarHorizontal, 'SVG/Graph/BarHorizontal')
7
+ autoload(:Line, 'SVG/Graph/Line')
8
+ autoload(:Pie, 'SVG/Graph/Pie')
9
+ autoload(:Plot, 'SVG/Graph/Plot')
10
+ autoload(:Schedule, 'SVG/Graph/Schedule')
11
+ autoload(:TimeSeries, 'SVG/Graph/TimeSeries')
12
+ autoload(:DataPoint, 'SVG/Graph/DataPoint')
13
+ end
14
+ end
@@ -0,0 +1,67 @@
1
+ $: << File.dirname(__FILE__) + '/../lib'
2
+ require "test/unit"
3
+ require "SVG/Graph/DataPoint"
4
+
5
+ class TestDataPoint < Test::Unit::TestCase
6
+ def setup
7
+ DataPoint.reset_shape_criteria
8
+ end
9
+ def teardown
10
+ DataPoint.reset_shape_criteria
11
+ end
12
+ def test_default_shape_is_circle_with_2_point_5_radius
13
+ assert_equal([['circle', {
14
+ "cx" => 100.0,
15
+ "cy" => 100.0,
16
+ "r" => "2.5",
17
+ "class" => "dataPoint1"
18
+ }]], DataPoint.new(100.0, 100.0, 1).shape)
19
+ end
20
+ def test_default_shape_based_on_description_without_criteria_is_circle_with_2_point_5_radius
21
+ assert_equal([['circle', {
22
+ "cx" => 100.0,
23
+ "cy" => 100.0,
24
+ "r" => "2.5",
25
+ "class" => "dataPoint1"
26
+ }]], DataPoint.new(100.0, 100.0, 1).shape("description"))
27
+ end
28
+ def test_shape_for_matching_regular_expression_is_lambda_value
29
+ DataPoint.configure_shape_criteria(
30
+ [/angle/, lambda{|x,y,line| ['rect', {
31
+ "x" => x,
32
+ "y" => y,
33
+ "width" => "5",
34
+ "height" => "5",
35
+ "class" => "dataPoint#{line}"
36
+ }]
37
+ }]
38
+ )
39
+ assert_equal([['rect', {
40
+ "x" => 100.0,
41
+ "y" => 50.0,
42
+ "width" => "5",
43
+ "height" => "5",
44
+ "class" => "dataPoint2"
45
+ }]], DataPoint.new(100.0, 50.0, 2).shape("rectangle"))
46
+ end
47
+ def test_multiple_criteria_generate_shapes_in_order
48
+ DataPoint.configure_shape_criteria(
49
+ [/3/, lambda{|x,y,line| "three" }],
50
+ [/2/, lambda{|x,y,line| "two" }],
51
+ [/1/, lambda{|x,y,line| "one" }]
52
+ )
53
+ assert_equal(["three", "two", "one"], DataPoint.new(100.0, 50.0, 2).shape("1 3 2"))
54
+ end
55
+ def test_overlay_match_is_last_and_does_not_prevent_default
56
+ DataPoint.configure_shape_criteria(
57
+ [/3/, lambda{|x,y,line| "three" }, DataPoint::OVERLAY]
58
+ )
59
+ default_circle = ['circle', {
60
+ "cx" => 100.0,
61
+ "cy" => 50.0,
62
+ "r" => "2.5",
63
+ "class" => "dataPoint2"
64
+ }]
65
+ assert_equal([default_circle, "three"], DataPoint.new(100.0, 50.0, 2).shape("1 3 2"))
66
+ end
67
+ end
data/test/test_plot.rb CHANGED
@@ -1,40 +1,47 @@
1
1
  $: << File.dirname(__FILE__) + '/../lib'
2
2
  require "test/unit"
3
3
  require "svggraph"
4
+ require "SVG/Graph/DataPoint"
4
5
 
5
6
  class TestSvgGraphPlot < Test::Unit::TestCase
6
- def _test_plot
7
-
8
- projection = [
9
- 6, 11, 0, 5, 18, 7, 1, 11, 13, 9, 1, 2, 19, 0, 3, 13,
10
- 7, 9
11
- ]
12
- actual = [
13
- 0, 18, 8, 15, 9, 4, 18, 14, 10, 2, 11, 6, 14, 12,
14
- 15, 6, 4, 17, 2, 12
15
- ]
16
-
17
- graph = SVG::Graph::Plot.new({
18
- :height => 500,
19
- :width => 300,
20
- :key => true,
21
- :scale_x_integers => true,
22
- :scale_y_integerrs => true,
23
- })
24
-
25
- graph.add_data({
26
- :data => projection,
27
- :title => 'Projected',
28
- })
29
-
30
- graph.add_data({
31
- :data => actual,
32
- :title => 'Actual',
33
- })
34
-
35
- out=graph.burn()
36
- assert(out=~/Created with SVG::Graph/)
37
- end
7
+ def setup
8
+ DataPoint.reset_shape_criteria
9
+ end
10
+ def teardown
11
+ DataPoint.reset_shape_criteria
12
+ end
13
+ def test_plot
14
+
15
+ projection = [
16
+ 6, 11, 0, 5, 18, 7, 1, 11, 13, 9, 1, 2, 19, 0, 3, 13,
17
+ 7, 9
18
+ ]
19
+ actual = [
20
+ 0, 18, 8, 15, 9, 4, 18, 14, 10, 2, 11, 6, 14, 12,
21
+ 15, 6, 4, 17, 2, 12
22
+ ]
23
+
24
+ graph = SVG::Graph::Plot.new({
25
+ :height => 500,
26
+ :width => 300,
27
+ :key => true,
28
+ :scale_x_integers => true,
29
+ :scale_y_integerrs => true,
30
+ })
31
+
32
+ graph.add_data({
33
+ :data => projection,
34
+ :title => 'Projected',
35
+ })
36
+
37
+ graph.add_data({
38
+ :data => actual,
39
+ :title => 'Actual',
40
+ })
41
+
42
+ out=graph.burn()
43
+ assert(out=~/Created with SVG::Graph/)
44
+ end
38
45
  def test_default_plot_emits_polyline_connecting_data_points
39
46
  actual = [
40
47
  0, 18, 8, 15, 9, 4, 18, 14, 10, 2, 11, 6, 14, 12,
@@ -57,7 +64,7 @@ class TestSvgGraphPlot < Test::Unit::TestCase
57
64
  assert_match(/path.*class='line1'/, out)
58
65
  end
59
66
 
60
- def _test_disabling_show_lines_does_not_emit_polyline_connecting_data_points
67
+ def test_disabling_show_lines_does_not_emit_polyline_connecting_data_points
61
68
  actual = [
62
69
  0, 18, 8, 15, 9, 4, 18, 14, 10, 2, 11, 6, 14, 12,
63
70
  15, 6, 4, 17, 2, 12
@@ -80,7 +87,7 @@ class TestSvgGraphPlot < Test::Unit::TestCase
80
87
  out=graph.burn()
81
88
  assert_no_match(/path class='line1' d='M.* L.*'/, out)
82
89
  end
83
- def _test_popup_values_round_to_integer_by_default_in_popups
90
+ def test_popup_values_round_to_integer_by_default_in_popups
84
91
  actual = [
85
92
  0.1, 18, 8.55, 15.1234, 9.09876765, 4,
86
93
  ]
@@ -107,7 +114,7 @@ class TestSvgGraphPlot < Test::Unit::TestCase
107
114
  assert_no_match(/\(9.09876765, 4\)/, out)
108
115
  assert_match(/\(9, 4\)/, out)
109
116
  end
110
- def _test_do_not_round_popup_values_shows_decimal_values_in_popups
117
+ def test_do_not_round_popup_values_shows_decimal_values_in_popups
111
118
  actual = [
112
119
  0.1, 18, 8.55, 15.1234, 9.09876765, 4,
113
120
  ]
@@ -135,7 +142,7 @@ class TestSvgGraphPlot < Test::Unit::TestCase
135
142
  assert_match(/\(9.09876765, 4\)/, out)
136
143
  assert_no_match(/\(9, 4\)/, out)
137
144
  end
138
- def _test_description_is_shown_in_popups_if_provided
145
+ def test_description_is_shown_in_popups_if_provided
139
146
  actual = [
140
147
  8.55, 15.1234, 9.09876765, 4, 0.1, 18,
141
148
  ]
@@ -167,4 +174,106 @@ class TestSvgGraphPlot < Test::Unit::TestCase
167
174
  assert_match(/\(0.1, 18, third\)/, out)
168
175
  assert_no_match(/\(0.1, 18\)/, out)
169
176
  end
177
+ def test_combine_different_shapes_based_on_description
178
+ actual = [
179
+ 8.55, 15.1234, 9.09876765, 4, 2.1, 18,
180
+ ]
181
+ description = [
182
+ 'one is a circle', 'two is a rectangle', 'three is a rectangle with strikethrough',
183
+ ]
184
+
185
+ DataPoint.configure_shape_criteria(
186
+ [/^t.*/, lambda{|x,y,line| ['polygon', {
187
+ "points" => "#{x-1.5},#{y+2.5} #{x+1.5},#{y+2.5} #{x+1.5},#{y-2.5} #{x-1.5},#{y-2.5}",
188
+ "class" => "dataPoint#{line}"
189
+ }]
190
+ }],
191
+ [/^three.*/, lambda{|x,y,line| ['line', {
192
+ "x1" => "#{x-4}",
193
+ "y1" => y.to_s,
194
+ "x2" => "#{x+4}",
195
+ "y2" => y.to_s,
196
+ "class" => "axis"
197
+ }]
198
+ }]
199
+ )
200
+ graph = SVG::Graph::Plot.new({
201
+ :height => 500,
202
+ :width => 300,
203
+ :key => true,
204
+ :scale_x_integers => true,
205
+ :scale_y_integers => true,
206
+ :add_popups => true,
207
+ :round_popups => false,
208
+ })
209
+
210
+ graph.add_data({
211
+ :data => actual,
212
+ :title => 'Actual',
213
+ :description => description,
214
+ })
215
+
216
+ out=graph.burn()
217
+ assert_match(/polygon.*points/, out)
218
+ assert_match(/line.*axis/, out)
219
+ end
220
+ def test_popup_radius_is_10_by_default
221
+ actual = [
222
+ 1, 1, 5, 5, 10, 10,
223
+ ]
224
+ description = [
225
+ 'first', 'second', 'third',
226
+ ]
227
+
228
+ graph = SVG::Graph::Plot.new({
229
+ :height => 500,
230
+ :width => 300,
231
+ :key => true,
232
+ :scale_x_integers => true,
233
+ :scale_y_integers => true,
234
+ :add_popups => true,
235
+ :round_popups => false,
236
+ })
237
+
238
+ graph.add_data({
239
+ :data => actual,
240
+ :title => 'Actual',
241
+ :description => description,
242
+ })
243
+
244
+ out=graph.burn()
245
+ assert_match(/circle .* r='10'/, out)
246
+ assert_match(/circle .* onmouseover=.*/, out)
247
+
248
+ end
249
+ def test_popup_radius_is_overridable
250
+ actual = [
251
+ 1, 1, 5, 5, 10, 10,
252
+ ]
253
+ description = [
254
+ 'first', 'second', 'third',
255
+ ]
256
+
257
+ graph = SVG::Graph::Plot.new({
258
+ :height => 500,
259
+ :width => 300,
260
+ :key => true,
261
+ :scale_x_integers => true,
262
+ :scale_y_integers => true,
263
+ :add_popups => true,
264
+ :round_popups => false,
265
+ :popup_radius => 1.23
266
+ })
267
+
268
+ graph.add_data({
269
+ :data => actual,
270
+ :title => 'Actual',
271
+ :description => description,
272
+ })
273
+
274
+ out=graph.burn()
275
+ assert_match(/circle .* r='1.23'/, out)
276
+ assert_match(/circle .* onmouseover=.*/, out)
277
+
278
+ end
170
279
  end
@@ -1,24 +1,25 @@
1
1
  $: << File.dirname(__FILE__) + '/../lib'
2
2
  require "test/unit"
3
3
  require "svggraph"
4
+ require "SVG/Graph/DataPoint"
4
5
 
5
6
  class TestSvgGraph < Test::Unit::TestCase
6
- def test_bar_line_and_pie
7
- fields = %w(Jan Feb Mar);
8
- data_sales_02 = [12, 45, 21]
9
- [SVG::Graph::Bar, SVG::Graph::BarHorizontal, SVG::Graph::Line, SVG::Graph::Pie].each do
10
- |klass|
11
- graph = klass.new(
12
- :height => 500,
13
- :width => 300,
14
- :fields => fields
15
- )
16
- graph.add_data(
17
- :data => data_sales_02,
18
- :title => 'Sales 2002'
19
- )
20
- out=graph.burn
21
- assert(out=~/Created with SVG::Graph/)
22
- end
23
- end
7
+ def test_bar_line_and_pie
8
+ fields = %w(Jan Feb Mar);
9
+ data_sales_02 = [12, 45, 21]
10
+ [SVG::Graph::Bar, SVG::Graph::BarHorizontal, SVG::Graph::Line, SVG::Graph::Pie].each do
11
+ |klass|
12
+ graph = klass.new(
13
+ :height => 500,
14
+ :width => 300,
15
+ :fields => fields
16
+ )
17
+ graph.add_data(
18
+ :data => data_sales_02,
19
+ :title => 'Sales 2002'
20
+ )
21
+ out=graph.burn
22
+ assert(out=~/Created with SVG::Graph/)
23
+ end
24
+ end
24
25
  end
metadata CHANGED
@@ -1,8 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: svg-graph
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 1.0.3
4
+ hash: 31
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 4
10
+ version: 1.0.4
6
11
  platform: ruby
7
12
  authors:
8
13
  - Sean Russell
@@ -34,7 +39,7 @@ cert_chain:
34
39
  rpP0jjs0
35
40
  -----END CERTIFICATE-----
36
41
 
37
- date: 2011-08-04 00:00:00 -04:00
42
+ date: 2011-10-03 00:00:00 -03:00
38
43
  default_executable:
39
44
  dependencies:
40
45
  - !ruby/object:Gem::Dependency
@@ -45,12 +50,17 @@ dependencies:
45
50
  requirements:
46
51
  - - ">="
47
52
  - !ruby/object:Gem::Version
53
+ hash: 47
54
+ segments:
55
+ - 2
56
+ - 8
57
+ - 0
48
58
  version: 2.8.0
49
59
  type: :development
50
60
  version_requirements: *id001
51
61
  description: |-
52
- This is a minor revision of the [SVG::Graph library](http://www.germane-software.com/software/SVG/SVG::Graph/) by Sean Russell with few minor touch-ups to make it run on Ruby 1.9.x and to have it gem-installable
53
-
62
+ This is a revision of the [SVG::Graph library](http://www.germane-software.com/software/SVG/SVG::Graph/) by Sean Russell with touch-ups to make it run on Ruby 1.9.x and be gem-installable. See History.txt for other changes
63
+
54
64
  SVG:::Graph is a pure Ruby library for generating charts, which are a type of graph where the values of one axis are not scalar. SVG::Graph has a verry similar API to the Perl library SVG::TT::Graph, and the resulting charts also look the same. This isn't surprising, because SVG::Graph started as a loose port of SVG::TT::Graph, although the internal code no longer resembles the Perl original at all.
55
65
  email:
56
66
  - ser_AT_germane-software.com
@@ -102,6 +112,7 @@ files:
102
112
  - lib/SVG/Graph/Bar.rb
103
113
  - lib/SVG/Graph/BarBase.rb
104
114
  - lib/SVG/Graph/BarHorizontal.rb
115
+ - lib/SVG/Graph/DataPoint.rb
105
116
  - lib/SVG/Graph/Graph.rb
106
117
  - lib/SVG/Graph/Line.rb
107
118
  - lib/SVG/Graph/Pie.rb
@@ -119,11 +130,12 @@ files:
119
130
  - test/schedule.rb
120
131
  - test/single.rb
121
132
  - test/test.rb
133
+ - test/test_data_point.rb
134
+ - test/test_plot.rb
122
135
  - test/test_svg_graph.rb
123
136
  - test/timeseries.rb
124
- - test/test_plot.rb
125
137
  has_rdoc: true
126
- homepage: http://www.germane-software.com/software/SVG/SVG::Graph/
138
+ homepage: http://www.germane-software.com/software/SVG/SVG::Graph/
127
139
  licenses: []
128
140
 
129
141
  post_install_message:
@@ -137,20 +149,27 @@ required_ruby_version: !ruby/object:Gem::Requirement
137
149
  requirements:
138
150
  - - ">="
139
151
  - !ruby/object:Gem::Version
152
+ hash: 3
153
+ segments:
154
+ - 0
140
155
  version: "0"
141
156
  required_rubygems_version: !ruby/object:Gem::Requirement
142
157
  none: false
143
158
  requirements:
144
159
  - - ">="
145
160
  - !ruby/object:Gem::Version
161
+ hash: 3
162
+ segments:
163
+ - 0
146
164
  version: "0"
147
165
  requirements: []
148
166
 
149
167
  rubyforge_project: ruby-statsample
150
- rubygems_version: 1.6.0
168
+ rubygems_version: 1.3.7
151
169
  signing_key:
152
170
  specification_version: 3
153
- summary: This is a minor revision of the [SVG::Graph library](http://www.germane-software.com/software/SVG/SVG::Graph/) by Sean Russell with few minor touch-ups to make it run on Ruby 1.9.x and to have it gem-installable
154
171
 
155
172
  SVG:::Graph is a pure Ruby library for generating charts, which are a type of graph where the values of one axis are not scalar
173
+ summary: This is a revision of the [SVG::Graph library](http://www.germane-software.com/software/SVG/SVG::Graph/) by Sean Russell with touch-ups to make it run on Ruby 1.9.x and be gem-installable
156
174
  test_files:
175
+ - test/test_data_point.rb
157
176
  - test/test_svg_graph.rb
158
177
  - test/test_plot.rb
metadata.gz.sig CHANGED
@@ -1,2 +1,3 @@
1
- E��|ZP�/Umy���r�
2
- xt��b�}] ����ڸ�r�)
3
- cL#�-����V�t�§D5�����ʋ�Y��9���i�����i������*��0U(�pʼ�����M��㔃��SG��Wl�.6�Z|e~sL���$5��HŜ(��<N�ܱ�����m�7�"G� �H�qǺ%}����(�+u�!�gM��h�\`5⋃؅���b�f��q�����Z��,���{��lN�h�~/
1
+ D����5O�,R��Xd�*pF����҆
2
+ �b1��0��B��b|�v�,V�\�gw�r�mJ�G2B=���q��>���8�K4o�� �6mD9�� �x�`{��;�d�SP� �6
3
+ �6��;��^��H���