prawn_charts 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (24) hide show
  1. data/lib/data_collectors/container/container_data_collector.rb +57 -55
  2. data/lib/data_collectors/container/graph_title_data_collector.rb +12 -10
  3. data/lib/data_collectors/graph/horizontal_lines_data_collector.rb +16 -14
  4. data/lib/data_collectors/graph/linear_y_pdf_data_collector.rb +17 -15
  5. data/lib/data_collectors/graph/log_y_pdf_data_collector.rb +16 -14
  6. data/lib/data_collectors/graph/pdf_data_collector.rb +20 -18
  7. data/lib/data_collectors/graph/x_labels_data_collector.rb +22 -20
  8. data/lib/data_collectors/graph/x_pdf_data_collector.rb +12 -10
  9. data/lib/data_collectors/graph/y_labels_data_collector.rb +27 -25
  10. data/lib/data_collectors/graph/y_pdf_data_collector.rb +17 -15
  11. data/lib/examples/log_example.rb +124 -122
  12. data/lib/examples/simple_linear_example.rb +56 -54
  13. data/lib/examples/simple_log_example.rb +56 -54
  14. data/lib/prawn_charts/version.rb +1 -1
  15. data/lib/renderers/prawn_chart_renderer.rb +21 -19
  16. data/spec/data_collectors/container/container_data_collector_spec.rb +43 -41
  17. data/spec/data_collectors/graph/horizontal_lines_data_collector_spec.rb +13 -11
  18. data/spec/data_collectors/graph/linear_y_pdf_data_collector_spec.rb +13 -11
  19. data/spec/data_collectors/graph/log_y_pdf_data_collector_spec.rb +19 -17
  20. data/spec/data_collectors/graph/pdf_data_collector_spec.rb +38 -36
  21. data/spec/data_collectors/graph/x_labels_data_collector_spec.rb +14 -12
  22. data/spec/data_collectors/graph/x_pdf_data_collector_spec.rb +15 -13
  23. data/spec/data_collectors/graph/y_labels_data_collector_spec.rb +15 -13
  24. metadata +1 -1
@@ -1,17 +1,19 @@
1
1
  require "spec_helper"
2
2
 
3
- describe HorizontalLinesDataCollector do
4
- before do
5
- graph_height_pdf = 60
6
- graph_width_pdf = 80
7
- y_labels = [0, 10, 100, 1_000, 10_000, 100_000, 1_000_000]
8
- @horizontal_lines_data_collector = HorizontalLinesDataCollector.new(graph_height_pdf, graph_width_pdf, y_labels)
9
- end
3
+ module PrawnCharts
4
+ describe HorizontalLinesDataCollector do
5
+ before do
6
+ graph_height_pdf = 60
7
+ graph_width_pdf = 80
8
+ y_labels = [0, 10, 100, 1_000, 10_000, 100_000, 1_000_000]
9
+ @horizontal_lines_data_collector = HorizontalLinesDataCollector.new(graph_height_pdf, graph_width_pdf, y_labels)
10
+ end
10
11
 
11
- context "#collect" do
12
- it "returns an array with the start, end, and y position of the horizontal lines" do
13
- expected = [[0, 80, 0.0], [0, 80, 10.0], [0, 80, 20.0], [0, 80, 30.0], [0, 80, 40.0], [0, 80, 50.0], [0, 80, 60.0]]
14
- expect(@horizontal_lines_data_collector.collect).to eq(expected)
12
+ context "#collect" do
13
+ it "returns an array with the start, end, and y position of the horizontal lines" do
14
+ expected = [[0, 80, 0.0], [0, 80, 10.0], [0, 80, 20.0], [0, 80, 30.0], [0, 80, 40.0], [0, 80, 50.0], [0, 80, 60.0]]
15
+ expect(@horizontal_lines_data_collector.collect).to eq(expected)
16
+ end
15
17
  end
16
18
  end
17
19
  end
@@ -1,17 +1,19 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe LinearYPdfDataCollector do
4
- before do
5
- input_data = [["Jan 11", 5], ["Feb 11", 2], ["Mar 11", 12]]
6
- graph_height_pdf = 160
7
- y_labels = [0, 4, 8, 12, 16]
8
- @linear_y_pdf_data_collector = LinearYPdfDataCollector.new(input_data, graph_height_pdf, y_labels)
9
- end
3
+ module PrawnCharts
4
+ describe LinearYPdfDataCollector do
5
+ before do
6
+ input_data = [["Jan 11", 5], ["Feb 11", 2], ["Mar 11", 12]]
7
+ graph_height_pdf = 160
8
+ y_labels = [0, 4, 8, 12, 16]
9
+ @linear_y_pdf_data_collector = LinearYPdfDataCollector.new(input_data, graph_height_pdf, y_labels)
10
+ end
10
11
 
