class MiniHistogram::MiniUnicodePlot::Barplot

Constants

DEFAULT_COLOR
DEFAULT_SYMBOL
MIN_WIDTH

Attributes

max_freq[R]
max_len[R]
width[R]

Public Class Methods

new(bars, width, color, symbol, transform, **kw) click to toggle source
# File lib/mini_histogram/plot.rb, line 720
def initialize(bars, width, color, symbol, transform, **kw)
  if symbol.length > 1
    raise ArgumentError, "symbol must be a single character"
  end
  @bars = bars
  @symbol = symbol
  @max_freq, i = find_max(transform_values(transform, bars))
  @max_len = bars[i].to_s.length
  @width = [width, max_len + 7, MIN_WIDTH].max
  @color = color
  @symbol = symbol
  @transform = transform
  super(**kw)
end

Public Instance Methods

add_row!(bars) click to toggle source
# File lib/mini_histogram/plot.rb, line 747
def add_row!(bars)
  @bars.concat(bars)
  @max_freq, i = find_max(transform_values(@transform, bars))
  @max_len = @bars[i].to_s.length
end
n_columns() click to toggle source
# File lib/mini_histogram/plot.rb, line 743
def n_columns
  @width
end
n_rows() click to toggle source
# File lib/mini_histogram/plot.rb, line 739
def n_rows
  @bars.length
end
print_row(out, row_index) click to toggle source

Private Instance Methods

find_max(values) click to toggle source
# File lib/mini_histogram/plot.rb, line 770
        def find_max(values)
  i = j = 0
  max = values[i]
  while j < values.length
    if values[j] > max
      i, max = j, values[j]
    end
    j += 1
  end
  [max, i]
end