class Charty::Plotters::ScatterPlotter

Attributes

alpha[R]
edge_color[R]
line_width[R]

Public Class Methods

new(data: nil, variables: {}, **options, &block) click to toggle source
# File lib/charty/plotters/scatter_plotter.rb, line 4
def initialize(data: nil, variables: {}, **options, &block)
  x, y, color, style, size = variables.values_at(:x, :y, :color, :style, :size)
  super(x, y, color, style, size, data: data, **options, &block)
end

Public Instance Methods

alpha=(val) click to toggle source
# File lib/charty/plotters/scatter_plotter.rb, line 11
def alpha=(val)
  case val
  when nil, :auto, 0..1
    @alpha = val
  when "auto"
    @alpha = val.to_sym
  when Numeric
    raise ArgumentError,
          "the given alpha is out of bounds " +
          "(%p for nil, :auto, or number 0..1)" % val
  else
    raise ArgumentError,
          "invalid value of alpha " +
          "(%p for nil, :auto, or number in 0..1)" % val
  end
end
edge_color=(val) click to toggle source
# File lib/charty/plotters/scatter_plotter.rb, line 34
def edge_color=(val)
  @line_width = check_color(val, :edge_color, allow_nil: true)
end
line_width=(val) click to toggle source
# File lib/charty/plotters/scatter_plotter.rb, line 30
def line_width=(val)
  @line_width = check_number(val, :line_width, allow_nil: true)
end

Private Instance Methods

annotate_axes(backend) click to toggle source
# File lib/charty/plotters/scatter_plotter.rb, line 72
        def annotate_axes(backend)
  backend.set_title(self.title) if self.title

  xlabel = self.x_label || self.variables[:x]
  ylabel = self.y_label || self.variables[:y]
  backend.set_xlabel(xlabel) unless xlabel.nil?
  backend.set_ylabel(ylabel) unless ylabel.nil?
end
draw_points(backend) click to toggle source
# File lib/charty/plotters/scatter_plotter.rb, line 43
        def draw_points(backend)
  map_color(palette: palette, order: color_order, norm: color_norm)
  map_size(sizes: sizes, order: size_order, norm: size_norm)
  map_style(markers: markers, order: style_order)

  data = @plot_data.drop_na

  # TODO: shold pass key_color to backend's scatter method.
  #       In pyplot backend, it is passed as color parameter.

  x = data[:x]
  y = data[:y]
  color = data[:color] if @variables.key?(:color)
  style = data[:style] if @variables.key?(:style)
  size = data[:size] if @variables.key?(:size)

  # TODO: key_color
  backend.scatter(
    x, y, @variables,
    color: color, color_mapper: @color_mapper,
    style: style, style_mapper: @style_mapper,
    size: size, size_mapper: @size_mapper
  )

  if legend
    backend.add_scatter_plot_legend(@variables, @color_mapper, @size_mapper, @style_mapper, legend)
  end
end
render_plot(backend, **) click to toggle source
# File lib/charty/plotters/scatter_plotter.rb, line 38
        def render_plot(backend, **)
  draw_points(backend)
  annotate_axes(backend)
end