11
- context "#collect" do
12
- it "returns an array of y values in pdf points" do
13
- expected = [50, 20, 120]
14
- expect(@linear_y_pdf_data_collector.collect).to eq(expected)
12
+ context "#collect" do
13
+ it "returns an array of y values in pdf points" do
14
+ expected = [50, 20, 120]
15
+ expect(@linear_y_pdf_data_collector.collect).to eq(expected)
16
+ end
15
17
  end
16
18
  end
17
19
  end
@@ -1,24 +1,26 @@
1
1
  require "spec_helper"
2
2
 
3
- describe LogYPdfDataCollector do
4
- before do
5
- @graph_height_pdf = 60
6
- @y_labels = [0, 10, 100, 1_000, 10_000, 100_000, 1_000_000]
7
- end
8
-
9
- context "#collect" do
10
- it "returns an array of [x_pdf, y_pdf] for all data points" do
11
- input_data = [["Jan 11", 5], ["Feb 11", 900], ["Mar 11", 800_000]]
12
- log_y_pdf_data_collector = LogYPdfDataCollector.new(input_data, @graph_height_pdf, @y_labels)
13
- expected = [10 * Math.log10(5), 10 * Math.log10(900), 10 * Math.log10(800_000)]
14
- expect(log_y_pdf_data_collector.collect).to eq(expected)
3
+ module PrawnCharts
4
+ describe LogYPdfDataCollector do
5
+ before do
6
+ @graph_height_pdf = 60
7
+ @y_labels = [0, 10, 100, 1_000, 10_000, 100_000, 1_000_000]
15
8
  end
16
9
 
17
- it "it returns nil when a value is nil" do
18
- input_data = [["Jan 11", 5], ["Feb 11", nil], ["Mar 11", 800_000]]
19
- log_y_pdf_data_collector = LogYPdfDataCollector.new(input_data, @graph_height_pdf, @y_labels)
20
- expected = [10 * Math.log10(5), nil, 10 * Math.log10(800_000)]
21
- expect(log_y_pdf_data_collector.collect).to eq(expected)
10
+ context "#collect" do
11
+ it "returns an array of [x_pdf, y_pdf] for all data points" do
12
+ input_data = [["Jan 11", 5], ["Feb 11", 900], ["Mar 11", 800_000]]
13
+ log_y_pdf_data_collector = LogYPdfDataCollector.new(input_data, @graph_height_pdf, @y_labels)
14
+ expected = [10 * Math.log10(5), 10 * Math.log10(900), 10 * Math.log10(800_000)]
15
+ expect(log_y_pdf_data_collector.collect).to eq(expected)
16
+ end
17
+
18
+ it "it returns nil when a value is nil" do
19
+ input_data = [["Jan 11", 5], ["Feb 11", nil], ["Mar 11", 800_000]]
20
+ log_y_pdf_data_collector = LogYPdfDataCollector.new(input_data, @graph_height_pdf, @y_labels)
21
+ expected = [10 * Math.log10(5), nil, 10 * Math.log10(800_000)]
22
+ expect(log_y_pdf_data_collector.collect).to eq(expected)
23
+ end
22
24
  end
23
25
  end
24
26
  end
@@ -1,47 +1,49 @@
1
1
  require "spec_helper"
2
2
 
3
- describe PdfDataCollector do
4
- context "linear" do
5
- before do
6
- scale = :linear
7
- input_data = [["Jan 11", 5], ["Feb 11", 2], ["Mar 11", 12]]
8
- graph_width_pdf = 100
9
- graph_height_pdf = 120
10
- y_labels = [0, 3, 6, 9, 12]
11
- @linear_pdf_data_collector = PdfDataCollector.new(scale, input_data, graph_width_pdf, graph_height_pdf, y_labels)
12
- end
3
+ module PrawnCharts
4
+ describe PdfDataCollector do
5
+ context "linear" do
6
+ before do
7
+ scale = :linear
8
+ input_data = [["Jan 11", 5], ["Feb 11", 2], ["Mar 11", 12]]
9
+ graph_width_pdf = 100
10
+ graph_height_pdf = 120
11
+ y_labels = [0, 3, 6, 9, 12]
12
+ @linear_pdf_data_collector = PdfDataCollector.new(scale, input_data, graph_width_pdf, graph_height_pdf, y_labels)
13
+ end
13
14
 
