class UnicodePlot::StringStemplot

Public Class Methods

new(vector, scale: 10, string_padchar: '_', **_kw) click to toggle source
Calls superclass method UnicodePlot::Stemplot::new
# File lib/unicode_plot/stemplot.rb, line 186
def initialize(vector, scale: 10, string_padchar: '_', **_kw)
  super
  stem_places = Math.log10(scale).floor
  raise ArgumentError, "Cannot take fewer than 1 place from stem.  Scale parameter should be greater than or equal to 10." if stem_places < 1
  vector.each do |value|
    # Strings may be shorter than the number of places we desire,
    # so we will pad them with a string-pad-character.
    padded_value = value.ljust(stem_places+1, string_padchar)
    stem = padded_value[0...stem_places]
    leaf = padded_value[stem_places]
    self.insert(stem, leaf)
  end
end
sorted_stem_list(stems, all: true) click to toggle source

Used when we have stems from a back-to-back stemplot and a combined list of stems is given @param stems [Array] Concatenated list of stems from two plots @param all [Boolean] Return all stems if true, otherwise only return stems if a leaf exists for a stem @return [Array] Sorted list of stems

# File lib/unicode_plot/stemplot.rb, line 212
def self.sorted_stem_list(stems, all: true)
  if all
    rmin, rmax = stems.minmax
    return (rmin .. rmax).to_a
  else
    stems.sort
  end
end

Public Instance Methods

print_key(_scale, _divider) click to toggle source

Function prototype to provide same interface as {NumericStemplot}. This function does not do anything. @return [false]