svg-graph19 0.6.2
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.
- data/README.markdown +4 -0
- data/lib/SVG/Graph/BarBase.rb +139 -0
- data/lib/SVG/Graph/BarHorizontal.rb +149 -0
- data/lib/SVG/Graph/Graph.rb +978 -0
- data/lib/SVG/Graph/Line.rb +444 -0
- data/lib/SVG/Graph/Pie.rb +395 -0
- data/lib/SVG/Graph/Plot.rb +500 -0
- data/lib/SVG/Graph/Schedule.rb +384 -0
- data/lib/SVG/Graph/TimeSeries.rb +252 -0
- data/lib/SVG/Graph/bar.rb +148 -0
- metadata +65 -0
@@ -0,0 +1,148 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
require 'SVG/Graph/Graph'
|
3
|
+
require 'SVG/Graph/BarBase'
|
4
|
+
|
5
|
+
module SVG
|
6
|
+
module Graph
|
7
|
+
# === Create presentation quality SVG bar graphs easily
|
8
|
+
#
|
9
|
+
# = Synopsis
|
10
|
+
#
|
11
|
+
# require 'SVG/Graph/Bar'
|
12
|
+
#
|
13
|
+
# fields = %w(Jan Feb Mar);
|
14
|
+
# data_sales_02 = [12, 45, 21]
|
15
|
+
#
|
16
|
+
# graph = SVG::Graph::Bar.new(
|
17
|
+
# :height => 500,
|
18
|
+
# :width => 300,
|
19
|
+
# :fields => fields
|
20
|
+
# )
|
21
|
+
#
|
22
|
+
# graph.add_data(
|
23
|
+
# :data => data_sales_02,
|
24
|
+
# :title => 'Sales 2002'
|
25
|
+
# )
|
26
|
+
#
|
27
|
+
# print "Content-type: image/svg+xml\r\n\r\n"
|
28
|
+
# print graph.burn
|
29
|
+
#
|
30
|
+
# = Description
|
31
|
+
#
|
32
|
+
# This object aims to allow you to easily create high quality
|
33
|
+
# SVG[http://www.w3c.org/tr/svg bar graphs. You can either use the default
|
34
|
+
# style sheet or supply your own. Either way there are many options which
|
35
|
+
# can be configured to give you control over how the graph is generated -
|
36
|
+
# with or without a key, data elements at each point, title, subtitle etc.
|
37
|
+
#
|
38
|
+
# = Notes
|
39
|
+
#
|
40
|
+
# The default stylesheet handles upto 12 data sets, if you
|
41
|
+
# use more you must create your own stylesheet and add the
|
42
|
+
# additional settings for the extra data sets. You will know
|
43
|
+
# if you go over 12 data sets as they will have no style and
|
44
|
+
# be in black.
|
45
|
+
#
|
46
|
+
# = Examples
|
47
|
+
#
|
48
|
+
# * http://germane-software.com/repositories/public/SVG/test/test.rb
|
49
|
+
#
|
50
|
+
# = See also
|
51
|
+
#
|
52
|
+
# * SVG::Graph::Graph
|
53
|
+
# * SVG::Graph::BarHorizontal
|
54
|
+
# * SVG::Graph::Line
|
55
|
+
# * SVG::Graph::Pie
|
56
|
+
# * SVG::Graph::Plot
|
57
|
+
# * SVG::Graph::TimeSeries
|
58
|
+
class Bar < BarBase
|
59
|
+
include REXML
|
60
|
+
|
61
|
+
# See Graph::initialize and BarBase::set_defaults
|
62
|
+
def set_defaults
|
63
|
+
super
|
64
|
+
self.top_align = self.top_font = 1
|
65
|
+
end
|
66
|
+
|
67
|
+
protected
|
68
|
+
|
69
|
+
def get_x_labels
|
70
|
+
@config[:fields]
|
71
|
+
end
|
72
|
+
|
73
|
+
def get_y_labels
|
74
|
+
maxvalue = max_value
|
75
|
+
minvalue = min_value
|
76
|
+
range = maxvalue - minvalue
|
77
|
+
|
78
|
+
top_pad = range == 0 ? 10 : range / 20.0
|
79
|
+
scale_range = (maxvalue + top_pad) - minvalue
|
80
|
+
|
81
|
+
scale_division = scale_divisions || (scale_range / 10.0)
|
82
|
+
|
83
|
+
if scale_integers
|
84
|
+
scale_division = scale_division < 1 ? 1 : scale_division.round
|
85
|
+
end
|
86
|
+
|
87
|
+
rv = []
|
88
|
+
maxvalue = maxvalue%scale_division == 0 ?
|
89
|
+
maxvalue : maxvalue + scale_division
|
90
|
+
minvalue.step( maxvalue, scale_division ) {|v| rv << v}
|
91
|
+
return rv
|
92
|
+
end
|
93
|
+
|
94
|
+
def x_label_offset( width )
|
95
|
+
width / 2.0
|
96
|
+
end
|
97
|
+
|
98
|
+
def draw_data
|
99
|
+
minvalue = min_value
|
100
|
+
fieldwidth = field_width
|
101
|
+
|
102
|
+
unit_size = (@graph_height.to_f - font_size*2*top_font) /
|
103
|
+
(get_y_labels.max - get_y_labels.min)
|
104
|
+
bargap = bar_gap ? (fieldwidth < 10 ? fieldwidth / 2 : 10) : 0
|
105
|
+
|
106
|
+
bar_width = fieldwidth - bargap
|
107
|
+
bar_width /= @data.length if stack == :side
|
108
|
+
x_mod = (@graph_width-bargap)/2 - (stack==:side ? bar_width/2 : 0)
|
109
|
+
|
110
|
+
bottom = @graph_height
|
111
|
+
|
112
|
+
field_count = 0
|
113
|
+
@config[:fields].each_index { |i|
|
114
|
+
dataset_count = 0
|
115
|
+
for dataset in @data
|
116
|
+
|
117
|
+
# cases (assume 0 = +ve):
|
118
|
+
# value min length
|
119
|
+
# +ve +ve value - min
|
120
|
+
# +ve -ve value - 0
|
121
|
+
# -ve -ve value.abs - 0
|
122
|
+
|
123
|
+
value = dataset[:data][i]
|
124
|
+
|
125
|
+
left = (fieldwidth * field_count)
|
126
|
+
|
127
|
+
length = (value.abs - (minvalue > 0 ? minvalue : 0)) * unit_size
|
128
|
+
# top is 0 if value is negative
|
129
|
+
top = bottom - (((value < 0 ? 0 : value) - minvalue) * unit_size)
|
130
|
+
left += bar_width * dataset_count if stack == :side
|
131
|
+
|
132
|
+
@graph.add_element( "rect", {
|
133
|
+
"x" => left.to_s,
|
134
|
+
"y" => top.to_s,
|
135
|
+
"width" => bar_width.to_s,
|
136
|
+
"height" => length.to_s,
|
137
|
+
"class" => "fill#{dataset_count+1}"
|
138
|
+
})
|
139
|
+
|
140
|
+
make_datapoint_text(left + bar_width/2.0, top - 6, value.to_s)
|
141
|
+
dataset_count += 1
|
142
|
+
end
|
143
|
+
field_count += 1
|
144
|
+
}
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: svg-graph19
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.6.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sean Russell. Paolo Bosetti moved into gem and made 1.9-compatible
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-12-01 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: THIS VERSION IS RUBY 1.9.x COMPATIBLE! Gem version of SVG:::Graph. 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.
|
17
|
+
email: paolo.bosetti@me.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- README.markdown
|
26
|
+
- lib/SVG/Graph/bar.rb
|
27
|
+
- lib/SVG/Graph/BarBase.rb
|
28
|
+
- lib/SVG/Graph/BarHorizontal.rb
|
29
|
+
- lib/SVG/Graph/Graph.rb
|
30
|
+
- lib/SVG/Graph/Line.rb
|
31
|
+
- lib/SVG/Graph/Pie.rb
|
32
|
+
- lib/SVG/Graph/Plot.rb
|
33
|
+
- lib/SVG/Graph/Schedule.rb
|
34
|
+
- lib/SVG/Graph/TimeSeries.rb
|
35
|
+
has_rdoc: true
|
36
|
+
homepage: http://github.com/pbosetti/svg-graph19
|
37
|
+
licenses: []
|
38
|
+
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options:
|
41
|
+
- --inline-source
|
42
|
+
- --charset=UTF-8
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: "0"
|
50
|
+
version:
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: "0"
|
56
|
+
version:
|
57
|
+
requirements: []
|
58
|
+
|
59
|
+
rubyforge_project: svg-graph19
|
60
|
+
rubygems_version: 1.3.5
|
61
|
+
signing_key:
|
62
|
+
specification_version: 3
|
63
|
+
summary: SVG:::Graph is a pure Ruby library for generating charts in SVG.
|
64
|
+
test_files: []
|
65
|
+
|