prawn_charts 0.0.1 → 0.0.2

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.
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,131 +1,133 @@
1
1
  require_relative "./../prawn_charts"
2
2
 
3
- ##################################
4
- #Graph Data Collectors
5
- ##################################
6
- input_data = [["Apr-11", 5_000_000],
7
- ["May-11", nil],
8
- ["Jun-11", nil],
9
- ["Jul-11", nil],
10
- ["Aug-11", 1_000_000],
11
- ["Sep-11", nil],
12
- ["Oct-11", nil],
13
- ["Dec-11", 10_000],
14
- ["Jan-12", nil],
15
- ["Feb-12", nil],
16
- ["Mar-12", 150_000],
17
- ["Apr-12", nil],
18
- ["May-12", nil],
19
- ["Jun-12", 7_500_000]]
20
- scale = :log
21
- graph_height_pdf = 200
22
- graph_width_pdf = graph_height_pdf * 1.7
23
- dot_radius = 4
24
-
25
- x_label_width = 50
26
- x_label_height = 35
27
- x_label_text_box_options = { overflow: :shrink_to_fit, align: :center, rotate: 45 }
28
-
29
- y_labels = [0, 10, 100, 1_000, 10_000, 100_000, 1_000_000, 10_000_000]
30
- y_label_height = 30
31
- y_label_width = 65
32
- y_label_offset = 10
33
- y_label_text_box_options = { align: :right, valign: :center }
34
-
35
- graph_title_text = "Cool Prawn Graph"
36
- graph_title_height = 40
37
-
38
- y_title_width = 30
39
- y_title_text = "HCV Viral Load"
40
-
41
- x_title_height = 40
42
- x_title_text = "Month"
43
-
44
- pdf_data = PdfDataCollector.new(scale, input_data, graph_width_pdf, graph_height_pdf, y_labels).collect
45
- x_label_data = XLabelsDataCollector.new(input_data, graph_width_pdf, x_label_height, x_label_width).collect
46
- y_label_data = YLabelsDataCollector.new(y_labels, graph_height_pdf, y_label_width, y_label_height, y_label_offset).collect
47
- horizontal_lines_data = HorizontalLinesDataCollector.new(graph_height_pdf, graph_width_pdf, y_labels).collect
48
-
49
- ##################################
50
- #Container Data Collectors
51
- ##################################
52
-
53
- container_inputs = {
54
- container_left_padding: 0,
55
- y_label_offset: y_label_offset,
56
- y_label_width: y_label_width,
57
- y_title_width: y_title_width,
58
- container_right_padding: 20,
59
- container_top_padding: 20,
60
- graph_title_height: graph_title_height,
61
- container_bottom_padding: 0,
62
- x_label_height: x_label_height,
63
- x_title_height: x_title_height,
64
- graph_height: graph_height_pdf,
65
- graph_width: graph_width_pdf
66
- }
67
-
68
- container_data_collector = ContainerDataCollector.new(container_inputs)
69
-
70
- graph_title_position = container_data_collector.graph_title_top_left
71
- graph_title_options = { align: :center, valign: :center}
72
- graph_title_data = GraphTitleDataCollector.new(graph_title_text, graph_title_position, graph_title_height, graph_width_pdf).collect
73
-
74
- y_title_position = container_data_collector.y_title_top_left
75
- # specifying width is a temp hack solution because of a Prawn bug: https://github.com/prawnpdf/prawn/pull/505
76
- y_title_options = { align: :center, valign: :center, rotate: 90, rotate_around: :center, width: 65 }
77
- y_title_data = GraphTitleDataCollector.new(y_title_text, y_title_position, graph_height_pdf, y_title_width).collect
78
-
79
- x_title_position = container_data_collector.x_title_top_left
80
- x_title_options = { align: :center, valign: :center }
81
- x_title_data = GraphTitleDataCollector.new(x_title_text, x_title_position, x_title_height, graph_width_pdf).collect
82
-
83
- graph_top_left = container_data_collector.graph_top_left
84
-
85
- ##################################
86
- #Colors
87
- ##################################
88
-
89
- orange = "D95D2E"
90
- green = "62C545"
91
- light_blue = "EDF1F7"
92
- white = "FFFFFF"
93
- black = "000000"
94
-
95
- ##################################
96
- #Create PDF
97
- ##################################
98
-
99
- Prawn::Document.extensions << PrawnChartRenderer
100
-
101
- pdf = Prawn::Document.new
102
- pdf.bounding_box([0, pdf.cursor], :width => container_data_collector.width, :height => container_data_collector.height) do
103
- pdf.stroke_bounds
104
- pdf.fill_color = light_blue
105
- pdf.fill_rectangle([0, pdf.cursor], container_data_collector.width, container_data_collector.height)
106
- pdf.fill_color = black
107
-
108
- pdf.draw_title(graph_title_data, graph_title_options)
109
- pdf.draw_title(y_title_data, y_title_options)
110
- pdf.draw_title(x_title_data, x_title_options)
111
-
112
- pdf.bounding_box(container_data_collector.graph_top_left, :width => graph_width_pdf, :height => graph_height_pdf) do
3
+ module PrawnCharts
4
+ ##################################
5
+ #Graph Data Collectors
6
+ ##################################
7
+ input_data = [["Apr-11", 5_000_000],
8
+ ["May-11", nil],
9
+ ["Jun-11", nil],
10
+ ["Jul-11", nil],
11
+ ["Aug-11", 1_000_000],
12
+ ["Sep-11", nil],
13
+ ["Oct-11", nil],
14
+ ["Dec-11", 10_000],
15
+ ["Jan-12", nil],
16
+ ["Feb-12", nil],
17
+ ["Mar-12", 150_000],
18
+ ["Apr-12", nil],
19
+ ["May-12", nil],
20
+ ["Jun-12", 7_500_000]]
21
+ scale = :log
22
+ graph_height_pdf = 200
23
+ graph_width_pdf = graph_height_pdf * 1.7
24
+ dot_radius = 4
25
+
26
+ x_label_width = 50
27
+ x_label_height = 35
28
+ x_label_text_box_options = { overflow: :shrink_to_fit, align: :center, rotate: 45 }
29
+
30
+ y_labels = [0, 10, 100, 1_000, 10_000, 100_000, 1_000_000, 10_000_000]
31
+ y_label_height = 30
32
+ y_label_width = 65
33
+ y_label_offset = 10
34
+ y_label_text_box_options = { align: :right, valign: :center }
35
+
36
+ graph_title_text = "Cool Prawn Graph"
37
+ graph_title_height = 40
38
+
39
+ y_title_width = 30
40
+ y_title_text = "HCV Viral Load"
41
+
42
+ x_title_height = 40
43
+ x_title_text = "Month"
44
+
45
+ pdf_data = PdfDataCollector.new(scale, input_data, graph_width_pdf, graph_height_pdf, y_labels).collect
46
+ x_label_data = XLabelsDataCollector.new(input_data, graph_width_pdf, x_label_height, x_label_width).collect
47
+ y_label_data = YLabelsDataCollector.new(y_labels, graph_height_pdf, y_label_width, y_label_height, y_label_offset).collect
48
+ horizontal_lines_data = HorizontalLinesDataCollector.new(graph_height_pdf, graph_width_pdf, y_labels).collect
49
+
50
+ ##################################
51
+ #Container Data Collectors
52
+ ##################################
53
+
54
+ container_inputs = {
55
+ container_left_padding: 0,
56
+ y_label_offset: y_label_offset,
57
+ y_label_width: y_label_width,
58
+ y_title_width: y_title_width,
59
+ container_right_padding: 20,
60
+ container_top_padding: 20,
61
+ graph_title_height: graph_title_height,
62
+ container_bottom_padding: 0,
63
+ x_label_height: x_label_height,
64
+ x_title_height: x_title_height,
65
+ graph_height: graph_height_pdf,
66
+ graph_width: graph_width_pdf
67
+ }
68
+
69
+ container_data_collector = ContainerDataCollector.new(container_inputs)
70
+
71
+ graph_title_position = container_data_collector.graph_title_top_left
72
+ graph_title_options = { align: :center, valign: :center}
73
+ graph_title_data = GraphTitleDataCollector.new(graph_title_text, graph_title_position, graph_title_height, graph_width_pdf).collect
74
+
75
+ y_title_position = container_data_collector.y_title_top_left
76
+ # specifying width is a temp hack solution because of a Prawn bug: https://github.com/prawnpdf/prawn/pull/505
77
+ y_title_options = { align: :center, valign: :center, rotate: 90, rotate_around: :center, width: 65 }
78
+ y_title_data = GraphTitleDataCollector.new(y_title_text, y_title_position, graph_height_pdf, y_title_width).collect
79
+
80
+ x_title_position = container_data_collector.x_title_top_left
81
+ x_title_options = { align: :center, valign: :center }
82
+ x_title_data = GraphTitleDataCollector.new(x_title_text, x_title_position, x_title_height, graph_width_pdf).collect
83
+
84
+ graph_top_left = container_data_collector.graph_top_left
85
+
86
+ ##################################
87
+ #Colors
88
+ ##################################
89
+
90
+ orange = "D95D2E"
91
+ green = "62C545"
92
+ light_blue = "EDF1F7"
93
+ white = "FFFFFF"
94
+ black = "000000"
95
+
96
+ ##################################
97
+ #Create PDF
98
+ ##################################
99
+
100
+ Prawn::Document.extensions << PrawnChartRenderer
101
+
102
+ pdf = Prawn::Document.new
103
+ pdf.bounding_box([0, pdf.cursor], :width => container_data_collector.width, :height => container_data_collector.height) do
113
104
  pdf.stroke_bounds
