Class: Gruff::BarConversion

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

Overview

This class perfoms the y coordinats conversion for the bar class There are 3 cases: 1. Bars all go from zero in positiv direction 2. Bars all go from zero to negativ direction 3. Bars either go from zero to positiv or from zero to negativ

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.



25
26
27
# File 'lib/gruff/bar_conversion.rb', line 25

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.



24
25
26
# File 'lib/gruff/bar_conversion.rb', line 24

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.



26
27
28
# File 'lib/gruff/bar_conversion.rb', line 26

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.



22
23
24
# File 'lib/gruff/bar_conversion.rb', line 22

def mode=(value)
  @mode = value
end

#spread=(value) ⇒ Object (writeonly)

Sets the attribute spread

Parameters:

  • value

    the value to set the attribute spread to.



27
28
29
# File 'lib/gruff/bar_conversion.rb', line 27

def spread=(value)
  @spread = value
end

#zero=(value) ⇒ Object (writeonly)

Sets the attribute zero

Parameters:

  • value

    the value to set the attribute zero to.



23
24
25
# File 'lib/gruff/bar_conversion.rb', line 23

def zero=(value)
  @zero = value
end

Instance Method Details

#getLeftYRightYscaled(data_point, result) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/gruff/bar_conversion.rb', line 29

def getLeftYRightYscaled( 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 ) then
   		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