googlecharts 1.5.0 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.5.0
1
+ 1.5.1
data/lib/gchart.rb CHANGED
@@ -59,7 +59,7 @@ class Gchart
59
59
  DYNCLASSMETH
60
60
  end
61
61
 
62
- def version
62
+ def self.version
63
63
  Gchart::VERSION::STRING
64
64
  end
65
65
 
@@ -256,7 +256,7 @@ class Gchart
256
256
  def write
257
257
  io_or_file = filename || Gchart.default_filename
258
258
  return io_or_file.write(fetch) if io_or_file.respond_to?(:write)
259
- open(io_or_file, "w+") { |io| io.write(fetch) }
259
+ open(io_or_file, "wb+") { |io| io.write(fetch) }
260
260
  end
261
261
 
262
262
  # Format
@@ -435,8 +435,13 @@ class Gchart
435
435
  # a passed axis_range should look like:
436
436
  # [[10,100]] or [[10,100,4]] or [[10,100], [20,300]]
437
437
  # in the second example, 4 is the interval
438
- if datasets && datasets.respond_to?(:each) && datasets.first.respond_to?(:each)
439
- 'chxr=' + datasets.enum_for(:each_with_index).map{|range, index| [index, (min_value || range[0]), range[1], (max_value || range[2])].compact.uniq.join(',')}.join("|")
438
+ set = axis_range || datasets
439
+ # in the case of a line graph, the first axis range should 1
440
+ index_increase = type.to_s == 'line' ? 1 : 0
441
+ if set && set.respond_to?(:each) && set.first.respond_to?(:each)
442
+ 'chxr=' + datasets.enum_for(:each_with_index).map do |range, index|
443
+ [(index + index_increase), (min_value || range.first), (max_value || range.last)].compact.uniq.join(',')
444
+ end.join("|")
440
445
  else
441
446
  nil
442
447
  end
@@ -2,7 +2,7 @@ module GchartInfo #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 1
4
4
  MINOR = 5
5
- TINY = 0
5
+ TINY = 1
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/spec/gchart_spec.rb CHANGED
@@ -111,7 +111,18 @@ describe "generating a default Gchart" do
111
111
  Gchart.line(:axis_labels => [['Jan','July','Jan','July','Jan']]).include?(Gchart.jstize('chxl=0:|Jan|July|Jan|July|Jan')).should be_true
112
112
  Gchart.line(:axis_labels => [['Jan','July','Jan','July','Jan'], ['0','100'], ['A','B','C'], ['2005','2006','2007']]).include?(Gchart.jstize('chxl=0:|Jan|July|Jan|July|Jan|1:|0|100|2:|A|B|C|3:|2005|2006|2007')).should be_true
113
113
  end
114
-
114
+
115
+ it "should display ranges properly" do
116
+ data = [85,107,123,131,155,172,173,189,203,222,217,233,250,239,256,267,247,261,275,295,288,305,322,307,325,347,331,346,363,382,343,359,383,352,374,393,358,379,396,416,377,398,419,380,409,426,453,432,452,465,436,460,480,440,457,474,501,457,489,507,347,373,413,402,424,448,475,488,513,475,507,530,440,476,500,518,481,512,531,367,396,423,387,415,446,478,442,469,492,463,489,508,463,491,518,549,503,526,547,493,530,549,493,520,541,564,510,535,564,492,512,537,502,530,548,491,514,538,568,524,548,568,512,533,552,577,520,545,570,516,536,555,514,536,566,521,553,579,604,541,569,595,551,581,602,549,576,606,631,589,615,650,597,624,646,672,605,626,654,584,608,631,574,597,622,559,591,614,644,580,603,629,584,615,631,558,591,618,641,314,356,395,397,429,450,421,454,477,507,458,490,560,593]
117
+ url = Gchart.line(:data => data, :axis_with_labels => 'x,y', :axis_labels => [(1.upto(24).to_a << 1)])
118
+ url.should include('chxr=1,85,593')
119
+ end
120
+
121
+ it "should take in consideration the max value when creating a range" do
122
+ data = [85,107,123,131,155,172,173,189,203,222,217,233,250,239,256,267,247,261,275,295,288,305,322,307,325,347,331,346,363,382,343,359,383,352,374,393,358,379,396,416,377,398,419,380,409,426,453,432,452,465,436,460,480,440,457,474,501,457,489,507,347,373,413,402,424,448,475,488,513,475,507,530,440,476,500,518,481,512,531,367,396,423,387,415,446,478,442,469,492,463,489,508,463,491,518,549,503,526,547,493,530,549,493,520,541,564,510,535,564,492,512,537,502,530,548,491,514,538,568,524,548,568,512,533,552,577,520,545,570,516,536,555,514,536,566,521,553,579,604,541,569,595,551,581,602,549,576,606,631,589,615,650,597,624,646,672,605,626,654,584,608,631,574,597,622,559,591,614,644,580,603,629,584,615,631,558,591,618,641,314,356,395,397,429,450,421,454,477,507,458,490,560,593]
123
+ url = Gchart.line(:data => data, :axis_with_labels => 'x,y', :axis_labels => [(1.upto(24).to_a << 1)], :max_value => 700)
124
+ url.should include('chxr=1,85,700')
125
+ end
115
126
 
116
127
  end
117
128
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: googlecharts
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Aimonetti