prawn-graph 0.0.4 → 0.9.0
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 +7 -0
- data/.codeclimate.yml +16 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.rubocop.yml +1168 -0
- data/.travis.yml +17 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/CONTRIBUTORS.md +6 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +142 -0
- data/Rakefile +7 -43
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/prawn-graph.rb +16 -0
- data/lib/prawn/graph/calculations.rb +1 -0
- data/lib/prawn/graph/calculations/layout_calculator.rb +108 -0
- data/lib/prawn/graph/chart_components.rb +2 -0
- data/lib/prawn/graph/chart_components/canvas.rb +138 -0
- data/lib/prawn/graph/chart_components/series_renderer.rb +173 -0
- data/lib/prawn/graph/charts.rb +4 -0
- data/lib/prawn/graph/charts/bar.rb +18 -0
- data/lib/prawn/graph/charts/base.rb +69 -0
- data/lib/prawn/graph/charts/legacy.rb +4 -0
- data/lib/prawn/graph/charts/legacy/bar.rb +28 -0
- data/lib/prawn/graph/charts/legacy/base.rb +193 -0
- data/lib/prawn/graph/charts/legacy/grid.rb +51 -0
- data/lib/prawn/graph/charts/legacy/line.rb +39 -0
- data/lib/prawn/graph/charts/line.rb +18 -0
- data/lib/prawn/graph/extension.rb +59 -0
- data/lib/prawn/graph/series.rb +79 -0
- data/lib/prawn/graph/theme.rb +41 -0
- data/lib/prawn/graph/version.rb +5 -0
- data/prawn-graph.gemspec +42 -0
- metadata +156 -80
- data/README.markdown +0 -64
- data/examples/example_helper.rb +0 -10
- data/examples/graph/advanced_bar_chart.rb +0 -22
- data/examples/graph/bar_chart.pdf +0 -185
- data/examples/graph/bar_chart.rb +0 -18
- data/examples/graph/line_chart.pdf +0 -219
- data/examples/graph/line_chart.rb +0 -18
- data/examples/graph/themed_bar_chart.rb +0 -18
- data/examples/graph/themed_line_chart.rb +0 -18
- data/lib/prawn/graph.rb +0 -94
- data/lib/prawn/graph/bar.rb +0 -64
- data/lib/prawn/graph/base.rb +0 -231
- data/lib/prawn/graph/chart.rb +0 -4
- data/lib/prawn/graph/errors.rb +0 -7
- data/lib/prawn/graph/grid.rb +0 -50
- data/lib/prawn/graph/line.rb +0 -74
- data/lib/prawn/graph/themes.rb +0 -116
- data/lib/prawn/graph/themes/37signals.yml +0 -14
- data/lib/prawn/graph/themes/keynote.yml +0 -14
- data/lib/prawn/graph/themes/monochome.yml +0 -8
- data/lib/prawn/graph/themes/odeo.yml +0 -14
data/examples/graph/bar_chart.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
#
|
3
|
-
require "#{File.dirname(__FILE__)}/../example_helper.rb"
|
4
|
-
|
5
|
-
# Simplest bar chart example
|
6
|
-
#
|
7
|
-
|
8
|
-
data = [
|
9
|
-
['Cats',20],
|
10
|
-
['Dogs',36],
|
11
|
-
['Hamsters',45],
|
12
|
-
['Goldfish', 5]
|
13
|
-
]
|
14
|
-
|
15
|
-
Prawn::Document.generate('bar_chart.pdf') do
|
16
|
-
bar_chart data, :at => [10, 10]
|
17
|
-
end
|
18
|
-
|
@@ -1,219 +0,0 @@
|
|
1
|
-
%PDF-1.3
|
2
|
-
%����
|
3
|
-
1 0 obj
|
4
|
-
<< /Creator (Prawn)
|
5
|
-
/Producer (Prawn)
|
6
|
-
>>
|
7
|
-
endobj
|
8
|
-
2 0 obj
|
9
|
-
<< /Count 1
|
10
|
-
/Type /Pages
|
11
|
-
/Kids [5 0 R]
|
12
|
-
>>
|
13
|
-
endobj
|
14
|
-
3 0 obj
|
15
|
-
<< /Pages 2 0 R
|
16
|
-
/Type /Catalog
|
17
|
-
>>
|
18
|
-
endobj
|
19
|
-
4 0 obj
|
20
|
-
<< /Length 2391
|
21
|
-
>>
|
22
|
-
stream
|
23
|
-
/DeviceRGB cs
|
24
|
-
0.000 0.000 0.000 scn
|
25
|
-
/DeviceRGB CS
|
26
|
-
0.000 0.000 0.000 SCN
|
27
|
-
q
|
28
|
-
1.000 0.278 0.643 scn
|
29
|
-
46.000 46.000 500.000 200.000 re
|
30
|
-
b
|
31
|
-
1.000 1.000 1.000 SCN
|
32
|
-
61.000 66.000 m
|
33
|
-
0.5 w
|
34
|
-
546.000 66.000 l
|
35
|
-
S
|
36
|
-
61.000 86.000 m
|
37
|
-
0.5 w
|
38
|
-
546.000 86.000 l
|
39
|
-
S
|
40
|
-
61.000 106.000 m
|
41
|
-
0.5 w
|
42
|
-
546.000 106.000 l
|
43
|
-
S
|
44
|
-
61.000 126.000 m
|
45
|
-
0.5 w
|
46
|
-
546.000 126.000 l
|
47
|
-
S
|
48
|
-
61.000 146.000 m
|
49
|
-
0.5 w
|
50
|
-
546.000 146.000 l
|
51
|
-
S
|
52
|
-
61.000 166.000 m
|
53
|
-
0.5 w
|
54
|
-
546.000 166.000 l
|
55
|
-
S
|
56
|
-
61.000 186.000 m
|
57
|
-
0.5 w
|
58
|
-
546.000 186.000 l
|
59
|
-
S
|
60
|
-
61.000 206.000 m
|
61
|
-
0.5 w
|
62
|
-
546.000 206.000 l
|
63
|
-
S
|
64
|
-
61.000 226.000 m
|
65
|
-
0.5 w
|
66
|
-
546.000 226.000 l
|
67
|
-
S
|
68
|
-
61.000 246.000 m
|
69
|
-
0.5 w
|
70
|
-
546.000 246.000 l
|
71
|
-
S
|
72
|
-
61.000 46.000 m
|
73
|
-
2 w
|
74
|
-
61.000 246.000 l
|
75
|
-
S
|
76
|
-
61.000 46.000 m
|
77
|
-
2 w
|
78
|
-
546.000 46.000 l
|
79
|
-
S
|
80
|
-
61.000 246.000 m
|
81
|
-
0.000 0.000 0.000 SCN
|
82
|
-
1 w
|
83
|
-
61.000 46.000 m
|
84
|
-
|
85
|
-
BT
|
86
|
-
47 247.0 Td
|
87
|
-
/F1.0 5 Tf
|
88
|
-
[<3435>] TJ
|
89
|
-
ET
|
90
|
-
|
91
|
-
|
92
|
-
BT
|
93
|
-
47 47.0 Td
|
94
|
-
/F1.0 5 Tf
|
95
|
-
[<30>] TJ
|
96
|
-
ET
|
97
|
-
|
98
|
-
|
99
|
-
BT
|
100
|
-
122 32.0 Td
|
101
|
-
/F1.0 5 Tf
|
102
|
-
[<4a> 20 <616e> 10 <756172> -30 <79>] TJ
|
103
|
-
ET
|
104
|
-
|
105
|
-
|
106
|
-
BT
|
107
|
-
243 32.0 Td
|
108
|
-
/F1.0 5 Tf
|
109
|
-
[<46> 30 <656272> -15 <756172> -30 <79>] TJ
|
110
|
-
ET
|
111
|
-
|
112
|
-
|
113
|
-
BT
|
114
|
-
364 32.0 Td
|
115
|
-
/F1.0 5 Tf
|
116
|
-
[<4d61726368>] TJ
|
117
|
-
ET
|
118
|
-
|
119
|
-
|
120
|
-
BT
|
121
|
-
485 32.0 Td
|
122
|
-
/F1.0 5 Tf
|
123
|
-
[<417072> -15 <696c>] TJ
|
124
|
-
ET
|
125
|
-
|
126
|
-
60 w
|
127
|
-
148.000 47.000 m
|
128
|
-
0.125 0.125 0.125 scn
|
129
|
-
149.000 135.000 m
|
130
|
-
149.000 135.552 148.552 136.000 148.000 136.000 c
|
131
|
-
147.448 136.000 147.000 135.552 147.000 135.000 c
|
132
|
-
147.000 134.448 147.448 134.000 148.000 134.000 c
|
133
|
-
148.552 134.000 149.000 134.448 149.000 135.000 c
|
134
|
-
148.000 135.000 m
|
135
|
-
f
|
136
|
-
269.000 47.000 m
|
137
|
-
0.125 0.125 0.125 scn
|
138
|
-
270.000 207.000 m
|
139
|
-
270.000 207.552 269.552 208.000 269.000 208.000 c
|
140
|
-
268.448 208.000 268.000 207.552 268.000 207.000 c
|
141
|
-
268.000 206.448 268.448 206.000 269.000 206.000 c
|
142
|
-
269.552 206.000 270.000 206.448 270.000 207.000 c
|
143
|
-
269.000 207.000 m
|
144
|
-
f
|
145
|
-
390.000 47.000 m
|
146
|
-
0.125 0.125 0.125 scn
|
147
|
-
391.000 247.000 m
|
148
|
-
391.000 247.552 390.552 248.000 390.000 248.000 c
|
149
|
-
389.448 248.000 389.000 247.552 389.000 247.000 c
|
150
|
-
389.000 246.448 389.448 246.000 390.000 246.000 c
|
151
|
-
390.552 246.000 391.000 246.448 391.000 247.000 c
|
152
|
-
390.000 247.000 m
|
153
|
-
f
|
154
|
-
511.000 47.000 m
|
155
|
-
0.125 0.125 0.125 scn
|
156
|
-
512.000 69.000 m
|
157
|
-
512.000 69.552 511.552 70.000 511.000 70.000 c
|
158
|
-
510.448 70.000 510.000 69.552 510.000 69.000 c
|
159
|
-
510.000 68.448 510.448 68.000 511.000 68.000 c
|
160
|
-
511.552 68.000 512.000 68.448 512.000 69.000 c
|
161
|
-
511.000 69.000 m
|
162
|
-
f
|
163
|
-
2 w
|
164
|
-
0.125 0.125 0.125 SCN
|
165
|
-
62.000 47.000 m
|
166
|
-
148.000 135.000 l
|
167
|
-
S
|
168
|
-
148.000 135.000 m
|
169
|
-
269.000 207.000 l
|
170
|
-
S
|
171
|
-
269.000 207.000 m
|
172
|
-
390.000 247.000 l
|
173
|
-
S
|
174
|
-
390.000 247.000 m
|
175
|
-
511.000 69.000 l
|
176
|
-
S
|
177
|
-
1 w
|
178
|
-
0.000 0.000 0.000 SCN
|
179
|
-
0.000 0.000 0.000 scn
|
180
|
-
61.000 46.000 m
|
181
|
-
Q
|
182
|
-
|
183
|
-
endstream
|
184
|
-
endobj
|
185
|
-
5 0 obj
|
186
|
-
<< /Contents 4 0 R
|
187
|
-
/Type /Page
|
188
|
-
/Parent 2 0 R
|
189
|
-
/Resources << /Font << /F1.0 6 0 R
|
190
|
-
>>
|
191
|
-
/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
|
192
|
-
>>
|
193
|
-
/MediaBox [0 0 612.0 792.0]
|
194
|
-
>>
|
195
|
-
endobj
|
196
|
-
6 0 obj
|
197
|
-
<< /Encoding /WinAnsiEncoding
|
198
|
-
/Subtype /Type1
|
199
|
-
/Type /Font
|
200
|
-
/BaseFont /Helvetica
|
201
|
-
>>
|
202
|
-
endobj
|
203
|
-
xref
|
204
|
-
0 7
|
205
|
-
0000000000 65535 f
|
206
|
-
0000000015 00000 n
|
207
|
-
0000000071 00000 n
|
208
|
-
0000000128 00000 n
|
209
|
-
0000000177 00000 n
|
210
|
-
0000002620 00000 n
|
211
|
-
0000002798 00000 n
|
212
|
-
trailer
|
213
|
-
<< /Root 3 0 R
|
214
|
-
/Info 1 0 R
|
215
|
-
/Size 7
|
216
|
-
>>
|
217
|
-
startxref
|
218
|
-
2895
|
219
|
-
%%EOF
|
@@ -1,18 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
#
|
3
|
-
require "#{File.dirname(__FILE__)}/../example_helper.rb"
|
4
|
-
|
5
|
-
# Simplest line chart example
|
6
|
-
#
|
7
|
-
|
8
|
-
data = [
|
9
|
-
['January',20],
|
10
|
-
['February',36],
|
11
|
-
['March',45],
|
12
|
-
['April', 5]
|
13
|
-
]
|
14
|
-
|
15
|
-
Prawn::Document.generate('line_chart.pdf') do
|
16
|
-
line_chart data, :at => [10, 10]
|
17
|
-
end
|
18
|
-
|
@@ -1,18 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
#
|
3
|
-
require "#{File.dirname(__FILE__)}/../example_helper.rb"
|
4
|
-
|
5
|
-
# Simplest bar chart example
|
6
|
-
#
|
7
|
-
|
8
|
-
data = [
|
9
|
-
['Cats',20],
|
10
|
-
['Dogs',36],
|
11
|
-
['Hamsters',45],
|
12
|
-
['Goldfish', 5]
|
13
|
-
]
|
14
|
-
|
15
|
-
Prawn::Document.generate('bar_chart.pdf') do
|
16
|
-
bar_chart data, :at => [10, 10], :theme => Prawn::Chart::Themes.keynote
|
17
|
-
end
|
18
|
-
|
@@ -1,18 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
#
|
3
|
-
require "#{File.dirname(__FILE__)}/../example_helper.rb"
|
4
|
-
|
5
|
-
# Simplest line chart example
|
6
|
-
#
|
7
|
-
|
8
|
-
data = [
|
9
|
-
['January',20],
|
10
|
-
['February',36],
|
11
|
-
['March',45],
|
12
|
-
['April', 5]
|
13
|
-
]
|
14
|
-
|
15
|
-
Prawn::Document.generate('line_chart.pdf') do
|
16
|
-
line_chart data, :at => [10, 10], :theme => Prawn::Chart::Themes.odeo
|
17
|
-
end
|
18
|
-
|
data/lib/prawn/graph.rb
DELETED
@@ -1,94 +0,0 @@
|
|
1
|
-
require 'bigdecimal'
|
2
|
-
|
3
|
-
require File.dirname(__FILE__) + '/graph/errors'
|
4
|
-
require File.dirname(__FILE__) + '/graph/chart'
|
5
|
-
require File.dirname(__FILE__) + '/graph/base'
|
6
|
-
require File.dirname(__FILE__) + '/graph/grid'
|
7
|
-
require File.dirname(__FILE__) + '/graph/bar'
|
8
|
-
require File.dirname(__FILE__) + '/graph/line'
|
9
|
-
require File.dirname(__FILE__) + '/graph/themes'
|
10
|
-
|
11
|
-
module Prawn
|
12
|
-
|
13
|
-
class Document
|
14
|
-
|
15
|
-
Prawn::Chart::Themes.initialize_themes
|
16
|
-
|
17
|
-
# Draws a fairly simple bar chart. Data should be passed in as an array of
|
18
|
-
# arrays, much like how Tables are dealt with:
|
19
|
-
#
|
20
|
-
# [
|
21
|
-
# [ 'Field Title', 10 ],
|
22
|
-
# [ 'Another Title', 20]
|
23
|
-
# ]
|
24
|
-
#
|
25
|
-
# options[:at] MUST be specified, as the coordinates where you want your
|
26
|
-
# bar chart to be drawn.
|
27
|
-
#
|
28
|
-
# options[:width] Sets the width of the chart, defaults to 500
|
29
|
-
# options[:height] Sets the height of the chart, defaults to 200
|
30
|
-
# options[:spacing] Sets the spacing between the grid squares of the chart, defaults to 20
|
31
|
-
#
|
32
|
-
# It will do its best to try and size content to fit the available size; but at
|
33
|
-
# the moment it's not too clever. If your graph looks squashed; make it bigger.
|
34
|
-
#
|
35
|
-
# Other available options are:
|
36
|
-
#
|
37
|
-
# :label_x Which sets a label to be shown along the X Axis.
|
38
|
-
# :label_y Which sets a label to be shown along the Y Axis.
|
39
|
-
# :title Which sets a Title for the chart
|
40
|
-
#
|
41
|
-
# For now, these values DO NOT scale in size. X/Y labels are always 8 points and Titles
|
42
|
-
# are always 10 points.
|
43
|
-
#
|
44
|
-
def bar_chart(data, options = {})
|
45
|
-
if data.nil? || data.empty?
|
46
|
-
raise Prawn::Errors::NoGraphData,
|
47
|
-
"data must be a non-empty, non-nil, two dimensional array " +
|
48
|
-
"in the form [ [ 'Title', SomeValue ] ]"
|
49
|
-
end
|
50
|
-
Prawn::Chart::Bar.new(data, self, options).draw
|
51
|
-
end
|
52
|
-
alias :bar_graph :bar_chart
|
53
|
-
|
54
|
-
# Draws a fairly simple line chart. Data should be passed in as an array of
|
55
|
-
# arrays, much like how Tables are dealt with:
|
56
|
-
#
|
57
|
-
# [
|
58
|
-
# [ 'Field Title', 10 ],
|
59
|
-
# [ 'Another Title', 20]
|
60
|
-
# ]
|
61
|
-
#
|
62
|
-
# options[:at] MUST be specified, as the coordinates where you want your
|
63
|
-
# bar chart to be drawn.
|
64
|
-
#
|
65
|
-
# options[:width] Sets the width of the chart, defaults to 500
|
66
|
-
# options[:height] Sets the height of the chart, defaults to 200
|
67
|
-
# options[:spacing] Sets the spacing between the grid squares of the chart, defaults to 20
|
68
|
-
#
|
69
|
-
# It will do its best to try and size content to fit the available size; but at
|
70
|
-
# the moment it's not too clever. If your graph looks squashed; make it bigger.
|
71
|
-
#
|
72
|
-
# Other available options are:
|
73
|
-
#
|
74
|
-
# :label_x Which sets a label to be shown along the X Axis.
|
75
|
-
# :label_y Which sets a label to be shown along the Y Axis.
|
76
|
-
# :title Which sets a Title for the chart
|
77
|
-
#
|
78
|
-
# For now, these values DO NOT scale in size. X/Y labels are always 8 points and Titles
|
79
|
-
# are always 10 points.
|
80
|
-
#
|
81
|
-
def line_chart(data, options = {})
|
82
|
-
if data.nil? || data.empty?
|
83
|
-
raise Prawn::Errors::NoGraphData,
|
84
|
-
"data must be a non-empty, non-nil, two dimensional array " +
|
85
|
-
"in the form [ [ 'Title', SomeValue ] ]"
|
86
|
-
end
|
87
|
-
Prawn::Chart::Line.new(data, self, options).draw
|
88
|
-
end
|
89
|
-
alias :line_graph :line_chart
|
90
|
-
|
91
|
-
|
92
|
-
end
|
93
|
-
|
94
|
-
end
|
data/lib/prawn/graph/bar.rb
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
module Prawn
|
2
|
-
module Chart
|
3
|
-
|
4
|
-
# Prawn::Chart::Bar plots its values as a Bar graph, relatively
|
5
|
-
# sized to fit within the space defined by the Prawn::Chart::Grid
|
6
|
-
# associated with it.
|
7
|
-
#
|
8
|
-
# Call to new will return a new instance of Prawn::Chart::Bar ready to
|
9
|
-
# be rendered.
|
10
|
-
#
|
11
|
-
# Takes an Array of +data+, which should contain complete rows of data for
|
12
|
-
# values to be plotted; a reference to a +document+ which should be an
|
13
|
-
# instance of Prawn::Document and an +options+ with at least a value for :at
|
14
|
-
# specified.
|
15
|
-
#
|
16
|
-
# Options are:
|
17
|
-
#
|
18
|
-
# :at , which should be an Array representing the point at which the graph
|
19
|
-
# should be drawn.
|
20
|
-
#
|
21
|
-
# :title, the title for this graph, wil be rendered centered to the top of
|
22
|
-
# the Grid.
|
23
|
-
#
|
24
|
-
# :label_x, a label to be shown along the X axis of he graph, rendered centered
|
25
|
-
# on the grid.
|
26
|
-
#
|
27
|
-
# :label_y, a label to be shown along the Y axis of he graph, rendered centered
|
28
|
-
# on the grid and rotated to be perpendicular to the axis.
|
29
|
-
#
|
30
|
-
# Data should be formatted like:
|
31
|
-
#
|
32
|
-
# [
|
33
|
-
# [ 'Column Heading', SomeValue ],
|
34
|
-
# [ 'Column Heading', SomeValue ],
|
35
|
-
# [ 'Column Heading', SomeValue ],
|
36
|
-
# [ 'Column Heading', SomeValue ],
|
37
|
-
# [ 'Column Heading', SomeValue ],
|
38
|
-
# [ 'Column Heading', SomeValue ]
|
39
|
-
# ]
|
40
|
-
#
|
41
|
-
class Bar < Base
|
42
|
-
|
43
|
-
|
44
|
-
private
|
45
|
-
|
46
|
-
def plot_values
|
47
|
-
base_x = @grid.start_x + 1
|
48
|
-
base_y = @grid.start_y + 1
|
49
|
-
bar_width = calculate_bar_width
|
50
|
-
@document.line_width bar_width
|
51
|
-
last_position = base_x
|
52
|
-
point_spacing = calculate_plot_spacing
|
53
|
-
@values.each do |value|
|
54
|
-
@document.move_to [base_x + last_position, base_y]
|
55
|
-
bar_height = calculate_point_height_from value
|
56
|
-
@document.stroke_color @theme.next_colour
|
57
|
-
@document.stroke_line_to [base_x + last_position, base_y + bar_height]
|
58
|
-
last_position += point_spacing
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|