114
- pdf.fill_color = white
115
- pdf.fill_rectangle([0, pdf.cursor], graph_width_pdf, graph_height_pdf)
105
+ pdf.fill_color = light_blue
106
+ pdf.fill_rectangle([0, pdf.cursor], container_data_collector.width, container_data_collector.height)
107
+ pdf.fill_color = black
116
108
 
117
- pdf.stroke_color = green
118
- pdf.draw_chart(pdf_data)
119
- pdf.fill_color = orange
120
- pdf.draw_dots(pdf_data, dot_radius)
109
+ pdf.draw_title(graph_title_data, graph_title_options)
110
+ pdf.draw_title(y_title_data, y_title_options)
111
+ pdf.draw_title(x_title_data, x_title_options)
121
112
 
122
- pdf.fill_color = black
123
- pdf.draw_labels(x_label_data, x_label_width, x_label_height, x_label_text_box_options)
113
+ pdf.bounding_box(container_data_collector.graph_top_left, :width => graph_width_pdf, :height => graph_height_pdf) do
114
+ pdf.stroke_bounds
115
+ pdf.fill_color = white
116
+ pdf.fill_rectangle([0, pdf.cursor], graph_width_pdf, graph_height_pdf)
117
+
118
+ pdf.stroke_color = green
119
+ pdf.draw_chart(pdf_data)
120
+ pdf.fill_color = orange
121
+ pdf.draw_dots(pdf_data, dot_radius)
122
+
123
+ pdf.fill_color = black
124
+ pdf.draw_labels(x_label_data, x_label_width, x_label_height, x_label_text_box_options)
124
125
 
