]> projects.mako.cc - selectricity-live/blob - vendor/plugins/gruff/lib/gruff/bar_conversion.rb
880daca8f82d0b6a43caa4cd26cf9f7c28a1d08c
[selectricity-live] / vendor / plugins / gruff / lib / gruff / bar_conversion.rb
1 ##
2 # Original Author: David Stokar
3 #
4 #       This class perfoms the y coordinats conversion for the bar class.
5 #
6 #       There are three cases: 
7 #
8 #   1. Bars all go from zero in positive direction
9 #               2. Bars all go from zero to negative direction  
10 #               3. Bars either go from zero to positive or from zero to negative
11 #
12 class Gruff::BarConversion
13         attr_writer :mode
14         attr_writer :zero
15         attr_writer :graph_top
16         attr_writer :graph_height
17         attr_writer :minimum_value
18         attr_writer :spread
19         
20         def getLeftYRightYscaled( data_point, result )
21                 case @mode
22                 when 1 then # Case one
23                         # minimum value >= 0 ( only positiv values )
24       result[0] = @graph_top + @graph_height*(1 - data_point) + 1
25                 result[1] = @graph_top + @graph_height - 1
26                 when 2 then  # Case two
27                         # only negativ values
28                 result[0] = @graph_top + 1
29                 result[1] = @graph_top + @graph_height*(1 - data_point) - 1
30                 when 3 then # Case three
31                         # positiv and negativ values
32         val = data_point-@minimum_value/@spread
33         if ( data_point >= @zero ) then
34                 result[0] = @graph_top + @graph_height*(1 - (val-@zero)) + 1
35                 result[1] = @graph_top + @graph_height*(1 - @zero) - 1
36         else
37                                 result[0] = @graph_top + @graph_height*(1 - (val-@zero)) + 1
38                 result[1] = @graph_top + @graph_height*(1 - @zero) - 1
39         end
40                 else
41                         result[0] = 0.0
42                         result[1] = 0.0
43                 end                             
44         end     
45
46 end

Benjamin Mako Hill || Want to submit a patch?