Class: Squid::Axis
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
-
#initialize(data, steps:, stack:, format:, &block) ⇒ Axis
constructor
A new instance of Axis.
- #labels ⇒ Object
- #minmax ⇒ Object
- #width ⇒ Object
Methods included from Format
#format_for, #number_to_float, #number_to_minutes_and_seconds
Constructor Details
#initialize(data, steps:, stack:, format:, &block) ⇒ Axis
Returns a new instance of Axis.
10 11 12 13 |
# File 'lib/squid/axis.rb', line 10 def initialize(data, steps:, stack:, format:, &block) @data, @steps, @stack, @format = data, steps, stack, format @width_proc = block if block_given? end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
8 9 10 |
# File 'lib/squid/axis.rb', line 8 def data @data end |
Instance Method Details
#labels ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/squid/axis.rb', line 21 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 |
#minmax ⇒ Object
15 16 17 18 19 |
# File 'lib/squid/axis.rb', line 15 def minmax @minmax ||= [min, max].compact.map do |number| approximate number end end |
#width ⇒ Object
31 32 33 |
# File 'lib/squid/axis.rb', line 31 def width @width ||= labels.map{|label| label_width label}.max || 0 end |