125
- pdf.draw_labels(y_label_data, y_label_width, y_label_height, y_label_text_box_options)
126
+ pdf.draw_labels(y_label_data, y_label_width, y_label_height, y_label_text_box_options)
126
127
 
127
- pdf.stroke_color = black
128
- pdf.draw_horizontal_lines(horizontal_lines_data)
128
+ pdf.stroke_color = black
129
+ pdf.draw_horizontal_lines(horizontal_lines_data)
130
+ end
129
131
  end
132
+ pdf.render_file(Dir.home + "/desktop/log_prawn_graph.pdf")
130
133
  end
131
- pdf.render_file(Dir.home + "/desktop/log_prawn_graph.pdf")
@@ -1,57 +1,59 @@
1
1
  require_relative "./../prawn_charts"
2
2
 
3
- ##################################
4
- #Graph Data Collectors
5
- ##################################
6
- input_data = [["Apr-11", 10],
7
- ["May-11", 30],
8
- ["Jun-11", 50],
9
- ["Jul-11", 3],
10
- ["Aug-11", 40],
11
- ["Sep-11", nil],
12
- ["Oct-11", nil],
13
- ["Dec-11", 100],
14
- ["Jan-12", nil],
15
- ["Feb-12", nil],
16
- ["Mar-12", 5],
17
- ["Apr-12", nil],
18
- ["May-12", nil],
19
- ["Jun-12", 75]]
20
- scale = :linear
21
- graph_height_pdf = 200
22
- graph_width_pdf = graph_height_pdf * 1.7
23
- dot_radius = 4
24
-
25
- x_label_width = 50
26
- x_label_height = 35
27
- x_label_text_box_options = { overflow: :shrink_to_fit, align: :center, rotate: 45 }
28
-
29
- y_labels = [0, 25, 50, 75, 100, 125]
30
- y_label_height = 30
31
- y_label_width = 65
32
- y_label_offset = 10
33
- y_label_text_box_options = { align: :right, valign: :center }
34
-
35
- pdf_data = PdfDataCollector.new(scale, input_data, graph_width_pdf, graph_height_pdf, y_labels).collect
36
- x_label_data = XLabelsDataCollector.new(input_data, graph_width_pdf, x_label_height, x_label_width).collect
37
- y_label_data = YLabelsDataCollector.new(y_labels, graph_height_pdf, y_label_width, y_label_height, y_label_offset).collect
38
- horizontal_lines_data = HorizontalLinesDataCollector.new(graph_height_pdf, graph_width_pdf, y_labels).collect
39
-
40
- ##################################
41
- #Create PDF
42
- ##################################
43
-
44
- Prawn::Document.extensions << PrawnChartRenderer
45
-
46
- pdf = Prawn::Document.new
47
-
48
- pdf.bounding_box([50, pdf.cursor], :width => graph_width_pdf, :height => graph_height_pdf) do
49
- pdf.stroke_bounds
50
- pdf.draw_chart(pdf_data)
51
- pdf.draw_dots(pdf_data, dot_radius)
52
- pdf.draw_labels(x_label_data, x_label_width, x_label_height, x_label_text_box_options)
53
- pdf.draw_labels(y_label_data, y_label_width, y_label_height, y_label_text_box_options)
54
- pdf.draw_horizontal_lines(horizontal_lines_data)
3
+ module PrawnCharts
4
+ ##################################
5
+ #Graph Data Collectors
6
+ ##################################
7
+ input_data = [["Apr-11", 10],
8
+ ["May-11", 30],
9
+ ["Jun-11", 50],
10
+ ["Jul-11", 3],
11
+ ["Aug-11", 40],
12
+ ["Sep-11", nil],
13
+ ["Oct-11", nil],
14
+ ["Dec-11", 100],
15
+ ["Jan-12", nil],
16
+ ["Feb-12", nil],
17
+ ["Mar-12", 5],
18
+ ["Apr-12", nil],
19
+ ["May-12", nil],
20
+ ["Jun-12", 75]]
21
+ scale = :linear
22
+ graph_height_pdf = 200
23
+ graph_width_pdf = graph_height_pdf * 1.7
24
+ dot_radius = 4
25
+
26
+ x_label_width = 50
27
+ x_label_height = 35
28
+ x_label_text_box_options = { overflow: :shrink_to_fit, align: :center, rotate: 45 }
29
+
30
+ y_labels = [0, 25, 50, 75, 100, 125]
31
+ y_label_height = 30
32
+ y_label_width = 65
33
+ y_label_offset = 10
34
+ y_label_text_box_options = { align: :right, valign: :center }
35
+
36
+ pdf_data = PdfDataCollector.new(scale, input_data, graph_width_pdf, graph_height_pdf, y_labels).collect
37
+ x_label_data = XLabelsDataCollector.new(input_data, graph_width_pdf, x_label_height, x_label_width).collect
38
+ y_label_data = YLabelsDataCollector.new(y_labels, graph_height_pdf, y_label_width, y_label_height, y_label_offset).collect
39
+ horizontal_lines_data = HorizontalLinesDataCollector.new(graph_height_pdf, graph_width_pdf, y_labels).collect
40
+
41
+ ##################################
42
+ #Create PDF
43
+ ##################################
44
+
45
+ Prawn::Document.extensions << PrawnChartRenderer
46
+
47
+ pdf = Prawn::Document.new
48
+
49
+ pdf.bounding_box([50, pdf.cursor], :width => graph_width_pdf, :height => graph_height_pdf) do
50
+ pdf.stroke_bounds
51
+ pdf.draw_chart(pdf_data)
52
+ pdf.draw_dots(pdf_data, dot_radius)
53
+ pdf.draw_labels(x_label_data, x_label_width, x_label_height, x_label_text_box_options)
54
+ pdf.draw_labels(y_label_data, y_label_width, y_label_height, y_label_text_box_options)
55
+ pdf.draw_horizontal_lines(horizontal_lines_data)
56
+ end
57
+
58
+ pdf.render_file(Dir.home + "/desktop/simple_linear_prawn_graph.pdf")
55
59
  end
