Class: Charty::RenderContext
- Inherits:
-
Object
- Object
- Charty::RenderContext
- Defined in:
- lib/charty/plotter.rb
Defined Under Namespace
Classes: Configurator
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#function ⇒ Object
readonly
Returns the value of attribute function.
-
#labels ⇒ Object
readonly
Returns the value of attribute labels.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#range ⇒ Object
readonly
Returns the value of attribute range.
-
#series ⇒ Object
readonly
Returns the value of attribute series.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#xlabel ⇒ Object
readonly
Returns the value of attribute xlabel.
-
#ylabel ⇒ Object
readonly
Returns the value of attribute ylabel.
Instance Method Summary collapse
- #apply(backend) ⇒ Object
-
#initialize(method, **args, &block) ⇒ RenderContext
constructor
A new instance of RenderContext.
- #range_x ⇒ Object
- #range_y ⇒ Object
- #render(filename = nil) ⇒ Object
- #save(filename = nil, **kw) ⇒ Object
Constructor Details
#initialize(method, **args, &block) ⇒ RenderContext
Returns a new instance of RenderContext.
168 169 170 171 172 173 174 |
# File 'lib/charty/plotter.rb', line 168 def initialize(method, **args, &block) @method = method configurator = Configurator.new(**args) configurator.instance_eval(&block) # TODO: label も外から付けられた方がよさそう (@range, @series, @function, @data, @title, @xlabel, @ylabel, @labels) = configurator.to_a end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
166 167 168 |
# File 'lib/charty/plotter.rb', line 166 def data @data end |
#function ⇒ Object (readonly)
Returns the value of attribute function.
166 167 168 |
# File 'lib/charty/plotter.rb', line 166 def function @function end |
#labels ⇒ Object (readonly)
Returns the value of attribute labels.
166 167 168 |
# File 'lib/charty/plotter.rb', line 166 def labels @labels end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
166 167 168 |
# File 'lib/charty/plotter.rb', line 166 def method @method end |
#range ⇒ Object (readonly)
Returns the value of attribute range.
166 167 168 |
# File 'lib/charty/plotter.rb', line 166 def range @range end |
#series ⇒ Object (readonly)
Returns the value of attribute series.
166 167 168 |
# File 'lib/charty/plotter.rb', line 166 def series @series end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
166 167 168 |
# File 'lib/charty/plotter.rb', line 166 def title @title end |
#xlabel ⇒ Object (readonly)
Returns the value of attribute xlabel.
166 167 168 |
# File 'lib/charty/plotter.rb', line 166 def xlabel @xlabel end |
#ylabel ⇒ Object (readonly)
Returns the value of attribute ylabel.
166 167 168 |
# File 'lib/charty/plotter.rb', line 166 def ylabel @ylabel end |
Instance Method Details
#apply(backend) ⇒ Object
247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
# File 'lib/charty/plotter.rb', line 247 def apply(backend) case when !@series.empty? backend.series = @series when @function linspace = Linspace.new(@range[:x], 100) # TODO: set label with function # TODO: set ys to xs when gruff curve with function @series << Series.new(linspace.to_a, linspace.map{|x| @function.call(x) }, label: "function" ) end @backend = backend self end |
#range_x ⇒ Object
231 232 233 |
# File 'lib/charty/plotter.rb', line 231 def range_x @range[:x] end |
#range_y ⇒ Object
235 236 237 |
# File 'lib/charty/plotter.rb', line 235 def range_y @range[:y] end |
#render(filename = nil) ⇒ Object
239 240 241 |
# File 'lib/charty/plotter.rb', line 239 def render(filename=nil) @backend.old_style_render(self, filename) end |
#save(filename = nil, **kw) ⇒ Object
243 244 245 |
# File 'lib/charty/plotter.rb', line 243 def save(filename=nil, **kw) @backend.old_style_save(self, filename, **kw) end |