Skip to content

Commit

Permalink
fixed a windows bug and fixed the range display
Browse files Browse the repository at this point in the history
  • Loading branch information
mattetti committed Jan 22, 2010
1 parent bd2e314 commit 1942767
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
9 changes: 7 additions & 2 deletions lib/gchart.rb
Expand Up @@ -435,8 +435,13 @@ def set_axis_range
# a passed axis_range should look like:
# [[10,100]] or [[10,100,4]] or [[10,100], [20,300]]
# in the second example, 4 is the interval
if datasets && datasets.respond_to?(:each) && datasets.first.respond_to?(:each)
'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("|")
set = axis_range || datasets
# in the case of a line graph, the first axis range should 1
index_increase = type.to_s == 'line' ? 1 : 0
if set && set.respond_to?(:each) && set.first.respond_to?(:each)
'chxr=' + datasets.enum_for(:each_with_index).map do |range, index|
[(index + index_increase), (min_value || range.first), (max_value || range.last)].compact.uniq.join(',')
end.join("|")
else
nil
end
Expand Down
13 changes: 12 additions & 1 deletion spec/gchart_spec.rb
Expand Up @@ -111,7 +111,18 @@
Gchart.line(:axis_labels => [['Jan','July','Jan','July','Jan']]).include?(Gchart.jstize('chxl=0:|Jan|July|Jan|July|Jan')).should be_true
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
end


it "should display ranges properly" do
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]
url = Gchart.line(:data => data, :axis_with_labels => 'x,y', :axis_labels => [(1.upto(24).to_a << 1)])
url.should include('chxr=1,85,593')
end

it "should take in consideration the max value when creating a range" do
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]
url = Gchart.line(:data => data, :axis_with_labels => 'x,y', :axis_labels => [(1.upto(24).to_a << 1)], :max_value => 700)
url.should include('chxr=1,85,700')
end

end

Expand Down

0 comments on commit 1942767

Please sign in to comment.