rchart 2.0.2 → 2.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.2
1
+ 2.0.4
@@ -4,9 +4,7 @@ module ColorPalette
4
4
  # You must provide an rgb color.
5
5
  def set_color_palette(id,r,g,b)
6
6
  b,g,r=validate_color(b, g, r)
7
- @palette[id]["r"] = r
8
- @palette[id]["g"] = g
9
- @palette[id]["b"] = b
7
+ set_palette(id, r, g, b)
10
8
  end
11
9
 
12
10
  # Create a color palette shading from one color to another
@@ -17,12 +15,11 @@ module ColorPalette
17
15
  b_factor = (b2-b1)/shades
18
16
  i= 0
19
17
  while(i<= shades-1)
20
- @palette[i]["r"] = r1+r_factor*i
21
- @palette[i]["g"] = g1+g_factor*i
22
- @palette[i]["b"] = b1+b_factor*i
18
+ set_palette(i, r1+r_factor*i, g1+g_factor*i, b1+b_factor*i)
23
19
  i = i+1
24
20
  end
25
21
  end
22
+
26
23
  # This function will load the color scheme from a text file.
27
24
  # This file must be formatted with three values per line ( r,g,b ).
28
25
  # By default the delimiter is a coma but you can specify it.
@@ -32,9 +29,7 @@ module ColorPalette
32
29
  while (line = infile.gets)
33
30
  values = line.split(",")
34
31
  if ( values.length == 3 )
35
- @palette[color_id]["r"] = values[0].to_i
36
- @palette[color_id]["g"] = values[1].to_i
37
- @palette[color_id]["b"] = values[2].to_i
32
+ set_palette(color_id, values[0].to_i, values[1].to_i, values[2].to_i)
38
33
  color_id+=1
39
34
  end
40
35
  end
@@ -46,11 +41,17 @@ module ColorPalette
46
41
  color_id = 0
47
42
  color_palette.each do |palette|
48
43
  if palette.length == 3
49
- @palette[color_id]["r"] = palette[0].to_i
50
- @palette[color_id]["g"] = palette[1].to_i
51
- @palette[color_id]["b"] = palette[2].to_i
44
+ set_palette(
45
+ color_id, palette[0].to_i, palette[1].to_i, palette[2].to_i)
52
46
  color_id+=1
53
47
  end
54
48
  end
55
49
  end
50
+
51
+ private
52
+
53
+ def set_palette(id,r,g,b)
54
+ @palette[id] = { "r" => r, "g" => g, "b" => b }
55
+ end
56
+
56
57
  end
@@ -149,10 +149,10 @@ module LineChart
149
149
  x_last = -1
150
150
  data.each do |key|
151
151
  if ( !key[y_serie_name].nil? && !key[x_serie_name].nil? )
152
- x= key[x_serie_name]
152
+ x = key[x_serie_name]
153
153
  y = key[y_serie_name]
154
154
  y = @g_area_y2 - ((y-@vmin) * @division_ratio)
155
- x= @g_area_x1 + ((x-@v_x_min) * @x_division_ratio)
155
+ x = @g_area_x1 + ((x-@v_x_min) * @x_division_ratio)
156
156
  if (x_last != -1 && y_last != -1)
157
157
  draw_line(x_last,y_last,x,y,@palette[palette_id]["r"],@palette[palette_id]["g"],@palette[palette_id]["b"],true)
158
158
  end
@@ -113,38 +113,38 @@ module PlotChart
113
113
  y_last = -1
114
114
  x_last = -1
115
115
  data.each do |key|
116
- if (!key[y_serie_name].nil? && !key[x_serie_name])
117
- x = key[x_serie_name]
118
- y = key[y_serie_name]
119
- y = @g_area_y2 - ((y-@vmin) * @division_ratio)
120
- x = @g_area_x1 + ((x-@v_x_min) * @x_division_ratio)
121
- if ( shadow )
122
- if ( r3 !=-1 && g3 !=-1 && b3 !=-1 )
123
- self.draw_filled_circle(x+2,y+2,big_radius,r3,g3,b3)
124
- else
125
- r3 = @palette[palette_id]["r"]-20
126
- r = 0 if ( r < 0 )
127
- g3 = @palette[palette_id]["g"]-20
128
- g = 0 if ( g < 0 )
129
- b3 = @palette[palette_id]["b"]-20
130
- b = 0 if ( b < 0 )
131
- draw_filled_circle(x+2,y+2,big_radius,r3,g3,b3)
132
- end
133
- end
134
- draw_filled_circle(x+1,y+1,big_radius,r,g,b)
116
+ next if (key[y_serie_name].nil? or key[x_serie_name].nil?)
135
117
 
