-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from raphaelcm/image_charts
Add image charts to image charts.
- Loading branch information
Showing
8 changed files
with
427 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
module GoogleVisualr | ||
module Image | ||
|
||
# http://code.google.com/apis/chart/interactive/docs/gallery/imagebarchart.html | ||
class BarChart < BaseChart | ||
include GoogleVisualr::Packages::ImageChart | ||
|
||
# For Configuration Options, please refer to: | ||
# http://code.google.com/apis/chart/interactive/docs/gallery/imagebarchart.html | ||
|
||
# Create URI for image bar chart. Override parameters by passing in a hash. | ||
# (see http://code.google.com/apis/chart/image/docs/chart_params.html) | ||
# | ||
# Parameters: | ||
# *params [Optional] Hash of url query parameters | ||
def uri(params = {}) | ||
query_params = {} | ||
|
||
# isStacked/isVertical, Chart Type | ||
chart_type = "b" | ||
chart_type += @options["isVertical"] ? "v" : "h" | ||
chart_type += @options["isStacked"] == false ? "g" : "s" | ||
query_params[:cht] = chart_type | ||
|
||
# showCategoryLabels (works as long as :chxt => "x,y") | ||
labels = "" | ||
val_column = @options["isVertical"] ? 1 : 0 | ||
cat_column = @options["isVertical"] ? 0 : 1 | ||
if @options["showCategoryLabels"] == false | ||
labels = "#{cat_column}:||" | ||
else | ||
labels = "#{cat_column}:|" + data_table.get_column(0).join('|') + "|" | ||
end | ||
|
||
# showValueLabels (works as long as :chxt => "x,y") | ||
if @options["showValueLabels"] == false | ||
labels += "#{val_column}:||" | ||
end | ||
|
||
query_params[:chxl] = labels unless labels.blank? | ||
|
||
chart_image_url(query_params.merge(params)) | ||
end | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
module GoogleVisualr | ||
module Image | ||
|
||
# http://code.google.com/apis/chart/interactive/docs/gallery/imagelinechart.html | ||
class LineChart < BaseChart | ||
include GoogleVisualr::Packages::ImageChart | ||
|
||
# For Configuration Options, please refer to: | ||
# http://code.google.com/apis/chart/interactive/docs/gallery/imagelinechart.html | ||
|
||
# Create URI for image line chart. Override parameters by passing in a hash. | ||
# (see http://code.google.com/apis/chart/image/docs/chart_params.html) | ||
# | ||
# Parameters: | ||
# *params [Optional] Hash of url query parameters | ||
def uri(params = {}) | ||
query_params = {} | ||
|
||
# Chart type: line | ||
query_params[:cht] = "lc" | ||
|
||
# showAxisLines | ||
if @options["showAxisLines"] == false | ||
query_params[:cht] = "lc:nda" | ||
end | ||
|
||
# showCategoryLabels (works as long as :chxt => "x,y") | ||
labels = "" | ||
if @options["showCategoryLabels"] == false | ||
labels = "0:||" | ||
else | ||
labels = "0:|" + data_table.get_column(0).join('|') + "|" | ||
end | ||
|
||
# showValueLabels (works as long as :chxt => "x,y") | ||
if @options["showValueLabels"] == false | ||
labels += "1:||" | ||
end | ||
|
||
query_params[:chxl] = labels unless labels.blank? | ||
|
||
chart_image_url(query_params.merge(params)) | ||
end | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
module GoogleVisualr | ||
module Image | ||
|
||
# http://code.google.com/apis/chart/interactive/docs/gallery/imagepiechart.html | ||
class PieChart < BaseChart | ||
include GoogleVisualr::Packages::ImageChart | ||
|
||
# For Configuration Options, please refer to: | ||
# http://code.google.com/apis/chart/interactive/docs/gallery/imagepiechart.html | ||
|
||
# Create URI for image pie chart. Override parameters by passing in a hash. | ||
# (see http://code.google.com/apis/chart/image/docs/chart_params.html) | ||
# | ||
# Parameters: | ||
# *params [Optional] Hash of url query parameters | ||
def uri(params = {}) | ||
query_params = {} | ||
|
||
# Chart Type: normal or 3D | ||
query_params[:cht] = @options["is3D"] ? "p3" : "p" | ||
|
||
# Legend (override generic image chart behavior) | ||
query_params[:chdl] = @data_table.get_column(0).join('|') | ||
|
||
# Labels | ||
case options["labels"] | ||
when "name" | ||
query_params[:chl] = @data_table.get_column(0).join('|') | ||
when "value" | ||
query_params[:chl] = @data_table.get_column(1).join('|') | ||
else | ||
query_params[:chl] = "" | ||
end | ||
|
||
# data (override generic chart behavior) | ||
query_params[:chd] = "t:" + @data_table.get_column(1).join(',') | ||
|
||
# Chart Colors (override generic chart default) | ||
query_params[:chco] = @options["colors"].join('|').gsub(/#/, '') if @options["colors"] | ||
|
||
chart_image_url(query_params.merge(params)) | ||
end | ||
|
||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
require 'spec_helper' | ||
|
||
describe GoogleVisualr::Image::PieChart do | ||
describe "#uri" do | ||
let(:chart){ GoogleVisualr::Image::PieChart.new( data_table, {} )} | ||
image_pie_options.each_with_index do |opts, i| | ||
context "#{opts.inspect}" do | ||
it "generates correct URI" do | ||
chart.options = opts | ||
uri = chart.uri | ||
#puts uri.to_s | ||
CGI.parse(uri.query).should == CGI.parse(image_pie_chart_uris[i].query) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
describe GoogleVisualr::Image::LineChart do | ||
describe "#uri" do | ||
let(:chart){ GoogleVisualr::Image::LineChart.new( data_table, {} )} | ||
image_line_options.each_with_index do |opts, i| | ||
context "#{opts.inspect}" do | ||
it "generates correct URI" do | ||
chart.options = opts | ||
uri = chart.uri | ||
#puts uri.to_s | ||
CGI.parse(uri.query).should == CGI.parse(image_line_chart_uris[i].query) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
describe GoogleVisualr::Image::BarChart do | ||
describe "#uri" do | ||
let(:chart){ GoogleVisualr::Image::BarChart.new( data_table, {} )} | ||
image_bar_options.each_with_index do |opts, i| | ||
context "#{opts.inspect}" do | ||
it "generates correct URI" do | ||
chart.options = opts | ||
uri = chart.uri | ||
#puts uri.to_s | ||
CGI.parse(uri.query).should == CGI.parse(image_bar_chart_uris[i].query) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
describe GoogleVisualr::Image::SparkLine do | ||
describe "#uri" do | ||
let(:chart){ GoogleVisualr::Image::SparkLine.new( data_table, {} )} | ||
sparkline_options.each_with_index do |opts, i| | ||
context "#{opts.inspect}" do | ||
it "generates correct URI" do | ||
chart.options = opts | ||
uri = chart.uri | ||
#puts uri.to_s | ||
CGI.parse(uri.query).should == CGI.parse(sparkline_uris[i].query) | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.