prawn-graph 1.0.0.pre1 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +10 -0
- data/README.md +72 -36
- data/Rakefile +6 -0
- data/lib/prawn-graph.rb +6 -1
- data/lib/prawn/graph/calculations.rb +1 -0
- data/lib/prawn/graph/calculations/layout_calculator.rb +109 -0
- data/lib/prawn/graph/chart_components.rb +4 -0
- data/lib/prawn/graph/chart_components/bar_chart_renderer.rb +94 -0
- data/lib/prawn/graph/chart_components/canvas.rb +128 -0
- data/lib/prawn/graph/chart_components/line_chart_renderer.rb +92 -0
- data/lib/prawn/graph/chart_components/series_renderer.rb +120 -0
- data/lib/prawn/graph/extension.rb +16 -23
- data/lib/prawn/graph/series.rb +57 -8
- data/lib/prawn/graph/theme.rb +23 -6
- data/lib/prawn/graph/version.rb +1 -1
- data/prawn-graph.gemspec +8 -2
- metadata +44 -15
- data/lib/prawn/graph/charts.rb +0 -4
- data/lib/prawn/graph/charts/bar.rb +0 -18
- data/lib/prawn/graph/charts/base.rb +0 -69
- data/lib/prawn/graph/charts/legacy.rb +0 -4
- data/lib/prawn/graph/charts/legacy/bar.rb +0 -28
- data/lib/prawn/graph/charts/legacy/base.rb +0 -195
- data/lib/prawn/graph/charts/legacy/grid.rb +0 -51
- data/lib/prawn/graph/charts/legacy/line.rb +0 -39
- data/lib/prawn/graph/charts/line.rb +0 -18
data/lib/prawn/graph/theme.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'ostruct'
|
2
|
-
|
3
1
|
module Prawn
|
4
2
|
module Graph
|
5
3
|
module Theme
|
@@ -10,14 +8,33 @@ module Prawn
|
|
10
8
|
'85929E',
|
11
9
|
'34495E',
|
12
10
|
'1B2631',
|
11
|
+
'EBEDEF',
|
12
|
+
'D6DBDF',
|
13
|
+
'85929E',
|
14
|
+
'34495E',
|
15
|
+
'1B2631',
|
16
|
+
'EBEDEF',
|
17
|
+
'D6DBDF',
|
18
|
+
'85929E',
|
19
|
+
'34495E',
|
20
|
+
'1B2631',
|
13
21
|
],
|
14
|
-
title: '
|
22
|
+
title: '17202A',
|
15
23
|
background: 'FFFFFF',
|
16
24
|
grid: 'F2F4F4',
|
17
25
|
axes: '17202A',
|
18
|
-
markers: '
|
19
|
-
|
20
|
-
default: '
|
26
|
+
markers: '34495E',
|
27
|
+
stroke_grid_lines: true,
|
28
|
+
default: '333333',
|
29
|
+
average: '34495E',
|
30
|
+
max: '17202A',
|
31
|
+
min: '17202A',
|
32
|
+
font_sizes: OpenStruct.new({
|
33
|
+
default: 8,
|
34
|
+
main_title: 10,
|
35
|
+
axis_labels: 5,
|
36
|
+
series_key: 8,
|
37
|
+
}),
|
21
38
|
})
|
22
39
|
end
|
23
40
|
end
|
data/lib/prawn/graph/version.rb
CHANGED
data/prawn-graph.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
|
18
18
|
spec.summary = %q{Easily add graphs to Prawn PDF documents}
|
19
19
|
spec.description = %q{Prawn::Graph adds straightforward native graph drawing to Prawn without the need to depend on anything else. All generated graphs are pure PDF Vector Images. It results in smaller document sizes and less complication.}
|
20
|
-
spec.homepage = "
|
20
|
+
spec.homepage = "http://prawn-graph.ryanstenhouse.jp"
|
21
21
|
spec.license = "MIT"
|
22
22
|
|
23
23
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
@@ -28,10 +28,16 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.add_development_dependency "bundler", "~> 1.11"
|
29
29
|
spec.add_development_dependency "rake", "~> 10.0"
|
30
30
|
spec.add_development_dependency "rspec", "~> 3.0"
|
31
|
+
spec.add_development_dependency "codeclimate-test-reporter"
|
31
32
|
spec.add_development_dependency "simplecov"
|
32
|
-
|
33
|
+
spec.add_development_dependency "yard"
|
33
34
|
|
34
35
|
spec.required_ruby_version = '>= 2.0.0'
|
35
36
|
|
36
37
|
spec.add_runtime_dependency "prawn", ">= 0.11.1", "< 3"
|
38
|
+
|
39
|
+
spec.metadata = {
|
40
|
+
"issue_tracker" => "https://github.com/HHRy/prawn-graph/issues",
|
41
|
+
"source_code" => "https://github.com/HHRy/prawn-graph"
|
42
|
+
}
|
37
43
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prawn-graph
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Stenhouse
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-07-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -53,6 +53,20 @@ dependencies:
|
|
53
53
|
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '3.0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: codeclimate-test-reporter
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
56
70
|
- !ruby/object:Gem::Dependency
|
57
71
|
name: simplecov
|
58
72
|
requirement: !ruby/object:Gem::Requirement
|
@@ -67,6 +81,20 @@ dependencies:
|
|
67
81
|
- - ">="
|
68
82
|
- !ruby/object:Gem::Version
|
69
83
|
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: yard
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
70
98
|
- !ruby/object:Gem::Dependency
|
71
99
|
name: prawn
|
72
100
|
requirement: !ruby/object:Gem::Requirement
|
@@ -111,24 +139,24 @@ files:
|
|
111
139
|
- bin/console
|
112
140
|
- bin/setup
|
113
141
|
- lib/prawn-graph.rb
|
114
|
-
- lib/prawn/graph/
|
115
|
-
- lib/prawn/graph/
|
116
|
-
- lib/prawn/graph/
|
117
|
-
- lib/prawn/graph/
|
118
|
-
- lib/prawn/graph/
|
119
|
-
- lib/prawn/graph/
|
120
|
-
- lib/prawn/graph/
|
121
|
-
- lib/prawn/graph/charts/legacy/line.rb
|
122
|
-
- lib/prawn/graph/charts/line.rb
|
142
|
+
- lib/prawn/graph/calculations.rb
|
143
|
+
- lib/prawn/graph/calculations/layout_calculator.rb
|
144
|
+
- lib/prawn/graph/chart_components.rb
|
145
|
+
- lib/prawn/graph/chart_components/bar_chart_renderer.rb
|
146
|
+
- lib/prawn/graph/chart_components/canvas.rb
|
147
|
+
- lib/prawn/graph/chart_components/line_chart_renderer.rb
|
148
|
+
- lib/prawn/graph/chart_components/series_renderer.rb
|
123
149
|
- lib/prawn/graph/extension.rb
|
124
150
|
- lib/prawn/graph/series.rb
|
125
151
|
- lib/prawn/graph/theme.rb
|
126
152
|
- lib/prawn/graph/version.rb
|
127
153
|
- prawn-graph.gemspec
|
128
|
-
homepage:
|
154
|
+
homepage: http://prawn-graph.ryanstenhouse.jp
|
129
155
|
licenses:
|
130
156
|
- MIT
|
131
|
-
metadata:
|
157
|
+
metadata:
|
158
|
+
issue_tracker: https://github.com/HHRy/prawn-graph/issues
|
159
|
+
source_code: https://github.com/HHRy/prawn-graph
|
132
160
|
post_install_message:
|
133
161
|
rdoc_options: []
|
134
162
|
require_paths:
|
@@ -140,9 +168,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
140
168
|
version: 2.0.0
|
141
169
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
142
170
|
requirements:
|
143
|
-
- - "
|
171
|
+
- - ">="
|
144
172
|
- !ruby/object:Gem::Version
|
145
|
-
version:
|
173
|
+
version: '0'
|
146
174
|
requirements: []
|
147
175
|
rubyforge_project:
|
148
176
|
rubygems_version: 2.5.1
|
@@ -150,3 +178,4 @@ signing_key:
|
|
150
178
|
specification_version: 4
|
151
179
|
summary: Easily add graphs to Prawn PDF documents
|
152
180
|
test_files: []
|
181
|
+
has_rdoc:
|
data/lib/prawn/graph/charts.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
module Prawn
|
2
|
-
module Graph
|
3
|
-
module Charts
|
4
|
-
class Bar < Base
|
5
|
-
|
6
|
-
private
|
7
|
-
|
8
|
-
def chart_object
|
9
|
-
Prawn::Graph::Charts::Legacy::Bar.new(@series.collect(&:to_a), @prawn, @options)
|
10
|
-
end
|
11
|
-
|
12
|
-
def series_type
|
13
|
-
:bar
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
module Prawn
|
2
|
-
module Graph
|
3
|
-
module Charts
|
4
|
-
|
5
|
-
class Base
|
6
|
-
VALID_OPTIONS = [:at, :width, :height]
|
7
|
-
attr_reader :series, :prawn, :options, :lowest_value, :highest_value
|
8
|
-
|
9
|
-
def initialize(data, prawn, options = {}, &block)
|
10
|
-
Prawn.verify_options VALID_OPTIONS, options
|
11
|
-
|
12
|
-
if data.is_a?(Array) || (!data.is_a?(Array) && data.is_a?(Prawn::Graph::Series))
|
13
|
-
data = [ data ] unless data.is_a?(Array)
|
14
|
-
else
|
15
|
-
raise ArgumentError.new("data must be a multidimensional Array, array of Prawn::Graph::Series or a single Prawn::Graph::Series")
|
16
|
-
end
|
17
|
-
|
18
|
-
@series = []
|
19
|
-
data.each do |s|
|
20
|
-
if s.is_a?(Prawn::Graph::Series)
|
21
|
-
@series << s
|
22
|
-
else
|
23
|
-
title = s.shift
|
24
|
-
@series << Prawn::Graph::Series.new(s, title, series_type)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
@prawn = prawn
|
29
|
-
@options = options
|
30
|
-
calculate_extreme_values!
|
31
|
-
end
|
32
|
-
|
33
|
-
def titles
|
34
|
-
@series.collect(&:title)
|
35
|
-
end
|
36
|
-
|
37
|
-
def position
|
38
|
-
end
|
39
|
-
|
40
|
-
def draw
|
41
|
-
chart_object.draw
|
42
|
-
end
|
43
|
-
|
44
|
-
private
|
45
|
-
|
46
|
-
def chart_object
|
47
|
-
raise RuntimeError.new("I need to be subclassed.")
|
48
|
-
end
|
49
|
-
|
50
|
-
def series_type
|
51
|
-
:bar
|
52
|
-
end
|
53
|
-
|
54
|
-
def calculate_extreme_values!
|
55
|
-
@lowest_value = @series.collect(&:min).min
|
56
|
-
@highest_value = @series.collect(&:max).max
|
57
|
-
end
|
58
|
-
|
59
|
-
def process_the(data_array)
|
60
|
-
col = []
|
61
|
-
val = []
|
62
|
-
data_array.each { |i| val << i[1]; col << i[0] }
|
63
|
-
[ col, val, val.min, val.max ]
|
64
|
-
end
|
65
|
-
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
module Prawn
|
2
|
-
module Graph
|
3
|
-
module Charts
|
4
|
-
module Legacy
|
5
|
-
class Bar < Prawn::Graph::Charts::Legacy::Base
|
6
|
-
|
7
|
-
private
|
8
|
-
|
9
|
-
def plot_values
|
10
|
-
base_x = @grid.start_x + 1
|
11
|
-
base_y = @grid.start_y + 1
|
12
|
-
bar_width = calculate_bar_width
|
13
|
-
@document.line_width bar_width
|
14
|
-
last_position = base_x
|
15
|
-
point_spacing = calculate_plot_spacing
|
16
|
-
@values.each do |value|
|
17
|
-
@document.move_to [base_x + last_position, base_y]
|
18
|
-
bar_height = calculate_point_height_from value
|
19
|
-
@document.stroke_color @theme.series.sample
|
20
|
-
@document.stroke_line_to [base_x + last_position, base_y + bar_height]
|
21
|
-
last_position += point_spacing
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,195 +0,0 @@
|
|
1
|
-
require "bigdecimal"
|
2
|
-
|
3
|
-
module Prawn
|
4
|
-
module Graph
|
5
|
-
module Charts
|
6
|
-
module Legacy
|
7
|
-
|
8
|
-
class Base
|
9
|
-
|
10
|
-
attr_accessor :grid, :headings, :values, :highest_value, :document, :colour
|
11
|
-
|
12
|
-
def initialize(data, document, options = {})
|
13
|
-
opts = { :theme => Prawn::Graph::Theme::Default, :width => 500, :height => 200, :spacing => 20, :at => [0,0] }.merge(options)
|
14
|
-
(@headings, @values, @highest_value) = process_the data
|
15
|
-
(grid_x_start, grid_y_start, grid_width, grid_height) = parse_sizing_from opts
|
16
|
-
@colour = false
|
17
|
-
@document = document
|
18
|
-
@theme = Prawn::Graph::Theme::Default
|
19
|
-
off = 20
|
20
|
-
@grid = Prawn::Graph::Charts::Legacy::Grid.new(grid_x_start, grid_y_start, grid_width, grid_height, opts[:spacing], document, Prawn::Graph::Theme::Default)
|
21
|
-
end
|
22
|
-
|
23
|
-
# Draws the graph on the document which we have a reference to.
|
24
|
-
#
|
25
|
-
def draw
|
26
|
-
draw_bounding_box
|
27
|
-
@grid.draw
|
28
|
-
label_axes
|
29
|
-
if @title
|
30
|
-
draw_title
|
31
|
-
end
|
32
|
-
plot_values
|
33
|
-
if @x_label
|
34
|
-
draw_x_axis_label
|
35
|
-
end
|
36
|
-
if @y_label
|
37
|
-
draw_y_axis_label
|
38
|
-
end
|
39
|
-
reset
|
40
|
-
end
|
41
|
-
|
42
|
-
private
|
43
|
-
|
44
|
-
def draw_bounding_box
|
45
|
-
@document.fill_color @theme.background
|
46
|
-
@document.fill_and_stroke_rectangle [(@point.first - 10), (@point.last + ( @total_height + 40 ))], @document.bounds.width, (@total_height + 40)
|
47
|
-
@document.fill_color '000000'
|
48
|
-
end
|
49
|
-
|
50
|
-
def label_axes
|
51
|
-
@document.fill_color @theme.title
|
52
|
-
base_x = @grid.start_x + 1
|
53
|
-
base_y = @grid.start_y + 1
|
54
|
-
|
55
|
-
# Put the values up the Y Axis
|
56
|
-
#
|
57
|
-
@document.draw_text @highest_value, :at => [base_x - 15, base_y + @grid.height], :size => 5
|
58
|
-
@document.draw_text '0', :at => [base_x - 15, base_y ], :size => 5
|
59
|
-
|
60
|
-
# Put the column headings along the X Axis
|
61
|
-
#
|
62
|
-
point_spacing = calculate_plot_spacing
|
63
|
-
last_position = base_x + (point_spacing / 2)
|
64
|
-
@headings.each do |heading|
|
65
|
-
@document.draw_text heading, :at => [last_position, base_y - 15 ], :size => 5
|
66
|
-
last_position += point_spacing
|
67
|
-
end
|
68
|
-
@document.fill_color @theme.background
|
69
|
-
end
|
70
|
-
|
71
|
-
def draw_title
|
72
|
-
@document.fill_color @theme.title
|
73
|
-
x_coord = calculate_x_axis_center_point(@title, 10)
|
74
|
-
y_coord = @grid.start_y + @grid.height + 10
|
75
|
-
@document.draw_text @title, :at => [x_coord, y_coord] ,:size => 10
|
76
|
-
@document.fill_color @theme.background
|
77
|
-
end
|
78
|
-
|
79
|
-
def draw_x_axis_label
|
80
|
-
@document.fill_color @theme.axes
|
81
|
-
x_coord = calculate_x_axis_center_point(@x_label, 8)
|
82
|
-
y_coord = @grid.start_y - 30
|
83
|
-
@document.draw_text @x_label, :at => [x_coord, y_coord] ,:size => 8
|
84
|
-
@document.fill_color @theme.background
|
85
|
-
end
|
86
|
-
|
87
|
-
def draw_y_axis_label
|
88
|
-
@document.fill_color @theme.axes
|
89
|
-
y_coord = calculate_y_axis_center_point(@y_label, 8)
|
90
|
-
x_coord = @grid.start_x - 30
|
91
|
-
@document.draw_text @y_label, :at => [x_coord, y_coord] ,:size => 8, :rotate => 90
|
92
|
-
@document.fill_color @theme.background
|
93
|
-
end
|
94
|
-
|
95
|
-
# All subclasses of Prawn::Chart::Base must implement thier own plot_values
|
96
|
-
# method, which does the actual real heavy lifting of drawing the graph.
|
97
|
-
#
|
98
|
-
def plot_values
|
99
|
-
raise Prawn::Errors::NoPlotValuesMethod, 'subclasses of Prawn::Chart::Base must implement '
|
100
|
-
+ 'their own plot_values method.'
|
101
|
-
end
|
102
|
-
|
103
|
-
def reset
|
104
|
-
@document.line_width 1
|
105
|
-
@document.stroke_color '000000'
|
106
|
-
@document.fill_color '000000'
|
107
|
-
@document.move_to @grid.point
|
108
|
-
end
|
109
|
-
|
110
|
-
|
111
|
-
# Utility methods for dealing with working out where things should be
|
112
|
-
# the calculations and such done here are all very rough, but are
|
113
|
-
# sufficient for now to plot just what we need.
|
114
|
-
#
|
115
|
-
|
116
|
-
|
117
|
-
def parse_sizing_from(o)
|
118
|
-
x_offset = 15
|
119
|
-
y_offset = 0
|
120
|
-
move_y_up = 0
|
121
|
-
grid_width = o[:width]
|
122
|
-
grid_height = o[:height]
|
123
|
-
|
124
|
-
@total_width = o[:width]
|
125
|
-
@total_height = o[:height]
|
126
|
-
@point = o[:at].dup
|
127
|
-
|
128
|
-
# Make room for the title if we're choosing to Render it.
|
129
|
-
#
|
130
|
-
if o[:title]
|
131
|
-
@title = o[:title]
|
132
|
-
y_offset += 10
|
133
|
-
end
|
134
|
-
|
135
|
-
# Make room for X Axis labels if we're using them.
|
136
|
-
#
|
137
|
-
if o[:label_x]
|
138
|
-
y_offset += 30
|
139
|
-
move_y_up += 30
|
140
|
-
@x_label = o[:label_x]
|
141
|
-
end
|
142
|
-
|
143
|
-
# Make room for Y Axis labels if we're using them.
|
144
|
-
#
|
145
|
-
if o[:label_y]
|
146
|
-
@y_label = o[:label_y]
|
147
|
-
x_offset += 15
|
148
|
-
end
|
149
|
-
|
150
|
-
|
151
|
-
# Return the values calculated here.
|
152
|
-
#
|
153
|
-
[ (o[:at][0] + x_offset), (o[:at][1] + move_y_up + 20), (grid_width - (x_offset - 20)), (grid_height - y_offset) ]
|
154
|
-
end
|
155
|
-
|
156
|
-
def process_the(data_array)
|
157
|
-
col = []
|
158
|
-
val = []
|
159
|
-
data_array.each { |i| val << i[1]; col << i[0] }
|
160
|
-
[ col, val ,val.sort.last ]
|
161
|
-
end
|
162
|
-
|
163
|
-
def calculate_x_axis_center_point(text, text_size, graph_start_x = @grid.start_x, graph_width = @grid.width)
|
164
|
-
((graph_start_x + (graph_width / 2)) - ((text.length * text_size) / 4))
|
165
|
-
end
|
166
|
-
alias calculate_x_axis_centre_point calculate_x_axis_center_point
|
167
|
-
|
168
|
-
def calculate_y_axis_center_point(text, text_size, graph_start_y = @grid.start_y, graph_height = @grid.height)
|
169
|
-
((graph_start_y + (graph_height / 2)) - ((text.length * text_size) / 4))
|
170
|
-
end
|
171
|
-
alias calculate_y_axis_centre_point calculate_y_axis_center_point
|
172
|
-
|
173
|
-
def calculate_plot_spacing
|
174
|
-
(@grid.width / @values.count)
|
175
|
-
end
|
176
|
-
|
177
|
-
def calculate_bar_width
|
178
|
-
calculate_plot_spacing / 2
|
179
|
-
end
|
180
|
-
|
181
|
-
def calculate_point_height_from(column_value)
|
182
|
-
cv = BigDecimal("#{column_value}")
|
183
|
-
hv = BigDecimal("#{@highest_value}")
|
184
|
-
gh = BigDecimal("#{@grid.height}")
|
185
|
-
percentage = (cv / (hv / 100))
|
186
|
-
((gh / 100) * percentage).to_i
|
187
|
-
end
|
188
|
-
|
189
|
-
|
190
|
-
end
|
191
|
-
|
192
|
-
end
|
193
|
-
end
|
194
|
-
end
|
195
|
-
end
|