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.
- data.tar.gz.sig +0 -0
- data/History.txt +7 -5
- data/Manifest.txt +53 -17
- data/README.markdown +14 -0
- data/README.txt +10 -3
- data/Rakefile +6 -0
- data/build.xml +143 -0
- data/dist.xml.in +46 -0
- data/images/bar.png +0 -0
- data/images/bar.svg +76 -0
- data/images/bar.svgz +0 -0
- data/images/barhorizontal.png +0 -0
- data/images/barhorizontal.svg +76 -0
- data/images/barhorizontal.svgz +0 -0
- data/images/line.png +0 -0
- data/images/line.svg +80 -0
- data/images/line.svgz +0 -0
- data/images/pie.png +0 -0
- data/images/pie.svg +70 -0
- data/images/pie.svgz +0 -0
- data/images/plot.png +0 -0
- data/images/plot.svg +131 -0
- data/images/plot.svgz +0 -0
- data/images/schedule.png +0 -0
- data/images/schedule.svg +67 -0
- data/images/timeseries.png +0 -0
- data/images/timeseries.svg +179 -0
- data/images/timeseries.svgz +0 -0
- data/index.xml +281 -0
- data/install.rb +161 -0
- data/lib/SVG/Graph/Bar.rb +1 -1
- data/lib/SVG/Graph/Graph.rb +11 -9
- data/lib/SVG/Graph/Line.rb +1 -0
- data/lib/SVG/Graph/Pie.rb +3 -3
- data/lib/SVG/Graph/Plot.rb +69 -20
- data/lib/SVG/Graph/Schedule.rb +19 -5
- data/lib/SVG/Graph/TimeSeries.rb +62 -45
- data/lib/svggraph.rb +1 -2
- data/screenshots.xml +148 -0
- data/style/common.xsl +37 -0
- data/style/release_html.xsl +169 -0
- data/style/release_txt.xsl +25 -0
- data/svg-graph.gemspec +59 -0
- data/test/data.txt +4 -0
- data/test/plot.rb +51 -0
- data/test/schedule.rb +43 -0
- data/test/single.rb +33 -0
- data/test/test.rb +54 -0
- data/test/test_plot.rb +170 -0
- data/test/test_svg_graph.rb +24 -55
- data/test/timeseries.rb +58 -0
- metadata +79 -14
- metadata.gz.sig +2 -1
data/test/data.txt
ADDED
data/test/plot.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
$: << File.dirname(__FILE__) + '/../lib'
|
2
|
+
require 'SVG/Graph/Plot'
|
3
|
+
|
4
|
+
|
5
|
+
title = "Plot"
|
6
|
+
#data1 = []
|
7
|
+
#(rand(10)+5).times{
|
8
|
+
# data1 << rand(20)
|
9
|
+
# data1 << rand(20)
|
10
|
+
#}
|
11
|
+
data1 = [6.1, 11.2, 0.3, 5.4, 18.5, 7.6, 1.7, 11.8, 13.9, 9.11, 11.22, 2.33, 19.44, 0.555, 3.6666, 13.77777, 7.888888, 9.9999999]
|
12
|
+
#data2 = []
|
13
|
+
#(rand(10)+5).times{
|
14
|
+
# data2 << rand(20)
|
15
|
+
# data2 << rand(20)
|
16
|
+
#}
|
17
|
+
data2 = [0, 18, 8, 15, 9, 4, 18, 14, 10, 2, 11, 6, 14, 12, 15, 6, 4, 17, 2, 12]
|
18
|
+
|
19
|
+
|
20
|
+
graph = SVG::Graph::Plot.new( {
|
21
|
+
:width => 640,
|
22
|
+
:height => 480,
|
23
|
+
:graph_title => title,
|
24
|
+
:show_graph_title => true,
|
25
|
+
:no_css => true,
|
26
|
+
:key => true,
|
27
|
+
:scale_x_integers => true,
|
28
|
+
:scale_y_integers => false,
|
29
|
+
:min_x_value => 0,
|
30
|
+
:min_y_value => 0,
|
31
|
+
:show_data_labels => true,
|
32
|
+
:show_x_guidelines => true,
|
33
|
+
:show_x_title => true,
|
34
|
+
:x_title => "Time",
|
35
|
+
:show_y_title => true,
|
36
|
+
:y_title => "Ice Cream Cones",
|
37
|
+
:y_title_text_direction => :bt,
|
38
|
+
:show_lines => false,
|
39
|
+
:add_popups => true,
|
40
|
+
:round_popups => false
|
41
|
+
})
|
42
|
+
graph.add_data(
|
43
|
+
:data => data1,
|
44
|
+
:title => "Dataset 1"
|
45
|
+
)
|
46
|
+
graph.add_data(
|
47
|
+
:data => data2,
|
48
|
+
:title => "Dataset 2"
|
49
|
+
)
|
50
|
+
puts graph.burn
|
51
|
+
|
data/test/schedule.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'SVG/Graph/Schedule'
|
2
|
+
|
3
|
+
|
4
|
+
title = "Billy's Schedule"
|
5
|
+
data1 = [
|
6
|
+
"History 107", "5/19/04", "6/30/04",
|
7
|
+
"Algebra 011", "6/2/04", "8/11/04",
|
8
|
+
"Psychology 101", "6/28/04", "8/9/04",
|
9
|
+
"Acting 105", "7/7/04", "8/16/04"
|
10
|
+
]
|
11
|
+
|
12
|
+
graph = SVG::Graph::Schedule.new( {
|
13
|
+
:width => 640,
|
14
|
+
:height => 480,
|
15
|
+
:graph_title => title,
|
16
|
+
:show_graph_title => true,
|
17
|
+
:no_css => true,
|
18
|
+
:key => false,
|
19
|
+
:scale_x_integers => true,
|
20
|
+
:scale_y_integers => true,
|
21
|
+
:show_data_labels => true,
|
22
|
+
:show_y_guidelines => false,
|
23
|
+
:show_x_guidelines => true,
|
24
|
+
:show_x_title => true,
|
25
|
+
:x_title => "Time",
|
26
|
+
:show_y_title => false,
|
27
|
+
:rotate_x_labels => true,
|
28
|
+
:rotate_y_labels => false,
|
29
|
+
:x_label_format => "%m/%d",
|
30
|
+
:timescale_divisions => "1 weeks",
|
31
|
+
:add_popups => true,
|
32
|
+
:popup_format => "%m/%d/%y",
|
33
|
+
:area_fill => true,
|
34
|
+
:min_y_value => 0,
|
35
|
+
})
|
36
|
+
|
37
|
+
graph.add_data(
|
38
|
+
:data => data1,
|
39
|
+
:title => "Data"
|
40
|
+
)
|
41
|
+
|
42
|
+
puts graph.burn
|
43
|
+
|
data/test/single.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'SVG/Graph/BarHorizontal'
|
2
|
+
require 'SVG/Graph/Bar'
|
3
|
+
require 'SVG/Graph/Line'
|
4
|
+
require 'SVG/Graph/Pie'
|
5
|
+
|
6
|
+
|
7
|
+
File.open( "data.txt" ) { |fin|
|
8
|
+
title = fin.readline
|
9
|
+
fields = fin.readline.split( /,/ )
|
10
|
+
female_data = fin.readline.split( " " ).collect{|x| x.to_i}
|
11
|
+
male_data = fin.readline.split( " " ).collect{|x| x.to_i}
|
12
|
+
|
13
|
+
graph = SVG::Graph::Pie.new( {
|
14
|
+
:width => 640,
|
15
|
+
:height => 480,
|
16
|
+
:fields => fields,
|
17
|
+
:graph_title => title,
|
18
|
+
:show_graph_title => true,
|
19
|
+
:no_css => true,
|
20
|
+
:expanded => true,
|
21
|
+
:show_data_labels => true
|
22
|
+
})
|
23
|
+
graph.add_data( {
|
24
|
+
:data => female_data,
|
25
|
+
:title => "Female"
|
26
|
+
})
|
27
|
+
graph.add_data( {
|
28
|
+
:data => male_data,
|
29
|
+
:title => "Male"
|
30
|
+
})
|
31
|
+
puts graph.burn
|
32
|
+
}
|
33
|
+
|
data/test/test.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'SVG/Graph/BarHorizontal'
|
2
|
+
require 'SVG/Graph/Bar'
|
3
|
+
require 'SVG/Graph/Line'
|
4
|
+
require 'SVG/Graph/Pie'
|
5
|
+
|
6
|
+
def gen klass, args, title, fields, female_data, male_data
|
7
|
+
args[ :width ] = 640
|
8
|
+
args[ :height ] = 480
|
9
|
+
#args[ :compress ] = true
|
10
|
+
args[ :fields ] = fields
|
11
|
+
args[ :graph_title ] = title
|
12
|
+
args[ :show_graph_title ] = true
|
13
|
+
args[ :no_css ] = true
|
14
|
+
puts klass.name
|
15
|
+
graph = klass.new( args )
|
16
|
+
graph.add_data( {
|
17
|
+
:data => female_data,
|
18
|
+
:title => "Female"
|
19
|
+
})
|
20
|
+
graph.add_data( {
|
21
|
+
:data => male_data,
|
22
|
+
:title => "Male"
|
23
|
+
})
|
24
|
+
return graph.burn
|
25
|
+
end
|
26
|
+
|
27
|
+
File.open( "data.txt" ) { |fin|
|
28
|
+
title = fin.readline
|
29
|
+
fields = fin.readline.split( /,/ )
|
30
|
+
female_data = fin.readline.split( " " ).collect{|x| x.to_i}
|
31
|
+
male_data = fin.readline.split( " " ).collect{|x| x.to_i}
|
32
|
+
|
33
|
+
for file, klass, args in [
|
34
|
+
[ "bar", SVG::Graph::Bar,
|
35
|
+
{ :scale_integers => true,
|
36
|
+
:stack => :side } ],
|
37
|
+
[ "barhorizontal",SVG::Graph::BarHorizontal,
|
38
|
+
{:scale_integers=> true,
|
39
|
+
:stack=>:side,
|
40
|
+
:rotate_x_labels => true
|
41
|
+
}],
|
42
|
+
[ "line", SVG::Graph::Line,
|
43
|
+
{ :scale_integers => true,
|
44
|
+
:area_fill => true, } ],
|
45
|
+
[ "pie", SVG::Graph::Pie,
|
46
|
+
{ :expand_greatest => true,
|
47
|
+
:show_data_labels => true, } ],
|
48
|
+
]
|
49
|
+
File.open("#{file}.svg", "w") {|fout|
|
50
|
+
fout.print( gen(klass, args, title, fields, female_data, male_data ) )
|
51
|
+
}
|
52
|
+
end
|
53
|
+
}
|
54
|
+
|
data/test/test_plot.rb
ADDED
@@ -0,0 +1,170 @@
|
|
1
|
+
$: << File.dirname(__FILE__) + '/../lib'
|
2
|
+
require "test/unit"
|
3
|
+
require "svggraph"
|
4
|
+
|
5
|
+
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
|
38
|
+
def test_default_plot_emits_polyline_connecting_data_points
|
39
|
+
actual = [
|
40
|
+
0, 18, 8, 15, 9, 4, 18, 14, 10, 2, 11, 6, 14, 12,
|
41
|
+
15, 6, 4, 17, 2, 12
|
42
|
+
]
|
43
|
+
|
44
|
+
graph = SVG::Graph::Plot.new({
|
45
|
+
:height => 500,
|
46
|
+
:width => 300,
|
47
|
+
:key => true,
|
48
|
+
:scale_x_integers => true,
|
49
|
+
:scale_y_integerrs => true,
|
50
|
+
})
|
51
|
+
|
52
|
+
graph.add_data({
|
53
|
+
:data => actual,
|
54
|
+
:title => 'Actual',
|
55
|
+
})
|
56
|
+
out=graph.burn()
|
57
|
+
assert_match(/path.*class='line1'/, out)
|
58
|
+
end
|
59
|
+
|
60
|
+
def _test_disabling_show_lines_does_not_emit_polyline_connecting_data_points
|
61
|
+
actual = [
|
62
|
+
0, 18, 8, 15, 9, 4, 18, 14, 10, 2, 11, 6, 14, 12,
|
63
|
+
15, 6, 4, 17, 2, 12
|
64
|
+
]
|
65
|
+
|
66
|
+
graph = SVG::Graph::Plot.new({
|
67
|
+
:height => 500,
|
68
|
+
:width => 300,
|
69
|
+
:key => true,
|
70
|
+
:scale_x_integers => true,
|
71
|
+
:scale_y_integers => true,
|
72
|
+
:show_lines => false,
|
73
|
+
})
|
74
|
+
|
75
|
+
graph.add_data({
|
76
|
+
:data => actual,
|
77
|
+
:title => 'Actual',
|
78
|
+
})
|
79
|
+
|
80
|
+
out=graph.burn()
|
81
|
+
assert_no_match(/path class='line1' d='M.* L.*'/, out)
|
82
|
+
end
|
83
|
+
def _test_popup_values_round_to_integer_by_default_in_popups
|
84
|
+
actual = [
|
85
|
+
0.1, 18, 8.55, 15.1234, 9.09876765, 4,
|
86
|
+
]
|
87
|
+
|
88
|
+
graph = SVG::Graph::Plot.new({
|
89
|
+
:height => 500,
|
90
|
+
:width => 300,
|
91
|
+
:key => true,
|
92
|
+
:scale_x_integers => true,
|
93
|
+
:scale_y_integers => true,
|
94
|
+
:add_popups => true,
|
95
|
+
})
|
96
|
+
|
97
|
+
graph.add_data({
|
98
|
+
:data => actual,
|
99
|
+
:title => 'Actual',
|
100
|
+
})
|
101
|
+
|
102
|
+
out=graph.burn()
|
103
|
+
assert_no_match(/\(0.1, 18\)/, out)
|
104
|
+
assert_match(/\(0, 18\)/, out)
|
105
|
+
assert_no_match(/\(8.55, 15.1234\)/, out)
|
106
|
+
assert_match(/\(8, 15\)/, out)
|
107
|
+
assert_no_match(/\(9.09876765, 4\)/, out)
|
108
|
+
assert_match(/\(9, 4\)/, out)
|
109
|
+
end
|
110
|
+
def _test_do_not_round_popup_values_shows_decimal_values_in_popups
|
111
|
+
actual = [
|
112
|
+
0.1, 18, 8.55, 15.1234, 9.09876765, 4,
|
113
|
+
]
|
114
|
+
|
115
|
+
graph = SVG::Graph::Plot.new({
|
116
|
+
:height => 500,
|
117
|
+
:width => 300,
|
118
|
+
:key => true,
|
119
|
+
:scale_x_integers => true,
|
120
|
+
:scale_y_integers => true,
|
121
|
+
:add_popups => true,
|
122
|
+
:round_popups => false,
|
123
|
+
})
|
124
|
+
|
125
|
+
graph.add_data({
|
126
|
+
:data => actual,
|
127
|
+
:title => 'Actual',
|
128
|
+
})
|
129
|
+
|
130
|
+
out=graph.burn()
|
131
|
+
assert_match(/\(0.1, 18\)/, out)
|
132
|
+
assert_no_match(/\(0, 18\)/, out)
|
133
|
+
assert_match(/\(8.55, 15.1234\)/, out)
|
134
|
+
assert_no_match(/\(8, 15\)/, out)
|
135
|
+
assert_match(/\(9.09876765, 4\)/, out)
|
136
|
+
assert_no_match(/\(9, 4\)/, out)
|
137
|
+
end
|
138
|
+
def _test_description_is_shown_in_popups_if_provided
|
139
|
+
actual = [
|
140
|
+
8.55, 15.1234, 9.09876765, 4, 0.1, 18,
|
141
|
+
]
|
142
|
+
description = [
|
143
|
+
'first', 'second', 'third',
|
144
|
+
]
|
145
|
+
|
146
|
+
graph = SVG::Graph::Plot.new({
|
147
|
+
:height => 500,
|
148
|
+
:width => 300,
|
149
|
+
:key => true,
|
150
|
+
:scale_x_integers => true,
|
151
|
+
:scale_y_integers => true,
|
152
|
+
:add_popups => true,
|
153
|
+
:round_popups => false,
|
154
|
+
})
|
155
|
+
|
156
|
+
graph.add_data({
|
157
|
+
:data => actual,
|
158
|
+
:title => 'Actual',
|
159
|
+
:description => description,
|
160
|
+
})
|
161
|
+
|
162
|
+
out=graph.burn()
|
163
|
+
assert_match(/\(8.55, 15.1234, first\)/, out)
|
164
|
+
assert_no_match(/\(8.55, 15.1234\)/, out)
|
165
|
+
assert_match(/\(9.09876765, 4, second\)/, out)
|
166
|
+
assert_no_match(/\(9.09876765, 4\)/, out)
|
167
|
+
assert_match(/\(0.1, 18, third\)/, out)
|
168
|
+
assert_no_match(/\(0.1, 18\)/, out)
|
169
|
+
end
|
170
|
+
end
|
data/test/test_svg_graph.rb
CHANGED
@@ -1,55 +1,24 @@
|
|
1
|
-
|
2
|
-
require "
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
[
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
:
|
13
|
-
:
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
:
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
projection = [
|
26
|
-
6, 11, 0, 5, 18, 7, 1, 11, 13, 9, 1, 2, 19, 0, 3, 13,
|
27
|
-
7, 9
|
28
|
-
]
|
29
|
-
actual = [
|
30
|
-
0, 18, 8, 15, 9, 4, 18, 14, 10, 2, 11, 6, 14, 12,
|
31
|
-
15, 6, 4, 17, 2, 12
|
32
|
-
]
|
33
|
-
|
34
|
-
graph = SVG::Graph::Plot.new({
|
35
|
-
:height => 500,
|
36
|
-
:width => 300,
|
37
|
-
:key => true,
|
38
|
-
:scale_x_integers => true,
|
39
|
-
:scale_y_integerrs => true,
|
40
|
-
})
|
41
|
-
|
42
|
-
graph.add_data({
|
43
|
-
:data => projection,
|
44
|
-
:title => 'Projected',
|
45
|
-
})
|
46
|
-
|
47
|
-
graph.add_data({
|
48
|
-
:data => actual,
|
49
|
-
:title => 'Actual',
|
50
|
-
})
|
51
|
-
|
52
|
-
out=graph.burn()
|
53
|
-
assert(out=~/Created with SVG::Graph/)
|
54
|
-
end
|
55
|
-
end
|
1
|
+
$: << File.dirname(__FILE__) + '/../lib'
|
2
|
+
require "test/unit"
|
3
|
+
require "svggraph"
|
4
|
+
|
5
|
+
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
|
24
|
+
end
|
data/test/timeseries.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'SVG/Graph/TimeSeries'
|
2
|
+
|
3
|
+
|
4
|
+
title = "Plot"
|
5
|
+
#data1 = []
|
6
|
+
#(rand(10)+5).times{
|
7
|
+
# data1 << rand(20)
|
8
|
+
# data1 << rand(20)
|
9
|
+
#}
|
10
|
+
data1 = ["6/17/74", 11, "1/11/74", 7, "4/13/04 17:31", 11, "9/11/01", 9, "9/1/85", 2, "9/1/88", 1, "1/15/95", 13]
|
11
|
+
#data2 = []
|
12
|
+
#(rand(10)+5).times{
|
13
|
+
# data2 << rand(20)
|
14
|
+
# data2 << rand(20)
|
15
|
+
#}
|
16
|
+
data2 = ["8/1/73", 18, "10/21/76", 15, "01/11/80", 4, "4/3/83", 14, "6/23/86", 6, "9/13/89", 12, "12/3/92", 6, "2/24/96", 17, "5/16/99", 12, "8/5/02", 7]
|
17
|
+
data3 = ["1/1/78", 5, "1/1/83", 13, "1/1/93", 10, "1/1/03", 5]
|
18
|
+
|
19
|
+
|
20
|
+
graph = SVG::Graph::TimeSeries.new( {
|
21
|
+
:width => 640,
|
22
|
+
:height => 480,
|
23
|
+
:graph_title => title,
|
24
|
+
:show_graph_title => true,
|
25
|
+
:no_css => true,
|
26
|
+
:key => true,
|
27
|
+
:scale_x_integers => true,
|
28
|
+
:scale_y_integers => true,
|
29
|
+
:show_data_values => true,
|
30
|
+
:show_x_guidelines => true,
|
31
|
+
:show_x_title => true,
|
32
|
+
:x_title => "Time",
|
33
|
+
:show_y_title => true,
|
34
|
+
:y_title => "Units",
|
35
|
+
:y_title_text_direction => :bt,
|
36
|
+
:stagger_x_labels => true,
|
37
|
+
:x_label_format => "%Y",
|
38
|
+
:min_x_value => "1/1/73",
|
39
|
+
:timescale_divisions => "5 years",
|
40
|
+
:add_popups => true,
|
41
|
+
:popup_format => "%m/%d/%y",
|
42
|
+
#:area_fill => true,
|
43
|
+
:min_y_value => 0,
|
44
|
+
})
|
45
|
+
graph.add_data(
|
46
|
+
:data => data1,
|
47
|
+
:title => "Ice Cream"
|
48
|
+
)
|
49
|
+
graph.add_data(
|
50
|
+
:data => data2,
|
51
|
+
:title => "Ice Cream Cones"
|
52
|
+
)
|
53
|
+
graph.add_data(
|
54
|
+
:data => data3,
|
55
|
+
:title => "Sprinkles"
|
56
|
+
)
|
57
|
+
puts graph.burn
|
58
|
+
|