Module: Bumpspark::Scale

Included in:
Graph
Defined in:
lib/bumpspark/scale.rb

Instance Method Summary collapse

Instance Method Details

#scaled_numbersObject



5
6
7
8
9
10
11
12
13
14
# File 'lib/bumpspark/scale.rb', line 5

def scaled_numbers
  nums = numbers.empty? ? [0] : numbers
  min, max = nums.min, nums.max
  width = max - min
  return [1] * nums.size if width == 0
  width = width * @scale
  nums.map do |result|
    ((result - min) * 100 / width.to_f).to_i
  end
end