Sha256: 30cc21b326becdf68e2254b2dd949a4299320ea86b3ceda848d204e7e7f713c9
Contents?: true
Size: 1.34 KB
Versions: 4
Compression:
Stored size: 1.34 KB
Contents
require 'squid/format' require 'active_support/core_ext/enumerable' # for Array#sum module Squid # @private class Axis include Format attr_reader :data def initialize(data, steps:, stack:, format:, &block) @data, @steps, @stack, @format = data, steps, stack, format @width_proc = block if block_given? end def minmax @minmax ||= [min, max].compact.map do |number| approximate number end end def labels min, max = minmax values = if min.nil? || max.nil? || @steps.zero? [] else max.step(by: (min - max)/@steps.to_f, to: min) end @labels ||= values.map{|value| format_for value, @format} end def width @width ||= labels.map{|label| label_width label}.max || 0 end private def label_width(label) @width_proc.call label if @width_proc end def min [values.first.min, 0].min if @data.any? && values.first.any? end def max [values.last.max, @steps].max if @data.any? && values.last.any? end def values @values ||= if @stack @data.transpose.map{|a| a.compact.partition{|n| n < 0}.map(&:sum)}.transpose else [@data.flatten.compact] end end def approximate(number) number_to_rounded(number, significant: true, precision: 2).to_f end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
squid-1.0.0 | lib/squid/axis.rb |
squid-1.0.0.beta4 | lib/squid/axis.rb |
squid-1.0.0.beta3 | lib/squid/axis.rb |
squid-1.0.0.beta2 | lib/squid/axis.rb |