14
- it "returns an array of pdf points where line should be plotted" do
15
- expected = [[0, 50], [50, 20], [100, 120]]
16
- expect(@linear_pdf_data_collector.collect).to eq(expected)
15
+ it "returns an array of pdf points where line should be plotted" do
16
+ expected = [[0, 50], [50, 20], [100, 120]]
17
+ expect(@linear_pdf_data_collector.collect).to eq(expected)
18
+ end
17
19
  end
18
- end
19
20
 
20
- context "log" do
21
- before do
22
- scale = :log
23
- input_data = [["Jan 11", 5], ["Feb 11", 900], ["Mar 11", 800_000]]
24
- graph_width_pdf = 200
25
- graph_height_pdf = 120
26
- y_labels = [0, 10, 100, 1_000, 10_000, 100_000, 1_000_000]
27
- @log_pdf_data_collector = PdfDataCollector.new(scale, input_data, graph_width_pdf, graph_height_pdf, y_labels)
28
- end
21
+ context "log" do
22
+ before do
23
+ scale = :log
24
+ input_data = [["Jan 11", 5], ["Feb 11", 900], ["Mar 11", 800_000]]
25
+ graph_width_pdf = 200
26
+ graph_height_pdf = 120
27
+ y_labels = [0, 10, 100, 1_000, 10_000, 100_000, 1_000_000]
28
+ @log_pdf_data_collector = PdfDataCollector.new(scale, input_data, graph_width_pdf, graph_height_pdf, y_labels)
29
+ end
29
30
 
30
- it "returns an array of pdf points where line should be plotted" do
31
- expected = [[0.0, Math.log10(5) * 20], [100.0, Math.log10(900) * 20], [200.0, Math.log10(800_000) * 20]]
32
- expect(@log_pdf_data_collector.collect).to eq(expected)
31
+ it "returns an array of pdf points where line should be plotted" do
32
+ expected = [[0.0, Math.log10(5) * 20], [100.0, Math.log10(900) * 20], [200.0, Math.log10(800_000) * 20]]
33
+ expect(@log_pdf_data_collector.collect).to eq(expected)
34
+ end
33
35
  end
34
- end
35
36
 
36
- context "invalid scale input" do
37
- it "raises an error unless scale is :linear or :log" do
38
- scale = :phattie
39
- input_data = [["Jan 11", 5], ["Feb 11", 900], ["Mar 11", 800_000]]
40
- graph_width_pdf = 200
41
- graph_height_pdf = 120
42
- y_labels = [0, 10, 100, 1_000, 10_000, 100_000, 1_000_000]
43
- log_pdf_data_collector = PdfDataCollector.new(scale, input_data, graph_width_pdf, graph_height_pdf, y_labels)
44
- expect{log_pdf_data_collector.collect}.to raise_error(RuntimeError)
37
+ context "invalid scale input" do
38
+ it "raises an error unless scale is :linear or :log" do
39
+ scale = :phattie
40
+ input_data = [["Jan 11", 5], ["Feb 11", 900], ["Mar 11", 800_000]]
41
+ graph_width_pdf = 200
42
+ graph_height_pdf = 120
43
+ y_labels = [0, 10, 100, 1_000, 10_000, 100_000, 1_000_000]
44
+ log_pdf_data_collector = PdfDataCollector.new(scale, input_data, graph_width_pdf, graph_height_pdf, y_labels)
45
+ expect{log_pdf_data_collector.collect}.to raise_error(RuntimeError)
46
+ end
45
47
  end
46
48
  end
47
49
  end
@@ -1,18 +1,20 @@
1
1
  require "spec_helper"
2
2
 
3
- describe XLabelsDataCollector do
4
- before do
5
- input_data = [["Jan 11", 5], ["Feb 11", 2], ["Mar 11", 12]]
6
- graph_width_pdf = 160
7
- vertical_offset = 20
8
- label_width = 50
9
- @x_labels_data_collector = XLabelsDataCollector.new(input_data, graph_width_pdf, vertical_offset, label_width)
10
- end
3
+ module PrawnCharts
4
+ describe XLabelsDataCollector do
5
+ before do
6
+ input_data = [["Jan 11", 5], ["Feb 11", 2], ["Mar 11", 12]]
7
+ graph_width_pdf = 160
8
+ vertical_offset = 20
9
+ label_width = 50
10
+ @x_labels_data_collector = XLabelsDataCollector.new(input_data, graph_width_pdf, vertical_offset, label_width)
11
+ end
11
12
 
