Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix handling of floating point values for scales

  • Loading branch information...
commit b921d326533e065985ca729a04b7f1c44883f7b1 1 parent 70f4b97
@seandmccarthy authored
Showing with 14 additions and 14 deletions.
  1. +2 −2 lib/line_chart.rb
  2. +12 −12 lib/scale.rb
View
4 lib/line_chart.rb
@@ -149,10 +149,10 @@ def draw_xy_graph(data,data_description,y_serie_name,x_serie_name,palette_id=0)
x_last = -1
data.each do |key|
if ( !key[y_serie_name].nil? && !key[x_serie_name].nil? )
- x= key[x_serie_name]
+ x = key[x_serie_name]
y = key[y_serie_name]
y = @g_area_y2 - ((y-@vmin) * @division_ratio)
- x= @g_area_x1 + ((x-@v_x_min) * @x_division_ratio)
+ x = @g_area_x1 + ((x-@v_x_min) * @x_division_ratio)
if (x_last != -1 && y_last != -1)
draw_line(x_last,y_last,x,y,@palette[palette_id]["r"],@palette[palette_id]["g"],@palette[palette_id]["b"],true)
end
View
24 lib/scale.rb
@@ -14,14 +14,14 @@ def clear_scale
# Allow you to fix the scale, use this to bypass the automatic scaling
# You can use this function to skip the automatic scaling.
# vmin and vmax will be used to render the graph.
- def set_fixed_scale(v_min,v_max,divisions=5,v_x_min=0,v_x_max=0,x_divisions=5)
+ def set_fixed_scale(v_min,v_max,divisions=5,v_x_min=nil,v_x_max=nil,x_divisions=5)
@vmin = v_min.to_f
@vmax = v_max.to_f
@divisions = divisions.to_f
- if (!v_x_min == 0 )
+ if (!v_x_min.nil?)
@v_x_min = v_x_min.to_f
- @v_x_max = v_x_max.to_f
+ @v_x_max = v_x_max.nil? ? 0.0 : v_x_max.to_f
@x_divisions = x_divisions.to_f
end
end
@@ -330,8 +330,8 @@ def draw_xy_scale(data,data_description,y_serie_name,x_serie_name,r,g,b,with_mar
scale = 2
end
if (!scale_ok)
- factor = factor * 10 if ( scale2 > 1 )
- factor = factor / 10 if ( scale2 < 1 )
+ factor = factor * 10.0 if ( scale2 > 1 )
+ factor = factor / 10.0 if ( scale2 < 1 )
end
end
if ((((@vmax*1.0 / scale) / factor)).floor != ((@vmax*1.0 / scale) / factor))
@@ -358,7 +358,7 @@ def draw_xy_scale(data,data_description,y_serie_name,x_serie_name,r,g,b,with_mar
divisions+=1
end
else
- divisions =@divisions
+ divisions = @divisions
end
@division_count = divisions
@@ -373,8 +373,8 @@ def draw_xy_scale(data,data_description,y_serie_name,x_serie_name,r,g,b,with_mar
while(i<= divisions+1)
self.draw_line(@g_area_x1,ypos,@g_area_x1-5,ypos,r,g,b)
value = @vmin*1.0 + (i-1) * (( @vmax - @vmin ) / divisions)
- value = (round_of(value * (10**decimals),2)) / (10**decimals)
- value= value.round if value.floor == value.ceil
+ value = value.round(decimals)
+ value = value.round if value.floor == value.ceil
value = "#{value} #{data_description['unit']['y']}" if ( data_description["format"]["y"]== "number")
value = self.to_time(value) if ( data_description["format"]["y"] == "time" )
value = self.to_date(value) if ( data_description["format"]["y"] == "date" )
@@ -489,10 +489,10 @@ def draw_xy_scale(data,data_description,y_serie_name,x_serie_name,r,g,b,with_mar
while(i<= x_divisions+1)
self.draw_line(xpos,@g_area_y2,xpos,@g_area_y2+5,r,g,b)
- value = @v_x_min + (i-1) * (( @v_x_max - @v_x_min ) / x_divisions)
- value = (round_of(value * (10**decimals),2)) / (10**decimals)
- value= value.round if value.floor == value.ceil
- value = "#{value}#{data_description['unit']['y']}" if ( data_description["format"]["y"]== "number")
+ value = @v_x_min + (i-1) * (( @v_x_max - @v_x_min ) / x_divisions)
+ value = value.round(decimals)
+ value = value.round if value.floor == value.ceil
+ value = "#{value}#{data_description['unit']['y']}" if ( data_description["format"]["y"] == "number")
value = self.to_time(value) if ( data_description["format"]["y"] == "time" )
value = self.to_date(value) if ( data_description["format"]["y"] == "date" )
value = self.to_metric(value) if ( data_description["format"]["Y"] == "metric" )
Please sign in to comment.
Something went wrong with that request. Please try again.