136
- if ( r2 !=-1 && g2 !=-1 && b2 !=-1 )
137
- draw_filled_circle(x+1,y+1,small_radius,r2,g2,b2)
118
+ x = key[x_serie_name]
119
+ y = key[y_serie_name]
120
+ y = @g_area_y2 - ((y-@vmin) * @division_ratio)
121
+ x = @g_area_x1 + ((x-@v_x_min) * @x_division_ratio)
122
+ if ( shadow )
123
+ if ( r3 !=-1 && g3 !=-1 && b3 !=-1 )
124
+ self.draw_filled_circle(x+2,y+2,big_radius,r3,g3,b3)
138
125
  else
139
- r2 = @palette[palette_id]["r"]+20
140
- r = 255 if ( r > 255 )
141
- g2 = @palette[palette_id]["g"]+20
142
- g = 255 if ( g > 255 )
143
- b2 = @palette[palette_id]["b"]+20
144
- b = 255 if ( b > 255 )
145
- draw_filled_circle(x+1,y+1,small_radius,r2,g2,b2)
126
+ r3 = @palette[palette_id]["r"]-20
127
+ r = 0 if ( r < 0 )
128
+ g3 = @palette[palette_id]["g"]-20
129
+ g = 0 if ( g < 0 )
130
+ b3 = @palette[palette_id]["b"]-20
131
+ b = 0 if ( b < 0 )
132
+ draw_filled_circle(x+2,y+2,big_radius,r3,g3,b3)
146
133
  end
147
134
  end
135
+ draw_filled_circle(x+1,y+1,big_radius,r,g,b)
136
+
137
+ if ( r2 !=-1 && g2 !=-1 && b2 !=-1 )
138
+ draw_filled_circle(x+1,y+1,small_radius,r2,g2,b2)
139
+ else
140
+ r2 = @palette[palette_id]["r"]+20
141
+ r = 255 if ( r > 255 )
142
+ g2 = @palette[palette_id]["g"]+20
143
+ g = 255 if ( g > 255 )
144
+ b2 = @palette[palette_id]["b"]+20
145
+ b = 255 if ( b > 255 )
146
+ draw_filled_circle(x+1,y+1,small_radius,r2,g2,b2)
147
+ end
148
148
  end
149
149
  end
150
150
  def draw_limits_graph(data,data_description,r=0,g=0,b=0)
@@ -14,14 +14,14 @@ module Scale
14
14
  # Allow you to fix the scale, use this to bypass the automatic scaling
15
15
  # You can use this function to skip the automatic scaling.
16
16
  # vmin and vmax will be used to render the graph.
17
- def set_fixed_scale(v_min,v_max,divisions=5,v_x_min=0,v_x_max=0,x_divisions=5)
17
+ def set_fixed_scale(v_min,v_max,divisions=5,v_x_min=nil,v_x_max=nil,x_divisions=5)
18
18
  @vmin = v_min.to_f
19
19
  @vmax = v_max.to_f
20
20
  @divisions = divisions.to_f
21
21
 
22
- if (!v_x_min == 0 )
22
+ if (!v_x_min.nil?)
23
23
  @v_x_min = v_x_min.to_f
24
- @v_x_max = v_x_max.to_f
24
+ @v_x_max = v_x_max.nil? ? 0.0 : v_x_max.to_f
25
25
  @x_divisions = x_divisions.to_f
26
26
  end
27
27
  end
@@ -330,8 +330,8 @@ module Scale
330
330
  scale = 2
331
331
  end
332
332
  if (!scale_ok)
333
- factor = factor * 10 if ( scale2 > 1 )
334
- factor = factor / 10 if ( scale2 < 1 )
333
+ factor = factor * 10.0 if ( scale2 > 1 )
334
+ factor = factor / 10.0 if ( scale2 < 1 )
335
335
  end
