svg-graph 2.1.1 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/History.txt +35 -1
- data/{README.markdown → README.md} +27 -6
- data/Rakefile +16 -5
- data/lib/SVG/Graph/Bar.rb +10 -3
- data/lib/SVG/Graph/BarBase.rb +21 -17
- data/lib/SVG/Graph/BarHorizontal.rb +12 -5
- data/lib/SVG/Graph/C3js.rb +274 -0
- data/lib/SVG/Graph/DataPoint.rb +28 -16
- data/lib/SVG/Graph/Graph.rb +211 -104
- data/lib/SVG/Graph/Line.rb +12 -7
- data/lib/SVG/Graph/Pie.rb +52 -41
- data/lib/SVG/Graph/Plot.rb +105 -94
- data/lib/SVG/Graph/TimeSeries.rb +27 -27
- data/lib/svggraph.rb +4 -2
- data/test/test_svg_graph.rb +7 -7
- metadata +14 -14
data/lib/SVG/Graph/TimeSeries.rb
CHANGED
@@ -4,20 +4,20 @@ require_relative 'Plot'
|
|
4
4
|
module SVG
|
5
5
|
module Graph
|
6
6
|
# === For creating SVG plots of scalar temporal data
|
7
|
-
#
|
7
|
+
#
|
8
8
|
# = Synopsis
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# require 'SVG/Graph/TimeSeries'
|
11
|
-
#
|
11
|
+
#
|
12
12
|
# # Data sets are x,y pairs
|
13
13
|
# projection = ["6/17/72", 11, "1/11/72", 7, "4/13/04", 11,
|
14
14
|
# "9/11/01", 9, "9/1/85", 2, "9/1/88", 1, "1/15/95", 13]
|
15
15
|
# actual = ["8/1/73", 18, "3/1/77", 15, "10/1/98", 4,
|
16
16
|
# "5/1/02", 14, "3/1/95", 6, "8/1/91", 12, "12/1/87", 6,
|
17
17
|
# "5/1/84", 17, "10/1/80", 12]
|
18
|
-
#
|
18
|
+
#
|
19
19
|
# title = "Ice Cream Cone Consumption"
|
20
|
-
#
|
20
|
+
#
|
21
21
|
# graph = SVG::Graph::TimeSeries.new( {
|
22
22
|
# :width => 640,
|
23
23
|
# :height => 480,
|
@@ -39,31 +39,31 @@ module SVG
|
|
39
39
|
# :stagger_x_labels => true,
|
40
40
|
# :x_label_format => "%m/%d/%y",
|
41
41
|
# })
|
42
|
-
#
|
42
|
+
#
|
43
43
|
# graph.add_data({
|
44
44
|
# :data => projection,
|
45
45
|
# :title => 'Projected',
|
46
46
|
# :template => '%d/%m/%y'
|
47
47
|
# })
|
48
|
-
#
|
48
|
+
#
|
49
49
|
# graph.add_data({
|
50
50
|
# :data => actual,
|
51
51
|
# :title => 'Actual',
|
52
52
|
# :template => '%d/%m/%y'
|
53
53
|
# })
|
54
|
-
#
|
54
|
+
#
|
55
55
|
# print graph.burn()
|
56
56
|
#
|
57
57
|
# = Description
|
58
|
-
#
|
58
|
+
#
|
59
59
|
# Produces a graph of temporal scalar data.
|
60
|
-
#
|
60
|
+
#
|
61
61
|
# = Examples
|
62
62
|
#
|
63
63
|
# http://www.germane-software/repositories/public/SVG/test/timeseries.rb
|
64
|
-
#
|
64
|
+
#
|
65
65
|
# = Notes
|
66
|
-
#
|
66
|
+
#
|
67
67
|
# The default stylesheet handles upto 10 data sets, if you
|
68
68
|
# use more you must create your own stylesheet and add the
|
69
69
|
# additional settings for the extra data sets. You will know
|
@@ -73,18 +73,18 @@ module SVG
|
|
73
73
|
# Unlike the other types of charts, data sets must contain x,y pairs:
|
74
74
|
#
|
75
75
|
# [ "12:30", 2 ] # A data set with 1 point: ("12:30",2)
|
76
|
-
# [ "01:00",2, "14:20",6] # A data set with 2 points: ("01:00",2) and
|
77
|
-
# # ("14:20",6)
|
76
|
+
# [ "01:00",2, "14:20",6] # A data set with 2 points: ("01:00",2) and
|
77
|
+
# # ("14:20",6)
|
78
78
|
#
|
79
|
-
# Note that multiple data sets within the same chart can differ in length,
|
79
|
+
# Note that multiple data sets within the same chart can differ in length,
|
80
80
|
# and that the data in the datasets needn't be in order; they will be ordered
|
81
81
|
# by the plot along the X-axis.
|
82
|
-
#
|
82
|
+
#
|
83
83
|
# The dates must be parseable by DateTime#parse or DateTime#strptime, but otherwise can be
|
84
84
|
# any order of magnitude (seconds within the hour, or years)
|
85
|
-
#
|
85
|
+
#
|
86
86
|
# = See also
|
87
|
-
#
|
87
|
+
#
|
88
88
|
# * SVG::Graph::Graph
|
89
89
|
# * SVG::Graph::BarHorizontal
|
90
90
|
# * SVG::Graph::Bar
|
@@ -117,9 +117,9 @@ module SVG
|
|
117
117
|
# See Time::strformat, default: '%Y-%m-%d %H:%M:%S'
|
118
118
|
attr_accessor :x_label_format
|
119
119
|
# Use this to set the spacing between dates on the axis. The value
|
120
|
-
# must be of the form
|
120
|
+
# must be of the form
|
121
121
|
# "\d+ ?(days|weeks|months|years|hours|minutes|seconds)?"
|
122
|
-
#
|
122
|
+
#
|
123
123
|
# EG:
|
124
124
|
#
|
125
125
|
# graph.timescale_divisions = "2 weeks"
|
@@ -133,9 +133,9 @@ module SVG
|
|
133
133
|
# Add data to the plot.
|
134
134
|
#
|
135
135
|
# d1 = [ "12:30", 2 ] # A data set with 1 point: ("12:30",2)
|
136
|
-
# d2 = [ "01:00",2, "14:20",6] # A data set with 2 points: ("01:00",2) and
|
137
|
-
# # ("14:20",6)
|
138
|
-
# graph.add_data(
|
136
|
+
# d2 = [ "01:00",2, "14:20",6] # A data set with 2 points: ("01:00",2) and
|
137
|
+
# # ("14:20",6)
|
138
|
+
# graph.add_data(
|
139
139
|
# :data => d1,
|
140
140
|
# :title => 'One',
|
141
141
|
# :template => '%H:%M' #template is optional
|
@@ -182,10 +182,10 @@ module SVG
|
|
182
182
|
def get_x_labels
|
183
183
|
get_x_values.collect { |v| Time.at(v).strftime( x_label_format ) }
|
184
184
|
end
|
185
|
-
|
185
|
+
|
186
186
|
private
|
187
187
|
|
188
|
-
# Accepts date time as a string, number of seconds since the epoch, or Time
|
188
|
+
# Accepts date time as a string, number of seconds since the epoch, or Time
|
189
189
|
# object and returns a Time object. Raises an error if not a valid date time
|
190
190
|
# representation.
|
191
191
|
def parse_time(time, template)
|
@@ -254,10 +254,10 @@ module SVG
|
|
254
254
|
return rv
|
255
255
|
end
|
256
256
|
end
|
257
|
-
min.step( max, @x_scale_division ) {|v| rv << v}
|
257
|
+
min.step( max , @x_scale_division ) {|v| rv << v}
|
258
258
|
return rv
|
259
259
|
end # get_x_values
|
260
|
-
|
260
|
+
|
261
261
|
end # class TimeSeries
|
262
262
|
end # module Graph
|
263
263
|
end # module SVG
|
data/lib/svggraph.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
module SVG
|
2
2
|
module Graph
|
3
|
-
VERSION = '2.
|
3
|
+
VERSION = '2.2.1'
|
4
|
+
|
4
5
|
end
|
5
6
|
end
|
7
|
+
require_relative 'SVG/Graph/C3js'
|
8
|
+
require_relative 'SVG/Graph/Graph'
|
6
9
|
require_relative 'SVG/Graph/DataPoint'
|
7
10
|
require_relative 'SVG/Graph/BarBase'
|
8
|
-
require_relative 'SVG/Graph/Graph'
|
9
11
|
require_relative 'SVG/Graph/Bar'
|
10
12
|
require_relative 'SVG/Graph/BarHorizontal'
|
11
13
|
require_relative 'SVG/Graph/ErrBar'
|
data/test/test_svg_graph.rb
CHANGED
@@ -12,7 +12,7 @@ class TestSvgGraph < Minitest::Test
|
|
12
12
|
def test_bar_line_and_pie
|
13
13
|
fields = %w(Jan Feb Mar);
|
14
14
|
data_sales_02 = [12, 45, 21]
|
15
|
-
[SVG::Graph::Bar, SVG::Graph::BarHorizontal, SVG::Graph::Line, SVG::Graph::Pie].each do
|
15
|
+
[SVG::Graph::Bar, SVG::Graph::BarHorizontal, SVG::Graph::Line, SVG::Graph::Pie].each do
|
16
16
|
|klass|
|
17
17
|
graph = klass.new(
|
18
18
|
:height => 500,
|
@@ -27,14 +27,14 @@ class TestSvgGraph < Minitest::Test
|
|
27
27
|
assert(out=~/Created with SVG::Graph/)
|
28
28
|
end
|
29
29
|
end # test_bar_line_and_pie
|
30
|
-
|
30
|
+
|
31
31
|
def test_pie_100_percent
|
32
32
|
fields = %w(Internet TV Newspaper Magazine Radio)
|
33
33
|
#data1 = [2, 3, 1, 3, 1]
|
34
34
|
#data2 = [0, 2, 1, 5, 4]
|
35
35
|
data1 = [0, 3, 0, 0, 0]
|
36
36
|
data2 = [0, 6, 0, 0, 0]
|
37
|
-
|
37
|
+
|
38
38
|
graph = SVG::Graph::Pie.new(
|
39
39
|
:height => 500,
|
40
40
|
:width => 300,
|
@@ -50,19 +50,19 @@ class TestSvgGraph < Minitest::Test
|
|
50
50
|
:data => data1,
|
51
51
|
:title => 'data1'
|
52
52
|
)
|
53
|
-
|
53
|
+
|
54
54
|
graph.add_data(
|
55
55
|
:data => data2,
|
56
56
|
:title => 'data2'
|
57
57
|
)
|
58
58
|
out = graph.burn
|
59
|
-
File.open("pie_100.svg", "w") {|fout|
|
59
|
+
File.open(File.expand_path("pie_100.svg",__dir__), "w") {|fout|
|
60
60
|
fout.print( out )
|
61
61
|
}
|
62
|
-
assert_match(/TV 100%/, out, "100% text not found in graph")
|
62
|
+
assert_match(/TV 100%/, out, "100% text not found in graph")
|
63
63
|
assert_match(/circle/, out, "no circle was found in graph")
|
64
64
|
|
65
65
|
end # test_pie_100_percent
|
66
|
-
|
66
|
+
|
67
67
|
end
|
68
68
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: svg-graph
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean Russell
|
@@ -9,17 +9,17 @@ authors:
|
|
9
9
|
- Liehann Loots
|
10
10
|
- Piergiuliano Bossi
|
11
11
|
- Manuel Widmer
|
12
|
-
autorequire:
|
12
|
+
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date:
|
15
|
+
date: 2020-12-26 00:00:00.000000000 Z
|
16
16
|
dependencies: []
|
17
17
|
description: "Gem version of SVG:::Graph. SVG:::Graph is a pure Ruby library for generating
|
18
|
-
charts
|
19
|
-
SVG::Graph has a verry similar API to
|
20
|
-
resulting charts also look the same. This isn't surprising
|
18
|
+
charts,\nwhich are a type of graph where the values of one axis are not scalar.
|
19
|
+
SVG::Graph has a verry similar API to\nthe Perl library SVG::TT::Graph, and the
|
20
|
+
resulting charts also look the same. This isn't surprising,\nbecause SVG::Graph
|
21
21
|
started as a loose port of SVG::TT::Graph, although the internal code no longer
|
22
|
-
resembles
|
22
|
+
resembles\nthe Perl original at all.\n "
|
23
23
|
email:
|
24
24
|
- ser_AT_germane-software.com
|
25
25
|
- clbustos_AT_gmail.com
|
@@ -30,18 +30,19 @@ executables: []
|
|
30
30
|
extensions: []
|
31
31
|
extra_rdoc_files:
|
32
32
|
- LICENSE.txt
|
33
|
-
- README.
|
33
|
+
- README.md
|
34
34
|
- README.txt
|
35
35
|
files:
|
36
36
|
- GPL.txt
|
37
37
|
- History.txt
|
38
38
|
- LICENSE.txt
|
39
|
-
- README.
|
39
|
+
- README.md
|
40
40
|
- README.txt
|
41
41
|
- Rakefile
|
42
42
|
- lib/SVG/Graph/Bar.rb
|
43
43
|
- lib/SVG/Graph/BarBase.rb
|
44
44
|
- lib/SVG/Graph/BarHorizontal.rb
|
45
|
+
- lib/SVG/Graph/C3js.rb
|
45
46
|
- lib/SVG/Graph/DataPoint.rb
|
46
47
|
- lib/SVG/Graph/ErrBar.rb
|
47
48
|
- lib/SVG/Graph/Graph.rb
|
@@ -52,11 +53,11 @@ files:
|
|
52
53
|
- lib/SVG/Graph/TimeSeries.rb
|
53
54
|
- lib/svggraph.rb
|
54
55
|
- test/test_svg_graph.rb
|
55
|
-
homepage:
|
56
|
+
homepage: https://github.com/lumean/svg-graph2
|
56
57
|
licenses:
|
57
58
|
- GPL-2.0
|
58
59
|
metadata: {}
|
59
|
-
post_install_message:
|
60
|
+
post_install_message:
|
60
61
|
rdoc_options: []
|
61
62
|
require_paths:
|
62
63
|
- lib
|
@@ -71,9 +72,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
71
72
|
- !ruby/object:Gem::Version
|
72
73
|
version: '0'
|
73
74
|
requirements: []
|
74
|
-
|
75
|
-
|
76
|
-
signing_key:
|
75
|
+
rubygems_version: 3.1.4
|
76
|
+
signing_key:
|
77
77
|
specification_version: 4
|
78
78
|
summary: SVG:::Graph is a pure Ruby library for generating charts, which are a type
|
79
79
|
of graph where the values of one axis are not scalar.
|