├── .gitignore ├── CONTRIBUTORS ├── LICENSE ├── README.rdoc ├── Rakefile ├── VERSION ├── init.rb ├── lib ├── seer.rb └── seer │ ├── area_chart.rb │ ├── bar_chart.rb │ ├── chart.rb │ ├── column_chart.rb │ ├── gauge.rb │ ├── geomap.rb │ ├── line_chart.rb │ └── pie_chart.rb ├── rdoc ├── classes │ ├── Seer.html │ └── Seer │ │ ├── AreaChart.html │ │ ├── BarChart.html │ │ ├── ColumnChart.html │ │ ├── Gauge.html │ │ ├── LineChart.html │ │ └── PieChart.html ├── created.rid ├── files │ ├── README_rdoc.html │ └── lib │ │ ├── seer │ │ ├── area_chart_rb.html │ │ ├── bar_chart_rb.html │ │ ├── chart_rb.html │ │ ├── column_chart_rb.html │ │ ├── gauge_rb.html │ │ ├── line_chart_rb.html │ │ └── pie_chart_rb.html │ │ └── seer_rb.html ├── fr_class_index.html ├── fr_file_index.html ├── fr_method_index.html ├── index.html └── rdoc-style.css ├── seer.gemspec └── spec ├── area_chart_spec.rb ├── bar_chart_spec.rb ├── chart_spec.rb ├── column_chart_spec.rb ├── custom_matchers.rb ├── gauge_spec.rb ├── geomap_spec.rb ├── helpers.rb ├── line_chart_spec.rb ├── pie_chart_spec.rb ├── seer_spec.rb ├── spec.opts └── spec_helper.rb /.gitignore: -------------------------------------------------------------------------------- 1 | pkg 2 | doc 3 | Manifest -------------------------------------------------------------------------------- /CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | Thanks go to the following individuals for their contributions: 2 | 3 | Alexey Kuleshov (http://github.com/kulesa) 4 | Harold Giménez (http://github.com/hgimenez) 5 | Henry Poydar (http://github.com/hpoydar) 6 | 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010 Corey Ehmke / SEO Logic 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.rdoc: -------------------------------------------------------------------------------- 1 | =Seer 2 | 3 | Seer is a lightweight, semantically rich wrapper for the Google Visualization API. It allows you to easily create a visualization of data in a variety of formats, including area charts, bar charts, column charts, gauges, line charts, and pie charts. 4 | 5 | ==Usage 6 | 7 | Add the following to the head of the page that will display a chart, or add it to your layout file: 8 | 9 | <%= Seer::init_visualization -%> 10 | 11 | Gather the data you want to visualize in an instance variable in your controller, then use the visualize method to insert the appropriate chart in your view. 12 | 13 | == Example 14 | 15 | In your controller: 16 | 17 | # @data must be an array, and each object in the array must respond to the data method specified 18 | # in the visualize call (in this example, 'quantity') 19 | @data = Widget.all 20 | 21 | In your view: 22 | 23 |
24 | 25 | <%= Seer::visualize( 26 | @widgets, 27 | :as => :bar_chart, 28 | :in_element => 'chart', 29 | :series => {:series_label => 'name', :data_method => 'quantity'}, 30 | :chart_options => { 31 | :height => 300, 32 | :width => 200 * @widgets.size, 33 | :is_3_d => false, 34 | :legend => 'none', 35 | :colors => ["#990000"], 36 | :title => "Widget Quantities", 37 | :title_x => 'Quantity', 38 | :title_y => 'Widgets' 39 | } 40 | ) 41 | -%> 42 | 43 | == More information 44 | 45 | For examples of additional chart types, refer to the documentation for each of the individual chart objects, or see the blog post announcing Seer: {Simple, Semantic Graphing for Ruby on Rails with Seer}[http://www.idolhands.com/ruby-on-rails/gems-plugins-and-engines/graphing-for-ruby-on-rails-with-seer] 46 | 47 | A {sample project}[http://github.com/Bantik/seer_sample] that demonstrates each of the chart types is available on GitHub. 48 | 49 | Seer is developed and maintained by {Corey Ehmke}[http://www.idolhands.com/] at {SEO Logic}[http://www.seologic.com/]. 50 | 51 | Copyright (c) 2010 Corey Ehmke / SEO Logic, released under the MIT license 52 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | require 'rake' 3 | 4 | begin 5 | require 'jeweler' 6 | Jeweler::Tasks.new do |gem| 7 | gem.name = "seer" 8 | gem.summary = %Q{Seer is a lightweight, semantically rich wrapper for the Google Visualization API.} 9 | gem.description = %Q{ Seer is a lightweight, semantically rich wrapper for the Google Visualization API. It allows you to easily create a visualization of data in a variety of formats, including area charts, bar charts, column charts, gauges, line charts, and pie charts.} 10 | gem.email = "corey@seologic.com" 11 | gem.homepage = "http://github.com/Bantik/seer" 12 | gem.authors = ["Corey Ehmke / SEO Logic"] 13 | gem.add_development_dependency "rspec", ">= 1.2.9" 14 | gem.files = [ 15 | "CONTRIBUTORS", 16 | "init.rb", 17 | "lib/seer.rb", 18 | "lib/seer/area_chart.rb", 19 | "lib/seer/bar_chart.rb", 20 | "lib/seer/chart.rb", 21 | "lib/seer/column_chart.rb", 22 | "lib/seer/gauge.rb", 23 | "lib/seer/geomap.rb", 24 | "lib/seer/line_chart.rb", 25 | "lib/seer/pie_chart.rb", 26 | "lib/seer/visualization_helper.rb", 27 | "LICENSE", 28 | "Rakefile", 29 | "README.rdoc", 30 | "rails/init.rb", 31 | "spec/spec.opts", 32 | "spec/spec_helper.rb", 33 | "spec/seer_spec.rb" 34 | ] 35 | end 36 | Jeweler::GemcutterTasks.new 37 | rescue LoadError 38 | puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler" 39 | end 40 | 41 | require 'rake/rdoctask' 42 | Rake::RDocTask.new do |rdoc| 43 | version = File.exist?('VERSION') ? File.read('VERSION') : "" 44 | 45 | rdoc.rdoc_dir = 'rdoc' 46 | rdoc.title = "seer #{version}" 47 | rdoc.rdoc_files.include('README*') 48 | rdoc.rdoc_files.include('lib/**/*.rb') 49 | end 50 | -------------------------------------------------------------------------------- /VERSION: -------------------------------------------------------------------------------- 1 | 0.10.0 -------------------------------------------------------------------------------- /init.rb: -------------------------------------------------------------------------------- 1 | require 'seer' 2 | -------------------------------------------------------------------------------- /lib/seer.rb: -------------------------------------------------------------------------------- 1 | module Seer 2 | 3 | require 'seer/chart' 4 | require 'seer/area_chart' 5 | require 'seer/bar_chart' 6 | require 'seer/column_chart' 7 | require 'seer/gauge' 8 | require 'seer/geomap' 9 | require 'seer/line_chart' 10 | require 'seer/pie_chart' 11 | 12 | VISUALIZERS = [:area_chart, :bar_chart, :column_chart, :gauge, :geomap, :line_chart, :pie_chart] 13 | 14 | def self.valid_hex_number?(val) #:nodoc: 15 | return false unless val.is_a?(String) && ! val.empty? 16 | ! (val =~ /^\#([0-9]|[a-f]|[A-F])+$/).nil? && val.length == 7 17 | end 18 | 19 | def self.log(message) #:nodoc: 20 | RAILS_DEFAULT_LOGGER.info(message) 21 | end 22 | 23 | def self.init_visualization 24 | %{ 25 | 29 | } 30 | end 31 | 32 | def self.visualize(data, args={}) 33 | raise ArgumentError, "Seer: Invalid visualizer: #{args[:as]}" unless args[:as] && VISUALIZERS.include?(args[:as]) 34 | raise ArgumentError, "Seer: No data provided!" unless data && ! data.empty? 35 | self.send(args[:as], data, args) 36 | end 37 | 38 | private 39 | 40 | def self.area_chart(data, args) 41 | AreaChart.render(data, args) 42 | end 43 | 44 | def self.bar_chart(data, args) 45 | BarChart.render(data, args) 46 | end 47 | 48 | def self.column_chart(data, args) 49 | ColumnChart.render(data, args) 50 | end 51 | 52 | def self.gauge(data, args) 53 | Gauge.render(data, args) 54 | end 55 | 56 | def self.geomap(data, args) 57 | Geomap.render(data, args) 58 | end 59 | 60 | def self.line_chart(data, args) 61 | LineChart.render(data, args) 62 | end 63 | 64 | def self.pie_chart(data, args) 65 | PieChart.render(data, args) 66 | end 67 | 68 | end 69 | -------------------------------------------------------------------------------- /lib/seer/area_chart.rb: -------------------------------------------------------------------------------- 1 | module Seer 2 | 3 | # =USAGE 4 | # 5 | # In your controller: 6 | # 7 | # @data = Widgets.all # Must be an array, and must respond 8 | # # to the data method specified below (in this example, 'quantity') 9 | # 10 | # @series = @data.map{|w| w.widget_stats} # An array of arrays 11 | # 12 | # In your view: 13 | # 14 | #
15 | # 16 | # <%= Seer::visualize( 17 | # @data, 18 | # :as => :area_chart, 19 | # :in_element => 'chart', 20 | # :series => { 21 | # :series_label => 'name', 22 | # :data_label => 'date', 23 | # :data_method => 'quantity', 24 | # :data_series => @series 25 | # }, 26 | # :chart_options => { 27 | # :height => 300, 28 | # :width => 300, 29 | # :axis_font_size => 11, 30 | # :colors => ['#7e7587','#990000','#009900'], 31 | # :title => "Widget Quantities", 32 | # :point_size => 5 33 | # } 34 | # ) 35 | # -%> 36 | # 37 | # For details on the chart options, see the Google API docs at 38 | # http://code.google.com/apis/visualization/documentation/gallery/areachart.html 39 | # 40 | class AreaChart 41 | 42 | include Seer::Chart 43 | 44 | # Graph options 45 | attr_accessor :axis_color, :axis_background_color, :axis_font_size, :background_color, :border_color, :data_table, :enable_tooltip, :focus_border_color, :height, :is_stacked, :legend, :legend_background_color, :legend_font_size, :legend_text_color, :line_size, :log_scale, :max, :min, :point_size, :reverse_axis, :show_categories, :title, :title_x, :title_y, :title_color, :title_font_size, :tooltip_font_size, :tooltip_height, :number, :tooltip_width, :width 46 | 47 | # Graph data 48 | attr_accessor :series_label, :data_label, :data, :data_method, :data_series 49 | 50 | def initialize(args={}) #:nodoc: 51 | 52 | # Standard options 53 | args.each{ |method,arg| self.send("#{method}=",arg) if self.respond_to?(method) } 54 | 55 | # Chart options 56 | args[:chart_options].each{ |method, arg| self.send("#{method}=",arg) if self.respond_to?(method) } 57 | 58 | # Handle defaults 59 | @colors ||= args[:chart_options][:colors] || DEFAULT_COLORS 60 | @legend ||= args[:chart_options][:legend] || DEFAULT_LEGEND_LOCATION 61 | @height ||= args[:chart_options][:height] || DEFAULT_HEIGHT 62 | @width ||= args[:chart_options][:width] || DEFAULT_WIDTH 63 | 64 | @data_table = [] 65 | 66 | end 67 | 68 | def data_columns #:nodoc: 69 | _data_columns = " data.addRows(#{data_rows.size});\r" 70 | _data_columns << " data.addColumn('string', 'Date');\r" 71 | data.each do |datum| 72 | _data_columns << " data.addColumn('number', '#{datum.send(series_label)}');\r" 73 | end 74 | _data_columns 75 | end 76 | 77 | def data_table #:nodoc: 78 | _rows = data_rows 79 | _rows.each_with_index do |r,i| 80 | @data_table << " data.setCell(#{i}, 0,'#{r}');\r" 81 | end 82 | data_series.each_with_index do |column,i| 83 | column.each_with_index do |c,j| 84 | @data_table << " data.setCell(#{j},#{i+1},#{c.send(data_method)});\r" 85 | end 86 | end 87 | @data_table 88 | end 89 | 90 | def data_rows 91 | data_series.inject([]) do |rows, element| 92 | rows |= element.map { |e| e.send(data_label) } 93 | end 94 | end 95 | 96 | def nonstring_options #:nodoc: 97 | [ :axis_font_size, :colors, :enable_tooltip, :height, :is_stacked, :legend_font_size, :line_size, :log_scale, :max, :min, :point_size, :reverse_axis, :show_categories, :title_font_size, :tooltip_font_size, :tooltip_height, :tooltip_width, :width] 98 | end 99 | 100 | def string_options #:nodoc: 101 | [ :axis_color, :axis_background_color, :background_color, :border_color, :focus_border_color, :legend, :legend_background_color, :legend_text_color, :title, :title_x, :title_y, :title_color ] 102 | end 103 | 104 | def to_js #:nodoc: 105 | 106 | %{ 107 | 121 | } 122 | end 123 | 124 | def self.render(data, args) #:nodoc: 125 | graph = Seer::AreaChart.new( 126 | :data => data, 127 | :series_label => args[:series][:series_label], 128 | :data_series => args[:series][:data_series], 129 | :data_label => args[:series][:data_label], 130 | :data_method => args[:series][:data_method], 131 | :chart_options => args[:chart_options], 132 | :chart_element => args[:in_element] || 'chart' 133 | ) 134 | graph.to_js 135 | end 136 | 137 | end 138 | 139 | end 140 | -------------------------------------------------------------------------------- /lib/seer/bar_chart.rb: -------------------------------------------------------------------------------- 1 | module Seer 2 | 3 | # =USAGE 4 | # 5 | # In your controller: 6 | # 7 | # @data = Widgets.all # Must be an array, and must respond 8 | # # to the data method specified below (in this example, 'quantity') 9 | # 10 | # In your view: 11 | # 12 | #
13 | # 14 | # <%= Seer::visualize( 15 | # @widgets, 16 | # :as => :bar_chart, 17 | # :in_element => 'chart', 18 | # :series => {:series_label => 'name', :data_method => 'quantity'}, 19 | # :chart_options => { 20 | # :height => 300, 21 | # :width => 200 * @widgets.size, 22 | # :is_3_d => false, 23 | # :legend => 'none', 24 | # :colors => ["#990000"], 25 | # :title => "Widget Quantities", 26 | # :title_x => 'Quantity', 27 | # :title_y => 'Widgets' 28 | # } 29 | # ) 30 | # -%> 31 | # 32 | # Colors are treated differently for 2d and 3d graphs. If you set is_3_d to true, set the 33 | # graph colors like this: 34 | # 35 | # :colors => "[{color:'#990000', darker:'#660000'}]", 36 | # 37 | # For details on the chart options, see the Google API docs at 38 | # http://code.google.com/apis/visualization/documentation/gallery/barchart.html 39 | # 40 | class BarChart 41 | 42 | include Seer::Chart 43 | 44 | # Chart options accessors 45 | attr_accessor :axis_color, :axis_background_color, :axis_font_size, :background_color, :border_color, :data_table, :enable_tooltip, :focus_border_color, :font_size, :height, :is_3_d, :is_stacked, :legend, :legend_background_color, :legend_font_size, :legend_text_color, :log_scale, :max, :min, :reverse_axis, :show_categories, :title, :title_x, :title_y, :title_color, :title_font_size, :tooltip_font_size, :tooltip_height, :tooltip_width, :width 46 | 47 | # Graph data 48 | attr_accessor :data, :data_method, :label_method 49 | 50 | def initialize(args={}) #:nodoc: 51 | 52 | # Standard options 53 | args.each{ |method,arg| self.send("#{method}=",arg) if self.respond_to?(method) } 54 | 55 | # Chart options 56 | args[:chart_options].each{ |method, arg| self.send("#{method}=",arg) if self.respond_to?(method) } 57 | 58 | # Handle defaults 59 | @colors ||= args[:chart_options][:colors] || DEFAULT_COLORS 60 | @legend ||= args[:chart_options][:legend] || DEFAULT_LEGEND_LOCATION 61 | @height ||= args[:chart_options][:height] || DEFAULT_HEIGHT 62 | @width ||= args[:chart_options][:width] || DEFAULT_WIDTH 63 | @is_3_d ||= args[:chart_options][:is_3_d] 64 | 65 | @data_table = [] 66 | 67 | end 68 | 69 | def data_table #:nodoc: 70 | data.each_with_index do |datum, column| 71 | @data_table << [ 72 | " data.setValue(#{column}, 0,'#{datum.send(label_method)}');\r", 73 | " data.setValue(#{column}, 1, #{datum.send(data_method)});\r" 74 | ] 75 | end 76 | @data_table 77 | end 78 | 79 | def is_3_d #:nodoc: 80 | @is_3_d.blank? ? false : @is_3_d 81 | end 82 | 83 | def nonstring_options #:nodoc: 84 | [:axis_font_size, :colors, :enable_tooltip, :is_3_d, :is_stacked, :legend_font_size, :log_scale, :max, :min, :reverse_axis, :show_categories, :title_font_size, :tooltip_font_size, :tooltip_width] 85 | end 86 | 87 | def string_options #:nodoc: 88 | [:axis_color, :axis_background_color, :background_color, :border_color, :focus_border_color, :height, :legend, :legend_background_color, :legend_text_color, :title, :title_x, :title_y, :title_color, :width] 89 | end 90 | 91 | def to_js #:nodoc: 92 | 93 | %{ 94 | 108 | } 109 | end 110 | 111 | def self.render(data, args) #:nodoc: 112 | graph = Seer::BarChart.new( 113 | :label_method => args[:series][:series_label], 114 | :data_method => args[:series][:data_method], 115 | :chart_options => args[:chart_options], 116 | :chart_element => args[:in_element] || 'chart', 117 | :data => data 118 | ) 119 | graph.to_js 120 | end 121 | 122 | end 123 | 124 | end 125 | -------------------------------------------------------------------------------- /lib/seer/chart.rb: -------------------------------------------------------------------------------- 1 | module Seer 2 | 3 | module Chart #:nodoc: 4 | 5 | attr_accessor :chart_element, :colors 6 | 7 | DEFAULT_COLORS = ['#324F69','#919E4B', '#A34D4D', '#BEC8BE'] 8 | DEFAULT_LEGEND_LOCATION = 'bottom' 9 | DEFAULT_HEIGHT = 350 10 | DEFAULT_WIDTH = 550 11 | 12 | def in_element=(elem) 13 | @chart_element = elem 14 | end 15 | 16 | def colors=(colors_list) 17 | unless colors_list.include?('darker') 18 | raise ArgumentError, "Invalid color option: #{colors_list}" unless colors_list.is_a?(Array) 19 | colors_list.each do |color| 20 | raise ArgumentError, "Invalid color option: #{colors_list}" unless Seer.valid_hex_number?(color) 21 | end 22 | end 23 | @colors = colors_list 24 | end 25 | 26 | def formatted_colors 27 | if @colors.include?('darker') 28 | @colors 29 | else 30 | "[#{@colors.map{|color| "'#{color.gsub(/\#/,'')}'"} * ','}]" 31 | end 32 | end 33 | 34 | def data_columns 35 | _data_columns = " data.addRows(#{data_table.size});\r" 36 | _data_columns << " data.addColumn('string', '#{label_method}');\r" 37 | _data_columns << " data.addColumn('number', '#{data_method}');\r" 38 | _data_columns 39 | end 40 | 41 | def options 42 | _options = "" 43 | nonstring_options.each do |opt| 44 | next unless self.send(opt) 45 | if opt == :colors 46 | _options << " options['#{opt.to_s.camelize(:lower)}'] = #{self.send(:formatted_colors)};\r" 47 | else 48 | _options << " options['#{opt.to_s.camelize(:lower)}'] = #{self.send(opt)};\r" 49 | end 50 | end 51 | string_options.each do |opt| 52 | next unless self.send(opt) 53 | _options << " options['#{opt.to_s.camelize(:lower)}'] = '#{self.send(opt)}';\r" 54 | end 55 | _options 56 | end 57 | 58 | end 59 | 60 | end -------------------------------------------------------------------------------- /lib/seer/column_chart.rb: -------------------------------------------------------------------------------- 1 | module Seer 2 | 3 | # =USAGE 4 | # 5 | # In your controller: 6 | # 7 | # @data = Widgets.all # Must be an array, and must respond 8 | # # to the data method specified below (in this example, 'quantity') 9 | # 10 | # In your view: 11 | # 12 | #
13 | # 14 | # <%= Seer::visualize( 15 | # @widgets, 16 | # :as => :column_chart, 17 | # :in_element => 'chart', 18 | # :series => {:series_label => 'name', :data_method => 'quantity'}, 19 | # :chart_options => { 20 | # :height => 300, 21 | # :width => 300, 22 | # :is_3_d => true, 23 | # :legend => 'none', 24 | # :colors => "[{color:'#990000', darker:'#660000'}]", 25 | # :title => "Widget Quantities", 26 | # :title_x => 'Widgets', 27 | # :title_y => 'Quantities' 28 | # } 29 | # ) 30 | # -%> 31 | # 32 | # Colors are treated differently for 2d and 3d graphs. If you set is_3_d to false, set the 33 | # graph color like this: 34 | # 35 | # :colors => "#990000" 36 | # 37 | # For details on the chart options, see the Google API docs at 38 | # http://code.google.com/apis/visualization/documentation/gallery/columnchart.html 39 | # 40 | class ColumnChart 41 | 42 | include Seer::Chart 43 | 44 | # Chart options accessors 45 | attr_accessor :axis_color, :axis_background_color, :axis_font_size, :background_color, :border_color, :enable_tooltip, :focus_border_color, :height, :is_3_d, :is_stacked, :legend, :legend_background_color, :legend_font_size, :legend_text_color, :log_scale, :max, :min, :reverse_axis, :show_categories, :title, :title_x, :title_y, :title_color, :title_font_size, :tooltip_font_size, :tooltip_height, :tooltip_width, :width 46 | 47 | # Graph data 48 | attr_accessor :data, :data_method, :data_table, :label_method 49 | 50 | def initialize(args={}) #:nodoc: 51 | 52 | # Standard options 53 | args.each{ |method,arg| self.send("#{method}=",arg) if self.respond_to?(method) } 54 | 55 | # Chart options 56 | args[:chart_options].each{ |method, arg| self.send("#{method}=",arg) if self.respond_to?(method) } 57 | 58 | # Handle defaults 59 | @colors ||= args[:chart_options][:colors] || DEFAULT_COLORS 60 | @legend ||= args[:chart_options][:legend] || DEFAULT_LEGEND_LOCATION 61 | @height ||= args[:chart_options][:height] || DEFAULT_HEIGHT 62 | @width ||= args[:chart_options][:width] || DEFAULT_WIDTH 63 | @is_3_d ||= args[:chart_options][:is_3_d] 64 | 65 | @data_table = [] 66 | 67 | end 68 | 69 | def data_table #:nodoc: 70 | data.each_with_index do |datum, column| 71 | @data_table << [ 72 | " data.setValue(#{column}, 0,'#{datum.send(label_method)}');\r", 73 | " data.setValue(#{column}, 1, #{datum.send(data_method)});\r" 74 | ] 75 | end 76 | @data_table 77 | end 78 | 79 | def is_3_d #:nodoc: 80 | @is_3_d.blank? ? false : @is_3_d 81 | end 82 | 83 | def nonstring_options #:nodoc: 84 | [:axis_font_size, :colors, :enable_tooltip, :height, :is_3_d, :is_stacked, :legend_font_size, :log_scale, :max, :min, :reverse_axis, :show_categories, :title_font_size, :tooltip_font_size, :tooltip_width, :width] 85 | end 86 | 87 | def string_options #:nodoc: 88 | [:axis_color, :axis_background_color, :background_color, :border_color, :focus_border_color, :legend, :legend_background_color, :legend_text_color, :title, :title_x, :title_y, :title_color] 89 | end 90 | 91 | def to_js #:nodoc: 92 | 93 | %{ 94 | 108 | } 109 | end 110 | 111 | def self.render(data, args) #:nodoc: 112 | graph = Seer::ColumnChart.new( 113 | :data => data, 114 | :label_method => args[:series][:series_label], 115 | :data_method => args[:series][:data_method], 116 | :chart_options => args[:chart_options], 117 | :chart_element => args[:in_element] || 'chart' 118 | ) 119 | graph.to_js 120 | end 121 | 122 | end 123 | 124 | end 125 | -------------------------------------------------------------------------------- /lib/seer/gauge.rb: -------------------------------------------------------------------------------- 1 | module Seer 2 | 3 | # =USAGE 4 | # 5 | # In your controller: 6 | # 7 | # @data = Widgets.all # Must be an array, and must respond 8 | # # to the data method specified below (in this example, 'quantity') 9 | # 10 | # In your view: 11 | # 12 | #
13 | # 14 | # <%= Seer::visualize( 15 | # @data, 16 | # :as => :gauge, 17 | # :in_element => 'chart', 18 | # :series => {:series_label => 'name', :data_method => 'quantity'}, 19 | # :chart_options => { 20 | # :green_from => 0, 21 | # :green_to => 50, 22 | # :height => 300, 23 | # :max => 100, 24 | # :min => 0, 25 | # :minor_ticks => 5, 26 | # :red_from => 76, 27 | # :red_to => 100, 28 | # :width => 600, 29 | # :yellow_from => 51, 30 | # :yellow_to => 75 31 | # } 32 | # ) 33 | # -%> 34 | # 35 | # For details on the chart options, see the Google API docs at 36 | # http://code.google.com/apis/visualization/documentation/gallery/gauge.html 37 | # 38 | class Gauge 39 | 40 | include Seer::Chart 41 | 42 | # Chart options accessors 43 | attr_accessor :green_from, :green_to, :height, :major_ticks, :max, :min, :minor_ticks, :red_from, :red_to, :width, :yellow_from, :yellow_to 44 | 45 | # Graph data 46 | attr_accessor :data, :data_method, :data_table, :label_method 47 | 48 | def initialize(args={}) #:nodoc: 49 | 50 | # Standard options 51 | args.each{ |method,arg| self.send("#{method}=",arg) if self.respond_to?(method) } 52 | 53 | # Chart options 54 | args[:chart_options].each{ |method, arg| self.send("#{method}=",arg) if self.respond_to?(method) } 55 | 56 | # Handle defaults 57 | @height ||= args[:chart_options][:height] || DEFAULT_HEIGHT 58 | @width ||= args[:chart_options][:width] || DEFAULT_WIDTH 59 | 60 | @data_table = [] 61 | 62 | end 63 | 64 | def data_table #:nodoc: 65 | data.each_with_index do |datum, column| 66 | @data_table << [ 67 | " data.setValue(#{column}, 0,'#{datum.send(label_method)}');\r", 68 | " data.setValue(#{column}, 1, #{datum.send(data_method)});\r" 69 | ] 70 | end 71 | @data_table 72 | end 73 | 74 | def is_3_d #:nodoc: 75 | @is_3_d.blank? ? false : @is_3_d 76 | end 77 | 78 | def nonstring_options #:nodoc: 79 | [:green_from, :green_to, :height, :major_ticks, :max, :min, :minor_ticks, :red_from, :red_to, :width, :yellow_from, :yellow_to] 80 | end 81 | 82 | def string_options #:nodoc: 83 | [] 84 | end 85 | 86 | def to_js #:nodoc: 87 | 88 | %{ 89 | 103 | } 104 | end 105 | 106 | def self.render(data, args) #:nodoc: 107 | graph = Seer::Gauge.new( 108 | :data => data, 109 | :label_method => args[:series][:series_label], 110 | :data_method => args[:series][:data_method], 111 | :chart_options => args[:chart_options], 112 | :chart_element => args[:in_element] || 'chart' 113 | ) 114 | graph.to_js 115 | end 116 | 117 | end 118 | 119 | end 120 | -------------------------------------------------------------------------------- /lib/seer/geomap.rb: -------------------------------------------------------------------------------- 1 | module Seer 2 | 3 | # Geomap creates a map of a country, continent, or region, with colors and values assigned to 4 | # specific regions. Values are displayed as a color scale, and you can specify optional hovertext 5 | # for regions. 6 | # 7 | # =USAGE= 8 | # 9 | # In your view: 10 | # 11 | #
12 | # 13 | # <%= Seer::visualize( 14 | # @locations, 15 | # :as => :geomap, 16 | # :in_element => 'my_geomap_container', 17 | # :series => { 18 | # :series_label => 'name', 19 | # :data_label => '# widgets', 20 | # :data_method => 'widget_count' 21 | # }, 22 | # :chart_options => { 23 | # :data_mode => 'regions', 24 | # :region => 'US', 25 | # } 26 | # ) 27 | # -%> 28 | # 29 | # ==@locations== 30 | # 31 | # A collection of objects (ActiveRecord or otherwise) that must respond to the 32 | # following methods: 33 | # 34 | # latitude # => returns the latitude in decimal format 35 | # longitude # => returns the longitude in decimal format 36 | # geocoded? # => result of latitude && longitude 37 | # 38 | # For details on the chart options, see the Google API docs at 39 | # http://code.google.com/apis/visualization/documentation/gallery/geomap.html 40 | # 41 | class Geomap 42 | 43 | include Seer::Chart 44 | 45 | COUNTRY_CODES = ['world', 'AX', 'AF', 'AL', 'DZ', 'AS', 'AD', 'AO', 'AI', 'AQ', 'AG', 'AR', 'AM', 'AW', 'AU', 'AT', 'AZ', 'BS', 'BH', 'BD', 'BB', 'BY', 'BE', 'BZ', 'BJ', 'BM', 'BT', 'BO', 'BA', 'BW', 'BV', 'BR', 'IO', 'BN', 'BG', 'BF', 'BI', 'KH', 'CM', 'CA', 'CV', 'KY', 'CF', 'TD', 'CL', 'CN', 'CX', 'CC', 'CO', 'KM', 'CD', 'CG', 'CK', 'CR', 'CI', 'HR', 'CU', 'CY', 'CZ', 'DK', 'DJ', 'DM', 'DO', 'EC', 'EG', 'SV', 'GQ', 'ER', 'EE', 'ET', 'FK', 'FO', 'FJ', 'FI', 'FR', 'GF', 'PF', 'TF', 'GA', 'GM', 'GE', 'DE', 'GH', 'GI', 'GR', 'GL', 'GD', 'GP', 'GU', 'GT', 'GN', 'GW', 'GY', 'HT', 'HM', 'HN', 'HK', 'HU', 'IS', 'IN', 'ID', 'IR', 'IQ', 'IE', 'IL', 'IT', 'JM', 'JP', 'JO', 'KZ', 'KE', 'KI', 'KP', 'KR', 'KW', 'KG', 'LA', 'LV', 'LB', 'LS', 'LR', 'LY', 'LI', 'LT', 'LU', 'MO', 'MK', 'MG', 'MW', 'MY', 'MV', 'ML', 'MT', 'MH', 'MQ', 'MR', 'MU', 'YT', 'MX', 'FM', 'MD', 'MC', 'MN', 'MS', 'MA', 'MZ', 'MM', 'NA', 'NR', 'NP', 'NL', 'AN', 'NC', 'NZ', 'NI', 'NE', 'NG', 'NU', 'NF', 'MP', 'NO', 'OM', 'PK', 'PW', 'PS', 'PA', 'PG', 'PY', 'PE', 'PH', 'PN', 'PL', 'PT', 'PR', 'QA', 'RE', 'RO', 'RU', 'RW', 'SH', 'KN', 'LC', 'PM', 'VC', 'WS', 'SM', 'ST', 'SA', 'SN', 'CS', 'SC', 'SL', 'SG', 'SK', 'SI', 'SB', 'SO', 'ZA', 'GS', 'ES', 'LK', 'SD', 'SR', 'SJ', 'SZ', 'SE', 'CH', 'SY', 'TW', 'TJ', 'TZ', 'TH', 'TL', 'TG', 'TK', 'TO', 'TT', 'TN', 'TR', 'TM', 'TC', 'TV', 'UG', 'UA', 'AE', 'GB', 'US', 'us_metro', 'UM', 'UY', 'UZ', 'VU', 'VA', 'VE', 'VN', 'VG', 'VI', 'WF', 'EH', 'YE', 'ZM', 'ZW', '005', '013', '021', '002', '017', '015', '018', '030', '034', '035', '143', '145', '151', '154', '155', '039'] 46 | 47 | # Chart options accessors 48 | attr_accessor :data_mode, :enable_tooltip, :height, :legend_background_color, :legend_font_size, :legend_text_color, :legend, :region, :show_legend, :show_zoom_out, :title_color, :title_font_size, :title_x, :title_y, :title, :tooltip_font_size, :tooltip_height, :tooltip_width, :width, :zoom_out_label 49 | 50 | # Graph data 51 | attr_accessor :data, :data_label, :data_method, :data_table, :label_method 52 | 53 | def initialize(args={}) #:nodoc: 54 | 55 | # Standard options 56 | args.each{ |method,arg| self.send("#{method}=",arg) if self.respond_to?(method) } 57 | 58 | # Chart options 59 | args[:chart_options].each{ |method, arg| self.send("#{method}=",arg) if self.respond_to?(method) } 60 | 61 | # Handle defaults 62 | @colors ||= args[:chart_options][:colors] || DEFAULT_COLORS 63 | @legend ||= args[:chart_options][:legend] || DEFAULT_LEGEND_LOCATION 64 | @height ||= args[:chart_options][:height] || DEFAULT_HEIGHT 65 | @width ||= args[:chart_options][:width] || DEFAULT_WIDTH 66 | 67 | end 68 | 69 | def data_columns #:nodoc: 70 | _data_columns = "data.addRows(#{data_table.size});" 71 | if self.data_mode == 'markers' 72 | _data_columns << %{ 73 | data.addColumn('number', 'LATITUDE'); 74 | data.addColumn('number', 'LONGITUDE'); 75 | data.addColumn('number', '#{data_method}'); 76 | data.addColumn('string', '#{label_method}'); 77 | } 78 | else 79 | _data_columns << " data.addColumn('string', '#{label_method}');" 80 | _data_columns << " data.addColumn('number', '#{data_method}');" 81 | _data_columns 82 | end 83 | _data_columns 84 | end 85 | 86 | def data_mode=(mode) #:nodoc: 87 | raise ArgumentError, "Invalid data mode option: #{mode}. Must be one of 'regions' or 'markers'." unless ['regions', 'markers'].include?(mode) 88 | @data_mode = mode 89 | end 90 | 91 | def data_table #:nodoc: 92 | @data_table = [] 93 | data.select{ |d| d.geocoded? }.each_with_index do |datum, column| 94 | if data_mode == "markers" 95 | @data_table << [ 96 | " data.setValue(#{column}, 0, #{datum.latitude});\r", 97 | " data.setValue(#{column}, 1, #{datum.longitude});\r", 98 | " data.setValue(#{column}, 2, #{datum.send(data_method)});\r", 99 | " data.setValue(#{column}, 3, '#{datum.send(label_method)}');\r" 100 | ] 101 | else # Regions 102 | @data_table << [ 103 | " data.setValue(#{column}, 0, '#{datum.name}');\r", 104 | " data.setValue(#{column}, 1, #{datum.send(data_method)});\r" 105 | ] 106 | end 107 | end 108 | @data_table 109 | end 110 | 111 | # Because Google is not consistent in their @#!$ API... 112 | def formatted_colors 113 | "[#{@colors.map{|color| "'#{color.gsub(/\#/,'0x')}'"} * ','}]" 114 | end 115 | 116 | def nonstring_options #:nodoc: 117 | [:colors, :enable_tooltip, :height, :legend_font_size, :title_font_size, :tooltip_font_size, :tooltip_width, :width] 118 | end 119 | 120 | def string_options #:nodoc: 121 | [:data_mode, :legend, :legend_background_color, :legend_text_color, :title, :title_x, :title_y, :title_color, :region] 122 | end 123 | 124 | def to_js 125 | %{ 126 | 140 | } 141 | end 142 | 143 | def region=(desired_region) 144 | raise ArgumentError, "Invalid region: #{desired_region}" unless COUNTRY_CODES.include?(desired_region) 145 | @region = desired_region 146 | end 147 | 148 | # ====================================== Class Methods ========================================= 149 | 150 | def self.render(data, args) 151 | map = Seer::Geomap.new( 152 | :region => args[:chart_options][:region], 153 | :data_mode => args[:chart_options][:data_mode], 154 | :data => data, 155 | :label_method => args[:series][:series_label], 156 | :data_method => args[:series][:data_method], 157 | :chart_options => args[:chart_options], 158 | :chart_element => args[:in_element] || 'chart' 159 | ) 160 | map.to_js 161 | end 162 | 163 | end 164 | 165 | end 166 | -------------------------------------------------------------------------------- /lib/seer/line_chart.rb: -------------------------------------------------------------------------------- 1 | module Seer 2 | 3 | # =USAGE 4 | # 5 | # In your controller: 6 | # 7 | # @data = Widgets.all # Must be an array of objects that respond to the specidied data method 8 | # # (In this example, 'quantity' 9 | # 10 | # @series = @data.map{|w| w.widget_stats} # An array of arrays 11 | # 12 | # In your view: 13 | # 14 | #
15 | # 16 | # <%= Seer::visualize( 17 | # @data, 18 | # :as => :line_chart, 19 | # :in_element => 'chart', 20 | # :series => { 21 | # :series_label => 'name', 22 | # :data_label => 'date', 23 | # :data_method => 'quantity', 24 | # :data_series => @series 25 | # }, 26 | # :chart_options => { 27 | # :height => 300, 28 | # :width => 300, 29 | # :axis_font_size => 11, 30 | # :colors => ['#7e7587','#990000','#009900'], 31 | # :title => "Widget Quantities", 32 | # :point_size => 5 33 | # } 34 | # ) 35 | # -%> 36 | # 37 | # For details on the chart options, see the Google API docs at 38 | # http://code.google.com/apis/visualization/documentation/gallery/linechart.html 39 | # 40 | class LineChart 41 | 42 | include Seer::Chart 43 | 44 | # Graph options 45 | attr_accessor :axis_color, :axis_background_color, :axis_font_size, :background_color, :border_color, :enable_tooltip, :focus_border_color, :height, :legend, :legend_background_color, :legend_font_size, :legend_text_color, :line_size, :log_scale, :max, :min, :point_size, :reverse_axis, :show_categories, :smooth_line, :title, :title_x, :title_y, :title_color, :title_font_size, :tooltip_font_size, :tooltip_height, :number, :tooltip_width, :width 46 | 47 | # Graph data 48 | attr_accessor :data, :data_label, :data_method, :data_series, :data_table, :series_label 49 | 50 | def initialize(args={}) #:nodoc: 51 | 52 | # Standard options 53 | args.each{ |method,arg| self.send("#{method}=",arg) if self.respond_to?(method) } 54 | 55 | # Chart options 56 | args[:chart_options].each{ |method, arg| self.send("#{method}=",arg) if self.respond_to?(method) } 57 | 58 | # Handle defaults 59 | @colors ||= args[:chart_options][:colors] || DEFAULT_COLORS 60 | @legend ||= args[:chart_options][:legend] || DEFAULT_LEGEND_LOCATION 61 | @height ||= args[:chart_options][:height] || DEFAULT_HEIGHT 62 | @width ||= args[:chart_options][:width] || DEFAULT_WIDTH 63 | 64 | @data_table = [] 65 | 66 | end 67 | 68 | def data_columns #:nodoc: 69 | _data_columns = " data.addRows(#{data_rows.size});\r" 70 | _data_columns << " data.addColumn('string', 'Date');\r" 71 | if data.first.respond_to?(series_label) 72 | data.each{ |datum| _data_columns << " data.addColumn('number', '#{datum.send(series_label)}');\r" } 73 | else 74 | data.each{ |datum| _data_columns << " data.addColumn('number', '#{series_label}');\r" } 75 | end 76 | _data_columns 77 | end 78 | 79 | def data_table #:nodoc: 80 | _rows = data_rows 81 | _rows.each_with_index do |r,i| 82 | @data_table << " data.setCell(#{i}, 0,'#{r}');\r" 83 | end 84 | data_series.each_with_index do |column,i| 85 | column.each_with_index do |c,j| 86 | @data_table << "data.setCell(#{j},#{i+1},#{c.send(data_method)});\r" 87 | end 88 | end 89 | @data_table 90 | end 91 | 92 | def data_rows 93 | data_series.inject([]) do |rows, element| 94 | rows |= element.map { |e| e.send(data_label) } 95 | end 96 | end 97 | 98 | def nonstring_options #:nodoc: 99 | [ :axis_font_size, :colors, :enable_tooltip, :height, :legend_font_size, :line_size, :log_scale, :max, :min, :point_size, :reverse_axis, :show_categories, :smooth_line, :title_font_size, :tooltip_font_size, :tooltip_height, :tooltip_width, :width] 100 | end 101 | 102 | def string_options #:nodoc: 103 | [ :axis_color, :axis_background_color, :background_color, :border_color, :focus_border_color, :legend, :legend_background_color, :legend_text_color, :title, :title_x, :title_y, :title_color ] 104 | end 105 | 106 | def to_js #:nodoc: 107 | 108 | %{ 109 | 123 | } 124 | end 125 | 126 | # ====================================== Class Methods ========================================= 127 | 128 | def self.render(data, args) #:nodoc: 129 | graph = Seer::LineChart.new( 130 | :data => data, 131 | :series_label => args[:series][:series_label], 132 | :data_series => args[:series][:data_series], 133 | :data_label => args[:series][:data_label], 134 | :data_method => args[:series][:data_method], 135 | :chart_options => args[:chart_options], 136 | :chart_element => args[:in_element] || 'chart' 137 | ) 138 | graph.to_js 139 | end 140 | 141 | end 142 | 143 | end 144 | -------------------------------------------------------------------------------- /lib/seer/pie_chart.rb: -------------------------------------------------------------------------------- 1 | module Seer 2 | 3 | # =USAGE 4 | # 5 | # In your controller: 6 | # 7 | # @data = Widgets.all # Must be an array of objects that respond to the specidied data method 8 | # # (In this example, 'quantity' 9 | # 10 | # In your view: 11 | # 12 | #
13 | # 14 | # <%= Seer::visualize( 15 | # @data, 16 | # :as => :pie_chart, 17 | # :series => {:series_label => 'name', :data_method => 'quantity'}, 18 | # :chart_options => { 19 | # :height => 300, 20 | # :width => 300, 21 | # :axis_font_size => 11, 22 | # :title => "Widget Quantities", 23 | # :point_size => 5, 24 | # :is_3_d => true 25 | # } 26 | # ) 27 | # -%> 28 | # 29 | # For details on the chart options, see the Google API docs at 30 | # http://code.google.com/apis/visualization/documentation/gallery/piechart.html 31 | # 32 | class PieChart 33 | 34 | include Seer::Chart 35 | 36 | # Chart options accessors 37 | attr_accessor :background_color, :border_color, :enable_tooltip, :focus_border_color, :height, :is_3_d, :legend, :legend_background_color, :legend_font_size, :legend_text_color, :pie_join_angle, :pie_minimal_angle, :title, :title_x, :title_y, :title_color, :title_font_size, :tooltip_font_size, :tooltip_height, :tooltip_width, :width 38 | 39 | # Graph data 40 | attr_accessor :data, :data_method, :data_table, :label_method 41 | 42 | def initialize(args={}) #:nodoc: 43 | 44 | # Standard options 45 | args.each{ |method,arg| self.send("#{method}=",arg) if self.respond_to?(method) } 46 | 47 | # Chart options 48 | args[:chart_options].each{ |method, arg| self.send("#{method}=",arg) if self.respond_to?(method) } 49 | 50 | # Handle defaults 51 | @colors ||= args[:chart_options][:colors] || DEFAULT_COLORS 52 | @legend ||= args[:chart_options][:legend] || DEFAULT_LEGEND_LOCATION 53 | @height ||= args[:chart_options][:height] || DEFAULT_HEIGHT 54 | @width ||= args[:chart_options][:width] || DEFAULT_WIDTH 55 | @is_3_d ||= args[:chart_options][:is_3_d] 56 | 57 | @data_table = [] 58 | 59 | end 60 | 61 | def data_table #:nodoc: 62 | data.each_with_index do |datum, column| 63 | @data_table << [ 64 | " data.setValue(#{column}, 0,'#{datum.send(label_method)}');\r", 65 | " data.setValue(#{column}, 1, #{datum.send(data_method)});\r" 66 | ] 67 | end 68 | @data_table 69 | end 70 | 71 | def is_3_d #:nodoc: 72 | @is_3_d.blank? ? false : @is_3_d 73 | end 74 | 75 | def nonstring_options #:nodoc: 76 | [:colors, :enable_tooltip, :height, :is_3_d, :legend_font_size, :pie_join_angle, :pie_minimal_angle, :title_font_size, :tooltip_font_size, :tooltip_width, :width] 77 | end 78 | 79 | def string_options #:nodoc: 80 | [:background_color, :border_color, :focus_border_color, :legend, :legend_background_color, :legend_text_color, :title, :title_color] 81 | end 82 | 83 | def to_js #:nodoc: 84 | 85 | %{ 86 | 100 | } 101 | end 102 | 103 | def self.render(data, args) #:nodoc: 104 | graph = Seer::PieChart.new( 105 | :data => data, 106 | :label_method => args[:series][:series_label], 107 | :data_method => args[:series][:data_method], 108 | :chart_options => args[:chart_options], 109 | :chart_element => args[:in_element] || 'chart' 110 | ) 111 | graph.to_js 112 | end 113 | 114 | end 115 | 116 | end 117 | -------------------------------------------------------------------------------- /rdoc/classes/Seer.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | Module: Seer 9 | 10 | 11 | 12 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 91 | 92 | 93 |
ModuleSeer
In: 58 | 59 | lib/seer/area_chart.rb 60 | 61 |
62 | 63 | lib/seer/bar_chart.rb 64 | 65 |
66 | 67 | lib/seer/chart.rb 68 | 69 |
70 | 71 | lib/seer/column_chart.rb 72 | 73 |
74 | 75 | lib/seer/gauge.rb 76 | 77 |
78 | 79 | lib/seer/line_chart.rb 80 | 81 |
82 | 83 | lib/seer/pie_chart.rb 84 | 85 |
86 | 87 | lib/seer.rb 88 | 89 |
90 |
94 |
95 | 96 | 97 |
98 | 99 | 100 | 101 |
102 | 103 | 104 | 105 |
106 | 107 |
108 |

Methods

109 | 110 |
111 | init_visualization   112 | visualize   113 |
114 |
115 | 116 |
117 | 118 | 119 | 120 | 121 |
122 | 123 |
124 |

Classes and Modules

125 | 126 | Class Seer::AreaChart
127 | Class Seer::BarChart
128 | Class Seer::ColumnChart
129 | Class Seer::Gauge
130 | Class Seer::LineChart
131 | Class Seer::PieChart
132 | 133 |
134 | 135 |
136 |

Constants

137 | 138 |
139 | 140 | 141 | 142 | 143 | 144 | 145 |
VISUALIZERS=[:area_chart, :bar_chart, :column_chart, :gauge, :line_chart, :pie_chart]
146 |
147 |
148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 |
156 |

Public Class methods

157 | 158 |
159 | 160 | 161 | 166 | 167 |
168 |

[Source]

170 |
171 |
172 | # File lib/seer.rb, line 22
173 |   def self.init_visualization
174 |     %{<script type="text/javascript" src="http://www.google.com/jsapi"></script>      }
175 |   end
176 | 
177 |
178 |
179 |
180 | 181 |
182 | 183 | 184 | 189 | 190 |
191 |

[Source]

193 |
194 |
195 | # File lib/seer.rb, line 26
196 |   def self.visualize(data, args={})
197 |     raise ArgumentError, "Seer: Invalid visualizer: #{args[:as]}" unless args[:as] && VISUALIZERS.include?(args[:as])
198 |     raise ArgumentError, "Seer: No data provided!" unless data && ! data.empty?
199 |     self.send(args[:as], data, args)
200 |   end
201 | 
202 |
203 |
204 |
205 | 206 | 207 |
208 | 209 | 210 |
211 | 212 | 213 |
214 |

[Validate]

215 |
216 | 217 | 218 | -------------------------------------------------------------------------------- /rdoc/classes/Seer/AreaChart.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | Class: Seer::AreaChart 9 | 10 | 11 | 12 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 65 | 66 | 67 | 70 | 71 |
ClassSeer::AreaChart
In: 58 | 59 | lib/seer/area_chart.rb 60 | 61 |
62 |
Parent: 68 | Object 69 |
72 |
73 | 74 | 75 |
76 | 77 | 78 | 79 |
80 | 81 |
82 |

USAGE

83 |

84 | In your controller: 85 |

86 |
 87 |   @data = Widgets.all # Must be an array, and must respond
 88 |                       # to the data method specified below (in this example, 'quantity')
 89 | 
 90 |   @series = @data.map{|w| w.widget_stats} # An array of arrays
 91 | 
92 |

93 | In your view: 94 |

95 |
 96 |   <div id="chart" class="chart"></div>
 97 | 
 98 |   <%= Seer::visualize(
 99 |         @data,
100 |         :as => :area_chart,
101 |         :in_element => 'chart',
102 |         :series => {
103 |           :series_label => 'name',
104 |           :data_label => 'date',
105 |           :data_method => 'quantity',
106 |           :data_series => @series
107 |         },
108 |         :chart_options => {
109 |           :height => 300,
110 |           :width => 300,
111 |           :axis_font_size => 11,
112 |           :colors => ['#7e7587','#990000','#009900'],
113 |           :title => "Widget Quantities",
114 |           :point_size => 5
115 |         }
116 |        )
117 |    -%>
118 | 
119 |

120 | For details on the chart options, see the Google API docs at code.google.com/apis/visualization/documentation/gallery/areachart.html 122 |

123 | 124 |
125 | 126 | 127 |
128 | 129 | 130 |
131 | 132 | 133 | 134 |
135 |

Included Modules

136 | 137 |
138 | Seer::Chart 139 |
140 |
141 | 142 |
143 | 144 | 145 | 146 | 147 | 148 |
149 |

Attributes

150 | 151 |
152 | 153 | 154 | 155 | 156 | 160 | 161 | 162 | 163 | 164 | 168 | 169 | 170 | 171 | 172 | 176 | 177 | 178 | 179 | 180 | 184 | 185 | 186 | 187 | 188 | 192 | 193 | 194 | 195 | 196 | 200 | 201 | 202 | 203 | 204 | 208 | 209 | 210 | 211 | 212 | 216 | 217 | 218 | 219 | 220 | 224 | 225 | 226 | 227 | 228 | 232 | 233 | 234 | 235 | 236 | 240 | 241 | 242 | 243 | 244 | 248 | 249 | 250 | 251 | 252 | 256 | 257 | 258 | 259 | 260 | 264 | 265 | 266 | 267 | 268 | 272 | 273 | 274 | 275 | 276 | 280 | 281 | 282 | 283 | 284 | 288 | 289 | 290 | 291 | 292 | 296 | 297 | 298 | 299 | 300 | 304 | 305 | 306 | 307 | 308 | 312 | 313 | 314 | 315 | 316 | 320 | 321 | 322 | 323 | 324 | 328 | 329 | 330 | 331 | 332 | 336 | 337 | 338 | 339 | 340 | 344 | 345 | 346 | 347 | 348 | 352 | 353 | 354 | 355 | 356 | 360 | 361 | 362 | 363 | 364 | 368 | 369 | 370 | 371 | 372 | 376 | 377 | 378 | 379 | 380 | 384 | 385 | 386 | 387 | 388 | 392 | 393 | 394 | 395 | 396 | 400 | 401 | 402 | 403 | 404 | 408 | 409 | 410 | 411 | 412 | 416 | 417 | 418 | 419 | 420 | 424 | 425 | 426 | 427 | 428 | 432 | 433 | 434 | 435 | 436 | 440 | 441 |
axis_background_color [RW]  157 | Graph options 158 | 159 |
axis_color [RW]  165 | Graph options 166 | 167 |
axis_font_size [RW]  173 | Graph options 174 | 175 |
background_color [RW]  181 | Graph options 182 | 183 |
border_color [RW]  189 | Graph options 190 | 191 |
data [RW]  197 | Graph data 198 | 199 |
data_label [RW]  205 | Graph data 206 | 207 |
data_method [RW]  213 | Graph data 214 | 215 |
data_series [RW]  221 | Graph data 222 | 223 |
data_table [RW]  229 | Graph options 230 | 231 |
enable_tooltip [RW]  237 | Graph options 238 | 239 |
focus_border_color [RW]  245 | Graph options 246 | 247 |
height [RW]  253 | Graph options 254 | 255 |
is_stacked [RW]  261 | Graph options 262 | 263 |
legend [RW]  269 | Graph options 270 | 271 |
legend_background_color [RW]  277 | Graph options 278 | 279 |
legend_font_size [RW]  285 | Graph options 286 | 287 |
legend_text_color [RW]  293 | Graph options 294 | 295 |
line_size [RW]  301 | Graph options 302 | 303 |
log_scale [RW]  309 | Graph options 310 | 311 |
max [RW]  317 | Graph options 318 | 319 |
min [RW]  325 | Graph options 326 | 327 |
number [RW]  333 | Graph options 334 | 335 |
point_size [RW]  341 | Graph options 342 | 343 |
reverse_axis [RW]  349 | Graph options 350 | 351 |
series_label [RW]  357 | Graph data 358 | 359 |
show_categories [RW]  365 | Graph options 366 | 367 |
title [RW]  373 | Graph options 374 | 375 |
title_color [RW]  381 | Graph options 382 | 383 |
title_font_size [RW]  389 | Graph options 390 | 391 |
title_x [RW]  397 | Graph options 398 | 399 |
title_y [RW]  405 | Graph options 406 | 407 |
tooltip_font_size [RW]  413 | Graph options 414 | 415 |
tooltip_height [RW]  421 | Graph options 422 | 423 |
tooltip_width [RW]  429 | Graph options 430 | 431 |
width [RW]  437 | Graph options 438 | 439 |
442 |
443 |
444 | 445 | 446 | 447 | 448 | 449 | 450 |
451 | 452 | 453 |
454 |

[Validate]

455 |
456 | 457 | 458 | -------------------------------------------------------------------------------- /rdoc/classes/Seer/BarChart.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | Class: Seer::BarChart 9 | 10 | 11 | 12 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 65 | 66 | 67 | 70 | 71 |
ClassSeer::BarChart
In: 58 | 59 | lib/seer/bar_chart.rb 60 | 61 |
62 |
Parent: 68 | Object 69 |
72 |
73 | 74 | 75 |
76 | 77 | 78 | 79 |
80 | 81 |
82 |

USAGE

83 |

84 | In your controller: 85 |

86 |
 87 |   @data = Widgets.all # Must be an array, and must respond
 88 |                       # to the data method specified below (in this example, 'quantity')
 89 | 
90 |

91 | In your view: 92 |

93 |
 94 |   <div id="chart" class="chart"></div>
 95 | 
 96 |   <%= Seer::visualize(
 97 |         @widgets,
 98 |         :as => :bar_chart,
 99 |         :in_element => 'chart',
100 |         :series => {:series_label => 'name', :data_method => 'quantity'},
101 |         :chart_options => {
102 |           :height => 300,
103 |           :width => 200 * @widgets.size,
104 |           :is_3_d => false,
105 |           :legend => 'none',
106 |           :colors => ["#990000"],
107 |           :title => "Widget Quantities",
108 |           :title_x => 'Quantity',
109 |           :title_y => 'Widgets'
110 |         }
111 |       )
112 |    -%>
113 | 
114 |

115 | Colors are treated differently for 2d and 3d graphs. If you set is_3_d to 116 | true, set the graph colors like this: 117 |

118 |
119 |           :colors   => "[{color:'#990000', darker:'#660000'}]",
120 | 
121 |

122 | For details on the chart options, see the Google API docs at code.google.com/apis/visualization/documentation/gallery/barchart.html 124 |

125 | 126 |
127 | 128 | 129 |
130 | 131 | 132 |
133 | 134 | 135 | 136 |
137 |

Included Modules

138 | 139 |
140 | Seer::Chart 141 |
142 |
143 | 144 |
145 | 146 | 147 | 148 | 149 | 150 |
151 |

Attributes

152 | 153 |
154 | 155 | 156 | 157 | 158 | 162 | 163 | 164 | 165 | 166 | 170 | 171 | 172 | 173 | 174 | 178 | 179 | 180 | 181 | 182 | 186 | 187 | 188 | 189 | 190 | 194 | 195 | 196 | 197 | 198 | 202 | 203 | 204 | 205 | 206 | 210 | 211 | 212 | 213 | 214 | 218 | 219 | 220 | 221 | 222 | 226 | 227 | 228 | 229 | 230 | 234 | 235 | 236 | 237 | 238 | 242 | 243 | 244 | 245 | 246 | 250 | 251 | 252 | 253 | 254 | 258 | 259 | 260 | 261 | 262 | 266 | 267 | 268 | 269 | 270 | 274 | 275 | 276 | 277 | 278 | 282 | 283 | 284 | 285 | 286 | 290 | 291 | 292 | 293 | 294 | 298 | 299 | 300 | 301 | 302 | 306 | 307 | 308 | 309 | 310 | 314 | 315 | 316 | 317 | 318 | 322 | 323 | 324 | 325 | 326 | 330 | 331 | 332 | 333 | 334 | 338 | 339 | 340 | 341 | 342 | 346 | 347 | 348 | 349 | 350 | 354 | 355 | 356 | 357 | 358 | 362 | 363 | 364 | 365 | 366 | 370 | 371 | 372 | 373 | 374 | 378 | 379 | 380 | 381 | 382 | 386 | 387 | 388 | 389 | 390 | 394 | 395 | 396 | 397 | 398 | 402 | 403 | 404 | 405 | 406 | 410 | 411 |
axis_background_color [RW]  159 | Chart options accessors 160 | 161 |
axis_color [RW]  167 | Chart options accessors 168 | 169 |
axis_font_size [RW]  175 | Chart options accessors 176 | 177 |
background_color [RW]  183 | Chart options accessors 184 | 185 |
border_color [RW]  191 | Chart options accessors 192 | 193 |
data [RW]  199 | Graph data 200 | 201 |
data_method [RW]  207 | Graph data 208 | 209 |
data_table [RW]  215 | Chart options accessors 216 | 217 |
enable_tooltip [RW]  223 | Chart options accessors 224 | 225 |
focus_border_color [RW]  231 | Chart options accessors 232 | 233 |
height [RW]  239 | Chart options accessors 240 | 241 |
is_3_d [RW]  247 | Chart options accessors 248 | 249 |
is_stacked [RW]  255 | Chart options accessors 256 | 257 |
label_method [RW]  263 | Graph data 264 | 265 |
legend [RW]  271 | Chart options accessors 272 | 273 |
legend_background_color [RW]  279 | Chart options accessors 280 | 281 |
legend_font_size [RW]  287 | Chart options accessors 288 | 289 |
legend_text_color [RW]  295 | Chart options accessors 296 | 297 |
log_scale [RW]  303 | Chart options accessors 304 | 305 |
max [RW]  311 | Chart options accessors 312 | 313 |
min [RW]  319 | Chart options accessors 320 | 321 |
reverse_axis [RW]  327 | Chart options accessors 328 | 329 |
show_categories [RW]  335 | Chart options accessors 336 | 337 |
title [RW]  343 | Chart options accessors 344 | 345 |
title_color [RW]  351 | Chart options accessors 352 | 353 |
title_font_size [RW]  359 | Chart options accessors 360 | 361 |
title_x [RW]  367 | Chart options accessors 368 | 369 |
title_y [RW]  375 | Chart options accessors 376 | 377 |
tooltip_font_size [RW]  383 | Chart options accessors 384 | 385 |
tooltip_height [RW]  391 | Chart options accessors 392 | 393 |
tooltip_width [RW]  399 | Chart options accessors 400 | 401 |
width [RW]  407 | Chart options accessors 408 | 409 |
412 |
413 |
414 | 415 | 416 | 417 | 418 | 419 | 420 |
421 | 422 | 423 |
424 |

[Validate]

425 |
426 | 427 | 428 | -------------------------------------------------------------------------------- /rdoc/classes/Seer/ColumnChart.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | Class: Seer::ColumnChart 9 | 10 | 11 | 12 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 65 | 66 | 67 | 70 | 71 |
ClassSeer::ColumnChart
In: 58 | 59 | lib/seer/column_chart.rb 60 | 61 |
62 |
Parent: 68 | Object 69 |
72 |
73 | 74 | 75 |
76 | 77 | 78 | 79 |
80 | 81 |
82 |

USAGE

83 |

84 | In your controller: 85 |

86 |
 87 |   @data = Widgets.all # Must be an array, and must respond
 88 |                       # to the data method specified below (in this example, 'quantity')
 89 | 
90 |

91 | In your view: 92 |

93 |
 94 |   <div id="chart" class="chart"></div>
 95 | 
 96 |   <%= Seer::visualize(
 97 |         @widgets,
 98 |         :as => :column_chart,
 99 |         :in_element => 'chart',
100 |         :series => {:series_label => 'name', :data_method => 'quantity'},
101 |         :chart_options => {
102 |           :height   => 300,
103 |           :width    => 300,
104 |           :is_3_d   => true,
105 |           :legend   => 'none',
106 |           :colors   => "[{color:'#990000', darker:'#660000'}]",
107 |           :title    => "Widget Quantities",
108 |           :title_x  => 'Widgets',
109 |           :title_y  => 'Quantities'
110 |         }
111 |       )
112 |    -%>
113 | 
114 |

115 | Colors are treated differently for 2d and 3d graphs. If you set is_3_d to 116 | false, set the graph color like this: 117 |

118 |
119 |           :colors   => "#990000"
120 | 
121 |

122 | For details on the chart options, see the Google API docs at code.google.com/apis/visualization/documentation/gallery/columnchart.html 124 |

125 | 126 |
127 | 128 | 129 |
130 | 131 | 132 |
133 | 134 | 135 | 136 |
137 |

Included Modules

138 | 139 |
140 | Seer::Chart 141 |
142 |
143 | 144 |
145 | 146 | 147 | 148 | 149 | 150 |
151 |

Attributes

152 | 153 |
154 | 155 | 156 | 157 | 158 | 162 | 163 | 164 | 165 | 166 | 170 | 171 | 172 | 173 | 174 | 178 | 179 | 180 | 181 | 182 | 186 | 187 | 188 | 189 | 190 | 194 | 195 | 196 | 197 | 198 | 202 | 203 | 204 | 205 | 206 | 210 | 211 | 212 | 213 | 214 | 218 | 219 | 220 | 221 | 222 | 226 | 227 | 228 | 229 | 230 | 234 | 235 | 236 | 237 | 238 | 242 | 243 | 244 | 245 | 246 | 250 | 251 | 252 | 253 | 254 | 258 | 259 | 260 | 261 | 262 | 266 | 267 | 268 | 269 | 270 | 274 | 275 | 276 | 277 | 278 | 282 | 283 | 284 | 285 | 286 | 290 | 291 | 292 | 293 | 294 | 298 | 299 | 300 | 301 | 302 | 306 | 307 | 308 | 309 | 310 | 314 | 315 | 316 | 317 | 318 | 322 | 323 | 324 | 325 | 326 | 330 | 331 | 332 | 333 | 334 | 338 | 339 | 340 | 341 | 342 | 346 | 347 | 348 | 349 | 350 | 354 | 355 | 356 | 357 | 358 | 362 | 363 | 364 | 365 | 366 | 370 | 371 | 372 | 373 | 374 | 378 | 379 | 380 | 381 | 382 | 386 | 387 | 388 | 389 | 390 | 394 | 395 | 396 | 397 | 398 | 402 | 403 | 404 | 405 | 406 | 410 | 411 |
axis_background_color [RW]  159 | Chart options accessors 160 | 161 |
axis_color [RW]  167 | Chart options accessors 168 | 169 |
axis_font_size [RW]  175 | Chart options accessors 176 | 177 |
background_color [RW]  183 | Chart options accessors 184 | 185 |
border_color [RW]  191 | Chart options accessors 192 | 193 |
data [RW]  199 | Graph data 200 | 201 |
data_method [RW]  207 | Graph data 208 | 209 |
data_table [RW]  215 | Graph data 216 | 217 |
enable_tooltip [RW]  223 | Chart options accessors 224 | 225 |
focus_border_color [RW]  231 | Chart options accessors 232 | 233 |
height [RW]  239 | Chart options accessors 240 | 241 |
is_3_d [RW]  247 | Chart options accessors 248 | 249 |
is_stacked [RW]  255 | Chart options accessors 256 | 257 |
label_method [RW]  263 | Graph data 264 | 265 |
legend [RW]  271 | Chart options accessors 272 | 273 |
legend_background_color [RW]  279 | Chart options accessors 280 | 281 |
legend_font_size [RW]  287 | Chart options accessors 288 | 289 |
legend_text_color [RW]  295 | Chart options accessors 296 | 297 |
log_scale [RW]  303 | Chart options accessors 304 | 305 |
max [RW]  311 | Chart options accessors 312 | 313 |
min [RW]  319 | Chart options accessors 320 | 321 |
reverse_axis [RW]  327 | Chart options accessors 328 | 329 |
show_categories [RW]  335 | Chart options accessors 336 | 337 |
title [RW]  343 | Chart options accessors 344 | 345 |
title_color [RW]  351 | Chart options accessors 352 | 353 |
title_font_size [RW]  359 | Chart options accessors 360 | 361 |
title_x [RW]  367 | Chart options accessors 368 | 369 |
title_y [RW]  375 | Chart options accessors 376 | 377 |
tooltip_font_size [RW]  383 | Chart options accessors 384 | 385 |
tooltip_height [RW]  391 | Chart options accessors 392 | 393 |
tooltip_width [RW]  399 | Chart options accessors 400 | 401 |
width [RW]  407 | Chart options accessors 408 | 409 |
412 |
413 |
414 | 415 | 416 | 417 | 418 | 419 | 420 |
421 | 422 | 423 |
424 |

[Validate]

425 |
426 | 427 | 428 | -------------------------------------------------------------------------------- /rdoc/classes/Seer/Gauge.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | Class: Seer::Gauge 9 | 10 | 11 | 12 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 65 | 66 | 67 | 70 | 71 |
ClassSeer::Gauge
In: 58 | 59 | lib/seer/gauge.rb 60 | 61 |
62 |
Parent: 68 | Object 69 |
72 |
73 | 74 | 75 |
76 | 77 | 78 | 79 |
80 | 81 |
82 |

USAGE

83 |

84 | In your controller: 85 |

86 |
 87 |   @data = Widgets.all # Must be an array, and must respond
 88 |                       # to the data method specified below (in this example, 'quantity')
 89 | 
90 |

91 | In your view: 92 |

93 |
 94 |   <div id="chart" class="chart"></div>
 95 | 
 96 |   <%= Seer::visualize(
 97 |         @data,
 98 |         :as => :gauge,
 99 |         :in_element => 'chart',
100 |         :series => {:series_label => 'name', :data_method => 'quantity'},
101 |         :chart_options => {
102 |           :green_from => 0,
103 |           :green_to => 50,
104 |           :height => 300,
105 |           :max => 100,
106 |           :min => 0,
107 |           :minor_ticks => 5,
108 |           :red_from => 76,
109 |           :red_to => 100,
110 |           :width => 600,
111 |           :yellow_from => 51,
112 |           :yellow_to => 75
113 |         }
114 |       )
115 |    -%>
116 | 
117 |

118 | For details on the chart options, see the Google API docs at code.google.com/apis/visualization/documentation/gallery/gauge.html 120 |

121 | 122 |
123 | 124 | 125 |
126 | 127 | 128 |
129 | 130 | 131 | 132 |
133 |

Included Modules

134 | 135 |
136 | Seer::Chart 137 |
138 |
139 | 140 |
141 | 142 | 143 | 144 | 145 | 146 |
147 |

Attributes

148 | 149 |
150 | 151 | 152 | 153 | 154 | 158 | 159 | 160 | 161 | 162 | 166 | 167 | 168 | 169 | 170 | 174 | 175 | 176 | 177 | 178 | 182 | 183 | 184 | 185 | 186 | 190 | 191 | 192 | 193 | 194 | 198 | 199 | 200 | 201 | 202 | 206 | 207 | 208 | 209 | 210 | 214 | 215 | 216 | 217 | 218 | 222 | 223 | 224 | 225 | 226 | 230 | 231 | 232 | 233 | 234 | 238 | 239 | 240 | 241 | 242 | 246 | 247 | 248 | 249 | 250 | 254 | 255 | 256 | 257 | 258 | 262 | 263 | 264 | 265 | 266 | 270 | 271 | 272 | 273 | 274 | 278 | 279 |
data [RW]  155 | Graph data 156 | 157 |
data_method [RW]  163 | Graph data 164 | 165 |
data_table [RW]  171 | Graph data 172 | 173 |
green_from [RW]  179 | Chart options accessors 180 | 181 |
green_to [RW]  187 | Chart options accessors 188 | 189 |
height [RW]  195 | Chart options accessors 196 | 197 |
label_method [RW]  203 | Graph data 204 | 205 |
major_ticks [RW]  211 | Chart options accessors 212 | 213 |
max [RW]  219 | Chart options accessors 220 | 221 |
min [RW]  227 | Chart options accessors 228 | 229 |
minor_ticks [RW]  235 | Chart options accessors 236 | 237 |
red_from [RW]  243 | Chart options accessors 244 | 245 |
red_to [RW]  251 | Chart options accessors 252 | 253 |
width [RW]  259 | Chart options accessors 260 | 261 |
yellow_from [RW]  267 | Chart options accessors 268 | 269 |
yellow_to [RW]  275 | Chart options accessors 276 | 277 |
280 |
281 |
282 | 283 | 284 | 285 | 286 | 287 | 288 |
289 | 290 | 291 |
292 |

[Validate]

293 |
294 | 295 | 296 | -------------------------------------------------------------------------------- /rdoc/classes/Seer/LineChart.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | Class: Seer::LineChart 9 | 10 | 11 | 12 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 65 | 66 | 67 | 70 | 71 |
ClassSeer::LineChart
In: 58 | 59 | lib/seer/line_chart.rb 60 | 61 |
62 |
Parent: 68 | Object 69 |
72 |
73 | 74 | 75 |
76 | 77 | 78 | 79 |
80 | 81 |
82 |

USAGE

83 |

84 | In your controller: 85 |

86 |
 87 |   @data = Widgets.all # Must be an array of objects that respond to the specidied data method
 88 |                       # (In this example, 'quantity'
 89 | 
 90 |   @series = @data.map{|w| w.widget_stats} # An array of arrays
 91 | 
92 |

93 | In your view: 94 |

95 |
 96 |   <div id="chart" class="chart"></div>
 97 | 
 98 |   <%= Seer::visualize(
 99 |         @data,
100 |         :as => :line_chart,
101 |         :in_element => 'chart',
102 |         :series => {
103 |           :series_label => 'name',
104 |           :data_label => 'date',
105 |           :data_method => 'quantity',
106 |           :data_series => @series
107 |         },
108 |         :chart_options => {
109 |           :height => 300,
110 |           :width => 300,
111 |           :axis_font_size => 11,
112 |           :colors => ['#7e7587','#990000','#009900'],
113 |           :title => "Widget Quantities",
114 |           :point_size => 5
115 |         }
116 |        )
117 |    -%>
118 | 
119 |

120 | For details on the chart options, see the Google API docs at code.google.com/apis/visualization/documentation/gallery/linechart.html 122 |

123 | 124 |
125 | 126 | 127 |
128 | 129 | 130 |
131 | 132 | 133 | 134 |
135 |

Included Modules

136 | 137 |
138 | Seer::Chart 139 |
140 |
141 | 142 |
143 | 144 | 145 | 146 | 147 | 148 |
149 |

Attributes

150 | 151 |
152 | 153 | 154 | 155 | 156 | 160 | 161 | 162 | 163 | 164 | 168 | 169 | 170 | 171 | 172 | 176 | 177 | 178 | 179 | 180 | 184 | 185 | 186 | 187 | 188 | 192 | 193 | 194 | 195 | 196 | 200 | 201 | 202 | 203 | 204 | 208 | 209 | 210 | 211 | 212 | 216 | 217 | 218 | 219 | 220 | 224 | 225 | 226 | 227 | 228 | 232 | 233 | 234 | 235 | 236 | 240 | 241 | 242 | 243 | 244 | 248 | 249 | 250 | 251 | 252 | 256 | 257 | 258 | 259 | 260 | 264 | 265 | 266 | 267 | 268 | 272 | 273 | 274 | 275 | 276 | 280 | 281 | 282 | 283 | 284 | 288 | 289 | 290 | 291 | 292 | 296 | 297 | 298 | 299 | 300 | 304 | 305 | 306 | 307 | 308 | 312 | 313 | 314 | 315 | 316 | 320 | 321 | 322 | 323 | 324 | 328 | 329 | 330 | 331 | 332 | 336 | 337 | 338 | 339 | 340 | 344 | 345 | 346 | 347 | 348 | 352 | 353 | 354 | 355 | 356 | 360 | 361 | 362 | 363 | 364 | 368 | 369 | 370 | 371 | 372 | 376 | 377 | 378 | 379 | 380 | 384 | 385 | 386 | 387 | 388 | 392 | 393 | 394 | 395 | 396 | 400 | 401 | 402 | 403 | 404 | 408 | 409 | 410 | 411 | 412 | 416 | 417 | 418 | 419 | 420 | 424 | 425 | 426 | 427 | 428 | 432 | 433 | 434 | 435 | 436 | 440 | 441 |
axis_background_color [RW]  157 | Graph options 158 | 159 |
axis_color [RW]  165 | Graph options 166 | 167 |
axis_font_size [RW]  173 | Graph options 174 | 175 |
background_color [RW]  181 | Graph options 182 | 183 |
border_color [RW]  189 | Graph options 190 | 191 |
data [RW]  197 | Graph data 198 | 199 |
data_label [RW]  205 | Graph data 206 | 207 |
data_method [RW]  213 | Graph data 214 | 215 |
data_series [RW]  221 | Graph data 222 | 223 |
data_table [RW]  229 | Graph data 230 | 231 |
enable_tooltip [RW]  237 | Graph options 238 | 239 |
focus_border_color [RW]  245 | Graph options 246 | 247 |
height [RW]  253 | Graph options 254 | 255 |
legend [RW]  261 | Graph options 262 | 263 |
legend_background_color [RW]  269 | Graph options 270 | 271 |
legend_font_size [RW]  277 | Graph options 278 | 279 |
legend_text_color [RW]  285 | Graph options 286 | 287 |
line_size [RW]  293 | Graph options 294 | 295 |
log_scale [RW]  301 | Graph options 302 | 303 |
max [RW]  309 | Graph options 310 | 311 |
min [RW]  317 | Graph options 318 | 319 |
number [RW]  325 | Graph options 326 | 327 |
point_size [RW]  333 | Graph options 334 | 335 |
reverse_axis [RW]  341 | Graph options 342 | 343 |
series_label [RW]  349 | Graph data 350 | 351 |
show_categories [RW]  357 | Graph options 358 | 359 |
smooth_line [RW]  365 | Graph options 366 | 367 |
title [RW]  373 | Graph options 374 | 375 |
title_color [RW]  381 | Graph options 382 | 383 |
title_font_size [RW]  389 | Graph options 390 | 391 |
title_x [RW]  397 | Graph options 398 | 399 |
title_y [RW]  405 | Graph options 406 | 407 |
tooltip_font_size [RW]  413 | Graph options 414 | 415 |
tooltip_height [RW]  421 | Graph options 422 | 423 |
tooltip_width [RW]  429 | Graph options 430 | 431 |
width [RW]  437 | Graph options 438 | 439 |
442 |
443 |
444 | 445 | 446 | 447 | 448 | 449 | 450 |
451 | 452 | 453 |
454 |

[Validate]

455 |
456 | 457 | 458 | -------------------------------------------------------------------------------- /rdoc/classes/Seer/PieChart.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | Class: Seer::PieChart 9 | 10 | 11 | 12 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 65 | 66 | 67 | 70 | 71 |
ClassSeer::PieChart
In: 58 | 59 | lib/seer/pie_chart.rb 60 | 61 |
62 |
Parent: 68 | Object 69 |
72 |
73 | 74 | 75 |
76 | 77 | 78 | 79 |
80 | 81 |
82 |

USAGE

83 |

84 | In your controller: 85 |

86 |
 87 |   @data = Widgets.all # Must be an array of objects that respond to the specidied data method
 88 |                       # (In this example, 'quantity'
 89 | 
90 |

91 | In your view: 92 |

93 |
 94 |   <div id="chart" class="chart"></div>
 95 | 
 96 |   <%= Seer::visualize(
 97 |         @data,
 98 |         :as => :pie_chart,
 99 |         :series => {:series_label => 'name', :data_method => 'quantity'},
100 |         :chart_options => {
101 |           :height => 300,
102 |           :width => 300,
103 |           :axis_font_size => 11,
104 |           :title => "Widget Quantities",
105 |           :point_size => 5,
106 |           :is_3_d => true
107 |         }
108 |        )
109 |    -%>
110 | 
111 |

112 | For details on the chart options, see the Google API docs at code.google.com/apis/visualization/documentation/gallery/piechart.html 114 |

115 | 116 |
117 | 118 | 119 |
120 | 121 | 122 |
123 | 124 | 125 | 126 |
127 |

Included Modules

128 | 129 |
130 | Seer::Chart 131 |
132 |
133 | 134 |
135 | 136 | 137 | 138 | 139 | 140 |
141 |

Attributes

142 | 143 |
144 | 145 | 146 | 147 | 148 | 152 | 153 | 154 | 155 | 156 | 160 | 161 | 162 | 163 | 164 | 168 | 169 | 170 | 171 | 172 | 176 | 177 | 178 | 179 | 180 | 184 | 185 | 186 | 187 | 188 | 192 | 193 | 194 | 195 | 196 | 200 | 201 | 202 | 203 | 204 | 208 | 209 | 210 | 211 | 212 | 216 | 217 | 218 | 219 | 220 | 224 | 225 | 226 | 227 | 228 | 232 | 233 | 234 | 235 | 236 | 240 | 241 | 242 | 243 | 244 | 248 | 249 | 250 | 251 | 252 | 256 | 257 | 258 | 259 | 260 | 264 | 265 | 266 | 267 | 268 | 272 | 273 | 274 | 275 | 276 | 280 | 281 | 282 | 283 | 284 | 288 | 289 | 290 | 291 | 292 | 296 | 297 | 298 | 299 | 300 | 304 | 305 | 306 | 307 | 308 | 312 | 313 | 314 | 315 | 316 | 320 | 321 | 322 | 323 | 324 | 328 | 329 | 330 | 331 | 332 | 336 | 337 | 338 | 339 | 340 | 344 | 345 |
background_color [RW]  149 | Chart options accessors 150 | 151 |
border_color [RW]  157 | Chart options accessors 158 | 159 |
data [RW]  165 | Graph data 166 | 167 |
data_method [RW]  173 | Graph data 174 | 175 |
data_table [RW]  181 | Graph data 182 | 183 |
enable_tooltip [RW]  189 | Chart options accessors 190 | 191 |
focus_border_color [RW]  197 | Chart options accessors 198 | 199 |
height [RW]  205 | Chart options accessors 206 | 207 |
is_3_d [RW]  213 | Chart options accessors 214 | 215 |
label_method [RW]  221 | Graph data 222 | 223 |
legend [RW]  229 | Chart options accessors 230 | 231 |
legend_background_color [RW]  237 | Chart options accessors 238 | 239 |
legend_font_size [RW]  245 | Chart options accessors 246 | 247 |
legend_text_color [RW]  253 | Chart options accessors 254 | 255 |
pie_join_angle [RW]  261 | Chart options accessors 262 | 263 |
pie_minimal_angle [RW]  269 | Chart options accessors 270 | 271 |
title [RW]  277 | Chart options accessors 278 | 279 |
title_color [RW]  285 | Chart options accessors 286 | 287 |
title_font_size [RW]  293 | Chart options accessors 294 | 295 |
title_x [RW]  301 | Chart options accessors 302 | 303 |
title_y [RW]  309 | Chart options accessors 310 | 311 |
tooltip_font_size [RW]  317 | Chart options accessors 318 | 319 |
tooltip_height [RW]  325 | Chart options accessors 326 | 327 |
tooltip_width [RW]  333 | Chart options accessors 334 | 335 |
width [RW]  341 | Chart options accessors 342 | 343 |
346 |
347 |
348 | 349 | 350 | 351 | 352 | 353 | 354 |
355 | 356 | 357 |
358 |

[Validate]

359 |
360 | 361 | 362 | -------------------------------------------------------------------------------- /rdoc/created.rid: -------------------------------------------------------------------------------- 1 | Tue, 16 Feb 2010 18:30:24 -0600 2 | -------------------------------------------------------------------------------- /rdoc/files/README_rdoc.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | File: README.rdoc 9 | 10 | 11 | 12 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 |

README.rdoc

51 | 52 | 53 | 54 | 56 | 57 | 58 | 59 | 60 | 61 |
Path:README.rdoc 55 |
Last Update:Tue Feb 16 14:10:55 -0600 2010
62 |
63 | 64 | 65 |
66 | 67 | 68 | 69 |
70 | 71 |
72 |

Seer

73 |

74 | Seer is a lightweight, semantically rich 75 | wrapper for the Google Visualization API. It allows you to easily create a 76 | visualization of data in a variety of formats, including area charts, bar 77 | charts, column charts, gauges, line charts, and pie charts. 78 |

79 |

Usage

80 |

81 | Add the following to the head of the page that will display a chart, or add 82 | it to your layout file: 83 |

84 |
 85 |   <%= Seer::init_visualization -%>
 86 | 
87 |

88 | Gather the data you want to visualize in an instance variable in your 89 | controller, then use the visualize method to insert the appropriate chart 90 | in your view. 91 |

92 |

Example

93 |

94 | In your controller: 95 |

96 |
 97 |   # @data must be an array, and each object in the array must respond to the data method specified
 98 |   # in the visualize call (in this example, 'quantity')
 99 |   @data = Widget.all
100 | 
101 |

102 | In your view: 103 |

104 |
105 |   <div id="chart" class="chart"></div>
106 | 
107 |   <%= Seer::visualize(
108 |         @widgets,
109 |         :as => :bar_chart,
110 |         :in_element => 'chart',
111 |         :series => {:series_label => 'name', :data_method => 'quantity'},
112 |         :chart_options => {
113 |           :height => 300,
114 |           :width => 200 * @widgets.size,
115 |           :is_3_d => false,
116 |           :legend => 'none',
117 |           :colors => ["#990000"],
118 |           :title => "Widget Quantities",
119 |           :title_x => 'Quantity',
120 |           :title_y => 'Widgets'
121 |         }
122 |       )
123 |    -%>
124 | 
125 |

126 | For examples of additional chart types, refer to the documentation for each 127 | of the individual chart objects. 128 |

129 |

130 | Copyright (c) 2010 Corey Ehmke / SEO Logic, released under the MIT license 131 |

132 | 133 |
134 | 135 | 136 |
137 | 138 | 139 |
140 | 141 | 142 | 143 | 144 |
145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 |
157 | 158 | 159 |
160 |

[Validate]

161 |
162 | 163 | 164 | -------------------------------------------------------------------------------- /rdoc/files/lib/seer/area_chart_rb.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | File: area_chart.rb 9 | 10 | 11 | 12 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 |

area_chart.rb

51 | 52 | 53 | 54 | 56 | 57 | 58 | 59 | 60 | 61 |
Path:lib/seer/area_chart.rb 55 |
Last Update:Tue Feb 16 17:31:17 -0600 2010
62 |
63 | 64 | 65 |
66 | 67 | 68 | 69 |
70 | 71 | 72 | 73 |
74 | 75 | 76 |
77 | 78 | 79 | 80 | 81 |
82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 |
94 | 95 | 96 |
97 |

[Validate]

98 |
99 | 100 | 101 | -------------------------------------------------------------------------------- /rdoc/files/lib/seer/bar_chart_rb.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | File: bar_chart.rb 9 | 10 | 11 | 12 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 |

bar_chart.rb

51 | 52 | 53 | 54 | 56 | 57 | 58 | 59 | 60 | 61 |
Path:lib/seer/bar_chart.rb 55 |
Last Update:Tue Feb 16 17:31:17 -0600 2010
62 |
63 | 64 | 65 |
66 | 67 | 68 | 69 |
70 | 71 | 72 | 73 |
74 | 75 | 76 |
77 | 78 | 79 | 80 | 81 |
82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 |
94 | 95 | 96 |
97 |

[Validate]

98 |
99 | 100 | 101 | -------------------------------------------------------------------------------- /rdoc/files/lib/seer/chart_rb.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | File: chart.rb 9 | 10 | 11 | 12 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 |

chart.rb

51 | 52 | 53 | 54 | 56 | 57 | 58 | 59 | 60 | 61 |
Path:lib/seer/chart.rb 55 |
Last Update:Tue Feb 16 14:01:36 -0600 2010
62 |
63 | 64 | 65 |
66 | 67 | 68 | 69 |
70 | 71 | 72 | 73 |
74 | 75 | 76 |
77 | 78 | 79 | 80 | 81 |
82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 |
94 | 95 | 96 |
97 |

[Validate]

98 |
99 | 100 | 101 | -------------------------------------------------------------------------------- /rdoc/files/lib/seer/column_chart_rb.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | File: column_chart.rb 9 | 10 | 11 | 12 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 |

column_chart.rb

51 | 52 | 53 | 54 | 56 | 57 | 58 | 59 | 60 | 61 |
Path:lib/seer/column_chart.rb 55 |
Last Update:Tue Feb 16 17:31:18 -0600 2010
62 |
63 | 64 | 65 |
66 | 67 | 68 | 69 |
70 | 71 | 72 | 73 |
74 | 75 | 76 |
77 | 78 | 79 | 80 | 81 |
82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 |
94 | 95 | 96 |
97 |

[Validate]

98 |
99 | 100 | 101 | -------------------------------------------------------------------------------- /rdoc/files/lib/seer/gauge_rb.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | File: gauge.rb 9 | 10 | 11 | 12 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 |

gauge.rb

51 | 52 | 53 | 54 | 56 | 57 | 58 | 59 | 60 | 61 |
Path:lib/seer/gauge.rb 55 |
Last Update:Tue Feb 16 17:31:18 -0600 2010
62 |
63 | 64 | 65 |
66 | 67 | 68 | 69 |
70 | 71 | 72 | 73 |
74 | 75 | 76 |
77 | 78 | 79 | 80 | 81 |
82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 |
94 | 95 | 96 |
97 |

[Validate]

98 |
99 | 100 | 101 | -------------------------------------------------------------------------------- /rdoc/files/lib/seer/line_chart_rb.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | File: line_chart.rb 9 | 10 | 11 | 12 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 |

line_chart.rb

51 | 52 | 53 | 54 | 56 | 57 | 58 | 59 | 60 | 61 |
Path:lib/seer/line_chart.rb 55 |
Last Update:Tue Feb 16 17:31:18 -0600 2010
62 |
63 | 64 | 65 |
66 | 67 | 68 | 69 |
70 | 71 | 72 | 73 |
74 | 75 | 76 |
77 | 78 | 79 | 80 | 81 |
82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 |
94 | 95 | 96 |
97 |

[Validate]

98 |
99 | 100 | 101 | -------------------------------------------------------------------------------- /rdoc/files/lib/seer/pie_chart_rb.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | File: pie_chart.rb 9 | 10 | 11 | 12 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 |

pie_chart.rb

51 | 52 | 53 | 54 | 56 | 57 | 58 | 59 | 60 | 61 |
Path:lib/seer/pie_chart.rb 55 |
Last Update:Tue Feb 16 17:31:18 -0600 2010
62 |
63 | 64 | 65 |
66 | 67 | 68 | 69 |
70 | 71 | 72 | 73 |
74 | 75 | 76 |
77 | 78 | 79 | 80 | 81 |
82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 |
94 | 95 | 96 |
97 |

[Validate]

98 |
99 | 100 | 101 | -------------------------------------------------------------------------------- /rdoc/files/lib/seer_rb.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | File: seer.rb 9 | 10 | 11 | 12 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 |

seer.rb

51 | 52 | 53 | 54 | 56 | 57 | 58 | 59 | 60 | 61 |
Path:lib/seer.rb 55 |
Last Update:Tue Feb 16 11:00:49 -0600 2010
62 |
63 | 64 | 65 |
66 | 67 | 68 | 69 |
70 | 71 | 72 |
73 |

Required files

74 | 75 |
76 | seer/chart   77 | seer/area_chart   78 | seer/bar_chart   79 | seer/column_chart   80 | seer/gauge   81 | seer/line_chart   82 | seer/pie_chart   83 |
84 |
85 | 86 |
87 | 88 | 89 |
90 | 91 | 92 | 93 | 94 |
95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 |
107 | 108 | 109 |
110 |

[Validate]

111 |
112 | 113 | 114 | -------------------------------------------------------------------------------- /rdoc/fr_class_index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 12 | 13 | 14 | Classes 15 | 16 | 17 | 18 | 19 | 20 |
21 |

Classes

22 |
23 | Seer
24 | Seer::AreaChart
25 | Seer::BarChart
26 | Seer::ColumnChart
27 | Seer::Gauge
28 | Seer::LineChart
29 | Seer::PieChart
30 |
31 |
32 | 33 | -------------------------------------------------------------------------------- /rdoc/fr_file_index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 12 | 13 | 14 | Files 15 | 16 | 17 | 18 | 19 | 20 |
21 |

Files

22 |
23 | README.rdoc
24 | lib/seer.rb
25 | lib/seer/area_chart.rb
26 | lib/seer/bar_chart.rb
27 | lib/seer/chart.rb
28 | lib/seer/column_chart.rb
29 | lib/seer/gauge.rb
30 | lib/seer/line_chart.rb
31 | lib/seer/pie_chart.rb
32 |
33 |
34 | 35 | -------------------------------------------------------------------------------- /rdoc/fr_method_index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 12 | 13 | 14 | Methods 15 | 16 | 17 | 18 | 19 | 20 |
21 |

Methods

22 |
23 | init_visualization (Seer)
24 | visualize (Seer)
25 |
26 |
27 | 28 | -------------------------------------------------------------------------------- /rdoc/index.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 12 | 13 | 14 | seer 0.4.0 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /rdoc/rdoc-style.css: -------------------------------------------------------------------------------- 1 | 2 | body { 3 | font-family: Verdana,Arial,Helvetica,sans-serif; 4 | font-size: 90%; 5 | margin: 0; 6 | margin-left: 40px; 7 | padding: 0; 8 | background: white; 9 | } 10 | 11 | h1,h2,h3,h4 { margin: 0; color: #efefef; background: transparent; } 12 | h1 { font-size: 150%; } 13 | h2,h3,h4 { margin-top: 1em; } 14 | 15 | a { background: #eef; color: #039; text-decoration: none; } 16 | a:hover { background: #039; color: #eef; } 17 | 18 | /* Override the base stylesheet's Anchor inside a table cell */ 19 | td > a { 20 | background: transparent; 21 | color: #039; 22 | text-decoration: none; 23 | } 24 | 25 | /* and inside a section title */ 26 | .section-title > a { 27 | background: transparent; 28 | color: #eee; 29 | text-decoration: none; 30 | } 31 | 32 | /* === Structural elements =================================== */ 33 | 34 | div#index { 35 | margin: 0; 36 | margin-left: -40px; 37 | padding: 0; 38 | font-size: 90%; 39 | } 40 | 41 | 42 | div#index a { 43 | margin-left: 0.7em; 44 | } 45 | 46 | div#index .section-bar { 47 | margin-left: 0px; 48 | padding-left: 0.7em; 49 | background: #ccc; 50 | font-size: small; 51 | } 52 | 53 | 54 | div#classHeader, div#fileHeader { 55 | width: auto; 56 | color: white; 57 | padding: 0.5em 1.5em 0.5em 1.5em; 58 | margin: 0; 59 | margin-left: -40px; 60 | border-bottom: 3px solid #006; 61 | } 62 | 63 | div#classHeader a, div#fileHeader a { 64 | background: inherit; 65 | color: white; 66 | } 67 | 68 | div#classHeader td, div#fileHeader td { 69 | background: inherit; 70 | color: white; 71 | } 72 | 73 | 74 | div#fileHeader { 75 | background: #057; 76 | } 77 | 78 | div#classHeader { 79 | background: #048; 80 | } 81 | 82 | 83 | .class-name-in-header { 84 | font-size: 180%; 85 | font-weight: bold; 86 | } 87 | 88 | 89 | div#bodyContent { 90 | padding: 0 1.5em 0 1.5em; 91 | } 92 | 93 | div#description { 94 | padding: 0.5em 1.5em; 95 | background: #efefef; 96 | border: 1px dotted #999; 97 | } 98 | 99 | div#description h1,h2,h3,h4,h5,h6 { 100 | color: #125;; 101 | background: transparent; 102 | } 103 | 104 | div#validator-badges { 105 | text-align: center; 106 | } 107 | div#validator-badges img { border: 0; } 108 | 109 | div#copyright { 110 | color: #333; 111 | background: #efefef; 112 | font: 0.75em sans-serif; 113 | margin-top: 5em; 114 | margin-bottom: 0; 115 | padding: 0.5em 2em; 116 | } 117 | 118 | 119 | /* === Classes =================================== */ 120 | 121 | table.header-table { 122 | color: white; 123 | font-size: small; 124 | } 125 | 126 | .type-note { 127 | font-size: small; 128 | color: #DEDEDE; 129 | } 130 | 131 | .xxsection-bar { 132 | background: #eee; 133 | color: #333; 134 | padding: 3px; 135 | } 136 | 137 | .section-bar { 138 | color: #333; 139 | border-bottom: 1px solid #999; 140 | margin-left: -20px; 141 | } 142 | 143 | 144 | .section-title { 145 | background: #79a; 146 | color: #eee; 147 | padding: 3px; 148 | margin-top: 2em; 149 | margin-left: -30px; 150 | border: 1px solid #999; 151 | } 152 | 153 | .top-aligned-row { vertical-align: top } 154 | .bottom-aligned-row { vertical-align: bottom } 155 | 156 | /* --- Context section classes ----------------------- */ 157 | 158 | .context-row { } 159 | .context-item-name { font-family: monospace; font-weight: bold; color: black; } 160 | .context-item-value { font-size: small; color: #448; } 161 | .context-item-desc { color: #333; padding-left: 2em; } 162 | 163 | /* --- Method classes -------------------------- */ 164 | .method-detail { 165 | background: #efefef; 166 | padding: 0; 167 | margin-top: 0.5em; 168 | margin-bottom: 1em; 169 | border: 1px dotted #ccc; 170 | } 171 | .method-heading { 172 | color: black; 173 | background: #ccc; 174 | border-bottom: 1px solid #666; 175 | padding: 0.2em 0.5em 0 0.5em; 176 | } 177 | .method-signature { color: black; background: inherit; } 178 | .method-name { font-weight: bold; } 179 | .method-args { font-style: italic; } 180 | .method-description { padding: 0 0.5em 0 0.5em; } 181 | 182 | /* --- Source code sections -------------------- */ 183 | 184 | a.source-toggle { font-size: 90%; } 185 | div.method-source-code { 186 | background: #262626; 187 | color: #ffdead; 188 | margin: 1em; 189 | padding: 0.5em; 190 | border: 1px dashed #999; 191 | overflow: hidden; 192 | } 193 | 194 | div.method-source-code pre { color: #ffdead; overflow: hidden; } 195 | 196 | /* --- Ruby keyword styles --------------------- */ 197 | 198 | .standalone-code { background: #221111; color: #ffdead; overflow: hidden; } 199 | 200 | .ruby-constant { color: #7fffd4; background: transparent; } 201 | .ruby-keyword { color: #00ffff; background: transparent; } 202 | .ruby-ivar { color: #eedd82; background: transparent; } 203 | .ruby-operator { color: #00ffee; background: transparent; } 204 | .ruby-identifier { color: #ffdead; background: transparent; } 205 | .ruby-node { color: #ffa07a; background: transparent; } 206 | .ruby-comment { color: #b22222; font-weight: bold; background: transparent; } 207 | .ruby-regexp { color: #ffa07a; background: transparent; } 208 | .ruby-value { color: #7fffd4; background: transparent; } -------------------------------------------------------------------------------- /seer.gemspec: -------------------------------------------------------------------------------- 1 | # Generated by jeweler 2 | # DO NOT EDIT THIS FILE DIRECTLY 3 | # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec' 4 | # -*- encoding: utf-8 -*- 5 | 6 | Gem::Specification.new do |s| 7 | s.name = %q{seer} 8 | s.version = "0.10.0" 9 | 10 | s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= 11 | s.authors = [%q{Corey Ehmke / SEO Logic}] 12 | s.date = %q{2011-09-06} 13 | s.description = %q{ Seer is a lightweight, semantically rich wrapper for the Google Visualization API. It allows you to easily create a visualization of data in a variety of formats, including area charts, bar charts, column charts, gauges, line charts, and pie charts.} 14 | s.email = %q{corey@seologic.com} 15 | s.extra_rdoc_files = [ 16 | "LICENSE", 17 | "README.rdoc" 18 | ] 19 | s.files = [ 20 | "CONTRIBUTORS", 21 | "LICENSE", 22 | "README.rdoc", 23 | "Rakefile", 24 | "init.rb", 25 | "lib/seer.rb", 26 | "lib/seer/area_chart.rb", 27 | "lib/seer/bar_chart.rb", 28 | "lib/seer/chart.rb", 29 | "lib/seer/column_chart.rb", 30 | "lib/seer/gauge.rb", 31 | "lib/seer/geomap.rb", 32 | "lib/seer/line_chart.rb", 33 | "lib/seer/pie_chart.rb", 34 | "spec/seer_spec.rb", 35 | "spec/spec.opts", 36 | "spec/spec_helper.rb" 37 | ] 38 | s.homepage = %q{http://github.com/Bantik/seer} 39 | s.require_paths = [%q{lib}] 40 | s.rubygems_version = %q{1.8.5} 41 | s.summary = %q{Seer is a lightweight, semantically rich wrapper for the Google Visualization API.} 42 | 43 | if s.respond_to? :specification_version then 44 | s.specification_version = 3 45 | 46 | if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then 47 | s.add_development_dependency(%q, [">= 1.2.9"]) 48 | else 49 | s.add_dependency(%q, [">= 1.2.9"]) 50 | end 51 | else 52 | s.add_dependency(%q, [">= 1.2.9"]) 53 | end 54 | end 55 | 56 | -------------------------------------------------------------------------------- /spec/area_chart_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path(File.dirname(__FILE__) + '/spec_helper') 2 | 3 | describe "Seer::AreaChart" do 4 | 5 | before :each do 6 | @chart = Seer::AreaChart.new( 7 | :data => [0,1,2,3], 8 | :series_label => 'to_s', 9 | :data_series => [[1,2,3],[3,4,5]], 10 | :data_label => 'to_s', 11 | :data_method => 'size', 12 | :chart_options => {}, 13 | :chart_element => 'chart' 14 | ) 15 | end 16 | 17 | describe 'defaults' do 18 | it_should_behave_like 'it sets default values' 19 | end 20 | 21 | describe 'graph options' do 22 | 23 | [:axis_color, :axis_background_color, :axis_font_size, :background_color, :border_color, :enable_tooltip, :focus_border_color, :height, :is_stacked, :legend, :legend_background_color, :legend_font_size, :legend_text_color, :line_size, :log_scale, :max, :min, :point_size, :reverse_axis, :show_categories, :title, :title_x, :title_y, :title_color, :title_font_size, :tooltip_font_size, :tooltip_height, :number, :tooltip_width, :width].each do |accessor| 24 | it "sets its #{accessor} value" do 25 | @chart.send("#{accessor}=", 'foo') 26 | @chart.send(accessor).should == 'foo' 27 | end 28 | end 29 | 30 | it_should_behave_like 'it has colors attribute' 31 | end 32 | 33 | it 'renders as JavaScript' do 34 | (@chart.to_js =~ /javascript/).should be_true 35 | (@chart.to_js =~ /areachart/).should be_true 36 | end 37 | 38 | it 'sets its data columns' do 39 | @chart.data_columns.should =~ /addRows\(5\)/ 40 | @chart.data_columns.should add_column('string', 'Date') 41 | @chart.data_columns.should add_column('number', '0') 42 | @chart.data_columns.should add_column('number', '1') 43 | @chart.data_columns.should add_column('number', '2') 44 | @chart.data_columns.should add_column('number', '3') 45 | end 46 | 47 | it 'sets its data table' do 48 | @chart.data_table.to_s.should set_cell(0, 0,'1') 49 | @chart.data_table.to_s.should set_cell(1, 0,'2') 50 | @chart.data_table.to_s.should set_cell(2, 0,'3') 51 | @chart.data_table.to_s.should set_cell(3, 0,'4') 52 | @chart.data_table.to_s.should set_cell(4, 0,'5') 53 | @chart.data_table.to_s.should set_cell(0,1,8) 54 | @chart.data_table.to_s.should set_cell(2,1,8) 55 | @chart.data_table.to_s.should set_cell(0,2,8) 56 | @chart.data_table.to_s.should set_cell(1,2,8) 57 | @chart.data_table.to_s.should set_cell(2,2,8) 58 | end 59 | 60 | describe 'when data_series is an array of arrays of arrays/hashes' do 61 | before(:each) do 62 | data_series = Array.new(3) {|i| [[i, i+1], [i+1, i+2]]} 63 | @chart = Seer::AreaChart.new( 64 | :data => [0,1,2,3], 65 | :series_label => 'to_s', 66 | :data_series => data_series, 67 | :data_label => 'first', 68 | :data_method => 'size', 69 | :chart_options => {}, 70 | :chart_element => 'chart' 71 | ) 72 | end 73 | 74 | it 'calculates number of rows' do 75 | @chart.data_columns.should =~ /addRows\(4\)/ 76 | end 77 | 78 | it 'sets its data table' do 79 | @chart.data_table.to_s.should set_cell(0, 0,'0') 80 | @chart.data_table.to_s.should set_cell(1, 0,'1') 81 | @chart.data_table.to_s.should set_cell(2, 0,'2') 82 | @chart.data_table.to_s.should set_cell(3, 0,'3') 83 | end 84 | end 85 | 86 | describe 'should receive options' do 87 | before(:each) do 88 | data_series = Array.new(3) {|i| [[i, i+1], [i+1, i+2]]} 89 | @options = { 90 | :data => [0,1,2,3], 91 | :series_label => 'to_s', 92 | :data_series => data_series, 93 | :data_label => 'first', 94 | :data_method => 'size', 95 | :chart_options => {}, 96 | :chart_element => 'chart' 97 | } 98 | end 99 | 100 | it 'should receive :is_stacked option' do 101 | create_chart_with_option(:is_stacked => true).to_js.should =~ /options\['isStacked'\] = true/ 102 | end 103 | end 104 | end 105 | 106 | def create_chart_with_option(option) 107 | Seer::AreaChart.new(@options.merge(option)) 108 | end 109 | -------------------------------------------------------------------------------- /spec/bar_chart_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path(File.dirname(__FILE__) + '/spec_helper') 2 | 3 | describe "Seer::BarChart" do 4 | 5 | before :each do 6 | @chart = Seer::BarChart.new( 7 | :data => [0,1,2,3], 8 | :label_method => 'to_s', 9 | :data_method => 'size', 10 | :chart_options => {}, 11 | :chart_element => 'chart' 12 | ) 13 | end 14 | 15 | describe 'defaults' do 16 | it_should_behave_like 'it sets default values' 17 | end 18 | 19 | describe 'graph options' do 20 | 21 | [:axis_color, :axis_background_color, :axis_font_size, :background_color, :border_color, :enable_tooltip, :focus_border_color, :height, :is_3_d, :is_stacked, :legend, :legend_background_color, :legend_font_size, :legend_text_color, :log_scale, :max, :min, :reverse_axis, :show_categories, :title, :title_x, :title_y, :title_color, :title_font_size, :tooltip_font_size, :tooltip_height, :tooltip_width, :width].each do |accessor| 22 | it "sets its #{accessor} value" do 23 | @chart.send("#{accessor}=", 'foo') 24 | @chart.send(accessor).should == 'foo' 25 | end 26 | end 27 | 28 | it_should_behave_like 'it has colors attribute' 29 | end 30 | 31 | it 'renders as JavaScript' do 32 | (@chart.to_js =~ /javascript/).should be_true 33 | (@chart.to_js =~ /barchart/).should be_true 34 | end 35 | 36 | it 'sets its data columns' do 37 | @chart.data_columns.should =~ /addRows\(4\)/ 38 | end 39 | 40 | it 'sets its data table' do 41 | @chart.data_table.to_s.should set_value(0, 0,'0') 42 | @chart.data_table.to_s.should set_value(0, 1, 8) 43 | @chart.data_table.to_s.should set_value(1, 0,'1') 44 | @chart.data_table.to_s.should set_value(1, 1, 8) 45 | @chart.data_table.to_s.should set_value(2, 0,'2') 46 | @chart.data_table.to_s.should set_value(2, 1, 8) 47 | @chart.data_table.to_s.should set_value(3, 0,'3') 48 | @chart.data_table.to_s.should set_value(3, 1, 8) 49 | end 50 | 51 | end 52 | -------------------------------------------------------------------------------- /spec/chart_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path(File.dirname(__FILE__) + '/spec_helper') 2 | 3 | describe "Seer::Chart" do 4 | 5 | before :all do 6 | @chart = Seer::AreaChart.new( 7 | :data => [0,1,2,3], 8 | :series_label => 'to_s', 9 | :data_series => [[1,2,3],[3,4,5]], 10 | :data_label => 'to_s', 11 | :data_method => 'size', 12 | :chart_options => { 13 | :legend => 'right', 14 | :title_x => 'Something' 15 | }, 16 | :chart_element => 'chart' 17 | ) 18 | end 19 | 20 | it 'sets the chart element' do 21 | @chart.in_element = 'foo' 22 | @chart.chart_element.should == 'foo' 23 | end 24 | 25 | describe 'sets colors' do 26 | 27 | it 'accepting valid values' do 28 | @chart.colors = ["#ff0000", "#00ff00"] 29 | @chart.colors.should == ["#ff0000", "#00ff00"] 30 | end 31 | 32 | it 'raising an error on invalid values' do 33 | lambda do 34 | @chart.colors = 'fred' 35 | end.should raise_error(ArgumentError) 36 | lambda do 37 | @chart.colors = [0,1,2] 38 | end.should raise_error(ArgumentError) 39 | end 40 | 41 | end 42 | 43 | it 'formats colors' do 44 | @chart.colors = ["#ff0000"] 45 | @chart.formatted_colors.should == "['ff0000']" 46 | end 47 | 48 | it 'sets its data columns' do 49 | @chart.data_columns.should =~ /addRows\(5\)/ 50 | @chart.data_columns.should =~ /addColumn\('string', 'Date'\)/ 51 | @chart.data_columns.should =~ /addColumn\('number', '0'\)/ 52 | @chart.data_columns.should =~ /addColumn\('number', '1'\)/ 53 | @chart.data_columns.should =~ /addColumn\('number', '2'\)/ 54 | @chart.data_columns.should =~ /addColumn\('number', '3'\)/ 55 | end 56 | 57 | it 'sets its options' do 58 | @chart.options.should =~ /options\['titleX'\] = 'Something'/ 59 | end 60 | 61 | 62 | end 63 | -------------------------------------------------------------------------------- /spec/column_chart_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path(File.dirname(__FILE__) + '/spec_helper') 2 | 3 | describe "Seer::ColumnChart" do 4 | 5 | before :each do 6 | @chart = Seer::ColumnChart.new( 7 | :data => [0,1,2,3], 8 | :label_method => 'to_s', 9 | :data_method => 'size', 10 | :chart_options => {}, 11 | :chart_element => 'chart' 12 | ) 13 | end 14 | 15 | describe 'defaults' do 16 | it_should_behave_like 'it sets default values' 17 | end 18 | 19 | describe 'graph options' do 20 | 21 | [:axis_color, :axis_background_color, :axis_font_size, :background_color, :border_color, :enable_tooltip, :focus_border_color, :height, :is_3_d, :is_stacked, :legend, :legend_background_color, :legend_font_size, :legend_text_color, :log_scale, :max, :min, :reverse_axis, :show_categories, :title, :title_x, :title_y, :title_color, :title_font_size, :tooltip_font_size, :tooltip_height, :tooltip_width, :width].each do |accessor| 22 | it "sets its #{accessor} value" do 23 | @chart.send("#{accessor}=", 'foo') 24 | @chart.send(accessor).should == 'foo' 25 | end 26 | end 27 | 28 | it_should_behave_like 'it has colors attribute' 29 | end 30 | 31 | it 'renders as JavaScript' do 32 | (@chart.to_js =~ /javascript/).should be_true 33 | (@chart.to_js =~ /columnchart/).should be_true 34 | end 35 | 36 | it 'sets its data columns' do 37 | @chart.data_columns.should =~ /addRows\(4\)/ 38 | end 39 | 40 | it 'sets its data table' do 41 | @chart.data_table.to_s.should set_value(0, 0,'0') 42 | @chart.data_table.to_s.should set_value(0, 1, 8) 43 | @chart.data_table.to_s.should set_value(1, 0,'1') 44 | @chart.data_table.to_s.should set_value(1, 1, 8) 45 | @chart.data_table.to_s.should set_value(2, 0,'2') 46 | @chart.data_table.to_s.should set_value(2, 1, 8) 47 | @chart.data_table.to_s.should set_value(3, 0,'3') 48 | @chart.data_table.to_s.should set_value(3, 1, 8) 49 | end 50 | 51 | end 52 | -------------------------------------------------------------------------------- /spec/custom_matchers.rb: -------------------------------------------------------------------------------- 1 | module CustomMatcher 2 | def set_cell(row, column, value) 3 | value = "'#{value}'" if value.is_a?(String) 4 | 5 | simple_matcher("setCell(#{row}, #{column}, #{value})") do |actual| 6 | actual =~ /data\.setCell\(#{row},\s*#{column},\s*#{value}\)/ 7 | end 8 | end 9 | 10 | def set_value(row, column, value) 11 | value = "'#{value}'" if value.is_a?(String) 12 | 13 | simple_matcher("setValue(#{row}, #{column}, #{value})") do |actual| 14 | actual =~ /data\.setValue\(#{row},\s*#{column},\s*#{value}\)/ 15 | end 16 | end 17 | 18 | def add_column(column_type, value) 19 | simple_matcher("addColumn('#{column_type}', '#{value}')") do |actual| 20 | actual =~ /data\.addColumn\('#{column_type}',\s*'#{value}'\)/ 21 | end 22 | end 23 | end -------------------------------------------------------------------------------- /spec/gauge_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path(File.dirname(__FILE__) + '/spec_helper') 2 | 3 | describe "Seer::Gauge" do 4 | 5 | before :each do 6 | @chart = Seer::Gauge.new( 7 | :data => [0,1,2,3], 8 | :label_method => 'to_s', 9 | :data_method => 'size', 10 | :chart_options => {}, 11 | :chart_element => 'chart' 12 | ) 13 | end 14 | 15 | describe 'defaults' do 16 | 17 | it 'height' do 18 | @chart.height.should == Seer::Chart::DEFAULT_HEIGHT 19 | end 20 | 21 | it 'width' do 22 | @chart.width.should == Seer::Chart::DEFAULT_WIDTH 23 | end 24 | 25 | end 26 | 27 | describe 'graph options' do 28 | 29 | [:green_from, :green_to, :height, :major_ticks, :max, :min, :minor_ticks, :red_from, :red_to, :width, :yellow_from, :yellow_to].each do |accessor| 30 | it "sets its #{accessor} value" do 31 | @chart.send("#{accessor}=", 'foo') 32 | @chart.send(accessor).should == 'foo' 33 | end 34 | end 35 | 36 | it_should_behave_like 'it has colors attribute' 37 | end 38 | 39 | it 'renders as JavaScript' do 40 | (@chart.to_js =~ /javascript/).should be_true 41 | (@chart.to_js =~ /gauge/).should be_true 42 | end 43 | 44 | it 'sets its data columns' do 45 | @chart.data_columns.should =~ /addRows\(4\)/ 46 | end 47 | 48 | it 'sets its data table' do 49 | @chart.data_table.to_s.should set_value(0, 0,'0') 50 | @chart.data_table.to_s.should set_value(0, 1, 8) 51 | @chart.data_table.to_s.should set_value(1, 0,'1') 52 | @chart.data_table.to_s.should set_value(1, 1, 8) 53 | @chart.data_table.to_s.should set_value(2, 0,'2') 54 | @chart.data_table.to_s.should set_value(2, 1, 8) 55 | @chart.data_table.to_s.should set_value(3, 0,'3') 56 | @chart.data_table.to_s.should set_value(3, 1, 8) 57 | end 58 | 59 | end 60 | -------------------------------------------------------------------------------- /spec/geomap_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path(File.dirname(__FILE__) + '/spec_helper') 2 | 3 | describe "Seer::Geomap" do 4 | 5 | before :each do 6 | 7 | class GeoThing 8 | def initialize; end 9 | def name; 'foo'; end 10 | def latitude; -90; end 11 | def longitude; -90; end 12 | def count; 8; end 13 | def geocoded?; true; end 14 | end 15 | 16 | @chart = Seer::Geomap.new( 17 | :data => [GeoThing.new, GeoThing.new, GeoThing.new], 18 | :label_method => 'name', 19 | :data_method => 'count', 20 | :chart_options => {}, 21 | :chart_element => 'geochart' 22 | ) 23 | end 24 | 25 | describe 'defaults' do 26 | 27 | it 'height' do 28 | @chart.height.should == Seer::Chart::DEFAULT_HEIGHT 29 | end 30 | 31 | it 'width' do 32 | @chart.width.should == Seer::Chart::DEFAULT_WIDTH 33 | end 34 | 35 | end 36 | 37 | describe 'graph options' do 38 | 39 | [:show_zoom_out, :zoom_out_label].each do |accessor| 40 | it "sets its #{accessor} value" do 41 | @chart.send("#{accessor}=", 'foo') 42 | @chart.send(accessor).should == 'foo' 43 | end 44 | end 45 | 46 | it_should_behave_like 'it has colors attribute' 47 | end 48 | 49 | it 'renders as JavaScript' do 50 | (@chart.to_js =~ /javascript/).should be_true 51 | (@chart.to_js =~ /geomap/).should be_true 52 | end 53 | 54 | it 'sets its data columns' do 55 | @chart.data_columns.should =~ /addRows\(3\)/ 56 | end 57 | 58 | it 'sets its data table' do 59 | @chart.data_table.to_s.should set_value(0, 0,'foo') 60 | @chart.data_table.to_s.should set_value(0, 1, 8) 61 | @chart.data_table.to_s.should set_value(1, 0,'foo') 62 | @chart.data_table.to_s.should set_value(1, 1, 8) 63 | @chart.data_table.to_s.should set_value(2, 0,'foo') 64 | @chart.data_table.to_s.should set_value(2, 1, 8) 65 | end 66 | 67 | end 68 | -------------------------------------------------------------------------------- /spec/helpers.rb: -------------------------------------------------------------------------------- 1 | describe "it has colors attribute", :shared => true do 2 | it 'sets its colors value' do 3 | color_list = ['#7e7587','#990000','#009900', '#3e5643', '#660000', '#003300'] 4 | @chart.colors = color_list 5 | @chart.colors.should == color_list 6 | end 7 | 8 | it 'colors should be an array' do 9 | lambda { 10 | @chart.colors = '#000000' 11 | }.should raise_error(ArgumentError) 12 | end 13 | 14 | it 'colors should be valid hex values' do 15 | lambda { 16 | @chart.colors = ['#000000', 'NOTHEX'] 17 | }.should raise_error(ArgumentError) 18 | end 19 | end 20 | 21 | describe "it sets default values", :shared => true do 22 | it 'colors' do 23 | @chart.colors.should == Seer::Chart::DEFAULT_COLORS 24 | end 25 | 26 | it 'legend' do 27 | @chart.legend.should == Seer::Chart::DEFAULT_LEGEND_LOCATION 28 | end 29 | 30 | it 'height' do 31 | @chart.height.should == Seer::Chart::DEFAULT_HEIGHT 32 | end 33 | 34 | it 'width' do 35 | @chart.width.should == Seer::Chart::DEFAULT_WIDTH 36 | end 37 | end -------------------------------------------------------------------------------- /spec/line_chart_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path(File.dirname(__FILE__) + '/spec_helper') 2 | 3 | describe "Seer::LineChart" do 4 | 5 | before :each do 6 | @chart = Seer::LineChart.new( 7 | :data => [0,1,2,3], 8 | :series_label => 'to_s', 9 | :data_series => [[1,2,3],[3,4,5]], 10 | :data_label => 'to_s', 11 | :data_method => 'size', 12 | :chart_options => {}, 13 | :chart_element => 'chart' 14 | ) 15 | end 16 | 17 | describe 'defaults' do 18 | it_should_behave_like 'it sets default values' 19 | end 20 | 21 | describe 'graph options' do 22 | 23 | [:axis_color, :axis_background_color, :axis_font_size, :background_color, :border_color, :enable_tooltip, :focus_border_color, :height, :legend, :legend_background_color, :legend_font_size, :legend_text_color, :line_size, :log_scale, :max, :min, :point_size, :reverse_axis, :show_categories, :smooth_line, :title, :title_x, :title_y, :title_color, :title_font_size, :tooltip_font_size, :tooltip_height, :number, :tooltip_width, :width].each do |accessor| 24 | it "sets its #{accessor} value" do 25 | @chart.send("#{accessor}=", 'foo') 26 | @chart.send(accessor).should == 'foo' 27 | end 28 | end 29 | 30 | it_should_behave_like 'it has colors attribute' 31 | end 32 | 33 | it 'renders as JavaScript' do 34 | (@chart.to_js =~ /javascript/).should be_true 35 | (@chart.to_js =~ /linechart/).should be_true 36 | end 37 | 38 | it 'sets its data columns' do 39 | @chart.data_columns.should =~ /addRows\(5\)/ 40 | @chart.data_columns.should add_column('string', 'Date') 41 | @chart.data_columns.should add_column('number', '0') 42 | @chart.data_columns.should add_column('number', '1') 43 | @chart.data_columns.should add_column('number', '2') 44 | @chart.data_columns.should add_column('number', '3') 45 | end 46 | 47 | it 'sets its data table' do 48 | @chart.data_table.to_s.should set_cell(0, 0,'1') 49 | @chart.data_table.to_s.should set_cell(1, 0,'2') 50 | @chart.data_table.to_s.should set_cell(2, 0,'3') 51 | @chart.data_table.to_s.should set_cell(3, 0,'4') 52 | @chart.data_table.to_s.should set_cell(4, 0,'5') 53 | @chart.data_table.to_s.should set_cell(0,1,8) 54 | @chart.data_table.to_s.should set_cell(2,1,8) 55 | @chart.data_table.to_s.should set_cell(0,2,8) 56 | @chart.data_table.to_s.should set_cell(1,2,8) 57 | @chart.data_table.to_s.should set_cell(2,2,8) 58 | end 59 | 60 | describe 'when data_series is an array of arrays of arrays/hashes' do 61 | before(:each) do 62 | data_series = Array.new(3) {|i| [[i, i+1], [i+1, i+2]]} 63 | @chart = Seer::LineChart.new( 64 | :data => [0,1,2,3], 65 | :series_label => 'to_s', 66 | :data_series => data_series, 67 | :data_label => 'first', 68 | :data_method => 'size', 69 | :chart_options => {}, 70 | :chart_element => 'chart' 71 | ) 72 | end 73 | 74 | it 'calculates number of rows' do 75 | @chart.data_columns.should =~ /addRows\(4\)/ 76 | end 77 | 78 | it 'sets its data table' do 79 | @chart.data_table.to_s.should set_cell(0, 0,'0') 80 | @chart.data_table.to_s.should set_cell(1, 0,'1') 81 | @chart.data_table.to_s.should set_cell(2, 0,'2') 82 | @chart.data_table.to_s.should set_cell(3, 0,'3') 83 | end 84 | end 85 | 86 | end 87 | -------------------------------------------------------------------------------- /spec/pie_chart_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path(File.dirname(__FILE__) + '/spec_helper') 2 | 3 | describe "Seer::PieChart" do 4 | 5 | before :each do 6 | @chart = Seer::PieChart.new( 7 | :data => [0,1,2,3], 8 | :label_method => 'to_s', 9 | :data_method => 'size', 10 | :chart_options => {}, 11 | :chart_element => 'chart' 12 | ) 13 | end 14 | 15 | describe 'defaults' do 16 | it_should_behave_like 'it sets default values' 17 | end 18 | 19 | describe 'graph options' do 20 | 21 | [:background_color, :border_color, :enable_tooltip, :focus_border_color, :height, :is_3_d, :legend, :legend_background_color, :legend_font_size, :legend_text_color, :pie_join_angle, :pie_minimal_angle, :title, :title_x, :title_y, :title_color, :title_font_size, :tooltip_font_size, :tooltip_height, :tooltip_width, :width].each do |accessor| 22 | it "sets its #{accessor} value" do 23 | @chart.send("#{accessor}=", 'foo') 24 | @chart.send(accessor).should == 'foo' 25 | end 26 | end 27 | 28 | it_should_behave_like 'it has colors attribute' 29 | end 30 | 31 | it 'renders as JavaScript' do 32 | (@chart.to_js =~ /javascript/).should be_true 33 | (@chart.to_js =~ /piechart/).should be_true 34 | end 35 | 36 | it 'sets its data columns' do 37 | @chart.data_columns.should =~ /addRows\(4\)/ 38 | end 39 | 40 | it 'sets its data table' do 41 | @chart.data_table.to_s.should set_value(0, 0,'0') 42 | @chart.data_table.to_s.should set_value(0, 1, 8) 43 | @chart.data_table.to_s.should set_value(1, 0,'1') 44 | @chart.data_table.to_s.should set_value(1, 1, 8) 45 | @chart.data_table.to_s.should set_value(2, 0,'2') 46 | @chart.data_table.to_s.should set_value(2, 1, 8) 47 | @chart.data_table.to_s.should set_value(3, 0,'3') 48 | @chart.data_table.to_s.should set_value(3, 1, 8) 49 | end 50 | 51 | end 52 | -------------------------------------------------------------------------------- /spec/seer_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path(File.dirname(__FILE__) + '/spec_helper') 2 | 3 | describe "Seer" do 4 | 5 | require 'rubygems' 6 | 7 | it 'validates hexadecimal numbers' do 8 | invalid = [nil, '', 'food', 'bdadce', 123456] 9 | valid = ['#000000','#ffffff'] 10 | invalid.each{ |e| Seer.valid_hex_number?(e).should be_false } 11 | valid.each { |e| Seer.valid_hex_number?(e).should be_true } 12 | end 13 | 14 | describe 'visualize' do 15 | 16 | it 'raises an error for invalid visualizaters' do 17 | invalid = [:random, 'something'] 18 | invalid.each do |e| 19 | lambda do 20 | Seer.visualize([1,2,3], :as => e) 21 | end.should raise_error(ArgumentError) 22 | end 23 | end 24 | 25 | it 'raises an error for missing data' do 26 | _data = [] 27 | lambda do 28 | Seer.visualize(_data, :as => :bar_chart) 29 | end.should raise_error(ArgumentError) 30 | end 31 | 32 | it 'accepts valid visualizers' do 33 | Seer::VISUALIZERS.each do |v| 34 | lambda do 35 | Seer::visualize( 36 | [0,1,2,3], 37 | :as => v, 38 | :in_element => 'chart', 39 | :series => {:label => 'to_s', :data => 'size'}, 40 | :chart_options => {} 41 | ) 42 | end.should_not raise_error(ArgumentError) 43 | end 44 | end 45 | 46 | end 47 | 48 | describe 'private chart methods' do 49 | 50 | it 'renders an area chart' do 51 | (Seer.send(:area_chart, 52 | [0,1,2,3], 53 | :as => :area_chart, 54 | :in_element => 'chart', 55 | :series => { 56 | :series_label => 'to_s', 57 | :data_label => 'to_s', 58 | :data_method => 'size', 59 | :data_series => [[1,2,3],[3,4,5]] 60 | }, 61 | :chart_options => {} 62 | ) =~ /areachart/).should be_true 63 | end 64 | 65 | it 'renders a bar chart' do 66 | (Seer.send(:bar_chart, 67 | [0,1,2,3], 68 | :as => :bar_chart, 69 | :in_element => 'chart', 70 | :series => { 71 | :series_label => 'to_s', 72 | :data_method => 'size' 73 | }, 74 | :chart_options => {} 75 | ) =~ /barchart/).should be_true 76 | end 77 | 78 | it 'renders a column chart' do 79 | (Seer.send(:column_chart, 80 | [0,1,2,3], 81 | :as => :column_chart, 82 | :in_element => 'chart', 83 | :series => { 84 | :series_label => 'to_s', 85 | :data_method => 'size' 86 | }, 87 | :chart_options => {} 88 | ) =~ /columnchart/).should be_true 89 | end 90 | 91 | it 'renders a gauge' do 92 | (Seer.send(:gauge, 93 | [0,1,2,3], 94 | :as => :gauge, 95 | :in_element => 'chart', 96 | :series => { 97 | :series_label => 'to_s', 98 | :data_method => 'size' 99 | }, 100 | :chart_options => {} 101 | ) =~ /gauge/).should be_true 102 | end 103 | 104 | it 'renders a line chart' do 105 | (Seer.send(:line_chart, 106 | [0,1,2,3], 107 | :as => :line_chart, 108 | :in_element => 'chart', 109 | :series => { 110 | :series_label => 'to_s', 111 | :data_label => 'to_s', 112 | :data_method => 'size', 113 | :data_series => [[1,2,3],[3,4,5]] 114 | }, 115 | :chart_options => {} 116 | ) =~ /linechart/).inspect #should be_true 117 | end 118 | 119 | it 'renders a pie chart' do 120 | (Seer.send(:pie_chart, 121 | [0,1,2,3], 122 | :as => :pie_chart, 123 | :in_element => 'chart', 124 | :series => { 125 | :series_label => 'to_s', 126 | :data_method => 'size' 127 | }, 128 | :chart_options => {} 129 | ) =~ /piechart/).should be_true 130 | end 131 | 132 | end 133 | 134 | end 135 | -------------------------------------------------------------------------------- /spec/spec.opts: -------------------------------------------------------------------------------- 1 | --color 2 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | $LOAD_PATH.unshift(File.dirname(__FILE__)) 2 | $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) 3 | require 'rubygems' 4 | require 'action_pack' 5 | require 'active_support' 6 | require 'spec' 7 | require 'spec/autorun' 8 | require 'seer' 9 | require File.dirname(__FILE__) + "/custom_matchers" 10 | require File.dirname(__FILE__) + '/helpers' 11 | Spec::Runner.configure do |config| 12 | config.include(CustomMatcher) 13 | end 14 | --------------------------------------------------------------------------------