Class: Gruff::BarConversion

Inherits:
Object
  • Object
show all
Defined in:
lib/gruff/bar_conversion.rb

Overview

Original Author: David Stokar

This class perfoms the y coordinats conversion for the bar class.

There are three cases:

1. Bars all go from zero in positive direction

2. Bars all go from zero to negative direction 3. Bars either go from zero to positive or from zero to negative

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#graph_height=(value) ⇒ Object (writeonly)

Sets the attribute graph_height

Parameters:

  • value

    the value to set the attribute graph_height to.



16
17
18
# File 'lib/gruff/bar_conversion.rb', line 16

def graph_height=(value)
  @graph_height = value
end

#graph_top=(value) ⇒ Object (writeonly)

Sets the attribute graph_top

Parameters:

  • value

    the value to set the attribute graph_top to.



15
16
17
# File 'lib/gruff/bar_conversion.rb', line 15

def graph_top=(value)
  @graph_top = value
end

#minimum_value=(value) ⇒ Object (writeonly)

Sets the attribute minimum_value

Parameters:

  • value

    the value to set the attribute minimum_value to.



17
18
19
# File 'lib/gruff/bar_conversion.rb', line 17

def minimum_value=(value)
  @minimum_value = value
end

#mode=(value) ⇒ Object (writeonly)

Sets the attribute mode

Parameters:

  • value

    the value to set the attribute mode to.



13
14
15
# File 'lib/gruff/bar_conversion.rb', line 13

def mode=(value)
  @mode = value
end

#spread=(value) ⇒ Object (writeonly)

Sets the attribute spread

Parameters:

  • value

    the value to set the attribute spread to.



18
19
20
# File 'lib/gruff/bar_conversion.rb', line 18

def spread=(value)
  @spread = value
end

#zero=(value) ⇒ Object (writeonly)

Sets the attribute zero

Parameters:

  • value

    the value to set the attribute zero to.



14
15
16
# File 'lib/gruff/bar_conversion.rb', line 14

def zero=(value)
  @zero = value
end

Instance Method Details

#get_left_y_right_y_scaled(data_point, result) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/gruff/bar_conversion.rb', line 20

def get_left_y_right_y_scaled(data_point, result)
  case @mode
  when 1 then # Case one
              # minimum value >= 0 ( only positiv values )
    result[0] = @graph_top + @graph_height*(1 - data_point) + 1
    result[1] = @graph_top + @graph_height - 1
  when 2 then # Case two
              # only negativ values
    result[0] = @graph_top + 1
    result[1] = @graph_top + @graph_height*(1 - data_point) - 1
  when 3 then # Case three
              # positiv and negativ values
    val = data_point-@minimum_value/@spread
    if data_point >= @zero
      result[0] = @graph_top + @graph_height*(1 - (val-@zero)) + 1
      result[1] = @graph_top + @graph_height*(1 - @zero) - 1
    else
      result[0] = @graph_top + @graph_height*(1 - (val-@zero)) + 1
      result[1] = @graph_top + @graph_height*(1 - @zero) - 1
    end
  else
    result[0] = 0.0
    result[1] = 0.0
  end
end