Skip to content

Commit

Permalink
Set label / legend for google-o-meter
Browse files Browse the repository at this point in the history
  • Loading branch information
mattetti committed Oct 5, 2008
1 parent 6f157ad commit 099db01
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 4 additions & 0 deletions History.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
== 1.3.5
* support nil values. The Google Charts API specifies that a single underscore (_) can be used to omit a value from a line chart with 'simple' data encoding, and a double underscore (__) can do the same for a chart with 'extended' data encoding. (Matt Moyer)
* allow a label to appear on a google-o-meter via the :legend option. (hallettj)

== 1.3.X
* added code to properly escape image tag URLs (mokolabs)
* added themes support + 4 default themes (keynote, thirty7signals, pastel, greyscale) chart.line(:theme=>:keynote) (jakehow)
Expand Down
12 changes: 6 additions & 6 deletions lib/gchart.rb
Original file line number Diff line number Diff line change
Expand Up @@ -325,12 +325,12 @@ def convert_to_simple_value(number)
# to about 300 pixels. Simple encoding is suitable for all other types of chart regardless of size.
def simple_encoding(dataset=[])
dataset = prepare_dataset(dataset)
@max_value = dataset.map{|ds| ds.max}.max if @max_value == 'auto'
@max_value = dataset.compact.map{|ds| ds.compact.max}.max if @max_value == 'auto'

if @max_value == false || @max_value == 'false' || @max_value == :false || @max_value == 0
"s:" + dataset.map { |ds| ds.map { |number| convert_to_simple_value(number) }.join }.join(',')
"s:" + dataset.map { |ds| ds.map { |number| number.nil? ? '_' : convert_to_simple_value(number) }.join }.join(',')
else
"s:" + dataset.map { |ds| ds.map { |number| convert_to_simple_value( (@@simple_chars.size - 1) * number / @max_value) }.join }.join(',')
"s:" + dataset.map { |ds| ds.map { |number| number.nil? ? '_' : convert_to_simple_value( (@@simple_chars.size - 1) * number / @max_value) }.join }.join(',')
end

end
Expand Down Expand Up @@ -361,12 +361,12 @@ def convert_to_extended_value(number)
def extended_encoding(dataset=[])

dataset = prepare_dataset(dataset)
@max_value = dataset.map{|ds| ds.max}.max if @max_value == 'auto'
@max_value = dataset.compact.map{|ds| ds.compact.max}.max if @max_value == 'auto'

if @max_value == false || @max_value == 'false' || @max_value == :false
"e:" + dataset.map { |ds| ds.map { |number| convert_to_extended_value(number)}.join }.join(',')
"e:" + dataset.map { |ds| ds.map { |number| number.nil? ? '__' : convert_to_extended_value(number)}.join }.join(',')
else
"e:" + dataset.map { |ds| ds.map { |number| convert_to_extended_value( (@@ext_pairs.size - 1) * number / @max_value) }.join }.join(',')
"e:" + dataset.map { |ds| ds.map { |number| number.nil? ? '__' : convert_to_extended_value( (@@ext_pairs.size - 1) * number / @max_value) }.join }.join(',')
end

end
Expand Down

0 comments on commit 099db01

Please sign in to comment.