Class: Charty::RenderContext

Inherits:
Object
  • Object
show all
Defined in:
lib/charty/plotter.rb

Defined Under Namespace

Classes: Configurator

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#dataObject (readonly)

Returns the value of attribute data.



166
167
168
# File 'lib/charty/plotter.rb', line 166

def data
  @data
end

#functionObject (readonly)

Returns the value of attribute function.



166
167
168
# File 'lib/charty/plotter.rb', line 166

def function
  @function
end

#labelsObject (readonly)

Returns the value of attribute labels.



166
167
168
# File 'lib/charty/plotter.rb', line 166

def labels
  @labels
end

#methodObject (readonly)

Returns the value of attribute method.



166
167
168
# File 'lib/charty/plotter.rb', line 166

def method
  @method
end

#rangeObject (readonly)

Returns the value of attribute range.



166
167
168
# File 'lib/charty/plotter.rb', line 166

def range
  @range
end

#seriesObject (readonly)

Returns the value of attribute series.



166
167
168
# File 'lib/charty/plotter.rb', line 166

def series
  @series
end

#titleObject (readonly)

Returns the value of attribute title.



166
167
168
# File 'lib/charty/plotter.rb', line 166

def title
  @title
end

#xlabelObject (readonly)

Returns the value of attribute xlabel.



166
167
168
# File 'lib/charty/plotter.rb', line 166

def xlabel
  @xlabel
end

#ylabelObject (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_xObject



231
232
233
# File 'lib/charty/plotter.rb', line 231

def range_x
  @range[:x]
end

#range_yObject



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