This repository has been archived by the owner on Dec 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
create_reference_images.rb
162 lines (134 loc) · 4.68 KB
/
create_reference_images.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
require 'spec_helper'
describe Rubyplot::Figure do
before do
@x1 = [1, 2, 3, 4, 5]
@y1 = [10, 20, 30, 40, 50]
@values = [0, 24, -12, 48]
@freqwise = [1, 2, 5, 6, 5, 9, 9, 1, 2, 9, 2, 6, 5]
@portfolio_names = ['Apples', 'Oranges', 'Bananas']
@portfolio = [20000, 8000, 34000]
end
context '#line' do
it 'creates a simple line graph' do
a = Rubyplot::Figure.new
a.line! @x1, @y1
a.save 'spec/reference_images/single_plot_graph/line_graph.bmp'
end
it 'creates a line graph with points marked' do
a = Rubyplot::Figure.new
a.line! @x1, @y1, marker_size: 1
a.save 'spec/reference_images/single_plot_graph/line_marker_graph.bmp'
end
it 'creates a red dashed line graph with points marked' do
a = Rubyplot::Figure.new
a.line! @x1, @y1, line_color: :red, line_type: :dashed
a.save 'spec/reference_images/single_plot_graph/dash_line_marker_graph.bmp'
end
end
context '#scatter' do
it 'creates a simple scatter graph' do
a = Rubyplot::Figure.new
a.scatter! @x1, @y1
a.save 'spec/reference_images/single_plot_graph/scatter_graph.bmp'
end
it 'creates a green cross scatter graph' do
a = Rubyplot::Figure.new
a.scatter! @x1, @y1, marker_color: :green, marker_size: 2,
marker_type: :diagonal_cross
a.save 'spec/reference_images/single_plot_graph/scatter_cross_graph.bmp'
end
end
context '#bar' do
it 'creates a simple bar graph' do
a = Rubyplot::Figure.new
a.bar! @values
a.save 'spec/reference_images/single_plot_graph/bar_graph.bmp'
end
it 'creates a bar graph with red color bars' do
a = Rubyplot::Figure.new
a.bar! @values, bar_color: :red
a.save 'spec/reference_images/single_plot_graph/red_bar_graph.bmp'
end
it 'creates a bar graph with orange color bars with spaces' do
a = Rubyplot::Figure.new
a.bar! @values, bar_color: :orange, bar_gap: 1
a.save 'spec/reference_images/single_plot_graph/blue_spaced_bar_graph.bmp'
end
end
context '#stacked_bar!' do
before do
@bars_data = [[12, 4, 53, 24],
[4, 34, 8, 25],
[20, 9, 31, 2],
[56, 12, 84, 30]]
end
it 'creates a stacked bar graph' do
a = Rubyplot::Figure.new
a.stacked_bar! @bars_data
a.save 'spec/reference_images/single_plot_graph/stacked_bar_graph.bmp'
end
it 'creates a stacked bar graph with user defined colors' do
a = Rubyplot::Figure.new
a.stacked_bar! @bars_data, bar_colors: [:black, :red, :green, :blue]
a.save 'spec/reference_images/single_plot_graph/user_color_stacked_bar_graph.bmp'
end
end
context '#line_plot!' do
it 'creates a simple line plot' do
a = Rubyplot::Figure.new
a.line_plot! @freqwise
a.save 'spec/reference_images/single_plot_graph/line_plot.bmp'
end
it 'creates a line plot with red markers' do
a = Rubyplot::Figure.new
a.line_plot! @values, marker_color: :red, marker_size: 2
a.save 'spec/reference_images/single_plot_graph/red_line_plot.bmp'
end
it 'creates a line plot with green solid bowtie markers' do
a = Rubyplot::Figure.new
a.line_plot! @values, marker_color: :green, marker_type: :solid_bowtie
a.save 'spec/reference_images/single_plot_graph/green _bowtie_line_plot.bmp'
end
end
context '#pie!' do
it 'creates a simple pie chart' do
a = Rubyplot::Figure.new
a.pie! @portfolio, @portfolio_names
a.save 'spec/reference_images/single_plot_graph/pie_chart.bmp'
end
end
context '#candlestick!' do
before do
@open = [10, 15, 24, 18]
@high = [20, 25, 30, 18]
@low = [5, 13, 15, 3]
@close = [15, 24, 18, 4]
# incoporate date ??
end
it 'creates a simple candle plot' do
a = Rubyplot::Figure.new
a.candlestick! @open, @high, @low, @close
a.save 'spec/reference_images/single_plot_graph/candlestick_plot.bmp'
end
it 'creates a candle plot with blue positive and black negative color' do
a = Rubyplot::Figure.new
a.candlestick! @open, @high, @low, @close, up_color: :blue, down_color: :black
a.save 'spec/reference_images/single_plot_graph/candlestick_diff_color_plot.bmp'
end
end
context '#line! #scatter!' do
before do
@x1 = [-10, 0, 5, 28]
@y1 = [1, 2, 3, 4]
@x2 = [2, 4, 16]
@y2 = [10, 20, -40]
end
it 'creates a line and scatter graph' do
a = Rubyplot::Figure.new
a.title = 'My cool graph'
a.line! @x1, @y1
a.scatter! @x2, @y2
a.save 'spec/reference_images/multi_plot_graph/line_scatter_graph.bmp'
end
end
end