Module: GoogleChart

Defined in:
lib/google_chart.rb,
lib/google_chart/base.rb,
lib/google_chart/qr_code.rb,
lib/google_chart/pie_chart.rb,
lib/google_chart/map_chart.rb,
lib/google_chart/bar_chart.rb,
lib/google_chart/line_chart.rb,
lib/google_chart/radar_chart.rb,
lib/google_chart/modules/grid.rb,
lib/google_chart/venn_diagram.rb,
lib/google_chart/modules/axis.rb,
lib/google_chart/linexy_chart.rb,
lib/google_chart/scatter_plot.rb,
lib/google_chart/modules/color.rb,
lib/google_chart/modules/label.rb,
lib/google_chart/modules/fills.rb,
lib/google_chart/modules/legend.rb,
lib/google_chart/sparkline_chart.rb,
lib/google_chart/modules/markers.rb,
lib/google_chart/modules/data_array.rb

Defined Under Namespace

Modules: Axis, Color, DataArray, Fills, Grid, Label, Legend, Markers Classes: BarChart, Base, LineChart, LineXYChart, MapChart, PieChart, QrCode, RadarChart, ScatterPlot, SparklineChart, VennDiagram

Constant Summary

URL =

Blatantly copied from GChart (gchart.rubyforge.org)

"http://chart.apis.google.com/chart"
SIMPLE_CHARS =
('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a
EXTENDED_CHARS =
('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a + %w[-
EXTENDED_PAIRS =
EXTENDED_CHARS.collect { |first| EXTENDED_CHARS.collect { |second| first + second } }.flatten
ENCODINGS =
[:simple, :text, :extended]

Class Method Summary (collapse)

Class Method Details

+ (Object) encode(encoding, n, max)

Encode n as a string. n is normalized based on max. Blatantly copied from GChart (gchart.rubyforge.org)



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/google_chart.rb', line 23

def encode(encoding, n, max)
  case encoding
  when :simple
    return "_" if n.nil?
    SIMPLE_CHARS[((n.zero? ? 0 : n/max.to_f) * (SIMPLE_CHARS.size - 1)).round]
  when :text
    return "-1" if n.nil?
    ((((n.zero? ? 0 : n/max.to_f) * 1000.0).round)/10.0).to_s
  when :extended
    return "__" if n.nil?
    EXTENDED_PAIRS[max.zero? ? 0 : ((n/max.to_f) * (EXTENDED_PAIRS.size - 1)).round]
  else
    raise ArgumentError, "unsupported encoding: #{encoding.inspect}"
  end
end