Class: UnicodePlot::StringStemplot

Inherits:
Stemplot
  • Object
show all
Defined in:
src/lib/unicode_plot/stemplot.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Stemplot

factory, #insert, #leaves, #max_stem_length, #raw_stems, #stems

Constructor Details

#initialize(vector, scale: 10, string_padchar: '_', **_kw) ⇒ StringStemplot

Returns a new instance of StringStemplot.

Raises:

  • (ArgumentError)


186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'src/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

Class Method Details

.sorted_stem_list(stems, all: true) ⇒ Array

Used when we have stems from a back-to-back stemplot and a combined list of stems is given

Parameters:

  • stems (Array)

    Concatenated list of stems from two plots

  • all (Boolean) (defaults to: true)

    Return all stems if true, otherwise only return stems if a leaf exists for a stem

Returns:

  • (Array)

    Sorted list of stems



212
213
214
215
216
217
218
219
# File 'src/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

Instance Method Details

Function prototype to provide same interface as NumericStemplot.
This function does not do anything.

Returns:

  • (false)


203
204
205
206
# File 'src/lib/unicode_plot/stemplot.rb', line 203

def print_key(_scale, _divider)
  # intentionally empty
  return false
end