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

#titleObject

Returns the value of attribute title.



98
99
100
# File 'lib/charty/plotters/abstract_plotter.rb', line 98

def title
  @title
end

#xObject

Returns the value of attribute x.



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

def x
  @x
end

#x_labelObject

Returns the value of attribute x_label.



86
87
88
# File 'lib/charty/plotters/abstract_plotter.rb', line 86

def x_label
  @x_label
end

#yObject

Returns the value of attribute y.



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

def y
  @y
end

#y_labelObject

Returns the value of attribute y_label.



92
93
94
# File 'lib/charty/plotters/abstract_plotter.rb', line 92

def y_label
  @y_label
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



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

def processed_data
  @processed_data ||= calculate_processed_data
end

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



252
253
254
255
256
# File 'lib/charty/plotters/abstract_plotter.rb', line 252

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



246
247
248
249
250
# File 'lib/charty/plotters/abstract_plotter.rb', line 246

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

#to_irubyObject



268
269
270
# File 'lib/charty/plotters/abstract_plotter.rb', line 268

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

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



272
273
274
275
276
277
278
279
280
# File 'lib/charty/plotters/abstract_plotter.rb', line 272

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