class Squid::Point

Attributes

height[R]
index[R]
label[R]
negative[R]
y[R]

Public Class Methods

for(series, minmax:, height:, labels:, stack:, formats:) click to toggle source
# File lib/squid/point.rb, line 7
def self.for(series, minmax:, height:, labels:, stack:, formats:)
  @min = Hash.new 0
  @max = Hash.new 0
  min, max = minmax
  offset = -> (value) { value * height.to_f / (max-min) }
  series.map.with_index do |values, series_i|
    values.map.with_index do |value, i|
      h = y_for value, index: i, stack: false, &offset if value
      y = y_for value, index: i, stack: stack, &offset if value
      y = y - offset.call([min, 0].min) if value
      label = format_for value, formats[series_i] if labels[series_i]
      new y: y, height: h, index: i, label: label, negative: value.to_f < 0
    end
  end
end
new(y:, height:, index:, label:, negative:) click to toggle source
# File lib/squid/point.rb, line 25
def initialize(y:, height:, index:, label:, negative:)
  @y, @height, @index, @label, @negative = y, height, index, label, negative
end

Private Class Methods

y_for(value, index:, stack:) { |hash| ... } click to toggle source
# File lib/squid/point.rb, line 31
def self.y_for(value, index:, stack:, &block)
  if stack
    hash = (value > 0) ? @max : @min
    yield(hash[index] += value)
  else
    yield(value)
  end
end