Class: Charty::Plotters::AbstractPlotter

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x, y, color, **options) {|_self| ... } ⇒ AbstractPlotter

Returns a new instance of AbstractPlotter.

Yields:

  • (_self)

Yield Parameters:



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/charty/plotters/abstract_plotter.rb', line 4

def initialize(x, y, color, **options)
  self.x = x
  self.y = y
  self.color = color
  self.data = data
  self.palette = palette
  substitute_options(options)

  @var_levels = {}
  @var_ordered = {x: false, y: false}

  yield self if block_given?
end

Instance Attribute Details

#colorObject

Returns the value of attribute color.



18
19
20
# File 'lib/charty/plotters/abstract_plotter.rb', line 18

def color
  @color
end

#color_orderObject

Returns the value of attribute color_order.



19
20
21
# File 'lib/charty/plotters/abstract_plotter.rb', line 19

def color_order
  @color_order
end

#dataObject

Returns the value of attribute data.



18
19
20
# File 'lib/charty/plotters/abstract_plotter.rb', line 18

def data
  @data
end

#key_colorObject

Returns the value of attribute key_color.



19
20
21
# File 'lib/charty/plotters/abstract_plotter.rb', line 19

def key_color
  @key_color
end

#paletteObject

Returns the value of attribute palette.



19
20
21
# File 'lib/charty/plotters/abstract_plotter.rb', line 19

def palette
  @palette
end

#xObject

Returns the value of attribute x.



18
19
20
# File 'lib/charty/plotters/abstract_plotter.rb', line 18

def x
  @x
end

#yObject

Returns the value of attribute y.



18
19
20
# File 'lib/charty/plotters/abstract_plotter.rb', line 18

def y
  @y
end

Instance Method Details

#inspectObject



33
34
35
# File 'lib/charty/plotters/abstract_plotter.rb', line 33

def inspect
  "#<#{self.class}:0x%016x>" % self.object_id
end

#processed_dataObject



205
206
207
# File 'lib/charty/plotters/abstract_plotter.rb', line 205

def processed_data
  @processed_data ||= calculate_processed_data
end

#render(notebook: false, **kwargs) ⇒ Object



220
221
222
223
224
# File 'lib/charty/plotters/abstract_plotter.rb', line 220

def render(notebook: false, **kwargs)
  backend = Backends.current
  call_render_plot(backend, notebook: notebook, **kwargs)
  backend.render(notebook: notebook, **kwargs)
end

#save(filename, **kwargs) ⇒ Object



214
215
216
217
218
# File 'lib/charty/plotters/abstract_plotter.rb', line 214

def save(filename, **kwargs)
  backend = Backends.current
  call_render_plot(backend, notebook: false, **kwargs)
  backend.save(filename, **kwargs)
end

#to_irubyObject



236
237
238
# File 'lib/charty/plotters/abstract_plotter.rb', line 236

def to_iruby
  render(notebook: IRubyHelper.iruby_notebook?)
end

#to_iruby_mimebundle(include: [], exclude: []) ⇒ Object



240
241
242
243
244
245
246
247
248
# File 'lib/charty/plotters/abstract_plotter.rb', line 240

def to_iruby_mimebundle(include: [], exclude: [])
  backend = Backends.current
  if backend.respond_to?(:render_mimebundle)
    call_render_plot(backend, notebook: true)
    backend.render_mimebundle(include: include, exclude: exclude)
  else
    {}
  end
end

#var_levelsObject



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/charty/plotters/abstract_plotter.rb', line 21

def var_levels
  variables.each_key do |var|
    # TODO: Move mappers from RelationalPlotter to here,
    #       and remove the use of instance_variable_get
    if instance_variable_defined?(:"@#{var}_mapper")
      mapper = instance_variable_get(:"@#{var}_mapper")
      @var_levels[var] = mapper.levels
    end
  end
  @var_levels
end