Class: Charty::Plotters::BarPlotter

Inherits:
CategoricalPlotter show all
Defined in:
lib/charty/plotters/bar_plotter.rb

Direct Known Subclasses

CountPlotter

Instance Attribute Summary collapse

Attributes inherited from CategoricalPlotter

#dodge, #group_label, #group_names, #order, #orient, #plot_data, #saturation, #value_label, #width

Attributes included from EstimationSupport

#ci, #estimator, #n_boot, #units

Attributes included from RandomSupport

#random

Attributes inherited from AbstractPlotter

#color, #color_order, #data, #key_color, #palette, #x, #y

Instance Method Summary collapse

Methods included from EstimationSupport

check_estimator

Methods included from RandomSupport

check_random

Methods inherited from AbstractPlotter

#to_iruby

Constructor Details

#initialize(data: nil, variables: {}, **options, &block) ⇒ BarPlotter

Returns a new instance of BarPlotter.



7
8
9
10
# File 'lib/charty/plotters/bar_plotter.rb', line 7

def initialize(data: nil, variables: {}, **options, &block)
  x, y, color = variables.values_at(:x, :y, :color)
  super(x, y, color, data: data, **options, &block)
end

Instance Attribute Details

#cap_sizeObject

Returns the value of attribute cap_size.



39
40
41
# File 'lib/charty/plotters/bar_plotter.rb', line 39

def cap_size
  @cap_size
end

#error_colorObject

Returns the value of attribute error_color.



12
13
14
# File 'lib/charty/plotters/bar_plotter.rb', line 12

def error_color
  @error_color
end

#error_widthObject

Returns the value of attribute error_width.



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

def error_width
  @error_width
end

Instance Method Details

#renderObject



45
46
47
48
49
50
51
52
# File 'lib/charty/plotters/bar_plotter.rb', line 45

def render
  backend = Backends.current
  backend.begin_figure
  draw_bars(backend)
  annotate_axes(backend)
  backend.invert_yaxis if orient == :h
  backend.show
end

#save(filename, **opts) ⇒ Object

TODO:

  • Should infer mime type from file’s extname

  • Should check backend’s supported mime type before begin_figure



57
58
59
60
61
62
63
64
# File 'lib/charty/plotters/bar_plotter.rb', line 57

def save(filename, **opts)
  backend = Backends.current
  backend.begin_figure
  draw_bars(backend)
  annotate_axes(backend)
  backend.invert_yaxis if orient == :h
  backend.save(filename, **opts)
end