rust 0.11 → 0.13

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.
@@ -0,0 +1,83 @@
1
+ require_relative 'core'
2
+
3
+ module Rust::Plots::GGPlot
4
+ class Geom < Layer
5
+ def initialize(type, arguments = [], **options)
6
+ super("geom_#{type}", **options)
7
+ @type = type
8
+ @arguments = Rust::Arguments.new(arguments)
9
+ end
10
+ end
11
+
12
+ class GeomPoint < Geom
13
+ def initialize(arguments = [], **options)
14
+ super("point", arguments, **options)
15
+ end
16
+ end
17
+
18
+ class GeomLine < Geom
19
+ def initialize(arguments = [], **options)
20
+ super("line", arguments, **options)
21
+ end
22
+ end
23
+
24
+ class GeomCol < Geom
25
+ def initialize(arguments = [], **options)
26
+ super("col", arguments, **options)
27
+ end
28
+ end
29
+
30
+ class GeomBoxplot < Geom
31
+ def initialize(arguments = [], **options)
32
+ super("boxplot", arguments, **options)
33
+ end
34
+ end
35
+
36
+ class GeomBar < Geom
37
+ def initialize(arguments = [], **options)
38
+ super("bar", arguments, **options)
39
+ end
40
+ end
41
+
42
+ class GeomHistogram < Geom
43
+ def initialize(arguments = [], **options)
44
+ super("histogram", arguments, **options)
45
+ end
46
+ end
47
+
48
+ class GeomDensity < Geom
49
+ def initialize(arguments = [], **options)
50
+ super("density", arguments, **options)
51
+ end
52
+ end
53
+ end
54
+
55
+ module Rust::RBindings
56
+ def geom_point(*arguments, **options)
57
+ return Rust::Plots::GGPlot::GeomPoint.new(*arguments, **options)
58
+ end
59
+
60
+ def geom_line(*arguments, **options)
61
+ return Rust::Plots::GGPlot::GeomLine.new(*arguments, **options)
62
+ end
63
+
64
+ def geom_col(*arguments, **options)
65
+ return Rust::Plots::GGPlot::GeomCol.new(*arguments, **options)
66
+ end
67
+
68
+ def geom_bar(*arguments, **options)
69
+ return Rust::Plots::GGPlot::GeomBar.new(*arguments, **options)
70
+ end
71
+
72
+ def geom_boxplot(*arguments, **options)
73
+ return Rust::Plots::GGPlot::GeomBoxplot.new(*arguments, **options)
74
+ end
75
+
76
+ def geom_histogram(*arguments, **options)
77
+ return Rust::Plots::GGPlot::GeomHistogram.new(*arguments, **options)
78
+ end
79
+
80
+ def geom_density(*arguments, **options)
81
+ return Rust::Plots::GGPlot::GeomDensity.new(*arguments, **options)
82
+ end
83
+ end
@@ -0,0 +1,292 @@
1
+ require_relative 'core'
2
+
3
+ Rust.prerequisite("ggplot2")
4
+
5
+ module Rust::Plots::GGPlot
6
+ class PlotBuilder
7
+ def self.for_dataframe(data_frame)
8
+ return PlotBuilder.new(data_frame)
9
+ end
10
+
11
+ def initialize(data=nil)
12
+ @data = data
13
+
14
+ @aes_options = {}
15
+ @label_options = {}
16
+
17
+ @current_context = :title
18
+
19
+ @layers = []
20
+ end
21
+
22
+ def with_x(variable, label = nil)
23
+ variable = variable.to_sym if variable.is_a?(String)
24
+
25
+ @aes_options[:x] = variable
26
+ @current_context = :x
27
+
28
+ return self
29
+ end
30
+
31
+ def with_y(variable)
32
+ variable = variable.to_sym if variable.is_a?(String)
33
+
34
+ @aes_options[:y] = variable
35
+ @current_context = :y
36
+
37
+ return self
38
+ end
39
+
40
+ def with_group(variable)
41
+ variable = variable.to_sym if variable.is_a?(String)
42
+
43
+ @aes_options[:group] = variable
44
+ @current_context = :group
45
+
46
+ return self
47
+ end
48
+
49
+ def with_color(variable)
50
+ variable = variable.to_sym if variable.is_a?(String)
51
+
52
+ @aes_options[:color] = variable
53
+ @current_context = :color
54
+
55
+ return self
56
+ end
57
+
58
+ def with_fill(variable)
59
+ variable = variable.to_sym if variable.is_a?(String)
60
+
61
+ @aes_options[:fill] = variable
62
+ @current_context = :fill
63
+
64
+ return self
65
+ end
66
+
67
+ def with_x_label(value)
68
+ @label_options[:x] = value
69
+
70
+ return self
71
+ end
72
+
73
+ def with_y_label(value)
74
+ @label_options[:y] = value
75
+
76
+ return self
77
+ end
78
+
79
+ def with_color_label(value)
80
+ @label_options[:color] = value
81
+
82
+ return self
83
+ end
84
+
85
+ def scale_x_continuous(**options)
86
+ raise "No context for assigning a label" unless @current_context
87
+ @layers << AxisScaler.new(:x, :continuous, **options)
88
+
89
+ return self
90
+ end
91
+
92
+ def scale_y_continuous(**options)
93
+ raise "No context for assigning a label" unless @current_context
94
+ @layers << AxisScaler.new(:y, :continuous, **options)
95
+
96
+ return self
97
+ end
98
+
99
+ def scale_x_discrete(**options)
100
+ raise "No context for assigning a label" unless @current_context
101
+ @layers << AxisScaler.new(:x, :discrete, **options)
102
+
103
+ return self
104
+ end
105
+
106
+ def scale_y_discrete(**options)
107
+ raise "No context for assigning a label" unless @current_context
108
+ @layers << AxisScaler.new(:y, :discrete, **options)
109
+
110
+ return self
111
+ end
112
+
113
+ def scale_x_log10(**options)
114
+ raise "No context for assigning a label" unless @current_context
115
+ @layers << AxisScaler.new(:x, :log10, **options)
116
+
117
+ return self
118
+ end
119
+
120
+ def scale_y_log10(**options)
121
+ raise "No context for assigning a label" unless @current_context
122
+ @layers << AxisScaler.new(:y, :log10, **options)
123
+
124
+ return self
125
+ end
126
+
127
+ def scale_x_reverse(**options)
128
+ raise "No context for assigning a label" unless @current_context
129
+ @layers << AxisScaler.new(:x, :reverse, **options)
130
+
131
+ return self
132
+ end
133
+
134
+ def scale_y_reverse(**options)
135
+ raise "No context for assigning a label" unless @current_context
136
+ @layers << AxisScaler.new(:y, :reverse, **options)
137
+
138
+ return self
139
+ end
140
+
141
+ def scale_x_sqrt(**options)
142
+ raise "No context for assigning a label" unless @current_context
143
+ @layers << AxisScaler.new(:x, :sqrt, **options)
144
+
145
+ return self
146
+ end
147
+
148
+ def scale_y_sqrt(**options)
149
+ raise "No context for assigning a label" unless @current_context
150
+ @layers << AxisScaler.new(:y, :sqrt, **options)
151
+
152
+ return self
153
+ end
154
+
155
+ def with_title(value)
156
+ @label_options[:title] = value
157
+
158
+ return self
159
+ end
160
+
161
+ def draw_points(**options)
162
+ @layers << GeomPoint.new(**options)
163
+
164
+ @current_context = nil
165
+
166
+ return self
167
+ end
168
+
169
+ def draw_lines(**options)
170
+ @layers << GeomLine.new(**options)
171
+
172
+ @current_context = nil
173
+
174
+ return self
175
+ end
176
+
177
+ def draw_bars(**options)
178
+ @layers << GeomBar.new(**options)
179
+
180
+ @current_context = nil
181
+
182
+ return self
183
+ end
184
+
185
+ def draw_cols(**options)
186
+ @layers << GeomCol.new(**options)
187
+
188
+ @current_context = nil
189
+
190
+ return self
191
+ end
192
+
193
+ def draw_boxplot(**options)
194
+ @layers << GeomBoxplot.new(**options)
195
+
196
+ @current_context = nil
197
+
198
+ return self
199
+ end
200
+
201
+ def draw_histogram(**options)
202
+ @layers << GeomHistogram.new(**options)
203
+
204
+ @current_context = nil
205
+
206
+ return self
207
+ end
208
+
209
+ def draw_density(**options)
210
+ @layers << GeomDensity.new(**options)
211
+
212
+ @current_context = nil
213
+
214
+ return self
215
+ end
216
+
217
+ def with_theme(theme)
218
+ @layers << theme
219
+
220
+ @current_context = nil
221
+
222
+ return self
223
+ end
224
+
225
+ def labeled(value)
226
+ raise "No context for assigning a label" unless @current_context
227
+ @label_options[@current_context] = value
228
+
229
+ return self
230
+ end
231
+
232
+ def scale_continuous(**options)
233
+ raise "No context for assigning a label" unless @current_context
234
+ @layers << AxisScaler.new(@current_context, :continuous, **options)
235
+
236
+ return self
237
+ end
238
+
239
+ def scale_discrete(**options)
240
+ raise "No context for assigning a label" unless @current_context
241
+ @layers << AxisScaler.new(@current_context, :discrete, **options)
242
+
243
+ return self
244
+ end
245
+
246
+ def scale_log10(**options)
247
+ raise "No context for assigning a label" unless @current_context
248
+ @layers << AxisScaler.new(@current_context, :log10, **options)
249
+
250
+ return self
251
+ end
252
+
253
+ def scale_reverse(**options)
254
+ raise "No context for assigning a label" unless @current_context
255
+ @layers << AxisScaler.new(@current_context, :reverse, **options)
256
+
257
+ return self
258
+ end
259
+
260
+ def scale_sqrt(**options)
261
+ raise "No context for assigning a label" unless @current_context
262
+ @layers << AxisScaler.new(@current_context, :sqrt, **options)
263
+
264
+ return self
265
+ end
266
+
267
+ def flip_coordinates
268
+ @layers << FlipCoordinates.new
269
+
270
+ @current_context = nil
271
+
272
+ return self
273
+ end
274
+
275
+ def build
276
+ plot = Plot.new(@data, Aes.new(**@aes_options))
277
+ plot.theme = @theme if @theme
278
+ plot << @layers if @layers.size > 0
279
+ if @label_options.size > 0
280
+ if @label_options.keys.include?(:group)
281
+ value = @label_options.delete(:group)
282
+ selected = [:x, :y] - @label_options.keys
283
+ @label_options[selected.first] = value if selected.size == 1
284
+ end
285
+
286
+ plot << Labels.new(**@label_options)
287
+ end
288
+
289
+ return plot
290
+ end
291
+ end
292
+ end
@@ -0,0 +1,12 @@
1
+ require_relative 'core'
2
+
3
+ module Rust::Plots::GGPlot
4
+ class AxisScaler < Layer
5
+ def initialize(axis, type = :continuous, **options)
6
+ @axis = axis
7
+ @type = type
8
+
9
+ super("scale_#{@axis}_#{@type}", **options)
10
+ end
11
+ end
12
+ end