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.
- data/lib/data_collectors/container/container_data_collector.rb +57 -55
- data/lib/data_collectors/container/graph_title_data_collector.rb +12 -10
- data/lib/data_collectors/graph/horizontal_lines_data_collector.rb +16 -14
- data/lib/data_collectors/graph/linear_y_pdf_data_collector.rb +17 -15
- data/lib/data_collectors/graph/log_y_pdf_data_collector.rb +16 -14
- data/lib/data_collectors/graph/pdf_data_collector.rb +20 -18
- data/lib/data_collectors/graph/x_labels_data_collector.rb +22 -20
- data/lib/data_collectors/graph/x_pdf_data_collector.rb +12 -10
- data/lib/data_collectors/graph/y_labels_data_collector.rb +27 -25
- data/lib/data_collectors/graph/y_pdf_data_collector.rb +17 -15
- data/lib/examples/log_example.rb +124 -122
- data/lib/examples/simple_linear_example.rb +56 -54
- data/lib/examples/simple_log_example.rb +56 -54
- data/lib/prawn_charts/version.rb +1 -1
- data/lib/renderers/prawn_chart_renderer.rb +21 -19
- data/spec/data_collectors/container/container_data_collector_spec.rb +43 -41
- data/spec/data_collectors/graph/horizontal_lines_data_collector_spec.rb +13 -11
- data/spec/data_collectors/graph/linear_y_pdf_data_collector_spec.rb +13 -11
- data/spec/data_collectors/graph/log_y_pdf_data_collector_spec.rb +19 -17
- data/spec/data_collectors/graph/pdf_data_collector_spec.rb +38 -36
- data/spec/data_collectors/graph/x_labels_data_collector_spec.rb +14 -12
- data/spec/data_collectors/graph/x_pdf_data_collector_spec.rb +15 -13
- data/spec/data_collectors/graph/y_labels_data_collector_spec.rb +15 -13
- metadata +1 -1
@@ -1,17 +1,19 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
15
|
-
|
16
|
-
|
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
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
-
|
31
|
-
|
32
|
-
|
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
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
17
|
-
|
18
|
-
|
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
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|