56
-
57
- pdf.render_file(Dir.home + "/desktop/simple_linear_prawn_graph.pdf")
@@ -1,57 +1,59 @@
1
1
  require_relative "./../prawn_charts"
2
2
 
3
- ##################################
4
- #Graph Data Collectors
5
- ##################################
6
- input_data = [["Apr-11", 5_000_000],
7
- ["May-11", nil],
8
- ["Jun-11", nil],
9
- ["Jul-11", nil],
10
- ["Aug-11", 1_000_000],
11
- ["Sep-11", nil],
12
- ["Oct-11", nil],
13
- ["Dec-11", 10_000],
14
- ["Jan-12", nil],
15
- ["Feb-12", nil],
16
- ["Mar-12", 150_000],
17
- ["Apr-12", nil],
18
- ["May-12", nil],
19
- ["Jun-12", 7_500_000]]
20
- scale = :log
21
- graph_height_pdf = 200
22
- graph_width_pdf = graph_height_pdf * 1.7
23
- dot_radius = 4
24
-
25
- x_label_width = 50
26
- x_label_height = 35
27
- x_label_text_box_options = { overflow: :shrink_to_fit, align: :center, rotate: 45 }
28
-
29
- y_labels = [0, 10, 100, 1_000, 10_000, 100_000, 1_000_000, 10_000_000]
30
- y_label_height = 30
31
- y_label_width = 65
32
- y_label_offset = 10
33
- y_label_text_box_options = { align: :right, valign: :center }
34
-
35
- pdf_data = PdfDataCollector.new(scale, input_data, graph_width_pdf, graph_height_pdf, y_labels).collect
36
- x_label_data = XLabelsDataCollector.new(input_data, graph_width_pdf, x_label_height, x_label_width).collect
37
- y_label_data = YLabelsDataCollector.new(y_labels, graph_height_pdf, y_label_width, y_label_height, y_label_offset).collect
38
- horizontal_lines_data = HorizontalLinesDataCollector.new(graph_height_pdf, graph_width_pdf, y_labels).collect
39
-
40
- ##################################
41
- #Create PDF
42
- ##################################
43
-
44
- Prawn::Document.extensions << PrawnChartRenderer
45
-
46
- pdf = Prawn::Document.new
47
-
48
- pdf.bounding_box([50, pdf.cursor], :width => graph_width_pdf, :height => graph_height_pdf) do
49
- pdf.stroke_bounds
50
- pdf.draw_chart(pdf_data)
51
- pdf.draw_dots(pdf_data, dot_radius)
52
- pdf.draw_labels(x_label_data, x_label_width, x_label_height, x_label_text_box_options)
53
- pdf.draw_labels(y_label_data, y_label_width, y_label_height, y_label_text_box_options)
54
- pdf.draw_horizontal_lines(horizontal_lines_data)
3
+ module PrawnCharts
4
+ ##################################
5
+ #Graph Data Collectors
6
+ ##################################
7
+ input_data = [["Apr-11", 5_000_000],
8
+ ["May-11", nil],
9
+ ["Jun-11", nil],
10
+ ["Jul-11", nil],
11
+ ["Aug-11", 1_000_000],
12
+ ["Sep-11", nil],
13
+ ["Oct-11", nil],
14
+ ["Dec-11", 10_000],
15
+ ["Jan-12", nil],
16
+ ["Feb-12", nil],
17
+ ["Mar-12", 150_000],
18
+ ["Apr-12", nil],
19
+ ["May-12", nil],
20
+ ["Jun-12", 7_500_000]]
21
+ scale = :log
22
+ graph_height_pdf = 200
23
+ graph_width_pdf = graph_height_pdf * 1.7
24
+ dot_radius = 4
25
+
26
+ x_label_width = 50
27
+ x_label_height = 35
28
+ x_label_text_box_options = { overflow: :shrink_to_fit, align: :center, rotate: 45 }
29
+
30
+ y_labels = [0, 10, 100, 1_000, 10_000, 100_000, 1_000_000, 10_000_000]
31
+ y_label_height = 30
32
+ y_label_width = 65
33
+ y_label_offset = 10
34
+ y_label_text_box_options = { align: :right, valign: :center }
35
+
36
+ pdf_data = PdfDataCollector.new(scale, input_data, graph_width_pdf, graph_height_pdf, y_labels).collect
37
+ x_label_data = XLabelsDataCollector.new(input_data, graph_width_pdf, x_label_height, x_label_width).collect
38
+ y_label_data = YLabelsDataCollector.new(y_labels, graph_height_pdf, y_label_width, y_label_height, y_label_offset).collect
39
+ horizontal_lines_data = HorizontalLinesDataCollector.new(graph_height_pdf, graph_width_pdf, y_labels).collect
40
+
41
+ ##################################
42
+ #Create PDF
43
+ ##################################
44
+
45
+ Prawn::Document.extensions << PrawnChartRenderer
46
+
47
+ pdf = Prawn::Document.new
48
+
49
+ pdf.bounding_box([50, pdf.cursor], :width => graph_width_pdf, :height => graph_height_pdf) do
50
+ pdf.stroke_bounds
51
+ pdf.draw_chart(pdf_data)
52
+ pdf.draw_dots(pdf_data, dot_radius)
53
+ pdf.draw_labels(x_label_data, x_label_width, x_label_height, x_label_text_box_options)
54
+ pdf.draw_labels(y_label_data, y_label_width, y_label_height, y_label_text_box_options)
55
+ pdf.draw_horizontal_lines(horizontal_lines_data)
56
+ end
57
+
58
+ pdf.render_file(Dir.home + "/desktop/simple_log_prawn_graph.pdf")
55
59
  end
