├── spec
├── dummy
│ ├── Gemfile
│ ├── log
│ │ ├── test.log
│ │ ├── server.log
│ │ ├── development.log
│ │ └── production.log
│ ├── lib
│ │ └── tasks
│ │ │ └── .gitkeep
│ ├── public
│ │ ├── favicon.ico
│ │ ├── stylesheets
│ │ │ └── .gitkeep
│ │ ├── images
│ │ │ └── rails.png
│ │ ├── javascripts
│ │ │ ├── application.js
│ │ │ ├── rails.js
│ │ │ └── dragdrop.js
│ │ ├── robots.txt
│ │ ├── 422.html
│ │ ├── 404.html
│ │ ├── 500.html
│ │ └── index.html
│ ├── vendor
│ │ └── plugins
│ │ │ └── .gitkeep
│ ├── app
│ │ ├── helpers
│ │ │ └── application_helper.rb
│ │ ├── controllers
│ │ │ └── application_controller.rb
│ │ └── views
│ │ │ └── layouts
│ │ │ └── application.html.erb
│ ├── Gemfile.lock
│ ├── config.ru
│ ├── config
│ │ ├── environment.rb
│ │ ├── boot.rb
│ │ ├── locales
│ │ │ └── en.yml
│ │ ├── initializers
│ │ │ ├── mime_types.rb
│ │ │ ├── inflections.rb
│ │ │ ├── backtrace_silencers.rb
│ │ │ ├── session_store.rb
│ │ │ └── secret_token.rb
│ │ ├── database.yml
│ │ ├── environments
│ │ │ ├── development.rb
│ │ │ ├── test.rb
│ │ │ └── production.rb
│ │ ├── application.rb
│ │ └── routes.rb
│ ├── doc
│ │ └── README_FOR_APP
│ ├── Rakefile
│ ├── test
│ │ ├── performance
│ │ │ └── browsing_test.rb
│ │ └── test_helper.rb
│ ├── script
│ │ └── rails
│ └── db
│ │ └── seeds.rb
├── spec_helper.rb
├── turbolinks_tests
│ ├── index.html
│ ├── old.html
│ ├── fixed.html
│ ├── broken.html
│ └── turbolinks.js
├── google_visualr
│ ├── app
│ │ └── helpers
│ │ │ └── view_helper_spec.rb
│ ├── param_helpers_spec.rb
│ ├── base_chart_spec.rb
│ ├── formatters_spec.rb
│ ├── image_charts_spec.rb
│ └── data_table_spec.rb
└── support
│ └── common.rb
├── .rspec
├── .ruby-version
├── .hound.yml
├── .gitignore
├── lib
├── google_visualr
│ ├── version.rb
│ ├── interactive
│ │ ├── gauge.rb
│ │ ├── map.rb
│ │ ├── sankey.rb
│ │ ├── table.rb
│ │ ├── geo_map.rb
│ │ ├── word_tree.rb
│ │ ├── calendar.rb
│ │ ├── timeline.rb
│ │ ├── tree_map.rb
│ │ ├── geo_chart.rb
│ │ ├── org_chart.rb
│ │ ├── motion_chart.rb
│ │ ├── annotation_chart.rb
│ │ ├── intensity_map.rb
│ │ ├── annotated_time_line.rb
│ │ ├── pie_chart.rb
│ │ ├── area_chart.rb
│ │ ├── bubble_chart.rb
│ │ ├── histogram.rb
│ │ ├── combo_chart.rb
│ │ ├── gantt_chart.rb
│ │ ├── stepped_area_chart.rb
│ │ ├── candlestick_chart.rb
│ │ ├── line_chart.rb
│ │ ├── scatter_chart.rb
│ │ ├── bar_chart.rb
│ │ └── column_chart.rb
│ ├── app
│ │ ├── railtie.rb
│ │ └── helpers
│ │ │ └── view_helper.rb
│ ├── image
│ │ ├── spark_line.rb
│ │ ├── line_chart.rb
│ │ ├── pie_chart.rb
│ │ └── bar_chart.rb
│ ├── formatters.rb
│ ├── param_helpers.rb
│ ├── base_chart.rb
│ ├── packages.rb
│ └── data_table.rb
└── google_visualr.rb
├── Gemfile
├── Rakefile
├── gemfiles
├── 3.2.gemfile
├── 4.0.gemfile
├── 4.1.gemfile
├── 4.0.gemfile.lock
├── 4.1.gemfile.lock
└── 3.2.gemfile.lock
├── .travis.yml
├── Appraisals
├── CONTRIBUTING.md
├── google_visualr.gemspec
├── MIT-LICENSE
├── CHANGELOG.md
└── README.md
/spec/dummy/Gemfile:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.rspec:
--------------------------------------------------------------------------------
1 | --colour
2 |
--------------------------------------------------------------------------------
/spec/dummy/log/test.log:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.ruby-version:
--------------------------------------------------------------------------------
1 | ruby-2.1.3
2 |
--------------------------------------------------------------------------------
/spec/dummy/log/server.log:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/spec/dummy/lib/tasks/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/spec/dummy/log/development.log:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/spec/dummy/log/production.log:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/spec/dummy/public/favicon.ico:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/spec/dummy/public/stylesheets/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/spec/dummy/vendor/plugins/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.hound.yml:
--------------------------------------------------------------------------------
1 | ruby:
2 | config_file: .ruby-style.yml
3 |
--------------------------------------------------------------------------------
/spec/dummy/app/helpers/application_helper.rb:
--------------------------------------------------------------------------------
1 | module ApplicationHelper
2 | end
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | pkg/*
2 | *.gem
3 | .bundle
4 | .idea
5 | vendor/bundle
6 | /Gemfile.lock
7 |
--------------------------------------------------------------------------------
/lib/google_visualr/version.rb:
--------------------------------------------------------------------------------
1 | module GoogleVisualr
2 | VERSION = "2.5.1"
3 | end
4 |
--------------------------------------------------------------------------------
/spec/dummy/Gemfile.lock:
--------------------------------------------------------------------------------
1 | GEM
2 | specs:
3 |
4 | PLATFORMS
5 | ruby
6 |
7 | DEPENDENCIES
8 |
--------------------------------------------------------------------------------
/spec/dummy/public/images/rails.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/winston/google_visualr/HEAD/spec/dummy/public/images/rails.png
--------------------------------------------------------------------------------
/spec/dummy/app/controllers/application_controller.rb:
--------------------------------------------------------------------------------
1 | class ApplicationController < ActionController::Base
2 | protect_from_forgery
3 | end
4 |
--------------------------------------------------------------------------------
/spec/dummy/config.ru:
--------------------------------------------------------------------------------
1 | # This file is used by Rack-based servers to start the application.
2 |
3 | require ::File.expand_path('../config/environment', __FILE__)
4 | run Dummy::Application
5 |
--------------------------------------------------------------------------------
/spec/dummy/config/environment.rb:
--------------------------------------------------------------------------------
1 | # Load the rails application
2 | require File.expand_path('../application', __FILE__)
3 |
4 | # Initialize the rails application
5 | Dummy::Application.initialize!
6 |
--------------------------------------------------------------------------------
/spec/dummy/public/javascripts/application.js:
--------------------------------------------------------------------------------
1 | // Place your application-specific JavaScript functions and classes here
2 | // This file is automatically included by javascript_include_tag :defaults
3 |
--------------------------------------------------------------------------------
/Gemfile:
--------------------------------------------------------------------------------
1 | source "https://rubygems.org"
2 |
3 | gemspec
4 |
5 | group :development do
6 | gem "bundler", ">= 1.3.5"
7 | gem "rspec", "~> 2.99.0"
8 | gem "appraisal"
9 | gem "rails", "~> 4.2.1"
10 | end
11 |
--------------------------------------------------------------------------------
/Rakefile:
--------------------------------------------------------------------------------
1 | # Bundler Gem Tasks
2 | require 'bundler'
3 | Bundler::GemHelper.install_tasks
4 |
5 | require 'rspec/core/rake_task'
6 | RSpec::Core::RakeTask.new(:spec)
7 |
8 | task test: :spec
9 | task default: :spec
10 |
--------------------------------------------------------------------------------
/spec/dummy/config/boot.rb:
--------------------------------------------------------------------------------
1 | require 'rubygems'
2 |
3 | # Set up gems listed in the Gemfile.
4 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
5 |
6 | require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
7 |
--------------------------------------------------------------------------------
/spec/dummy/doc/README_FOR_APP:
--------------------------------------------------------------------------------
1 | Use this README file to introduce your application and point to useful places in the API for learning more.
2 | Run "rake doc:app" to generate API documentation for your models, controllers, helpers, and libraries.
3 |
--------------------------------------------------------------------------------
/spec/dummy/public/robots.txt:
--------------------------------------------------------------------------------
1 | # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
2 | #
3 | # To ban all spiders from the entire site uncomment the next two lines:
4 | # User-Agent: *
5 | # Disallow: /
6 |
--------------------------------------------------------------------------------
/spec/dummy/config/locales/en.yml:
--------------------------------------------------------------------------------
1 | # Sample localization file for English. Add more files in this directory for other locales.
2 | # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3 |
4 | en:
5 | hello: "Hello world"
6 |
--------------------------------------------------------------------------------
/spec/dummy/config/initializers/mime_types.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Add new mime types for use in respond_to blocks:
4 | # Mime::Type.register "text/richtext", :rtf
5 | # Mime::Type.register_alias "text/html", :iphone
6 |
--------------------------------------------------------------------------------
/gemfiles/3.2.gemfile:
--------------------------------------------------------------------------------
1 | # This file was generated by Appraisal
2 |
3 | source "https://rubygems.org"
4 |
5 | group :development do
6 | gem "bundler", ">= 1.3.5"
7 | gem "rspec", "~> 2.99.0"
8 | gem "appraisal"
9 | gem "rails", "~> 3.2.21"
10 | end
11 |
12 | gemspec :path => "../"
13 |
--------------------------------------------------------------------------------
/gemfiles/4.0.gemfile:
--------------------------------------------------------------------------------
1 | # This file was generated by Appraisal
2 |
3 | source "https://rubygems.org"
4 |
5 | group :development do
6 | gem "bundler", ">= 1.3.5"
7 | gem "rspec", "~> 2.99.0"
8 | gem "appraisal"
9 | gem "rails", "~> 4.0.13"
10 | end
11 |
12 | gemspec :path => "../"
13 |
--------------------------------------------------------------------------------
/gemfiles/4.1.gemfile:
--------------------------------------------------------------------------------
1 | # This file was generated by Appraisal
2 |
3 | source "https://rubygems.org"
4 |
5 | group :development do
6 | gem "bundler", ">= 1.3.5"
7 | gem "rspec", "~> 2.99.0"
8 | gem "appraisal"
9 | gem "rails", "~> 4.1.10"
10 | end
11 |
12 | gemspec :path => "../"
13 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: ruby
2 | bundler_args: --retry=3 --jobs=3 --no-deployment
3 | cache: bundler
4 | sudo: false
5 |
6 | rvm:
7 | - 2.0.0
8 | - 2.1.6
9 | - 2.2.2
10 |
11 | gemfile:
12 | - gemfiles/3.2.gemfile
13 | - gemfiles/4.0.gemfile
14 | - gemfiles/4.1.gemfile
15 | - Gemfile
16 |
--------------------------------------------------------------------------------
/spec/dummy/Rakefile:
--------------------------------------------------------------------------------
1 | # Add your own tasks in files placed in lib/tasks ending in .rake,
2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3 |
4 | require File.expand_path('../config/application', __FILE__)
5 | require 'rake'
6 |
7 | Dummy::Application.load_tasks
8 |
--------------------------------------------------------------------------------
/spec/dummy/app/views/layouts/application.html.erb:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Dummy
5 | <%= stylesheet_link_tag :all %>
6 | <%= javascript_include_tag :defaults %>
7 | <%= csrf_meta_tag %>
8 |
9 |
10 |
11 | <%= yield %>
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/spec/dummy/test/performance/browsing_test.rb:
--------------------------------------------------------------------------------
1 | require 'test_helper'
2 | require 'rails/performance_test_help'
3 |
4 | # Profiling results for each test method are written to tmp/performance.
5 | class BrowsingTest < ActionDispatch::PerformanceTest
6 | def test_homepage
7 | get '/'
8 | end
9 | end
10 |
--------------------------------------------------------------------------------
/Appraisals:
--------------------------------------------------------------------------------
1 | appraise "3.2" do
2 | group :development do
3 | gem "rails", "~> 3.2.21"
4 | end
5 | end
6 |
7 | appraise "4.0" do
8 | group :development do
9 | gem "rails", "~> 4.0.13"
10 | end
11 | end
12 |
13 | appraise "4.1" do
14 | group :development do
15 | gem "rails", "~> 4.1.10"
16 | end
17 | end
18 |
--------------------------------------------------------------------------------
/spec/dummy/script/rails:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3 |
4 | APP_PATH = File.expand_path('../../config/application', __FILE__)
5 | require File.expand_path('../../config/boot', __FILE__)
6 | require 'rails/commands'
7 |
--------------------------------------------------------------------------------
/spec/dummy/db/seeds.rb:
--------------------------------------------------------------------------------
1 | # This file should contain all the record creation needed to seed the database with its default values.
2 | # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
3 | #
4 | # Examples:
5 | #
6 | # cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
7 | # Mayor.create(:name => 'Daley', :city => cities.first)
8 |
--------------------------------------------------------------------------------
/lib/google_visualr/interactive/gauge.rb:
--------------------------------------------------------------------------------
1 | module GoogleVisualr
2 | module Interactive
3 |
4 | # http://code.google.com/apis/chart/interactive/docs/gallery/gauge.html
5 | class Gauge < BaseChart
6 | # For Configuration Options, please refer to:
7 | # http://code.google.com/apis/chart/interactive/docs/gallery/gauge.html#Configuration_Options
8 | end
9 |
10 | end
11 | end
12 |
--------------------------------------------------------------------------------
/lib/google_visualr/interactive/map.rb:
--------------------------------------------------------------------------------
1 | module GoogleVisualr
2 | module Interactive
3 |
4 | # http://code.google.com/apis/chart/interactive/docs/gallery/map.html
5 | class Map < BaseChart
6 | # For Configuration Options, please refer to:
7 | # http://code.google.com/apis/chart/interactive/docs/gallery/map.html#Configuration_Options
8 | end
9 |
10 | end
11 | end
12 |
--------------------------------------------------------------------------------
/lib/google_visualr/interactive/sankey.rb:
--------------------------------------------------------------------------------
1 | module GoogleVisualr
2 | module Interactive
3 |
4 | # https://developers.google.com/chart/interactive/docs/gallery/sankey
5 | class Sankey < BaseChart
6 | # For Configuration Options, please refer to:
7 | # https://developers.google.com/chart/interactive/docs/gallery/sankey#configuration-options
8 | end
9 |
10 | end
11 | end
12 |
--------------------------------------------------------------------------------
/lib/google_visualr/interactive/table.rb:
--------------------------------------------------------------------------------
1 | module GoogleVisualr
2 | module Interactive
3 |
4 | # http://code.google.com/apis/chart/interactive/docs/gallery/table.html
5 | class Table < BaseChart
6 | # For Configuration Options, please refer to:
7 | # http://code.google.com/apis/chart/interactive/docs/gallery/table.html#Configuration_Options
8 | end
9 |
10 | end
11 | end
12 |
--------------------------------------------------------------------------------
/lib/google_visualr/interactive/geo_map.rb:
--------------------------------------------------------------------------------
1 | module GoogleVisualr
2 | module Interactive
3 |
4 | # http://code.google.com/apis/chart/interactive/docs/gallery/geomap.html
5 | class GeoMap < BaseChart
6 | # For Configuration Options, please refer to:
7 | # http://code.google.com/apis/chart/interactive/docs/gallery/geomap.html#Configuration_Options
8 | end
9 |
10 | end
11 | end
12 |
--------------------------------------------------------------------------------
/lib/google_visualr/interactive/word_tree.rb:
--------------------------------------------------------------------------------
1 | module GoogleVisualr
2 | module Interactive
3 |
4 | # https://developers.google.com/chart/interactive/docs/gallery/wordtree
5 | class WordTree < BaseChart
6 | # For Configuration Options, please refer to:
7 | # https://developers.google.com/chart/interactive/docs/gallery/wordtree#a-simple-example
8 | end
9 |
10 | end
11 | end
12 |
--------------------------------------------------------------------------------
/lib/google_visualr/interactive/calendar.rb:
--------------------------------------------------------------------------------
1 | module GoogleVisualr
2 | module Interactive
3 |
4 | # https://developers.google.com/chart/interactive/docs/gallery/calendar
5 | class Calendar < BaseChart
6 | # For Configuration Options, please refer to:
7 | # https://developers.google.com/chart/interactive/docs/gallery/calendar#configuration-options
8 | end
9 |
10 | end
11 | end
12 |
--------------------------------------------------------------------------------
/lib/google_visualr/interactive/timeline.rb:
--------------------------------------------------------------------------------
1 | module GoogleVisualr
2 | module Interactive
3 |
4 | # https://developers.google.com/chart/interactive/docs/gallery/timeline
5 | class Timeline < BaseChart
6 | # For Configuration Options, please refer to:
7 | # https://developers.google.com/chart/interactive/docs/gallery/timeline#Configuration_Options
8 | end
9 |
10 | end
11 | end
12 |
--------------------------------------------------------------------------------
/lib/google_visualr/interactive/tree_map.rb:
--------------------------------------------------------------------------------
1 | module GoogleVisualr
2 | module Interactive
3 |
4 | # http://code.google.com/apis/chart/interactive/docs/gallery/treemap.html
5 | class TreeMap < BaseChart
6 | # For Configuration Options, please refer to:
7 | # http://code.google.com/apis/chart/interactive/docs/gallery/treemap.html#Configuration_Options
8 | end
9 |
10 | end
11 | end
12 |
--------------------------------------------------------------------------------
/lib/google_visualr/interactive/geo_chart.rb:
--------------------------------------------------------------------------------
1 | module GoogleVisualr
2 | module Interactive
3 |
4 | # http://code.google.com/apis/chart/interactive/docs/gallery/geochart.html
5 | class GeoChart < BaseChart
6 | # For Configuration Options, please refer to:
7 | # http://code.google.com/apis/chart/interactive/docs/gallery/geochart.html#Configuration_Options
8 | end
9 |
10 | end
11 | end
12 |
--------------------------------------------------------------------------------
/lib/google_visualr/interactive/org_chart.rb:
--------------------------------------------------------------------------------
1 | module GoogleVisualr
2 | module Interactive
3 |
4 | # http://code.google.com/apis/chart/interactive/docs/gallery/orgchart.html
5 | class OrgChart < BaseChart
6 | # For Configuration Options, please refer to:
7 | # http://code.google.com/apis/chart/interactive/docs/gallery/orgchart.html#Configuration_Options
8 | end
9 |
10 | end
11 | end
12 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | ## Contributing
2 |
3 | ### Development
4 |
5 | We use [appraisal](https://github.com/thoughtbot/appraisal) to test against
6 | multiple rubies and rails versions.
7 |
8 | Run `appraisal install` to install all dependencies (See files under `gemfiles`
9 | folder).
10 |
11 | Run `appraisal rake` for tests with all versions of Rails.
12 |
13 | Run `appraisal 4.1 rake` for tests with Rails 4.1.
14 |
--------------------------------------------------------------------------------
/lib/google_visualr/interactive/motion_chart.rb:
--------------------------------------------------------------------------------
1 | module GoogleVisualr
2 | module Interactive
3 |
4 | # http://code.google.com/apis/chart/interactive/docs/gallery/motionchart.html
5 | class MotionChart < BaseChart
6 | # For Configuration Options, please refer to:
7 | # http://code.google.com/apis/chart/interactive/docs/gallery/motionchart.html#Configuration_Options
8 | end
9 |
10 | end
11 | end
12 |
--------------------------------------------------------------------------------
/lib/google_visualr/app/railtie.rb:
--------------------------------------------------------------------------------
1 | require "#{File.dirname(__FILE__)}/helpers/view_helper"
2 |
3 | module GoogleVisualr
4 |
5 | module Rails
6 |
7 | class Railtie < ::Rails::Railtie
8 |
9 | initializer "google_visualr" do
10 | ActiveSupport.on_load(:action_controller) do
11 | include GoogleVisualr::Rails::ViewHelper
12 | end
13 | end
14 |
15 | end
16 |
17 | end
18 |
19 | end
20 |
--------------------------------------------------------------------------------
/lib/google_visualr/interactive/annotation_chart.rb:
--------------------------------------------------------------------------------
1 | module GoogleVisualr
2 | module Interactive
3 |
4 | # https://developers.google.com/chart/interactive/docs/gallery/annotationchart
5 | class AnnotationChart < BaseChart
6 | # For Configuration Options, please refer to:
7 | # https://developers.google.com/chart/interactive/docs/gallery/annotationchart#configuration-options
8 | end
9 |
10 | end
11 | end
12 |
--------------------------------------------------------------------------------
/lib/google_visualr/interactive/intensity_map.rb:
--------------------------------------------------------------------------------
1 | module GoogleVisualr
2 | module Interactive
3 |
4 | # http://code.google.com/apis/chart/interactive/docs/gallery/intensitymap.html
5 | class IntensityMap < BaseChart
6 | # For Configuration Options, please refer to:
7 | # http://code.google.com/apis/chart/interactive/docs/gallery/intensitymap.html#Configuration_Options
8 | end
9 |
10 | end
11 | end
12 |
--------------------------------------------------------------------------------
/lib/google_visualr/interactive/annotated_time_line.rb:
--------------------------------------------------------------------------------
1 | module GoogleVisualr
2 | module Interactive
3 |
4 | # http://code.google.com/apis/chart/interactive/docs/gallery/annotatedtimeline.html
5 | class AnnotatedTimeLine < BaseChart
6 | # For Configuration Options, please refer to:
7 | # http://code.google.com/apis/chart/interactive/docs/gallery/annotatedtimeline.html#Configuration_Options
8 | end
9 |
10 | end
11 | end
12 |
--------------------------------------------------------------------------------
/spec/dummy/config/initializers/inflections.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Add new inflection rules using the following format
4 | # (all these examples are active by default):
5 | # ActiveSupport::Inflector.inflections do |inflect|
6 | # inflect.plural /^(ox)$/i, '\1en'
7 | # inflect.singular /^(ox)en/i, '\1'
8 | # inflect.irregular 'person', 'people'
9 | # inflect.uncountable %w( fish sheep )
10 | # end
11 |
--------------------------------------------------------------------------------
/lib/google_visualr/interactive/pie_chart.rb:
--------------------------------------------------------------------------------
1 | module GoogleVisualr
2 | module Interactive
3 |
4 | # http://code.google.com/apis/chart/interactive/docs/gallery/piechart.html
5 | class PieChart < BaseChart
6 | include GoogleVisualr::Packages::CoreChart
7 |
8 | # For Configuration Options, please refer to:
9 | # http://code.google.com/apis/chart/interactive/docs/gallery/piechart.html#Configuration_Options
10 | end
11 |
12 | end
13 | end
14 |
--------------------------------------------------------------------------------
/spec/dummy/config/initializers/backtrace_silencers.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4 | # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5 |
6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7 | # Rails.backtrace_cleaner.remove_silencers!
8 |
--------------------------------------------------------------------------------
/lib/google_visualr/interactive/area_chart.rb:
--------------------------------------------------------------------------------
1 | module GoogleVisualr
2 | module Interactive
3 |
4 | # http://code.google.com/apis/chart/interactive/docs/gallery/areachart.html
5 | class AreaChart < BaseChart
6 | include GoogleVisualr::Packages::CoreChart
7 |
8 | # For Configuration Options, please refer to:
9 | # http://code.google.com/apis/chart/interactive/docs/gallery/areachart.html#Configuration_Options
10 | end
11 |
12 | end
13 | end
14 |
--------------------------------------------------------------------------------
/lib/google_visualr/interactive/bubble_chart.rb:
--------------------------------------------------------------------------------
1 | module GoogleVisualr
2 | module Interactive
3 |
4 | # https://developers.google.com/chart/interactive/docs/gallery/bubblechart
5 | class BubbleChart < BaseChart
6 | include GoogleVisualr::Packages::CoreChart
7 |
8 | # For Configuration Options, please refer to:
9 | # https://developers.google.com/chart/interactive/docs/gallery/bubblechart#Configuration_Options
10 | end
11 |
12 | end
13 | end
14 |
--------------------------------------------------------------------------------
/lib/google_visualr/interactive/histogram.rb:
--------------------------------------------------------------------------------
1 | module GoogleVisualr
2 | module Interactive
3 |
4 | # https://developers.google.com/chart/interactive/docs/gallery/histogram
5 | class Histogram < BaseChart
6 | include GoogleVisualr::Packages::CoreChart
7 |
8 | # For Configuration Options, please refer to:
9 | # https://developers.google.com/chart/interactive/docs/gallery/histogram#Configuration_Options
10 | end
11 |
12 | end
13 | end
14 |
15 |
--------------------------------------------------------------------------------
/spec/dummy/config/initializers/session_store.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | Dummy::Application.config.session_store :cookie_store, :key => '_dummy_session'
4 |
5 | # Use the database for sessions instead of the cookie-based default,
6 | # which shouldn't be used to store highly confidential information
7 | # (create the session table with "rails generate session_migration")
8 | # Dummy::Application.config.session_store :active_record_store
9 |
--------------------------------------------------------------------------------
/lib/google_visualr/interactive/combo_chart.rb:
--------------------------------------------------------------------------------
1 | module GoogleVisualr
2 | module Interactive
3 |
4 | # http://code.google.com/apis/chart/interactive/docs/gallery/combochart.html
5 | class ComboChart < BaseChart
6 | include GoogleVisualr::Packages::CoreChart
7 |
8 | # For Configuration Options, please refer to:
9 | # http://code.google.com/apis/chart/interactive/docs/gallery/combochart.html#Configuration_Options
10 | end
11 |
12 | end
13 | end
14 |
--------------------------------------------------------------------------------
/lib/google_visualr/interactive/gantt_chart.rb:
--------------------------------------------------------------------------------
1 | module GoogleVisualr
2 | module Interactive
3 |
4 | # https://developers.google.com/chart/interactive/docs/gallery/ganttchart
5 | class GanttChart < BaseChart
6 |
7 | def package_name
8 | "gantt"
9 | end
10 |
11 | # For Configuration Options, please refer to:
12 | # https://developers.google.com/chart/interactive/docs/gallery/ganttchart#configuration-options
13 | end
14 |
15 | end
16 | end
17 |
--------------------------------------------------------------------------------
/lib/google_visualr/interactive/stepped_area_chart.rb:
--------------------------------------------------------------------------------
1 | module GoogleVisualr
2 | module Interactive
3 |
4 | # https://developers.google.com/chart/interactive/docs/gallery/steppedareachart
5 | class SteppedAreaChart < BaseChart
6 | include GoogleVisualr::Packages::CoreChart
7 |
8 | # For Configuration Options, please refer to:
9 | # https://developers.google.com/chart/interactive/docs/gallery/steppedareachart#Configuration_Options
10 | end
11 |
12 | end
13 | end
14 |
--------------------------------------------------------------------------------
/lib/google_visualr/interactive/candlestick_chart.rb:
--------------------------------------------------------------------------------
1 | module GoogleVisualr
2 | module Interactive
3 |
4 | # http://code.google.com/apis/chart/interactive/docs/gallery/candlestickchart.html
5 | class CandlestickChart < BaseChart
6 | include GoogleVisualr::Packages::CoreChart
7 |
8 | # For Configuration Options, please refer to:
9 | # http://code.google.com/apis/chart/interactive/docs/gallery/candlestickchart.html#Configuration_Options
10 | end
11 |
12 | end
13 | end
14 |
--------------------------------------------------------------------------------
/spec/dummy/test/test_helper.rb:
--------------------------------------------------------------------------------
1 | ENV["RAILS_ENV"] = "test"
2 | require File.expand_path('../../config/environment', __FILE__)
3 | require 'rails/test_help'
4 |
5 | class ActiveSupport::TestCase
6 | # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
7 | #
8 | # Note: You'll currently still have to declare fixtures explicitly in integration tests
9 | # -- they do not yet inherit this setting
10 | fixtures :all
11 |
12 | # Add more helper methods to be used by all tests here...
13 | end
14 |
--------------------------------------------------------------------------------
/spec/dummy/config/initializers/secret_token.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Your secret key for verifying the integrity of signed cookies.
4 | # If you change this key, all old signed cookies will become invalid!
5 | # Make sure the secret is at least 30 characters and all random,
6 | # no regular words or you'll be exposed to dictionary attacks.
7 | Dummy::Application.config.secret_token = 'd60ddb67fd1ec1a8398c7955513b94592ea310bcbe04be508e8adb4711464031b8cab58a747d2ac660c58c6df487d01d2a5d1df80f8f2d04abbc4c71a98df93e'
8 |
--------------------------------------------------------------------------------
/lib/google_visualr/interactive/line_chart.rb:
--------------------------------------------------------------------------------
1 | module GoogleVisualr
2 | module Interactive
3 |
4 | # http://code.google.com/apis/chart/interactive/docs/gallery/linechart.html
5 | class LineChart < BaseChart
6 | include GoogleVisualr::Packages::CoreChart
7 |
8 | def package_name
9 | if material
10 | "line"
11 | else
12 | super
13 | end
14 | end
15 |
16 | # For Configuration Options, please refer to:
17 | # http://code.google.com/apis/chart/interactive/docs/gallery/linechart.html#Configuration_Options
18 | end
19 |
20 | end
21 | end
22 |
--------------------------------------------------------------------------------
/spec/dummy/config/database.yml:
--------------------------------------------------------------------------------
1 | # SQLite version 3.x
2 | # gem install sqlite3
3 | development:
4 | adapter: sqlite3
5 | database: db/development.sqlite3
6 | pool: 5
7 | timeout: 5000
8 |
9 | # Warning: The database defined as "test" will be erased and
10 | # re-generated from your development database when you run "rake".
11 | # Do not set this db to the same as development or production.
12 | test:
13 | adapter: sqlite3
14 | database: db/test.sqlite3
15 | pool: 5
16 | timeout: 5000
17 |
18 | production:
19 | adapter: sqlite3
20 | database: db/production.sqlite3
21 | pool: 5
22 | timeout: 5000
23 |
--------------------------------------------------------------------------------
/lib/google_visualr/interactive/scatter_chart.rb:
--------------------------------------------------------------------------------
1 | module GoogleVisualr
2 | module Interactive
3 |
4 | # http://code.google.com/apis/chart/interactive/docs/gallery/scatterchart.html
5 | class ScatterChart < BaseChart
6 | include GoogleVisualr::Packages::CoreChart
7 |
8 | def package_name
9 | if material
10 | "scatter"
11 | else
12 | super
13 | end
14 | end
15 |
16 | # For Configuration Options, please refer to:
17 | # http://code.google.com/apis/chart/interactive/docs/gallery/scatterchart.html#Configuration_Options
18 | end
19 |
20 | end
21 | end
22 |
--------------------------------------------------------------------------------
/spec/spec_helper.rb:
--------------------------------------------------------------------------------
1 | require 'rubygems'
2 | require 'bundler/setup'
3 |
4 | # Configure Rails Environment
5 | ENV["RAILS_ENV"] = "test"
6 | require File.expand_path("../dummy/config/environment.rb", __FILE__)
7 |
8 | # Load Support Files
9 | Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
10 |
11 | module JavaScriptHelper
12 | def normalize_javascript(input)
13 | dupped = input.dup
14 |
15 | dupped.gsub!(/\\u003E/i, ">")
16 | dupped.gsub!(/\\u003C/i, "<")
17 |
18 | dupped
19 | end
20 | end
21 |
22 | RSpec.configure do |config|
23 | # some (optional) config here
24 | include JavaScriptHelper
25 | end
26 |
--------------------------------------------------------------------------------
/lib/google_visualr/app/helpers/view_helper.rb:
--------------------------------------------------------------------------------
1 | module GoogleVisualr
2 | module Rails
3 | module ViewHelper
4 | extend ActiveSupport::Concern
5 |
6 | included do
7 | # Rails 5 compatibility fix
8 | if respond_to?(:helper_method)
9 | helper_method "render_chart"
10 | end
11 | end
12 |
13 | def render_chart(chart, dom, options={})
14 | script_tag = options.fetch(:script_tag) { true }
15 | if script_tag
16 | chart.to_js(dom).html_safe
17 | else
18 | html = ""
19 | html << chart.load_js(dom)
20 | html << chart.draw_js(dom)
21 | html.html_safe
22 | end
23 | end
24 | end
25 | end
26 | end
27 |
--------------------------------------------------------------------------------
/lib/google_visualr/interactive/bar_chart.rb:
--------------------------------------------------------------------------------
1 | module GoogleVisualr
2 | module Interactive
3 |
4 | # http://code.google.com/apis/chart/interactive/docs/gallery/barchart.html
5 | class BarChart < BaseChart
6 | include GoogleVisualr::Packages::CoreChart
7 |
8 | def package_name
9 | if material
10 | "bar"
11 | else
12 | super
13 | end
14 | end
15 |
16 | def chart_name
17 | if material
18 | "Bar"
19 | else
20 | super
21 | end
22 | end
23 |
24 | # For Configuration Options, please refer to:
25 | # http://code.google.com/apis/chart/interactive/docs/gallery/barchart.html#Configuration_Options
26 | end
27 |
28 | end
29 | end
30 |
--------------------------------------------------------------------------------
/lib/google_visualr/interactive/column_chart.rb:
--------------------------------------------------------------------------------
1 | module GoogleVisualr
2 | module Interactive
3 |
4 | # http://code.google.com/apis/chart/interactive/docs/gallery/columnchart.html
5 | class ColumnChart < BaseChart
6 | include GoogleVisualr::Packages::CoreChart
7 |
8 | def package_name
9 | if material
10 | "bar"
11 | else
12 | super
13 | end
14 | end
15 |
16 | def chart_name
17 | if material
18 | "Bar"
19 | else
20 | super
21 | end
22 | end
23 |
24 | # For Configuration Options, please refer to:
25 | # http://code.google.com/apis/chart/interactive/docs/gallery/columnchart.html#Configuration_Options
26 | end
27 |
28 | end
29 | end
30 |
--------------------------------------------------------------------------------
/spec/turbolinks_tests/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Different methods for loading a chart with Turbolinks support
8 | You should test these in Firefox. In Chrome, each link click triggers a full page reload if running from localhost (which defeats the purpose of Turbolinks, and doesn't present the bug).
9 |
14 |
15 |
--------------------------------------------------------------------------------
/spec/dummy/public/422.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The change you wanted was rejected (422)
5 |
17 |
18 |
19 |
20 |
21 |
22 |
The change you wanted was rejected.
23 |
Maybe you tried to change something you didn't have access to.
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/spec/dummy/public/404.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The page you were looking for doesn't exist (404)
5 |
17 |
18 |
19 |
20 |
21 |
22 |
The page you were looking for doesn't exist.
23 |
You may have mistyped the address or the page may have moved.
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/spec/dummy/public/500.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | We're sorry, but something went wrong (500)
5 |
17 |
18 |
19 |
20 |
21 |
22 |
We're sorry, but something went wrong.
23 |
We've been notified about this issue and we'll take a look at it shortly.
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/spec/google_visualr/app/helpers/view_helper_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | describe "ApplicationController" do
4 | describe "#render_chart" do
5 | it "has method" do
6 | ApplicationController.instance_methods.should include :render_chart
7 | end
8 |
9 | it "includes method in corresponding helper" do
10 | ApplicationController.helpers.methods.should include :render_chart
11 | end
12 |
13 | it "returns html_safe javascript" do
14 | controller = ApplicationController.new
15 | js = controller.render_chart base_chart, "div_chart"
16 | js.should == base_chart_js("div_chart")
17 | end
18 |
19 | it "returns html_safe javascript without script tag" do
20 | controller = ApplicationController.new
21 | js = controller.render_chart base_chart, "div_chart", script_tag: false
22 | js.should == base_chart_js_without_script_tag("div_chart")
23 | end
24 | end
25 | end
26 |
--------------------------------------------------------------------------------
/spec/turbolinks_tests/old.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | home
8 |
9 |
16 |
17 |
--------------------------------------------------------------------------------
/google_visualr.gemspec:
--------------------------------------------------------------------------------
1 | $:.push File.expand_path("../lib", __FILE__)
2 |
3 | # Maintain your gem's version:
4 | require "google_visualr/version"
5 |
6 | Gem::Specification.new do |s|
7 | s.name = "google_visualr"
8 | s.version = GoogleVisualr::VERSION
9 | s.authors = ["Winston Teo"]
10 | s.email = ["winston.yongwei+google_visualr@gmail.com"]
11 | s.homepage = "https://github.com/winston/google_visualr"
12 | s.summary = "A Ruby wrapper around the Google Chart Tools that allows anyone to create the same beautiful charts with just plain Ruby."
13 | s.description = "This Ruby gem, GoogleVisualr, is a wrapper around the Google Chart Tools that allows anyone to create the same beautiful charts with just Ruby; you don't have to write any JavaScript at all."
14 |
15 | s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.md"]
16 | s.test_files = Dir["spec/**/*"]
17 |
18 | s.license = 'MIT'
19 | end
20 |
--------------------------------------------------------------------------------
/spec/turbolinks_tests/fixed.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | home
8 |
9 |
17 |
18 |
--------------------------------------------------------------------------------
/spec/turbolinks_tests/broken.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | home
8 |
9 |
18 |
19 |
--------------------------------------------------------------------------------
/MIT-LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License
2 |
3 | Copyright (c) 2011 Winston Teo Yong Wei
4 |
5 | Permission is hereby granted, free of charge, to any person
6 | obtaining a copy of this software and associated documentation files (the "Software"),
7 | to deal in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16 | INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
19 | FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
22 | OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/lib/google_visualr/image/spark_line.rb:
--------------------------------------------------------------------------------
1 | module GoogleVisualr
2 | module Image
3 |
4 | # http://code.google.com/apis/chart/interactive/docs/gallery/imagesparkline.html
5 | class SparkLine < BaseChart
6 | include GoogleVisualr::Packages::ImageChart
7 |
8 | # For Configuration Options, please refer to:
9 | # http://code.google.com/apis/chart/interactive/docs/gallery/imagesparkline.html
10 |
11 | # Create URI for sparkline. Override parameters by passing in a hash.
12 | # (see http://code.google.com/apis/chart/image/docs/chart_params.html)
13 | #
14 | # Parameters:
15 | # *params [Optional] Hash of url query parameters
16 | def uri(params = {})
17 | query_params = {}
18 |
19 | # Chart type: line
20 | query_params[:cht] = "ls"
21 |
22 | # showValueLabels (works as long as :chxt => "x,y")
23 | labels = "0:||"
24 | if @options["showValueLabels"] == false || !@options["showAxisLines"]
25 | labels += "1:||"
26 | end
27 |
28 | query_params[:chxl] = labels
29 |
30 | chart_image_url(query_params.merge(params))
31 | end
32 | end
33 | end
34 | end
35 |
--------------------------------------------------------------------------------
/spec/dummy/config/environments/development.rb:
--------------------------------------------------------------------------------
1 | Dummy::Application.configure do
2 | # Settings specified here will take precedence over those in config/application.rb.
3 |
4 | # In the development environment your application's code is reloaded on
5 | # every request. This slows down response time but is perfect for development
6 | # since you don't have to restart the web server when you make code changes.
7 | config.cache_classes = false
8 |
9 | # Do not eager load code on boot.
10 | config.eager_load = false
11 |
12 | # Show full error reports and disable caching.
13 | config.consider_all_requests_local = true
14 | config.action_controller.perform_caching = false
15 |
16 | # Don't care if the mailer can't send.
17 | config.action_mailer.raise_delivery_errors = false
18 |
19 | # Print deprecation notices to the Rails logger.
20 | config.active_support.deprecation = :log
21 |
22 | # Only use best-standards-support built into browsers.
23 | config.action_dispatch.best_standards_support = :builtin
24 |
25 | # Raise an error on page load if there are pending migrations
26 | config.active_record.migration_error = :page_load
27 |
28 | # Debug mode disables concatenation and preprocessing of assets.
29 | config.assets.debug = true
30 | end
31 |
--------------------------------------------------------------------------------
/lib/google_visualr/image/line_chart.rb:
--------------------------------------------------------------------------------
1 | module GoogleVisualr
2 | module Image
3 |
4 | # http://code.google.com/apis/chart/interactive/docs/gallery/imagelinechart.html
5 | class LineChart < BaseChart
6 | include GoogleVisualr::Packages::ImageChart
7 |
8 | # For Configuration Options, please refer to:
9 | # http://code.google.com/apis/chart/interactive/docs/gallery/imagelinechart.html
10 |
11 | # Create URI for image line chart. Override parameters by passing in a hash.
12 | # (see http://code.google.com/apis/chart/image/docs/chart_params.html)
13 | #
14 | # Parameters:
15 | # *params [Optional] Hash of url query parameters
16 | def uri(params = {})
17 | query_params = {}
18 |
19 | # Chart type: line
20 | query_params[:cht] = "lc"
21 |
22 | # showAxisLines
23 | if @options["showAxisLines"] == false
24 | query_params[:cht] = "lc:nda"
25 | end
26 |
27 | # showCategoryLabels (works as long as :chxt => "x,y")
28 | labels = ""
29 | if @options["showCategoryLabels"] == false
30 | labels = "0:||"
31 | else
32 | labels = "0:|" + data_table.get_column(0).join('|') + "|"
33 | end
34 |
35 | # showValueLabels (works as long as :chxt => "x,y")
36 | if @options["showValueLabels"] == false
37 | labels += "1:||"
38 | end
39 |
40 | query_params[:chxl] = labels unless labels.blank?
41 |
42 | chart_image_url(query_params.merge(params))
43 | end
44 | end
45 |
46 | end
47 | end
--------------------------------------------------------------------------------
/lib/google_visualr/image/pie_chart.rb:
--------------------------------------------------------------------------------
1 | module GoogleVisualr
2 | module Image
3 |
4 | # http://code.google.com/apis/chart/interactive/docs/gallery/imagepiechart.html
5 | class PieChart < BaseChart
6 | include GoogleVisualr::Packages::ImageChart
7 |
8 | # For Configuration Options, please refer to:
9 | # http://code.google.com/apis/chart/interactive/docs/gallery/imagepiechart.html
10 |
11 | # Create URI for image pie chart. Override parameters by passing in a hash.
12 | # (see http://code.google.com/apis/chart/image/docs/chart_params.html)
13 | #
14 | # Parameters:
15 | # *params [Optional] Hash of url query parameters
16 | def uri(params = {})
17 | query_params = {}
18 |
19 | # Chart Type: normal or 3D
20 | query_params[:cht] = @options["is3D"] ? "p3" : "p"
21 |
22 | # Legend (override generic image chart behavior)
23 | query_params[:chdl] = @data_table.get_column(0).join('|')
24 |
25 | # Labels
26 | case options["labels"]
27 | when "name"
28 | query_params[:chl] = @data_table.get_column(0).join('|')
29 | when "value"
30 | query_params[:chl] = @data_table.get_column(1).join('|')
31 | else
32 | query_params[:chl] = ""
33 | end
34 |
35 | # data (override generic chart behavior)
36 | query_params[:chd] = "t:" + @data_table.get_column(1).join(',')
37 |
38 | # Chart Colors (override generic chart default)
39 | query_params[:chco] = @options["colors"].join('|').gsub(/#/, '') if @options["colors"]
40 |
41 | chart_image_url(query_params.merge(params))
42 | end
43 |
44 | end
45 |
46 | end
47 | end
--------------------------------------------------------------------------------
/spec/dummy/config/application.rb:
--------------------------------------------------------------------------------
1 | require File.expand_path('../boot', __FILE__)
2 |
3 | require 'rails/all'
4 |
5 | Bundler.require
6 | require "google_visualr"
7 |
8 | module Dummy
9 | class Application < Rails::Application
10 | # Settings in config/environments/* take precedence over those specified here.
11 | # Application configuration should go into files in config/initializers
12 | # -- all .rb files in that directory are automatically loaded.
13 |
14 | # Custom directories with classes and modules you want to be autoloadable.
15 | # config.autoload_paths += %W(#{config.root}/extras)
16 |
17 | # Only load the plugins named here, in the order given (default is alphabetical).
18 | # :all can be used as a placeholder for all plugins not explicitly named.
19 | # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
20 |
21 | # Activate observers that should always be running.
22 | # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
23 |
24 | # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
25 | # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
26 | # config.time_zone = 'Central Time (US & Canada)'
27 |
28 | # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
29 | # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
30 | # config.i18n.default_locale = :de
31 |
32 | # Configure the default encoding used in templates for Ruby 1.9.
33 | config.encoding = "utf-8"
34 |
35 | # Configure sensitive parameters which will be filtered from the log file.
36 | config.filter_parameters += [:password]
37 | end
38 | end
39 |
--------------------------------------------------------------------------------
/lib/google_visualr/image/bar_chart.rb:
--------------------------------------------------------------------------------
1 | module GoogleVisualr
2 | module Image
3 |
4 | # http://code.google.com/apis/chart/interactive/docs/gallery/imagebarchart.html
5 | class BarChart < BaseChart
6 | include GoogleVisualr::Packages::ImageChart
7 |
8 | # For Configuration Options, please refer to:
9 | # http://code.google.com/apis/chart/interactive/docs/gallery/imagebarchart.html
10 |
11 | # Create URI for image bar chart. Override parameters by passing in a hash.
12 | # (see http://code.google.com/apis/chart/image/docs/chart_params.html)
13 | #
14 | # Parameters:
15 | # *params [Optional] Hash of url query parameters
16 | def uri(params = {})
17 | query_params = {}
18 |
19 | # isStacked/isVertical, Chart Type
20 | chart_type = "b"
21 | chart_type += @options["isVertical"] ? "v" : "h"
22 | chart_type += @options["isStacked"] == false ? "g" : "s"
23 | query_params[:cht] = chart_type
24 |
25 | # showCategoryLabels (works as long as :chxt => "x,y")
26 | labels = ""
27 | val_column = @options["isVertical"] ? 1 : 0
28 | cat_column = @options["isVertical"] ? 0 : 1
29 | if @options["showCategoryLabels"] == false
30 | labels = "#{cat_column}:||"
31 | else
32 | labels = "#{cat_column}:|" + data_table.get_column(0).join('|') + "|"
33 | end
34 |
35 | # showValueLabels (works as long as :chxt => "x,y")
36 | if @options["showValueLabels"] == false
37 | labels += "#{val_column}:||"
38 | end
39 |
40 | query_params[:chxl] = labels unless labels.blank?
41 |
42 | chart_image_url(query_params.merge(params))
43 | end
44 | end
45 |
46 | end
47 | end
48 |
--------------------------------------------------------------------------------
/spec/dummy/config/environments/test.rb:
--------------------------------------------------------------------------------
1 | Dummy::Application.configure do
2 | # Settings specified here will take precedence over those in config/application.rb.
3 |
4 | # The test environment is used exclusively to run your application's
5 | # test suite. You never need to work with it otherwise. Remember that
6 | # your test database is "scratch space" for the test suite and is wiped
7 | # and recreated between test runs. Don't rely on the data there!
8 | config.cache_classes = true
9 |
10 | # Do not eager load code on boot. This avoids loading your whole application
11 | # just for the purpose of running a single test. If you are using a tool that
12 | # preloads Rails for running tests, you may have to set it to true.
13 | config.eager_load = false
14 |
15 | # Disable serving static files from the `/public` folder by default since
16 | # Apache or NGINX already handles this.
17 | if Rails.version >= "4.2.0"
18 | config.serve_static_files = true
19 | else
20 | config.serve_static_assets = true
21 | end
22 | config.static_cache_control = "public, max-age=3600"
23 |
24 | # Show full error reports and disable caching.
25 | config.consider_all_requests_local = true
26 | config.action_controller.perform_caching = false
27 |
28 | # Raise exceptions instead of rendering exception templates.
29 | config.action_dispatch.show_exceptions = false
30 |
31 | # Disable request forgery protection in test environment.
32 | config.action_controller.allow_forgery_protection = false
33 |
34 | # Tell Action Mailer not to deliver emails to the real world.
35 | # The :test delivery method accumulates sent emails in the
36 | # ActionMailer::Base.deliveries array.
37 | config.action_mailer.delivery_method = :test
38 |
39 | # Print deprecation notices to the stderr.
40 | config.active_support.deprecation = :stderr
41 | end
42 |
--------------------------------------------------------------------------------
/spec/dummy/config/routes.rb:
--------------------------------------------------------------------------------
1 | Dummy::Application.routes.draw do
2 | # The priority is based upon order of creation:
3 | # first created -> highest priority.
4 |
5 | # Sample of regular route:
6 | # match 'products/:id' => 'catalog#view'
7 | # Keep in mind you can assign values other than :controller and :action
8 |
9 | # Sample of named route:
10 | # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
11 | # This route can be invoked with purchase_url(:id => product.id)
12 |
13 | # Sample resource route (maps HTTP verbs to controller actions automatically):
14 | # resources :products
15 |
16 | # Sample resource route with options:
17 | # resources :products do
18 | # member do
19 | # get 'short'
20 | # post 'toggle'
21 | # end
22 | #
23 | # collection do
24 | # get 'sold'
25 | # end
26 | # end
27 |
28 | # Sample resource route with sub-resources:
29 | # resources :products do
30 | # resources :comments, :sales
31 | # resource :seller
32 | # end
33 |
34 | # Sample resource route with more complex sub-resources
35 | # resources :products do
36 | # resources :comments
37 | # resources :sales do
38 | # get 'recent', :on => :collection
39 | # end
40 | # end
41 |
42 | # Sample resource route within a namespace:
43 | # namespace :admin do
44 | # # Directs /admin/products/* to Admin::ProductsController
45 | # # (app/controllers/admin/products_controller.rb)
46 | # resources :products
47 | # end
48 |
49 | # You can have the root of your site routed with "root"
50 | # just remember to delete public/index.html.
51 | # root :to => "welcome#index"
52 |
53 | # See how all your routes lay out with "rake routes"
54 |
55 | # This is a legacy wild controller route that's not recommended for RESTful applications.
56 | # Note: This route will make all actions in every controller accessible via GET requests.
57 | # match ':controller(/:action(/:id(.:format)))'
58 | end
59 |
--------------------------------------------------------------------------------
/lib/google_visualr/formatters.rb:
--------------------------------------------------------------------------------
1 | module GoogleVisualr
2 |
3 | # http://code.google.com/apis/chart/interactive/docs/reference.html#formatters
4 | class Formatter
5 | include GoogleVisualr::ParamHelpers
6 |
7 | def initialize(options={})
8 | @options = options
9 | end
10 |
11 |
12 | def columns(*columns)
13 | @columns = columns.flatten
14 | end
15 |
16 | def options(*options)
17 | @options = stringify_keys!(options.pop)
18 | end
19 |
20 | def to_js(&block)
21 | js = "\nvar formatter = new google.visualization.#{self.class.to_s.split('::').last}("
22 | js << js_parameters(@options)
23 | js << ");"
24 |
25 | yield js if block_given?
26 |
27 | @columns.each do |column|
28 | js << "\nformatter.format(data_table, #{column});"
29 | end
30 |
31 | js
32 | end
33 |
34 | end
35 |
36 | class ArrowFormat < Formatter
37 | end
38 |
39 | class BarFormat < Formatter
40 | end
41 |
42 | class ColorFormat < Formatter
43 |
44 | attr_accessor :ranges
45 | attr_accessor :gradient_ranges
46 |
47 | def initialize
48 | @ranges = Array.new
49 | @gradient_ranges = Array.new
50 | end
51 |
52 | def add_range(from, to, color, bgcolor)
53 | @ranges << { :from => from, :to => to, :color => color, :bgcolor => bgcolor }
54 | end
55 |
56 | def add_gradient_range(from, to, color, fromBgColor, toBgColor)
57 | @gradient_ranges << { :from => from, :to => to, :color => color, :fromBgColor => fromBgColor, :toBgColor => toBgColor }
58 | end
59 |
60 | def to_js
61 | super do |js|
62 | @ranges.each do |r|
63 | js << "\nformatter.addRange(#{typecast(r[:from])}, #{typecast(r[:to])}, #{typecast(r[:color])}, #{typecast(r[:bgcolor])});"
64 | end
65 | @gradient_ranges.each do |r|
66 | js << "\nformatter.addGradientRange(#{typecast(r[:from])}, #{typecast(r[:to])}, #{typecast(r[:color])}, #{typecast(r[:fromBgColor])}, #{typecast(r[:toBgColor])});"
67 | end
68 | end
69 | end
70 | end
71 |
72 | class DateFormat < Formatter
73 | end
74 |
75 | class NumberFormat < Formatter
76 | end
77 |
78 | end
--------------------------------------------------------------------------------
/lib/google_visualr/param_helpers.rb:
--------------------------------------------------------------------------------
1 | module GoogleVisualr
2 |
3 | module ParamHelpers
4 |
5 | def stringify_keys!(options)
6 | options.keys.each do |key|
7 | options[key.to_s] = options.delete(key)
8 | end
9 | options
10 | end
11 |
12 | def js_parameters(options)
13 | return "" if options.nil?
14 |
15 | attributes = options.collect { |(key, value)| "#{key}: #{typecast(value)}" }
16 | "{" + attributes.join(", ") + "}"
17 | end
18 |
19 | # If the column type is 'string' , the value should be a string.
20 | # If the column type is 'number' , the value should be a number.
21 | # If the column type is 'boolean' , the value should be a boolean.
22 | # If the column type is 'date' , the value should be a Date object.
23 | # If the column type is 'datetime' , the value should be a DateTime or Time object.
24 | # If the column type is 'timeofday' , the value should be an array of three or four numbers: [hour, minute, second, optional milliseconds].
25 | # Returns an array of strings if given an array
26 | # Returns 'null' when value is nil.
27 | # Recursive typecasting when value is a hash.
28 | def typecast(value, type = nil)
29 | case
30 | when value.is_a?(String)
31 | return value.to_json
32 | when value.is_a?(Integer) || value.is_a?(Float)
33 | return value
34 | when value.is_a?(TrueClass) || value.is_a?(FalseClass)
35 | return "#{value}"
36 | when value.is_a?(DateTime) || value.is_a?(Time)
37 | if type == "time"
38 | return "new Date(0, 0, 0, #{value.hour}, #{value.min}, #{value.sec})"
39 | else
40 | return "new Date(#{value.year}, #{value.month-1}, #{value.day}, #{value.hour}, #{value.min}, #{value.sec})"
41 | end
42 | when value.is_a?(Date)
43 | return "new Date(#{value.year}, #{value.month-1}, #{value.day})"
44 | when value.nil?
45 | return "null"
46 | when value.is_a?(Array)
47 | return "[" + value.map{|v| typecast(v) }.join(',') + "]"
48 | when value.is_a?(Hash)
49 | return js_parameters(value)
50 | else
51 | return value
52 | end
53 | end
54 |
55 | end
56 |
57 | end
--------------------------------------------------------------------------------
/lib/google_visualr.rb:
--------------------------------------------------------------------------------
1 | lib_path = File.dirname(__FILE__)
2 |
3 | # Common
4 | require "#{lib_path}/google_visualr/param_helpers"
5 |
6 | # Base Classes
7 | require "#{lib_path}/google_visualr/data_table"
8 |
9 | require "#{lib_path}/google_visualr/packages"
10 | require "#{lib_path}/google_visualr/base_chart"
11 |
12 | require "#{lib_path}/google_visualr/formatters"
13 |
14 | # Interactive Charts
15 |
16 | ## Main
17 | require "#{lib_path}/google_visualr/interactive/annotated_time_line"
18 | require "#{lib_path}/google_visualr/interactive/annotation_chart"
19 | require "#{lib_path}/google_visualr/interactive/area_chart"
20 | require "#{lib_path}/google_visualr/interactive/bar_chart"
21 | require "#{lib_path}/google_visualr/interactive/bubble_chart"
22 | require "#{lib_path}/google_visualr/interactive/calendar"
23 | require "#{lib_path}/google_visualr/interactive/candlestick_chart"
24 | require "#{lib_path}/google_visualr/interactive/column_chart"
25 | require "#{lib_path}/google_visualr/interactive/combo_chart"
26 | require "#{lib_path}/google_visualr/interactive/gantt_chart"
27 | require "#{lib_path}/google_visualr/interactive/gauge"
28 | require "#{lib_path}/google_visualr/interactive/geo_chart"
29 | require "#{lib_path}/google_visualr/interactive/geo_map"
30 | require "#{lib_path}/google_visualr/interactive/histogram"
31 | require "#{lib_path}/google_visualr/interactive/intensity_map"
32 | require "#{lib_path}/google_visualr/interactive/line_chart"
33 | require "#{lib_path}/google_visualr/interactive/map"
34 | require "#{lib_path}/google_visualr/interactive/motion_chart"
35 | require "#{lib_path}/google_visualr/interactive/org_chart"
36 | require "#{lib_path}/google_visualr/interactive/pie_chart"
37 | require "#{lib_path}/google_visualr/interactive/sankey"
38 | require "#{lib_path}/google_visualr/interactive/scatter_chart"
39 | require "#{lib_path}/google_visualr/interactive/stepped_area_chart"
40 | require "#{lib_path}/google_visualr/interactive/table"
41 | require "#{lib_path}/google_visualr/interactive/timeline"
42 | require "#{lib_path}/google_visualr/interactive/tree_map"
43 | require "#{lib_path}/google_visualr/interactive/word_tree"
44 |
45 | # Image Charts
46 | require "#{lib_path}/google_visualr/image/spark_line"
47 | require "#{lib_path}/google_visualr/image/bar_chart"
48 | require "#{lib_path}/google_visualr/image/line_chart"
49 | require "#{lib_path}/google_visualr/image/pie_chart"
50 |
51 |
52 | # Rails Helper
53 | require "#{lib_path}/google_visualr/app/railtie.rb" if defined?(Rails)
54 |
--------------------------------------------------------------------------------
/gemfiles/4.0.gemfile.lock:
--------------------------------------------------------------------------------
1 | PATH
2 | remote: ../
3 | specs:
4 | google_visualr (2.4.0)
5 |
6 | GEM
7 | remote: https://rubygems.org/
8 | specs:
9 | actionmailer (4.0.13)
10 | actionpack (= 4.0.13)
11 | mail (~> 2.5, >= 2.5.4)
12 | actionpack (4.0.13)
13 | activesupport (= 4.0.13)
14 | builder (~> 3.1.0)
15 | erubis (~> 2.7.0)
16 | rack (~> 1.5.2)
17 | rack-test (~> 0.6.2)
18 | activemodel (4.0.13)
19 | activesupport (= 4.0.13)
20 | builder (~> 3.1.0)
21 | activerecord (4.0.13)
22 | activemodel (= 4.0.13)
23 | activerecord-deprecated_finders (~> 1.0.2)
24 | activesupport (= 4.0.13)
25 | arel (~> 4.0.0)
26 | activerecord-deprecated_finders (1.0.4)
27 | activesupport (4.0.13)
28 | i18n (~> 0.6, >= 0.6.9)
29 | minitest (~> 4.2)
30 | multi_json (~> 1.3)
31 | thread_safe (~> 0.1)
32 | tzinfo (~> 0.3.37)
33 | appraisal (2.0.1)
34 | activesupport (>= 3.2.21)
35 | bundler
36 | rake
37 | thor (>= 0.14.0)
38 | arel (4.0.2)
39 | builder (3.1.4)
40 | diff-lcs (1.2.5)
41 | erubis (2.7.0)
42 | i18n (0.7.0)
43 | mail (2.6.3)
44 | mime-types (>= 1.16, < 3)
45 | mime-types (2.6.1)
46 | minitest (4.7.5)
47 | multi_json (1.11.0)
48 | rack (1.5.3)
49 | rack-test (0.6.3)
50 | rack (>= 1.0)
51 | rails (4.0.13)
52 | actionmailer (= 4.0.13)
53 | actionpack (= 4.0.13)
54 | activerecord (= 4.0.13)
55 | activesupport (= 4.0.13)
56 | bundler (>= 1.3.0, < 2.0)
57 | railties (= 4.0.13)
58 | sprockets-rails (~> 2.0)
59 | railties (4.0.13)
60 | actionpack (= 4.0.13)
61 | activesupport (= 4.0.13)
62 | rake (>= 0.8.7)
63 | thor (>= 0.18.1, < 2.0)
64 | rake (10.4.2)
65 | rspec (2.99.0)
66 | rspec-core (~> 2.99.0)
67 | rspec-expectations (~> 2.99.0)
68 | rspec-mocks (~> 2.99.0)
69 | rspec-core (2.99.2)
70 | rspec-expectations (2.99.2)
71 | diff-lcs (>= 1.1.3, < 2.0)
72 | rspec-mocks (2.99.3)
73 | sprockets (3.1.0)
74 | rack (~> 1.0)
75 | sprockets-rails (2.3.1)
76 | actionpack (>= 3.0)
77 | activesupport (>= 3.0)
78 | sprockets (>= 2.8, < 4.0)
79 | thor (0.19.1)
80 | thread_safe (0.3.5)
81 | tzinfo (0.3.44)
82 |
83 | PLATFORMS
84 | ruby
85 |
86 | DEPENDENCIES
87 | appraisal
88 | bundler (>= 1.3.5)
89 | google_visualr!
90 | rails (~> 4.0.13)
91 | rspec (~> 2.99.0)
92 |
--------------------------------------------------------------------------------
/gemfiles/4.1.gemfile.lock:
--------------------------------------------------------------------------------
1 | PATH
2 | remote: ../
3 | specs:
4 | google_visualr (2.4.0)
5 |
6 | GEM
7 | remote: https://rubygems.org/
8 | specs:
9 | actionmailer (4.1.10)
10 | actionpack (= 4.1.10)
11 | actionview (= 4.1.10)
12 | mail (~> 2.5, >= 2.5.4)
13 | actionpack (4.1.10)
14 | actionview (= 4.1.10)
15 | activesupport (= 4.1.10)
16 | rack (~> 1.5.2)
17 | rack-test (~> 0.6.2)
18 | actionview (4.1.10)
19 | activesupport (= 4.1.10)
20 | builder (~> 3.1)
21 | erubis (~> 2.7.0)
22 | activemodel (4.1.10)
23 | activesupport (= 4.1.10)
24 | builder (~> 3.1)
25 | activerecord (4.1.10)
26 | activemodel (= 4.1.10)
27 | activesupport (= 4.1.10)
28 | arel (~> 5.0.0)
29 | activesupport (4.1.10)
30 | i18n (~> 0.6, >= 0.6.9)
31 | json (~> 1.7, >= 1.7.7)
32 | minitest (~> 5.1)
33 | thread_safe (~> 0.1)
34 | tzinfo (~> 1.1)
35 | appraisal (2.0.1)
36 | activesupport (>= 3.2.21)
37 | bundler
38 | rake
39 | thor (>= 0.14.0)
40 | arel (5.0.1.20140414130214)
41 | builder (3.2.2)
42 | diff-lcs (1.2.5)
43 | erubis (2.7.0)
44 | i18n (0.7.0)
45 | json (1.8.2)
46 | mail (2.6.3)
47 | mime-types (>= 1.16, < 3)
48 | mime-types (2.6.1)
49 | minitest (5.7.0)
50 | rack (1.5.3)
51 | rack-test (0.6.3)
52 | rack (>= 1.0)
53 | rails (4.1.10)
54 | actionmailer (= 4.1.10)
55 | actionpack (= 4.1.10)
56 | actionview (= 4.1.10)
57 | activemodel (= 4.1.10)
58 | activerecord (= 4.1.10)
59 | activesupport (= 4.1.10)
60 | bundler (>= 1.3.0, < 2.0)
61 | railties (= 4.1.10)
62 | sprockets-rails (~> 2.0)
63 | railties (4.1.10)
64 | actionpack (= 4.1.10)
65 | activesupport (= 4.1.10)
66 | rake (>= 0.8.7)
67 | thor (>= 0.18.1, < 2.0)
68 | rake (10.4.2)
69 | rspec (2.99.0)
70 | rspec-core (~> 2.99.0)
71 | rspec-expectations (~> 2.99.0)
72 | rspec-mocks (~> 2.99.0)
73 | rspec-core (2.99.2)
74 | rspec-expectations (2.99.2)
75 | diff-lcs (>= 1.1.3, < 2.0)
76 | rspec-mocks (2.99.3)
77 | sprockets (3.1.0)
78 | rack (~> 1.0)
79 | sprockets-rails (2.3.1)
80 | actionpack (>= 3.0)
81 | activesupport (>= 3.0)
82 | sprockets (>= 2.8, < 4.0)
83 | thor (0.19.1)
84 | thread_safe (0.3.5)
85 | tzinfo (1.2.2)
86 | thread_safe (~> 0.1)
87 |
88 | PLATFORMS
89 | ruby
90 |
91 | DEPENDENCIES
92 | appraisal
93 | bundler (>= 1.3.5)
94 | google_visualr!
95 | rails (~> 4.1.10)
96 | rspec (~> 2.99.0)
97 |
--------------------------------------------------------------------------------
/spec/google_visualr/param_helpers_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | describe "GoogleVisualr::ParamsHelper" do
4 | module GoogleVisualr
5 | class Mock
6 | include GoogleVisualr::ParamHelpers
7 | end
8 | end
9 |
10 | before do
11 | @klass = GoogleVisualr::Mock.new
12 | end
13 |
14 | describe "#stringify" do
15 | it "converts symbol keys to string keys" do
16 | options = @klass.stringify_keys!({:a => 1})
17 | options.should == {"a" => 1}
18 | end
19 | end
20 |
21 | describe "#js_parameters" do
22 | it "converts params to be js-ready string" do
23 | options = @klass.js_parameters({:a => 1})
24 | options.should == "{a: 1}"
25 |
26 | options = @klass.js_parameters({:a => {:b=> 1}})
27 | options.should == "{a: {b: 1}}"
28 | end
29 |
30 | it "returns empty string for nil options" do
31 | options = @klass.js_parameters(nil)
32 | options.should == ""
33 | end
34 | end
35 |
36 | describe "#typecast" do
37 | def assert_equal(input, expected, type = nil)
38 | options = @klass.typecast(input, type)
39 | options.should == expected
40 | end
41 |
42 | it "returns string" do
43 | assert_equal("I'm \"AWESOME\"", "I'm \"AWESOME\"".to_json)
44 | end
45 |
46 | it "returns number" do
47 | assert_equal(1, 1)
48 | end
49 |
50 | it "returns boolean" do
51 | assert_equal(true , "true" )
52 | assert_equal(false, "false")
53 | end
54 |
55 | it "returns datetime" do
56 | date = DateTime.now
57 | expected = "new Date(#{date.year}, #{date.month-1}, #{date.day}, #{date.hour}, #{date.min}, #{date.sec})"
58 | assert_equal(date, expected)
59 | end
60 |
61 | it "returns time" do
62 | date = Time.now
63 | expected = "new Date(#{date.year}, #{date.month-1}, #{date.day}, #{date.hour}, #{date.min}, #{date.sec})"
64 | assert_equal(date, expected)
65 | end
66 |
67 | it "returns time, if specified" do
68 | date = Time.now
69 | expected = "new Date(0, 0, 0, #{date.hour}, #{date.min}, #{date.sec})"
70 | assert_equal(date, expected, "time")
71 | end
72 |
73 | it "returns date" do
74 | date = Date.today
75 | expected = "new Date(#{date.year}, #{date.month-1}, #{date.day})"
76 | assert_equal(date, expected)
77 | end
78 |
79 | it "returns null" do
80 | assert_equal(nil, "null")
81 | end
82 |
83 | it "returns array of strings" do
84 | assert_equal({:colors => ['a', 'b']}, "{colors: [\"a\",\"b\"]}")
85 | end
86 |
87 | it "recursively calls js_parameters" do
88 | assert_equal({:a => {:b => {:c => 1}}}, "{a: {b: {c: 1}}}")
89 | end
90 | end
91 | end
92 |
--------------------------------------------------------------------------------
/gemfiles/3.2.gemfile.lock:
--------------------------------------------------------------------------------
1 | PATH
2 | remote: ../
3 | specs:
4 | google_visualr (2.4.0)
5 |
6 | GEM
7 | remote: https://rubygems.org/
8 | specs:
9 | actionmailer (3.2.21)
10 | actionpack (= 3.2.21)
11 | mail (~> 2.5.4)
12 | actionpack (3.2.21)
13 | activemodel (= 3.2.21)
14 | activesupport (= 3.2.21)
15 | builder (~> 3.0.0)
16 | erubis (~> 2.7.0)
17 | journey (~> 1.0.4)
18 | rack (~> 1.4.5)
19 | rack-cache (~> 1.2)
20 | rack-test (~> 0.6.1)
21 | sprockets (~> 2.2.1)
22 | activemodel (3.2.21)
23 | activesupport (= 3.2.21)
24 | builder (~> 3.0.0)
25 | activerecord (3.2.21)
26 | activemodel (= 3.2.21)
27 | activesupport (= 3.2.21)
28 | arel (~> 3.0.2)
29 | tzinfo (~> 0.3.29)
30 | activeresource (3.2.21)
31 | activemodel (= 3.2.21)
32 | activesupport (= 3.2.21)
33 | activesupport (3.2.21)
34 | i18n (~> 0.6, >= 0.6.4)
35 | multi_json (~> 1.0)
36 | appraisal (2.0.1)
37 | activesupport (>= 3.2.21)
38 | bundler
39 | rake
40 | thor (>= 0.14.0)
41 | arel (3.0.3)
42 | builder (3.0.4)
43 | diff-lcs (1.2.5)
44 | erubis (2.7.0)
45 | hike (1.2.3)
46 | i18n (0.7.0)
47 | journey (1.0.4)
48 | json (1.8.2)
49 | mail (2.5.4)
50 | mime-types (~> 1.16)
51 | treetop (~> 1.4.8)
52 | mime-types (1.25.1)
53 | multi_json (1.11.0)
54 | polyglot (0.3.5)
55 | rack (1.4.5)
56 | rack-cache (1.2)
57 | rack (>= 0.4)
58 | rack-ssl (1.3.4)
59 | rack
60 | rack-test (0.6.3)
61 | rack (>= 1.0)
62 | rails (3.2.21)
63 | actionmailer (= 3.2.21)
64 | actionpack (= 3.2.21)
65 | activerecord (= 3.2.21)
66 | activeresource (= 3.2.21)
67 | activesupport (= 3.2.21)
68 | bundler (~> 1.0)
69 | railties (= 3.2.21)
70 | railties (3.2.21)
71 | actionpack (= 3.2.21)
72 | activesupport (= 3.2.21)
73 | rack-ssl (~> 1.3.2)
74 | rake (>= 0.8.7)
75 | rdoc (~> 3.4)
76 | thor (>= 0.14.6, < 2.0)
77 | rake (10.4.2)
78 | rdoc (3.12.2)
79 | json (~> 1.4)
80 | rspec (2.99.0)
81 | rspec-core (~> 2.99.0)
82 | rspec-expectations (~> 2.99.0)
83 | rspec-mocks (~> 2.99.0)
84 | rspec-core (2.99.2)
85 | rspec-expectations (2.99.2)
86 | diff-lcs (>= 1.1.3, < 2.0)
87 | rspec-mocks (2.99.3)
88 | sprockets (2.2.3)
89 | hike (~> 1.2)
90 | multi_json (~> 1.0)
91 | rack (~> 1.0)
92 | tilt (~> 1.1, != 1.3.0)
93 | thor (0.19.1)
94 | tilt (1.4.1)
95 | treetop (1.4.15)
96 | polyglot
97 | polyglot (>= 0.3.1)
98 | tzinfo (0.3.44)
99 |
100 | PLATFORMS
101 | ruby
102 |
103 | DEPENDENCIES
104 | appraisal
105 | bundler (>= 1.3.5)
106 | google_visualr!
107 | rails (~> 3.2.21)
108 | rspec (~> 2.99.0)
109 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | ## Change Log
2 |
3 | ### Version 2.5.1
4 |
5 | * [Pull Request 98](https://github.com/winston/google_visualr/pull/97) Do not force `en` as the default language.
6 |
7 | ### Version 2.5.0
8 |
9 | * [Pull Request 97](https://github.com/winston/google_visualr/pull/97) Add new Google charts.
10 | * [Pull Request 96](https://github.com/winston/google_visualr/pull/96) Allow charts to have a different locale.
11 | * [Pull Request 95](https://github.com/winston/google_visualr/pull/95) Allow charts to be styled with Material Design.
12 | * [Pull Request 72](https://github.com/winston/google_visualr/pull/72) Add ability to specify version of Google Chart library.
13 |
14 | ### Version 2.4.0
15 |
16 | * [Pull Request 75](https://github.com/winston/google_visualr/pull/75) Add Histogram chart.
17 |
18 | ### Version 2.3.0
19 |
20 | * [Issue 69](https://github.com/winston/google_visualr/pull/69) Support generating chart Javascript without `"
69 | js
70 | end
71 |
72 | # Generates JavaScript for loading the appropriate Google Visualization package, with callback to render chart.
73 | #
74 | # Parameters:
75 | # *div_id [Required] The ID of the DIV element that the Google Chart should be rendered in.
76 | def load_js(element_id)
77 | language_opt = ", language: '#{language}'" if language
78 |
79 | "\n google.load('visualization', '#{version}', {packages: ['#{package_name}']#{language_opt}, callback: #{chart_function_name(element_id)}});"
80 | end
81 |
82 | # Generates JavaScript function for rendering the chart.
83 | #
84 | # Parameters:
85 | # *div_id [Required] The ID of the DIV element that the Google Chart should be rendered in.
86 | def draw_js(element_id)
87 | js = ""
88 | js << "\n function #{chart_function_name(element_id)}() {"
89 | js << "\n #{@data_table.to_js}"
90 | js << "\n var chart = new google.#{chart_class}.#{chart_name}(document.getElementById('#{element_id}'));"
91 | @listeners.each do |listener|
92 | js << "\n google.visualization.events.addListener(chart, '#{listener[:event]}', #{listener[:callback]});"
93 | end
94 | js << "\n chart.draw(data_table, #{js_parameters(@options)});"
95 | js << "\n };"
96 | js
97 | end
98 | end
99 |
100 | end
101 |
--------------------------------------------------------------------------------
/spec/dummy/config/environments/production.rb:
--------------------------------------------------------------------------------
1 | Dummy::Application.configure do
2 | # Settings specified here will take precedence over those in config/application.rb.
3 |
4 | # Code is not reloaded between requests.
5 | config.cache_classes = true
6 |
7 | # Eager load code on boot. This eager loads most of Rails and
8 | # your application in memory, allowing both thread web servers
9 | # and those relying on copy on write to perform better.
10 | # Rake tasks automatically ignore this option for performance.
11 | config.eager_load = true
12 |
13 | # Full error reports are disabled and caching is turned on.
14 | config.consider_all_requests_local = false
15 | config.action_controller.perform_caching = true
16 |
17 | # Enable Rack::Cache to put a simple HTTP cache in front of your application
18 | # Add `rack-cache` to your Gemfile before enabling this.
19 | # For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid.
20 | # config.action_dispatch.rack_cache = true
21 |
22 | # Disable Rails's static asset server (Apache or nginx will already do this).
23 | if Rails.version >= "4.2.0"
24 | config.serve_static_files = false
25 | else
26 | config.serve_static_assets = false
27 | end
28 |
29 | # Compress JavaScripts and CSS.
30 | config.assets.js_compressor = :uglifier
31 | # config.assets.css_compressor = :sass
32 |
33 | # Whether to fallback to assets pipeline if a precompiled asset is missed.
34 | config.assets.compile = false
35 |
36 | # Generate digests for assets URLs.
37 | config.assets.digest = true
38 |
39 | # Version of your assets, change this if you want to expire all your assets.
40 | config.assets.version = '1.0'
41 |
42 | # Specifies the header that your server uses for sending files.
43 | # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
44 | # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
45 |
46 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
47 | # config.force_ssl = true
48 |
49 | # Set to :debug to see everything in the log.
50 | config.log_level = :info
51 |
52 | # Prepend all log lines with the following tags.
53 | # config.log_tags = [:subdomain, :uuid]
54 |
55 | # Use a different logger for distributed setups.
56 | # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
57 |
58 | # Use a different cache store in production.
59 | # config.cache_store = :mem_cache_store
60 |
61 | # Enable serving of images, stylesheets, and JavaScripts from an asset server.
62 | # config.action_controller.asset_host = "http://assets.example.com"
63 |
64 | # Precompile additional assets.
65 | # application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
66 | # config.assets.precompile += %w( search.js )
67 |
68 | # Ignore bad email addresses and do not raise email delivery errors.
69 | # Set this to true and configure the email server for immediate delivery to raise delivery errors.
70 | # config.action_mailer.raise_delivery_errors = false
71 |
72 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
73 | # the I18n.default_locale when a translation can not be found).
74 | config.i18n.fallbacks = true
75 |
76 | # Send deprecation notices to registered listeners.
77 | config.active_support.deprecation = :notify
78 |
79 | # Disable automatic flushing of the log to improve performance.
80 | # config.autoflush_log = false
81 |
82 | # Use default logging formatter so that PID and timestamp are not suppressed.
83 | config.log_formatter = ::Logger::Formatter.new
84 | end
85 |
--------------------------------------------------------------------------------
/lib/google_visualr/packages.rb:
--------------------------------------------------------------------------------
1 | module GoogleVisualr
2 | module Packages
3 | module CoreChart
4 | def package_name
5 | "corechart"
6 | end
7 | end
8 |
9 | module ImageChart
10 | def package_name
11 | "image#{self.class.to_s.split("::").last.downcase}"
12 | end
13 | def class_name
14 | "Image#{self.class.to_s.split('::').last}"
15 | end
16 |
17 | # Set defaults according to http://code.google.com/apis/chart/interactive/docs/gallery/genericimagechart.html#Configuration_Options
18 | IMAGE_DEFAULTS = {
19 | # Automatic Scaling
20 | :chds => "a",
21 | # Size
22 | :chs => "400x200",
23 | # Axes
24 | :chxt => "x,y"
25 | }
26 |
27 | # Generates HTTP GET URL for the chart image
28 | #
29 | # Parameters:
30 | # *opts [Optional] Hash of standard chart options (see http://code.google.com/apis/chart/image/docs/chart_params.html)
31 | def chart_image_url(superseding_params = {})
32 |
33 | #####
34 | # Generic image chart defaults
35 | query_params = IMAGE_DEFAULTS.clone
36 |
37 | # backgroundColor
38 | query_params[:chf] = "bg,s," + options["backgroundColor"].gsub(/#/, '') if options["backgroundColor"]
39 |
40 | # color, colors ('color' param is ignored if 'colors' is present)
41 | if options["colors"]
42 | query_params[:chco] = options["colors"].join(',').gsub(/#/, '')
43 | elsif options["color"]
44 | query_params[:chco] = options["color"].gsub(/#/, '')
45 | end
46 |
47 | # fill (this will often not look good - better for user to override this parameter)
48 | query_params[:chm] = "B,#{query_params[:chco].split(',').first},0,0,0" if options["fill"] && query_params[:chco]
49 |
50 | # firstHiddenColumn, singleColumnDisplay, data
51 | firstHiddenColumn = options["firstHiddenColumn"] ? options["firstHiddenColumn"] : data_table.cols.size - 1
52 | query_params[:chd] = "t:"
53 | unless options["singleColumnDisplay"]
54 | for i in 1..firstHiddenColumn do
55 | query_params[:chd] += "|" if i > 1
56 | query_params[:chd] += data_table.get_column(i).join(',')
57 | end
58 | else
59 | query_params[:chd] += data_dable.get_column(options["singleColumnDisplay"])
60 | end
61 |
62 | # height, width
63 | if options["height"] && options["width"]
64 | query_params[:chs] = "#{options["width"]}x#{options["height"]}"
65 | end
66 |
67 | # title
68 | query_params[:chtt] = options["title"] if options["title"]
69 |
70 | # legend
71 | unless options["legend"] == 'none'
72 | query_params[:chdlp] = options["legend"].first unless options["legend"].blank?
73 | query_params[:chdl] = data_table.cols[1..-1].map{|col| col[:label] }.join('|')
74 | else
75 | query_params.delete(:chdlp)
76 | query_params.delete(:chdl)
77 | end
78 |
79 | # min, max, valueLabelsInterval (works as long as :chxt => "x,y" and both 'min' and 'max' are set)
80 | if options["min"] && options["max"]
81 | query_params[:chxr] = "1,#{options['min']},#{options['max']}"
82 | query_params[:chxr] += ",#{options['valueLabelsInterval']}" if options['valueLabelsInterval']
83 | query_params[:chds] = "#{options['min']},#{options['max']}"
84 | end
85 | #####
86 |
87 | query_params = stringify_keys!(query_params.merge(superseding_params))
88 | base_url = "https://chart.googleapis.com/chart"
89 | query = ""
90 | query_params.each_with_index do |(k,v),i|
91 | query += (i == 0) ? "?" : "&"
92 | query += "#{k}=#{CGI.escape(v)}"
93 | end
94 | URI.parse(base_url + query)
95 | end
96 | end
97 | end
98 | end
99 |
--------------------------------------------------------------------------------
/spec/support/common.rb:
--------------------------------------------------------------------------------
1 | def data_table
2 | @cols = [
3 | { :type => "string", :label => "Year" },
4 | { :type => "number", :label => "Sales" },
5 | { :type => "number", :label => "Expenses" }
6 | ]
7 | @rows = [
8 | { :c => [{ :v => "2004" }, { :v => 1000 }, { :v => 400 }] },
9 | { :c => [{ :v => "2005" }, { :v => 1200 }, { :v => 450 }] },
10 | { :c => [{ :v => "2006" }, { :v => 1500 }, { :v => 600 }] },
11 | { :c => [{ :v => "2007" }, { :v => 800 }, { :v => 500 }] }
12 | ]
13 | GoogleVisualr::DataTable.new(:cols => @cols, :rows => @rows)
14 | end
15 |
16 | def base_chart(data_table = data_table())
17 | GoogleVisualr::BaseChart.new(data_table, { :legend => "Test Chart", :width => 800, :is3D => true })
18 | end
19 |
20 | def base_chart_js_without_script_tag(div_class = "div_class", language = nil)
21 | language_opt = ", language: '#{language}'" if language
22 |
23 | js = "\n google.load('visualization', '1.0', {packages: ['basechart']#{language_opt}, callback: draw_#{div_class}});"
24 | js << "\n function draw_#{div_class}() {"
25 | 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}'));"
26 | js << "\n chart.draw(data_table, {legend: \"Test Chart\", width: 800, is3D: true});"
27 | js << "\n };"
28 | end
29 |
30 | def base_chart_js(div_class = "div_class", language = nil)
31 | js = "\n"
34 | end
35 |
36 | def base_chart_with_listener_js(div_class = "div_class")
37 | js = "\n"
45 | end
46 |
47 | def material_chart(div_class = "div_class")
48 | js = "\n"
55 | end
56 |
--------------------------------------------------------------------------------
/spec/google_visualr/base_chart_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | describe GoogleVisualr::BaseChart do
4 |
5 | before do
6 | @dt = data_table
7 | @chart = base_chart(@dt)
8 | end
9 |
10 | describe "#initialize" do
11 | it "works" do
12 | @chart.data_table.should == @dt
13 | @chart.version.should == GoogleVisualr::BaseChart::DEFAULT_VERSION
14 | @chart.material.should == false
15 | @chart.options.should == { "legend" => "Test Chart", "width" => 800, "is3D" => true }
16 | @chart.language.should == nil
17 | end
18 |
19 | it "accepts version attribute" do
20 | @chart = GoogleVisualr::BaseChart.new(@dt, version: "1.1")
21 | @chart.version.should == "1.1"
22 | end
23 |
24 | it "accepts language attribute" do
25 | @chart = GoogleVisualr::BaseChart.new(@dt, language: "ja")
26 | @chart.language.should == "ja"
27 | end
28 |
29 | it "accepts material attribute" do
30 | @chart = GoogleVisualr::BaseChart.new(@dt, material: true)
31 | @chart.material.should == true
32 | end
33 | end
34 |
35 | describe "#package_name" do
36 | it "returns class name (without module) and downcased" do
37 | @chart.package_name.should == "basechart"
38 | end
39 | end
40 |
41 | describe "#class_name" do
42 | it "returns class name (without module)" do
43 | @chart.class_name.should == "BaseChart"
44 | end
45 | end
46 |
47 | describe "#chart_class" do
48 | it "returns 'charts' when material is true" do
49 | @chart.material = true
50 | @chart.chart_class.should == "charts"
51 | end
52 |
53 | it "returns 'charts' when material is false" do
54 | @chart.material = false
55 | @chart.chart_class.should == "visualization"
56 | end
57 | end
58 |
59 | describe "#chart_name" do
60 | it "returns class name (less module) when material is true" do
61 | @chart.material = true
62 | @chart.chart_name.should == "Base"
63 | end
64 |
65 | it "returns class name (less module) when material is false" do
66 | @chart.material = false
67 | @chart.chart_name.should == "BaseChart"
68 | end
69 | end
70 |
71 | describe "#chart_function_name" do
72 | it "returns a function name that is used to draw the chart in JS" do
73 | @chart.chart_function_name("base_chart").should == "draw_base_chart"
74 | end
75 |
76 | it "handles 'dashes' in element id" do
77 | @chart.chart_function_name("base-chart").should == "draw_base_chart"
78 | end
79 | end
80 |
81 | describe "#options=" do
82 | it "works" do
83 | @chart.options = { :legend => "Awesome Chart", :width => 1000, :is3D => false }
84 | @chart.options.should == { "legend" => "Awesome Chart", "width" => 1000, "is3D" => false }
85 | end
86 | end
87 |
88 | describe "#add_listener" do
89 | it "adds to listeners array" do
90 | @chart.add_listener("select", "function() {test_event(chart);}")
91 | @chart.listeners.should == [{ :event => "select", :callback => "function() {test_event(chart);}" }]
92 | end
93 | end
94 |
95 | describe "#to_js" do
96 | it "generates JS" do
97 | js = @chart.to_js("body")
98 | js.should == base_chart_js("body")
99 | js.should include("
185 |
186 |
187 |
188 |
201 |
202 |
203 |
207 |
208 |
212 |
213 |
214 |
Getting started
215 |
Here’s how to get rolling:
216 |
217 |
218 | -
219 |
Use rails generate to create your models and controllers
220 | To see all available options, run it without parameters.
221 |
222 |
223 | -
224 |
Set up a default route and remove or rename this file
225 | Routes are set up in config/routes.rb.
226 |
227 |
228 | -
229 |
Create your database
230 | Run rake db:migrate to create your database. If you're not using SQLite (the default), edit config/database.yml with your username and password.
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |