Class: Squid::Point
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#negative ⇒ Object
readonly
Returns the value of attribute negative.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(y:, height:, index:, label:, negative:) ⇒ Point
constructor
A new instance of Point.
Methods included from Format
format_for, number_to_float, number_to_minutes_and_seconds
Constructor Details
#initialize(y:, height:, index:, label:, negative:) ⇒ Point
Returns a new instance of Point.
25 26 27 |
# 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 |
Instance Attribute Details
#height ⇒ Object (readonly)
Returns the value of attribute height.
23 24 25 |
# File 'lib/squid/point.rb', line 23 def height @height end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
23 24 25 |
# File 'lib/squid/point.rb', line 23 def index @index end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
23 24 25 |
# File 'lib/squid/point.rb', line 23 def label @label end |
#negative ⇒ Object (readonly)
Returns the value of attribute negative.
23 24 25 |
# File 'lib/squid/point.rb', line 23 def negative @negative end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
23 24 25 |
# File 'lib/squid/point.rb', line 23 def y @y end |
Class Method Details
.for(series, minmax:, height:, labels:, stack:, formats:) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# 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 |