prawn-graph 0.9.9 → 0.9.10

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 211ca59ddae397b6e4139b5a638b29cd8cbf1273
4
- data.tar.gz: 2c77240a9b49b06ffaf78d7964304d604ad84cc2
3
+ metadata.gz: bb2a51bcf0e59ebb68b1d71b874dc8342343810e
4
+ data.tar.gz: 051ab456f7af3318a2c8a9d4a1e9b6a05669bbcf
5
5
  SHA512:
6
- metadata.gz: cc8b74b6554e51bee5c34bb03be7dc54bf7d1e81c58d2aa81db024810545aad168ccb471574d5b8b2a89ebb49eb5011db97c212667041fcc3ac574b4586240bd
7
- data.tar.gz: 0763fbe05942bb118537409cfe391b15a186739bda8cc463cfe2b371ba79e395271632982fe37df6017883876471b231fe4bbfccbd1ec7424ff18a8d13b16ede
6
+ metadata.gz: 0c31371f3411e0d707e1a1145718190268cb04516395bf490eb54172f6824bf510b681d370ebfa3bcedaf11394c5aee7f38b4230ff234059b5e8606190c924ef
7
+ data.tar.gz: 7fc938b7daffc5f4379207fc06893ea62120f962d6e90a7a2876d48af0dff72ca3c06f904ce8d6576ca119a37cf477f54cebfce88531cb12e75610cc7acb23bb
@@ -146,20 +146,20 @@ module Prawn
146
146
  prawn.stroke_vertical_line(0, @plot_area_height, at: 0)
147
147
  prawn.fill_and_stroke_ellipse [ 0,0], 1
148
148
 
149
- max = @series.max
150
- min = @series.min
151
- avg = @series.avg
152
- mid = (min + max) / 2
149
+ max = @series.max || 0
150
+ min = @series.min || 0
151
+ avg = @series.avg || 0
152
+ mid = (min + max) / 2 rescue 0
153
153
 
154
- max_y = (point_height_percentage(max) * @plot_area_height).to_f
155
- min_y = (point_height_percentage(min) * @plot_area_height).to_f
156
- mid_y = (point_height_percentage(mid) * @plot_area_height).to_f
157
- avg_y = (point_height_percentage(avg) * @plot_area_height).to_f
154
+ max_y = (point_height_percentage(max) * @plot_area_height)
155
+ min_y = (point_height_percentage(min) * @plot_area_height)
156
+ mid_y = (point_height_percentage(mid) * @plot_area_height)
157
+ avg_y = (point_height_percentage(avg) * @plot_area_height)
158
158
 
159
- prawn.text_box "#{max}", at: [-14, max_y], height: 5, overflow: :shrink_to_fit, width: 12, valign: :bottom, align: :right
160
- prawn.text_box "#{mid}", at: [-14, mid_y], height: 5, overflow: :shrink_to_fit, width: 12, valign: :bottom, align: :right
161
- prawn.text_box "#{avg}", at: [-14, avg_y], height: 5, overflow: :shrink_to_fit, width: 12, valign: :bottom, align: :right
162
- prawn.text_box "#{min}", at: [-14, min_y], height: 5, overflow: :shrink_to_fit, width: 12, valign: :bottom, align: :right
159
+ prawn.text_box "#{max}", at: [-14, max_y], height: 5, overflow: :shrink_to_fit, width: 12, valign: :bottom, align: :right unless max.zero?
160
+ prawn.text_box "#{mid}", at: [-14, mid_y], height: 5, overflow: :shrink_to_fit, width: 12, valign: :bottom, align: :right unless mid.zero?
161
+ prawn.text_box "#{avg}", at: [-14, avg_y], height: 5, overflow: :shrink_to_fit, width: 12, valign: :bottom, align: :right unless avg.zero?
162
+ prawn.text_box "#{min}", at: [-14, min_y], height: 5, overflow: :shrink_to_fit, width: 12, valign: :bottom, align: :right unless min.zero?
163
163
 
164
164
  return if @canvas.options[:xaxis_labels].size.zero?
165
165
 
@@ -177,7 +177,7 @@ module Prawn
177
177
  # the series.
178
178
  #
179
179
  def point_height_percentage(value)
180
- ((BigDecimal(value, 10)/BigDecimal(@canvas.series.collect(&:max).max, 10)) * BigDecimal(1)).round(2)
180
+ ((BigDecimal(value, 10)/BigDecimal(@canvas.series.collect(&:max).max, 10)) * BigDecimal(1)).round(2) rescue 0
181
181
  end
182
182
 
