Sha256: e6b877034d70f67bd1e88270aca05c30fff01cffc65f849115f8d6e64dd39df1
Contents?: true
Size: 1.09 KB
Versions: 2
Compression:
Stored size: 1.09 KB
Contents
require 'squid/format' module Squid class Point extend Format def self.for(series, minmax:, height:, labels:, stack:, format:) @min = Hash.new 0 @max = Hash.new 0 min, max = minmax offset = -> (value) { value * height.to_f / (max-min) } series.map do |values| 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, format) if labels new y: y, height: h, index: i, label: label, negative: value.to_f < 0 end end end attr_reader :y, :height, :index, :label, :negative def initialize(y:, height:, index:, label:, negative:) @y, @height, @index, @label, @negative = y, height, index, label, negative end private def self.y_for(value, index:, stack:, &block) if stack hash = (value > 0) ? @max : @min yield(hash[index] += value) else yield(value) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
squid-1.0.0.beta2 | lib/squid/point.rb |
squid-1.0.0.beta1 | lib/squid/point.rb |