Module: GoogleVisualr::Packages::ImageChart
- Included in:
- Image::BarChart, Image::LineChart, Image::PieChart, Image::SparkLine
- Defined in:
- lib/google_visualr/packages.rb
Constant Summary collapse
- IMAGE_DEFAULTS =
Set defaults according to code.google.com/apis/chart/interactive/docs/gallery/genericimagechart.html#Configuration_Options
{ # Automatic Scaling :chds => "a", # Size :chs => "400x200", # Axes :chxt => "x,y" }
Instance Method Summary collapse
-
#chart_image_url(superseding_params = {}) ⇒ Object
Generates HTTP GET URL for the chart image.
- #class_name ⇒ Object
- #package_name ⇒ Object
Instance Method Details
#chart_image_url(superseding_params = {}) ⇒ Object
Generates HTTP GET URL for the chart image
Parameters:
*opts [Optional] Hash of standard chart options (see http://code.google.com/apis/chart/image/docs/chart_params.html)
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/google_visualr/packages.rb', line 31 def chart_image_url(superseding_params = {}) ##### # Generic image chart defaults query_params = IMAGE_DEFAULTS.clone # backgroundColor query_params[:chf] = "bg,s," + ["backgroundColor"].gsub(/#/, '') if ["backgroundColor"] # color, colors ('color' param is ignored if 'colors' is present) if ["colors"] query_params[:chco] = ["colors"].join(',').gsub(/#/, '') elsif ["color"] query_params[:chco] = ["color"].gsub(/#/, '') end # fill (this will often not look good - better for user to override this parameter) query_params[:chm] = "B,#{query_params[:chco].split(',').first},0,0,0" if ["fill"] && query_params[:chco] # firstHiddenColumn, singleColumnDisplay, data firstHiddenColumn = ["firstHiddenColumn"] ? ["firstHiddenColumn"] : data_table.cols.size - 1 query_params[:chd] = "t:" unless ["singleColumnDisplay"] for i in 1..firstHiddenColumn do query_params[:chd] += "|" if i > 1 query_params[:chd] += data_table.get_column(i).join(',') end else query_params[:chd] += data_dable.get_column(["singleColumnDisplay"]) end # height, width if ["height"] && ["width"] query_params[:chs] = "#{["width"]}x#{["height"]}" end # title query_params[:chtt] = ["title"] if ["title"] # legend unless ["legend"] == 'none' query_params[:chdlp] = ["legend"].first unless ["legend"].blank? query_params[:chdl] = data_table.cols[1..-1].map{|col| col[:label] }.join('|') else query_params.delete(:chdlp) query_params.delete(:chdl) end # min, max, valueLabelsInterval (works as long as :chxt => "x,y" and both 'min' and 'max' are set) if ["min"] && ["max"] query_params[:chxr] = "1,#{['min']},#{['max']}" query_params[:chxr] += ",#{['valueLabelsInterval']}" if ['valueLabelsInterval'] query_params[:chds] = "#{['min']},#{['max']}" end ##### query_params = stringify_keys!(query_params.merge(superseding_params)) base_url = "https://chart.googleapis.com/chart" query = "" query_params.each_with_index do |(k,v),i| query += (i == 0) ? "?" : "&" query += "#{k}=#{CGI.escape(v)}" end URI.parse(base_url + query) end |
#class_name ⇒ Object
13 14 15 |
# File 'lib/google_visualr/packages.rb', line 13 def class_name "Image#{self.class.to_s.split('::').last}" end |
#package_name ⇒ Object
10 11 12 |
# File 'lib/google_visualr/packages.rb', line 10 def package_name "image#{self.class.to_s.split("::").last.downcase}" end |