56
-
57
- pdf.render_file(Dir.home + "/desktop/simple_log_prawn_graph.pdf")
@@ -1,3 +1,3 @@
1
1
  module PrawnCharts
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,29 +1,31 @@
1
- module PrawnChartRenderer
2
- def draw_chart(pdf_data)
3
- pdf_data.each_index do |i|
4
- stroke_line(pdf_data[i], pdf_data[i + 1]) unless pdf_data[i + 1].nil?
1
+ module PrawnCharts
2
+ module PrawnChartRenderer
3
+ def draw_chart(pdf_data)
4
+ pdf_data.each_index do |i|
5
+ stroke_line(pdf_data[i], pdf_data[i + 1]) unless pdf_data[i + 1].nil?
6
+ end
5
7
  end
6
- end
7
8
 
8
- def draw_dots(pdf_data, dot_radius)
9
- pdf_data.each do |point|
10
- fill_circle(point, dot_radius)
9
+ def draw_dots(pdf_data, dot_radius)
10
+ pdf_data.each do |point|
11
+ fill_circle(point, dot_radius)
12
+ end
11
13
  end
12
- end
13
14
 
14
- def draw_horizontal_lines(horizontal_lines_data)
15
- horizontal_lines_data.each do |start_x, end_x, y|
16
- stroke_horizontal_line start_x, end_x, at: y
15
+ def draw_horizontal_lines(horizontal_lines_data)
16
+ horizontal_lines_data.each do |start_x, end_x, y|
17
+ stroke_horizontal_line start_x, end_x, at: y
18
+ end
17
19
  end
