Class: Rust::Plots::GGPlot::ThemeComponentBuilder
- Inherits:
-
Object
- Object
- Rust::Plots::GGPlot::ThemeComponentBuilder
show all
- Defined in:
- lib/rust/external/ggplot2/themes.rb
Instance Method Summary
collapse
Constructor Details
Returns a new instance of ThemeComponentBuilder.
133
134
135
136
|
# File 'lib/rust/external/ggplot2/themes.rb', line 133
def initialize(namespace=nil)
@namespace = namespace
@options = {}
end
|
Instance Method Details
145
146
147
148
|
# File 'lib/rust/external/ggplot2/themes.rb', line 145
def [](key)
key = "#@namespace.#{key}" if @namespace
return @options[key]
end
|
#alignment_el(value) ⇒ Object
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
# File 'lib/rust/external/ggplot2/themes.rb', line 202
def alignment_el(value)
if value.is_a?(String) || value.is_a?(Symbol)
case value.to_s.downcase
when 'left'
value = 1
when 'right'
value = 0
else
value = 1
end
end
return value
end
|
222
223
224
|
# File 'lib/rust/external/ggplot2/themes.rb', line 222
def build
@options
end
|
#line_el(value) ⇒ Object
150
151
152
153
154
155
156
157
158
|
# File 'lib/rust/external/ggplot2/themes.rb', line 150
def line_el(value)
if value.is_a?(Theme::LineElement) || value.is_a?(Theme::BlankElement)
return value
elsif value.is_a?(Hash)
return Theme::LineElement.new(**value)
else
raise "Expected line or hash"
end
end
|
#numeric_el(value) ⇒ Object
217
218
219
220
|
# File 'lib/rust/external/ggplot2/themes.rb', line 217
def numeric_el(value)
raise "Expected number" unless value.is_a?(Numeric)
return value
end
|
#option(key, value) ⇒ Object
138
139
140
141
142
143
|
# File 'lib/rust/external/ggplot2/themes.rb', line 138
def option(key, value)
key = "#@namespace.#{key}" if @namespace
@options[key] = value
return self
end
|
#rect_el(value) ⇒ Object
160
161
162
163
164
165
166
167
168
|
# File 'lib/rust/external/ggplot2/themes.rb', line 160
def rect_el(value)
if value.is_a?(Theme::RectElement) || value.is_a?(Theme::BlankElement)
return value
elsif value.is_a?(Hash)
return Theme::RectElement.new(**value)
else
raise "Expected rect or hash"
end
end
|
#text_el(value) ⇒ Object
170
171
172
173
174
175
176
177
178
|
# File 'lib/rust/external/ggplot2/themes.rb', line 170
def text_el(value)
if value.is_a?(Theme::TextElement) || value.is_a?(Theme::BlankElement)
return value
elsif value.is_a?(Hash)
return Theme::TextElement.new(**value)
else
raise "Expected text or hash"
end
end
|
#unit_el(value) ⇒ Object
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
# File 'lib/rust/external/ggplot2/themes.rb', line 180
def unit_el(value)
numeric = nil
unit = nil
if input.is_a?(String)
numeric, unit = *input.scan(/^([0-9.]+)([A-Za-z]+)/).flatten
raise "Unclear numeric part in #{input}" unless numeric
raise "Unclear unit part in #{input}" unless unit
elsif input.is_a?(Numeric)
numeric = input
unit = "npc"
end
raise "Unable to handle #{input}" unless numeric && unit
function = Rust::Function.new("units")
function.arguments = Rust::Arguments.new([numeric, unit])
return function.to_R
end
|