12
- context "#collect" do
13
- it "returns array of labels and [x, y] coordinate where the label should be plotted" do
14
- expected = [["Jan 11", [-25.0, -20]], ["Feb 11", [55.0, -20]], ["Mar 11", [135.0, -20]]]
15
- expect(@x_labels_data_collector.collect).to eq(expected)
13
+ context "#collect" do
14
+ it "returns array of labels and [x, y] coordinate where the label should be plotted" do
15
+ expected = [["Jan 11", [-25.0, -20]], ["Feb 11", [55.0, -20]], ["Mar 11", [135.0, -20]]]
16
+ expect(@x_labels_data_collector.collect).to eq(expected)
17
+ end
16
18
  end
17
19
  end
18
20
  end
@@ -1,21 +1,23 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe XPdfDataCollector do
4
- before do
5
- input_data = [["Jan 11", 5], ["Feb 11", 2], ["Mar 11", 12]]
6
- graph_width_pdf = 160
7
- @x_pdf_data_collector = XPdfDataCollector.new(input_data, graph_width_pdf)
8
- end
3
+ module PrawnCharts
4
+ describe XPdfDataCollector do
5
+ before do
6
+ input_data = [["Jan 11", 5], ["Feb 11", 2], ["Mar 11", 12]]
7
+ graph_width_pdf = 160
8
+ @x_pdf_data_collector = XPdfDataCollector.new(input_data, graph_width_pdf)
9
+ end
9
10
 
10
- context "#pdf_points_per_unit" do
11
- it "returns number of pdf points per unit on x axis" do
12
- expect(@x_pdf_data_collector.pdf_points_per_unit).to eq(80.0)
11
+ context "#pdf_points_per_unit" do
12
+ it "returns number of pdf points per unit on x axis" do
13
+ expect(@x_pdf_data_collector.pdf_points_per_unit).to eq(80.0)
14
+ end
13
15
  end
14
- end
15
16
 
16
- context "#collect" do
17
- it "returns an array of x pdf points" do
18
- expect(@x_pdf_data_collector.collect).to eq([0, 80, 160])
17
+ context "#collect" do
18
+ it "returns an array of x pdf points" do
19
+ expect(@x_pdf_data_collector.collect).to eq([0, 80, 160])
20
+ end
19
21
  end
20
22
  end
21
23
  end
@@ -1,19 +1,21 @@
1
1
  require "spec_helper"
2
2
 
3
- describe YLabelsDataCollector do
4
- before do
5
- y_labels = [0, 10, 100, 1_000, 10_000, 100_000, 1_000_000, 10_000_000]
6
- graph_height_pdf = 560
7
- label_width = 15
8
- label_height = 20
9
- y_label_offset = 30
10
- @y_data_collector = YLabelsDataCollector.new(y_labels, graph_height_pdf, label_width, label_height, y_label_offset)
11
- end
3
+ module PrawnCharts
4
+ describe YLabelsDataCollector do
5
+ before do
6
+ y_labels = [0, 10, 100, 1_000, 10_000, 100_000, 1_000_000, 10_000_000]
7
+ graph_height_pdf = 560
8
+ label_width = 15
9
+ label_height = 20
10
+ y_label_offset = 30
11
+ @y_data_collector = YLabelsDataCollector.new(y_labels, graph_height_pdf, label_width, label_height, y_label_offset)
12
+ end
12
13
 
13
- context "#collect" do
14
- it "returns an array of y_labels and points where they should be plotted" do
15
- expected = [["0", [-45, 10.0]], ["10", [-45, 90.0]], ["100", [-45, 170.0]], ["1,000", [-45, 250.0]], ["10,000", [-45, 330.0]], ["100,000", [-45, 410.0]], ["1,000,000", [-45, 490.0]], ["10,000,000", [-45, 570.0]]]
16
- expect(@y_data_collector.collect).to eq(expected)
14
+ context "#collect" do
15
+ it "returns an array of y_labels and points where they should be plotted" do
16
+ expected = [["0", [-45, 10.0]], ["10", [-45, 90.0]], ["100", [-45, 170.0]], ["1,000", [-45, 250.0]], ["10,000", [-45, 330.0]], ["100,000", [-45, 410.0]], ["1,000,000", [-45, 490.0]], ["10,000,000", [-45, 570.0]]]
17
+ expect(@y_data_collector.collect).to eq(expected)
18
+ end
17
19
  end
18
20
  end
19
21
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prawn_charts
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: