prawn-graph 0.9.1 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -4
- data/lib/prawn/graph/calculations/layout_calculator.rb +2 -1
- data/lib/prawn/graph/chart_components/canvas.rb +1 -0
- data/lib/prawn/graph/chart_components/series_renderer.rb +18 -1
- data/lib/prawn/graph/extension.rb +6 -1
- data/lib/prawn/graph/series.rb +4 -0
- data/lib/prawn/graph/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bab79a3dc4ba1072ba72479b83ac9de8a1d38922
|
4
|
+
data.tar.gz: 6c23d7a89268e42bfff25b1da58bcb49adc7e3bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6b4482768b7d5470a3a3913698cd8669a391d8947a576c540d45938a76c62b644705f7572fd7474e21a218b2aab72d1a3a7c342d1dcacdbcfddbbcf79050898
|
7
|
+
data.tar.gz: d4666cd5006ccaef777fe90c882b36da57a170903dd1017588b037ddd9d5070b81533c86db743ce4fb2acab5083926a72888e0a1e07a3f20e5a617699611a4c9
|
data/README.md
CHANGED
@@ -104,10 +104,10 @@ Option | Data type | Description
|
|
104
104
|
require 'prawn-graph'
|
105
105
|
|
106
106
|
series = []
|
107
|
-
series << Prawn::Graph::Series.new([
|
108
|
-
series << Prawn::Graph::Series.new([5,4,3,2,
|
109
|
-
series << Prawn::Graph::Series.new([1,2,3,4,5,9,6,4,5,6,3,2,
|
110
|
-
series << Prawn::Graph::Series.new([1,2,3,4,5,
|
107
|
+
series << Prawn::Graph::Series.new([4,9,3,2,1,6,2,8,2,3,4,9,2], title: "A label for a series", type: :bar, mark_average: true)
|
108
|
+
series << Prawn::Graph::Series.new([5,4,3,2,7,9,2,8,7,5,4,9,2].reverse, title: "Another label", type: :line, mark_average: true)
|
109
|
+
series << Prawn::Graph::Series.new([1,2,3,4,5,9,6,4,5,6,3,2,11], title: "Yet another label", type: :bar)
|
110
|
+
series << Prawn::Graph::Series.new([1,2,3,4,5,12,6,4,5,6,3,2,9].shuffle, title: "One final label", type: :line, mark_average: true)
|
111
111
|
|
112
112
|
Prawn::Document.generate('test.pdf') do
|
113
113
|
graph series, width: 500, height: 200, title: "A Title for the chart", at: [10,700]
|
@@ -53,6 +53,7 @@ module Prawn
|
|
53
53
|
@canvas_height = BigDecimal(attributes[:height], 10) rescue 0
|
54
54
|
@num_series = attributes[:series_count] || 1
|
55
55
|
@title = attributes[:title]
|
56
|
+
@show_series_key = !attributes[:show_series_key].nil? ? attributes[:show_series_key] : true
|
56
57
|
end
|
57
58
|
|
58
59
|
def calculate_width_and_height_of_canvas
|
@@ -80,7 +81,7 @@ module Prawn
|
|
80
81
|
end
|
81
82
|
|
82
83
|
def calculate_key_area
|
83
|
-
if @num_series > 1
|
84
|
+
if @num_series > 1 && @show_series_key
|
84
85
|
@series_key_area[:width] = ( (canvas_width / 100) * 25 ).round
|
85
86
|
@series_key_area[:x] = (canvas_width - @series_key_area[:width] - hpadding)
|
86
87
|
@series_key_area[:y] = canvas_height + vpadding
|
@@ -62,6 +62,14 @@ module Prawn
|
|
62
62
|
j += 1
|
63
63
|
end
|
64
64
|
|
65
|
+
if @series.mark_average?
|
66
|
+
average_y_coordinate = (point_height_percentage(@series.avg) * @plot_area_height) - 5
|
67
|
+
prawn.line_width = 1
|
68
|
+
prawn.stroke_color = @color
|
69
|
+
prawn.dash(2)
|
70
|
+
prawn.stroke_line([0, average_y_coordinate], [ @plot_area_width, average_y_coordinate ])
|
71
|
+
prawn.undash
|
72
|
+
end
|
65
73
|
end
|
66
74
|
render_axes
|
67
75
|
end
|
@@ -79,7 +87,7 @@ module Prawn
|
|
79
87
|
# the series.
|
80
88
|
#
|
81
89
|
def point_height_percentage(value)
|
82
|
-
((BigDecimal(value, 10)/BigDecimal(@series.max, 10)) * BigDecimal(1)).round(2)
|
90
|
+
((BigDecimal(value, 10)/BigDecimal(@canvas.series.collect(&:max).max, 10)) * BigDecimal(1)).round(2)
|
83
91
|
end
|
84
92
|
|
85
93
|
def prawn
|
@@ -138,6 +146,15 @@ module Prawn
|
|
138
146
|
y_position = ((point_height_percentage(@series[series_index].values[point]) * @plot_area_height) - 5).to_f
|
139
147
|
|
140
148
|
prawn.fill_and_stroke_line([ x_position ,0], [x_position ,y_position])
|
149
|
+
|
150
|
+
if @series[series_index].mark_average?
|
151
|
+
average_y_coordinate = (point_height_percentage(@series[series_index].avg) * @plot_area_height) - 5
|
152
|
+
prawn.line_width = 1
|
153
|
+
prawn.stroke_color = @colors[series_index]
|
154
|
+
prawn.dash(2)
|
155
|
+
prawn.stroke_line([0, average_y_coordinate], [ @plot_area_width, average_y_coordinate ])
|
156
|
+
prawn.undash
|
157
|
+
end
|
141
158
|
end
|
142
159
|
|
143
160
|
end
|
@@ -34,7 +34,12 @@ module Prawn
|
|
34
34
|
# rendered graph
|
35
35
|
#
|
36
36
|
# @param series [Array] of Prawn::Graph::Series objects
|
37
|
-
# @param options [Hash] of options, which can be:
|
37
|
+
# @param options [Hash] of options, which can be:
|
38
|
+
# `:width` - The overall width of the graph to be drawn. `<Integer>`
|
39
|
+
# `:height` - The overall height of the graph to be drawn. `<Integer>`
|
40
|
+
# `:at` - The point from where the graph will be drawn. `[<Integer>x, <Integer>y]`
|
41
|
+
# `:title` - The title for this chart. Must be a string. `<String>`
|
42
|
+
# `:series_key` - Should we render the key to series in this chart? `<Boolean>`
|
38
43
|
#
|
39
44
|
def graph(series, options = {}, &block)
|
40
45
|
canvas = Prawn::Graph::ChartComponents::Canvas.new(series, self, options, &block)
|
data/lib/prawn/graph/series.rb
CHANGED
@@ -67,6 +67,10 @@ module Prawn
|
|
67
67
|
@values.size
|
68
68
|
end
|
69
69
|
|
70
|
+
def mark_average?
|
71
|
+
options.mark_average == true
|
72
|
+
end
|
73
|
+
|
70
74
|
# @deprecated Provided to allow for tempory backwards compatibilty with legacy graph drawing. Do not use.
|
71
75
|
# @return [Array] Series represented as an array in the format [ title, val1, val2... ]
|
72
76
|
#
|
data/lib/prawn/graph/version.rb
CHANGED
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: 0.9.
|
4
|
+
version: 0.9.2
|
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-06-
|
12
|
+
date: 2016-06-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|