336
336
  end
337
337
  if ((((@vmax*1.0 / scale) / factor)).floor != ((@vmax*1.0 / scale) / factor))
@@ -358,7 +358,7 @@ module Scale
358
358
  divisions+=1
359
359
  end
360
360
  else
361
- divisions =@divisions
361
+ divisions = @divisions
362
362
  end
363
363
  @division_count = divisions
364
364
 
@@ -373,8 +373,8 @@ module Scale
373
373
  while(i<= divisions+1)
374
374
  self.draw_line(@g_area_x1,ypos,@g_area_x1-5,ypos,r,g,b)
375
375
  value = @vmin*1.0 + (i-1) * (( @vmax - @vmin ) / divisions)
376
- value = (round_of(value * (10**decimals),2)) / (10**decimals)
377
- value= value.round if value.floor == value.ceil
376
+ value = value.round(decimals)
377
+ value = value.round if value.floor == value.ceil
378
378
  value = "#{value} #{data_description['unit']['y']}" if ( data_description["format"]["y"]== "number")
379
379
  value = self.to_time(value) if ( data_description["format"]["y"] == "time" )
380
380
  value = self.to_date(value) if ( data_description["format"]["y"] == "date" )
@@ -489,10 +489,10 @@ module Scale
489
489
 
490
490
  while(i<= x_divisions+1)
491
491
  self.draw_line(xpos,@g_area_y2,xpos,@g_area_y2+5,r,g,b)
492
- value = @v_x_min + (i-1) * (( @v_x_max - @v_x_min ) / x_divisions)
493
- value = (round_of(value * (10**decimals),2)) / (10**decimals)
494
- value= value.round if value.floor == value.ceil
495
- value = "#{value}#{data_description['unit']['y']}" if ( data_description["format"]["y"]== "number")
492
+ value = @v_x_min + (i-1) * (( @v_x_max - @v_x_min ) / x_divisions)
493
+ value = value.round(decimals)
494
+ value = value.round if value.floor == value.ceil
495
+ value = "#{value}#{data_description['unit']['y']}" if ( data_description["format"]["y"] == "number")
496
496
  value = self.to_time(value) if ( data_description["format"]["y"] == "time" )
497
497
  value = self.to_date(value) if ( data_description["format"]["y"] == "date" )
498
498
  value = self.to_metric(value) if ( data_description["format"]["Y"] == "metric" )
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rchart
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
5
- prerelease: false
4
+ hash: 7
5
+ prerelease:
6
6
  segments:
7
7
  - 2
8
8
  - 0
9
- - 2
10
- version: 2.0.2
9
+ - 4
10
+ version: 2.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - amardaxini
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-09 00:00:00 +05:30
18
+ date: 2011-12-22 00:00:00 +05:30
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -100,8 +100,8 @@ homepage: http://github.com/amardaxini/rchart
100
100
  licenses: []
101
101
 
102
102
  post_install_message:
103
- rdoc_options:
104
- - --charset=UTF-8
103
+ rdoc_options: []
104
+
105
105
  require_paths:
106
106
  - lib
107
107
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -125,31 +125,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
125
  requirements:
126
126
  - libgd-ruby, libpng-dev, libgd-dev package are required
127
127
  rubyforge_project: rchart
128
- rubygems_version: 1.3.7
128
+ rubygems_version: 1.4.2
129
129
  signing_key:
130
130
  specification_version: 3
131
131
  summary: Ruby port of the slick pChart charting library
132
- test_files:
133
- - test/helper.rb
134
- - test/test_rchart.rb
135
- - examples/example21.rb
136
- - examples/example17.rb
137
- - examples/example20.rb
138
- - examples/example12.rb
139
- - examples/example2.rb
140
- - examples/example18.rb
141
- - examples/example1.rb
142
- - examples/example11.rb
143
- - examples/example7.rb
144
- - examples/example8.rb
145
- - examples/example16.rb
146
- - examples/example5.rb
147
- - examples/example19.rb
148
- - examples/example14.rb
149
- - examples/example3.rb
150
- - examples/example6.rb
151
- - examples/example4.rb
152
- - examples/example9.rb
153
- - examples/example10.rb
154
- - examples/example13.rb
155
- - examples/example15.rb
132
+ test_files: []
133
+