Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds locale option as described in.. #96

Merged
merged 4 commits into from
Aug 27, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions lib/google_visualr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,33 @@
# Interactive Charts

## Main
require "#{lib_path}/google_visualr/interactive/annotated_time_line"
require "#{lib_path}/google_visualr/interactive/annotation_chart"
require "#{lib_path}/google_visualr/interactive/area_chart"
require "#{lib_path}/google_visualr/interactive/bar_chart"
require "#{lib_path}/google_visualr/interactive/bubble_chart"
require "#{lib_path}/google_visualr/interactive/calendar"
require "#{lib_path}/google_visualr/interactive/candlestick_chart"
require "#{lib_path}/google_visualr/interactive/column_chart"
require "#{lib_path}/google_visualr/interactive/combo_chart"
require "#{lib_path}/google_visualr/interactive/gantt_chart"
require "#{lib_path}/google_visualr/interactive/gauge"
require "#{lib_path}/google_visualr/interactive/geo_chart"
require "#{lib_path}/google_visualr/interactive/geo_map"
require "#{lib_path}/google_visualr/interactive/histogram"
require "#{lib_path}/google_visualr/interactive/intensity_map"
require "#{lib_path}/google_visualr/interactive/line_chart"
require "#{lib_path}/google_visualr/interactive/map"
require "#{lib_path}/google_visualr/interactive/motion_chart"
require "#{lib_path}/google_visualr/interactive/org_chart"
require "#{lib_path}/google_visualr/interactive/pie_chart"
require "#{lib_path}/google_visualr/interactive/sankey"
require "#{lib_path}/google_visualr/interactive/scatter_chart"
require "#{lib_path}/google_visualr/interactive/stepped_area_chart"
require "#{lib_path}/google_visualr/interactive/table"
require "#{lib_path}/google_visualr/interactive/tree_map"


## Additional
require "#{lib_path}/google_visualr/interactive/annotated_time_line"
require "#{lib_path}/google_visualr/interactive/intensity_map"
require "#{lib_path}/google_visualr/interactive/map"
require "#{lib_path}/google_visualr/interactive/motion_chart"
require "#{lib_path}/google_visualr/interactive/org_chart"
require "#{lib_path}/google_visualr/interactive/timeline"
require "#{lib_path}/google_visualr/interactive/tree_map"
require "#{lib_path}/google_visualr/interactive/word_tree"

# Image Charts
require "#{lib_path}/google_visualr/image/spark_line"
Expand Down
5 changes: 3 additions & 2 deletions lib/google_visualr/base_chart.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ class BaseChart

DEFAULT_VERSION = "1.0".freeze

attr_accessor :data_table, :listeners, :version, :material
attr_accessor :data_table, :listeners, :version, :language, :material

def initialize(data_table, options={})
@data_table = data_table
@listeners = []
@version = options.delete(:version) || DEFAULT_VERSION
@language = options.delete(:language) || "en"
@material = options.delete(:material) || false
send(:options=, options)
end
Expand Down Expand Up @@ -73,7 +74,7 @@ def to_js(element_id)
# Parameters:
# *div_id [Required] The ID of the DIV element that the Google Chart should be rendered in.
def load_js(element_id)
"\n google.load('visualization','#{version}', {packages: ['#{package_name}'], callback: #{chart_function_name(element_id)}});"
"\n google.load('visualization', '#{version}', {packages: ['#{package_name}'], language: '#{language}', callback: #{chart_function_name(element_id)}});"
end

# Generates JavaScript function for rendering the chart.
Expand Down
11 changes: 11 additions & 0 deletions lib/google_visualr/interactive/annotation_chart.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module GoogleVisualr
module Interactive

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra empty line detected at module body beginning.

# https://developers.google.com/chart/interactive/docs/gallery/annotationchart
class AnnotationChart < BaseChart
# For Configuration Options, please refer to:
# https://developers.google.com/chart/interactive/docs/gallery/annotationchart#configuration-options
end

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra empty line detected at module body end.

end
end
11 changes: 11 additions & 0 deletions lib/google_visualr/interactive/calendar.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module GoogleVisualr
module Interactive

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra empty line detected at module body beginning.

# https://developers.google.com/chart/interactive/docs/gallery/calendar
class Calendar < BaseChart
# For Configuration Options, please refer to:
# https://developers.google.com/chart/interactive/docs/gallery/calendar#configuration-options
end

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra empty line detected at module body end.

end
end
16 changes: 16 additions & 0 deletions lib/google_visualr/interactive/gantt_chart.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module GoogleVisualr
module Interactive

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra empty line detected at module body beginning.

# https://developers.google.com/chart/interactive/docs/gallery/ganttchart
class GanttChart < BaseChart

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra empty line detected at class body beginning.

def package_name
"gantt"
end

# For Configuration Options, please refer to:
# https://developers.google.com/chart/interactive/docs/gallery/ganttchart#configuration-options
end

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra empty line detected at module body end.

end
end
11 changes: 11 additions & 0 deletions lib/google_visualr/interactive/sankey.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module GoogleVisualr
module Interactive

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra empty line detected at module body beginning.

# https://developers.google.com/chart/interactive/docs/gallery/sankey
class Sankey < BaseChart
# For Configuration Options, please refer to:
# https://developers.google.com/chart/interactive/docs/gallery/sankey#configuration-options
end

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra empty line detected at module body end.

end
end
11 changes: 11 additions & 0 deletions lib/google_visualr/interactive/word_tree.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module GoogleVisualr
module Interactive

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra empty line detected at module body beginning.