18
- end
19
20
 
20
- def draw_labels(label_data, width, height, options = {})
21
- label_data.each do |label, pdf_point|
22
- text_box(label, { at: pdf_point, width: width, height: height }.merge(options))
21
+ def draw_labels(label_data, width, height, options = {})
22
+ label_data.each do |label, pdf_point|
23
+ text_box(label, { at: pdf_point, width: width, height: height }.merge(options))
24
+ end
23
25
  end
24
- end
25
26
 
26
- def draw_title(inputs, options = {})
27
- text_box(inputs[:title], { at: inputs[:at], width: inputs[:width], height: inputs[:height] }.merge(options))
27
+ def draw_title(inputs, options = {})
28
+ text_box(inputs[:title], { at: inputs[:at], width: inputs[:width], height: inputs[:height] }.merge(options))
29
+ end
28
30
  end
29
31
  end
@@ -1,57 +1,59 @@
1
1
  require "spec_helper"
2
2
 
3
- describe ContainerDataCollector do
4
- before do
5
- container_inputs = {
6
- container_left_padding: 7,
7
- y_label_offset: 50,
8
- y_label_width: 25,
9
- y_title_width: 30,
10
- container_right_padding: 20,
11
- container_top_padding: 9,
12
- graph_title_height: 25,
13
- container_bottom_padding: 40,
14
- x_label_height: 22,
15
- x_title_height: 43,
16
- graph_height: 400,
17
- graph_width: 500
18
- }
19
- @container_data_collector = ContainerDataCollector.new(container_inputs)
20
- end
3
+ module PrawnCharts
4
+ describe ContainerDataCollector do
5
+ before do
6
+ container_inputs = {
7
+ container_left_padding: 7,
8
+ y_label_offset: 50,
9
+ y_label_width: 25,
10
+ y_title_width: 30,
11
+ container_right_padding: 20,
12
+ container_top_padding: 9,
13
+ graph_title_height: 25,
14
+ container_bottom_padding: 40,
15
+ x_label_height: 22,
16
+ x_title_height: 43,
17
+ graph_height: 400,
18
+ graph_width: 500
19
+ }
20
+ @container_data_collector = ContainerDataCollector.new(container_inputs)
21
+ end
21
22
 
