class UnicodePlot::Boxplot

Constants

DEFAULT_COLOR
MIN_WIDTH

Attributes

max_x[R]
min_x[R]

Public Class Methods

new(data, width, color, min_x, max_x, **kw) click to toggle source
Calls superclass method
# File lib/unicode_plot/boxplot.rb, line 8
def initialize(data, width, color, min_x, max_x, **kw)
  if min_x == max_x
    min_x -= 1
    max_x += 1
  end
  width = [width, MIN_WIDTH].max
  @data = [data.percentile([0, 25, 50, 75, 100])]
  @color = color
  @width = [width, MIN_WIDTH].max
  @min_x = min_x
  @max_x = max_x
  super(**kw)
end

Public Instance Methods

add_series!(data) click to toggle source
# File lib/unicode_plot/boxplot.rb, line 37
def add_series!(data)
  mi, ma = data.minmax
  @data << data.percentile([0, 25, 50, 75, 100])
  @min_x = [mi, @min_x].min
  @max_x = [ma, @max_x].max
end
n_columns() click to toggle source
# File lib/unicode_plot/boxplot.rb, line 33
def n_columns
  @width
end
n_data() click to toggle source
# File lib/unicode_plot/boxplot.rb, line 25
def n_data
  @data.length
end
n_rows() click to toggle source
# File lib/unicode_plot/boxplot.rb, line 29
def n_rows
  3 * @data.length
end
print_row(out, row_index) click to toggle source

Private Instance Methods

transform(values) click to toggle source
# File lib/unicode_plot/boxplot.rb, line 86
        def transform(values)
  values.map do |val|
    val = (val - @min_x).fdiv(@max_x - @min_x) * @width
    val.round(half: :even).clamp(1, @width).to_i
  end
end