# https://developers.google.com/chart/interactive/docs/gallery/wordtree
class WordTree < BaseChart
# For Configuration Options, please refer to:
# https://developers.google.com/chart/interactive/docs/gallery/wordtree#a-simple-example
end

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra empty line detected at module body end.

end
end
20 changes: 18 additions & 2 deletions spec/google_visualr/base_chart_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,18 @@
@chart.options.should == { "legend" => "Test Chart", "width" => 800, "is3D" => true }
end

it "accepts material and version attributes" do
@chart = GoogleVisualr::BaseChart.new(@dt, { :version => "1.1", :material => true })
it "accepts version attribute" do
@chart = GoogleVisualr::BaseChart.new(@dt, version: "1.1")
@chart.version.should == "1.1"
end

it "accepts language attribute" do
@chart = GoogleVisualr::BaseChart.new(@dt, language: "ja")
@chart.language.should == "ja"
end

it "accepts material attribute" do
@chart = GoogleVisualr::BaseChart.new(@dt, material: true)
@chart.material.should == true
end
end
Expand Down Expand Up @@ -89,6 +98,13 @@
js.should include("<script")
end

it "generates JS of a different locale" do
@chart.language = "ja"

js = @chart.to_js("body")
js.should == base_chart_js("body", "ja")
end

it "generates JS with listeners" do
@chart.add_listener("select", "function() {test_event(chart);}")

Expand Down
14 changes: 7 additions & 7 deletions spec/support/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ def base_chart(data_table = data_table())
GoogleVisualr::BaseChart.new(data_table, { :legend => "Test Chart", :width => 800, :is3D => true })
end

def base_chart_js_without_script_tag(div_class="div_class")
js = "\n google.load('visualization','1.0', {packages: ['basechart'], callback: draw_#{div_class}});"
def base_chart_js_without_script_tag(div_class = "div_class", language = "en")
js = "\n google.load('visualization', '1.0', {packages: ['basechart'], language: '#{language}', callback: draw_#{div_class}});"
js << "\n function draw_#{div_class}() {"
js << "\n var data_table = new google.visualization.DataTable();data_table.addColumn({\"type\":\"string\",\"label\":\"Year\"});data_table.addColumn({\"type\":\"number\",\"label\":\"Sales\"});data_table.addColumn({\"type\":\"number\",\"label\":\"Expenses\"});data_table.addRow([{v: \"2004\"}, {v: 1000}, {v: 400}]);data_table.addRow([{v: \"2005\"}, {v: 1200}, {v: 450}]);data_table.addRow([{v: \"2006\"}, {v: 1500}, {v: 600}]);data_table.addRow([{v: \"2007\"}, {v: 800}, {v: 500}]);\n var chart = new google.visualization.BaseChart(document.getElementById('#{div_class}'));"
js << "\n chart.draw(data_table, {legend: \"Test Chart\", width: 800, is3D: true});"
js << "\n };"
end

def base_chart_js(div_class="div_class")
def base_chart_js(div_class = "div_class", language = "en")
js = "\n<script type='text/javascript'>"
js << base_chart_js_without_script_tag(div_class)
js << base_chart_js_without_script_tag(div_class, language)
js << "\n</script>"
end

def base_chart_with_listener_js(div_class="div_class")
def base_chart_with_listener_js(div_class = "div_class")
js = "\n<script type='text/javascript'>"
js << "\n google.load('visualization','1.0', {packages: ['basechart'], callback: draw_#{div_class}});"
js << "\n google.load('visualization', '1.0', {packages: ['basechart'], language: 'en', callback: draw_#{div_class}});"
js << "\n function draw_#{div_class}() {"
js << "\n var data_table = new google.visualization.DataTable();data_table.addColumn({\"type\":\"string\",\"label\":\"Year\"});data_table.addColumn({\"type\":\"number\",\"label\":\"Sales\"});data_table.addColumn({\"type\":\"number\",\"label\":\"Expenses\"});data_table.addRow([{v: \"2004\"}, {v: 1000}, {v: 400}]);data_table.addRow([{v: \"2005\"}, {v: 1200}, {v: 450}]);data_table.addRow([{v: \"2006\"}, {v: 1500}, {v: 600}]);data_table.addRow([{v: \"2007\"}, {v: 800}, {v: 500}]);\n var chart = new google.visualization.BaseChart(document.getElementById('#{div_class}'));"
js << "\n google.visualization.events.addListener(chart, 'select', function() {test_event(chart);});"
Expand All @@ -44,7 +44,7 @@ def base_chart_with_listener_js(div_class="div_class")

def material_chart(div_class = "div_class")
js = "\n<script type='text/javascript'>"
js << "\n google.load('visualization','1.0', {packages: ['basechart'], callback: draw_#{div_class}});"
js << "\n google.load('visualization', '1.0', {packages: ['basechart'], language: 'en', callback: draw_#{div_class}});"
js << "\n function draw_#{div_class}() {"
js << "\n var data_table = new google.visualization.DataTable();data_table.addColumn({\"type\":\"string\",\"label\":\"Year\"});data_table.addColumn({\"type\":\"number\",\"label\":\"Sales\"});data_table.addColumn({\"type\":\"number\",\"label\":\"Expenses\"});data_table.addRow([{v: \"2004\"}, {v: 1000}, {v: 400}]);data_table.addRow([{v: \"2005\"}, {v: 1200}, {v: 450}]);data_table.addRow([{v: \"2006\"}, {v: 1500}, {v: 600}]);data_table.addRow([{v: \"2007\"}, {v: 800}, {v: 500}]);\n var chart = new google.charts.Base(document.getElementById('#{div_class}'));"
js << "\n chart.draw(data_table, {legend: \"Test Chart\", width: 800, is3D: true});"
Expand Down