22
- context "#height" do
23
- it "returns the pdf_height of the graph container" do
24
- expect(@container_data_collector.height).to eq(539)
23
+ context "#height" do
24
+ it "returns the pdf_height of the graph container" do
25
+ expect(@container_data_collector.height).to eq(539)
26
+ end
25
27
  end
26
- end
27
28
 
28
- context "#width" do
29
- it "returns the pdf_width of the graph container" do
30
- expect(@container_data_collector.width).to eq(632)
29
+ context "#width" do
30
+ it "returns the pdf_width of the graph container" do
31
+ expect(@container_data_collector.width).to eq(632)
32
+ end
31
33
  end
32
- end
33
34
 
34
- context "#graph_top_left_corner" do
35
- it "returns the point for the top-left corner of the graph" do
36
- expect(@container_data_collector.graph_top_left).to eq([112, 505])
35
+ context "#graph_top_left_corner" do
36
+ it "returns the point for the top-left corner of the graph" do
37
+ expect(@container_data_collector.graph_top_left).to eq([112, 505])
38
+ end
37
39
  end
38
- end
39
40
 
40
- context "#graph_title_top_left" do
41
- it "returns x, y coordinate for placement of graph title" do
42
- expect(@container_data_collector.graph_title_top_left).to eq([112, 530])
41
+ context "#graph_title_top_left" do
42
+ it "returns x, y coordinate for placement of graph title" do
43
+ expect(@container_data_collector.graph_title_top_left).to eq([112, 530])
44
+ end
43
45
  end
44
- end
45
46
 
46
- context "#y_title_top_left" do
47
- it "returns x, y coordinate for placement of y title" do
48
- expect(@container_data_collector.y_title_top_left).to eq([7, 505])
47
+ context "#y_title_top_left" do
48
+ it "returns x, y coordinate for placement of y title" do
49
+ expect(@container_data_collector.y_title_top_left).to eq([7, 505])
50
+ end
49
51
  end
50
- end
51
52
 
52
- context "#x_title_top_left" do
53
- it "returns x, y coordinate for placement of x title" do
54
- expect(@container_data_collector.x_title_top_left).to eq([112, 83])
53
+ context "#x_title_top_left" do
54
+ it "returns x, y coordinate for placement of x title" do
55
+ expect(@container_data_collector.x_title_top_left).to eq([112, 83])
56
+ end
55
57
  end
56
58
  end
57
59
  end