183
183
  def prawn
@@ -219,8 +219,8 @@ module Prawn
219
219
 
220
220
  prawn.save_graphics_state do
221
221
  num_points = @series[0].size
222
- width_per_point = (@plot_area_width / num_points).round(2).to_f
223
- width = ((width_per_point * BigDecimal('0.9')) / @series.size).round(2).to_f
222
+ width_per_point = (@plot_area_width / num_points)
223
+ width = (((width_per_point * 0.9) / @series.size).round(2)).to_f
224
224
  min_marked = false
225
225
  max_marked = false
226
226
 
@@ -293,20 +293,20 @@ module Prawn
293
293
  prawn.stroke_vertical_line(0, @plot_area_height, at: 0)
294
294
  prawn.fill_and_stroke_ellipse [ 0,0], 1
295
295
 
296
- max = @series.collect(&:max).max
297
- min = @series.collect(&:min).min
298
- avg = ((BigDecimal(@series.collect(&:avg).inject(:+), 10) / @series.collect(&:avg).size).round(2)).to_f
299
- mid = (min + max) / 2
296
+ max = @series.collect(&:max).max || 0
297
+ min = @series.collect(&:min).min || 0
298
+ avg = ((BigDecimal(@series.collect(&:avg).inject(:+), 10) / @series.collect(&:avg).size).round(2)).to_f || 0
299
+ mid = (min + max) / 2 || 0
300
300
 
301
- max_y = (point_height_percentage(max) * @plot_area_height).to_f
302
- min_y = (point_height_percentage(min) * @plot_area_height).to_f
303
- mid_y = (point_height_percentage(mid) * @plot_area_height).to_f
304
- avg_y = (point_height_percentage(avg) * @plot_area_height).to_f
301
+ max_y = (point_height_percentage(max) * @plot_area_height)
302
+ min_y = (point_height_percentage(min) * @plot_area_height)
303
+ mid_y = (point_height_percentage(mid) * @plot_area_height)
304
+ avg_y = (point_height_percentage(avg) * @plot_area_height)
305
305
 
306
- prawn.text_box "#{max}", at: [-14, max_y], height: 5, overflow: :shrink_to_fit, width: 12, valign: :bottom, align: :right
307
- prawn.text_box "#{mid}", at: [-14, mid_y], height: 5, overflow: :shrink_to_fit, width: 12, valign: :bottom, align: :right
308
- prawn.text_box "#{avg}", at: [-14, avg_y], height: 5, overflow: :shrink_to_fit, width: 12, valign: :bottom, align: :right
309
- prawn.text_box "#{min}", at: [-14, min_y], height: 5, overflow: :shrink_to_fit, width: 12, valign: :bottom, align: :right
306
+ prawn.text_box "#{max}", at: [-14, max_y], height: 5, overflow: :shrink_to_fit, width: 12, valign: :bottom, align: :right unless max.zero?
307
+ prawn.text_box "#{mid}", at: [-14, mid_y], height: 5, overflow: :shrink_to_fit, width: 12, valign: :bottom, align: :right unless mid.zero?
308
+ prawn.text_box "#{avg}", at: [-14, avg_y], height: 5, overflow: :shrink_to_fit, width: 12, valign: :bottom, align: :right unless avg.zero?
309
+ prawn.text_box "#{min}", at: [-14, min_y], height: 5, overflow: :shrink_to_fit, width: 12, valign: :bottom, align: :right unless min.zero?
310
310
 
311
311
  return if @canvas.options[:xaxis_labels].size.zero?
312
312
 
@@ -324,7 +324,9 @@ module Prawn
324
324
  # the series.
325
325
  #
326
326
  def point_height_percentage(value)
327
- ((BigDecimal(value, 10)/BigDecimal(@series.collect(&:max).max, 10)) * BigDecimal(1)).round(2)
327
+ pc = ((BigDecimal(value, 10)/BigDecimal(@series.collect(&:max).max, 10)) * BigDecimal(1)).round(2)
328
+ pc = 0 if pc.nan?
329
+ pc
328
330
  end
329
331
 
330
332
  def prawn
@@ -334,4 +336,4 @@ module Prawn
334
336
  end
335
337
  end
336
338
  end
337
- end
339
+ end
@@ -1,5 +1,5 @@
1
1
  module Prawn
2
2
  module Graph
3
- VERSION = "0.9.9"
3
+ VERSION = "0.9.10"
4
4
  end
5
5
  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: 0.9.9
4
+ version: 0.9.10
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-17 00:00:00.000000000 Z
12
+ date: 2016-07-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler