prawn-graph 0.9.4 → 0.9.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 33dd1aa4f0429ff97c4b3884a7015e9953fab007
4
- data.tar.gz: 6dc03f1716e431ff2f5a77c3ad537812d78ca1da
3
+ metadata.gz: d3612a0dc1901afe56dcc1c6f2c1679330bdf758
4
+ data.tar.gz: 716552d134c3cc1eb5bd10af28758bb62dbcaac8
5
5
  SHA512:
6
- metadata.gz: 729c459c07fa3c2be69f5b0b914e53834432b23d5255ca73efe983d4ff8728e3dc444d76b71e40005dfe9b8587d574988fc3172a4ca40be48e3076c56ed6fd73
7
- data.tar.gz: e1b4d17c28db4d882471cae5fe286624055fe863eb6b4eebaac4148a8900de89e6c435988925cb0ad6cc939965d34bd3f719c6b9563baf5baee7a70f566874ad
6
+ metadata.gz: 20fad935934c6be4e53733c510dd407cc53eb94981464afee7aa7152fc657709340b773e7bb50e3f4dbd1b2cde3f8888ec59f4433a9389d6da5daa0006cf73ae
7
+ data.tar.gz: a2dde074ccb358c88f342d9f59885e6f45c6e97e9434bb63eabaf133c1af0a8da272860aaa282d373a4d7d1f48a8d67b330b6c3790c619e8abb8a3eb8f45e7d7
data/README.md CHANGED
@@ -121,13 +121,15 @@ Option | Data type | Description
121
121
  require 'prawn-graph'
122
122
 
123
123
  series = []
124
- 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)
125
- 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, mark_minimum: true)
124
+ 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)
125
+ series << Prawn::Graph::Series.new([5,4,3,2,7,9,2,8,7,5,4,9,2], title: "Another label", type: :line, mark_average: true, mark_minimum: true)
126
126
  series << Prawn::Graph::Series.new([1,2,3,4,5,9,6,4,5,6,3,2,11], title: "Yet another label", type: :bar)
127
127
  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, mark_maximum: true)
128
128
 
129
+ xaxis_labels = ['0900', '1000', '1100', '1200', '1300', '1400', '1500', '1600', '1700', '1800', '1900', '2000', '2100']
130
+
129
131
  Prawn::Document.generate('test.pdf') do
130
- graph series, width: 500, height: 200, title: "A Title for the chart", at: [10,700]
132
+ graph series, width: 500, height: 200, title: "A Title for the chart", at: [10,700], xaxis_labels: xaxis_labels
131
133
  end
132
134
  ```
133
135
 
@@ -5,7 +5,7 @@ module Prawn
5
5
  # as the container in which your chart / graph will be sized to fit within.
6
6
  #
7
7
  class Canvas
8
- attr_reader :layout, :series, :prawn, :theme
8
+ attr_reader :layout, :series, :prawn, :theme, :options
9
9
 
10
10
  # @param series [Array[Prawn::Graph::Series]]
11
11
  # @param prawn [Prawn::Document]
@@ -15,7 +15,7 @@ module Prawn
15
15
  def initialize(series, prawn, options = {}, &block)
16
16
  @series = series
17
17
  verify_series_are_ok!
18
- @options = options.merge({ series_count: series.size })
18
+ @options = {xaxis_labels: []}.merge(options.merge({ series_count: series.size }))
19
19
  @prawn = prawn
20
20
  @theme = Prawn::Graph::Theme::Default
21
21
  @layout = Prawn::Graph::Calculations::LayoutCalculator.new([prawn.bounds.width, prawn.bounds.height], @options, @theme).calculate
@@ -145,6 +145,17 @@ module Prawn
145
145
  prawn.stroke_horizontal_line(0, @plot_area_width, at: 0)
146
146
  prawn.stroke_vertical_line(0, @plot_area_height, at: 0)
147
147
  prawn.fill_and_stroke_ellipse [ 0,0], 1
148
+
149
+ return if @canvas.options[:xaxis_labels].size.zero?
150
+
151
+ width_of_each_label = (@plot_area_width / @canvas.options[:xaxis_labels].size) - 1
152
+ @canvas.options[:xaxis_labels].each_with_index do |label, i|
153
+ offset = i + 1
154
+ position = ((offset * width_of_each_label) - width_of_each_label) + 1
155
+
156
+ prawn.text_box label, at: [ position, -2 ], width: width_of_each_label, height: 6, valign: :center, align: :right,
157
+ overflow: :shrink_to_fit
158
+ end
148
159
  end
149
160
 
150
161
  # Calculates the relative height of a given point based on the maximum value present in
@@ -266,6 +277,17 @@ module Prawn
266
277
  prawn.stroke_horizontal_line(0, @plot_area_width, at: 0)
267
278
  prawn.stroke_vertical_line(0, @plot_area_height, at: 0)
268
279
  prawn.fill_and_stroke_ellipse [ 0,0], 1
280
+
281
+ return if @canvas.options[:xaxis_labels].size.zero?
282
+
283
+ width_of_each_label = (@plot_area_width / @canvas.options[:xaxis_labels].size) - 1
284
+ @canvas.options[:xaxis_labels].each_with_index do |label, i|
285
+ offset = i + 1
286
+ position = ((offset * width_of_each_label) - width_of_each_label) + 1
287
+
288
+ prawn.text_box label, at: [ position, -2 ], width: width_of_each_label, height: 6, valign: :center, align: :right,
289
+ overflow: :shrink_to_fit
290
+ end
269
291
  end
270
292
 
271
293
  # Calculates the relative height of a given point based on the maximum value present in
@@ -1,5 +1,5 @@
1
1
  module Prawn
2
2
  module Graph
3
- VERSION = "0.9.4"
3
+ VERSION = "0.9.5"
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.4
4
+ version: 0.9.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Stenhouse