Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 6 commits
  • 13 files changed
  • 0 commit comments
  • 1 contributor
View
8 README.rdoc
@@ -6,7 +6,8 @@ Seer is a lightweight, semantically rich wrapper for the Google Visualization AP
Add the following to the head of the page that will display a chart, or add it to your layout file:
- <%= Seer::init_visualization -%>
+ %script
+ = Seer::init_visualization
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.
@@ -20,9 +21,9 @@ In your controller:
In your view:
- <div id="chart"></div>
+ %div#chart
- <%= Seer::visualize(
+ = Seer::visualize(
@widgets,
:as => :bar_chart,
:in_element => 'chart',
@@ -38,7 +39,6 @@ In your view:
:title_y => 'Widgets'
}
)
- -%>
== More information
View
1  Rakefile
@@ -15,6 +15,7 @@ begin
"CONTRIBUTORS",
"init.rb",
"lib/seer.rb",
+ "lib/seer/annotated_timeline.rb",
"lib/seer/area_chart.rb",
"lib/seer/bar_chart.rb",
"lib/seer/chart.rb",
View
3  VERSION
@@ -1 +1,2 @@
-0.9.1
+0.9.2
+
View
6 lib/seer.rb
@@ -22,10 +22,8 @@ def self.log(message) #:nodoc:
def self.init_visualization
%{
- <script type="text/javascript">
- var jsapi = (("https:" == document.location.protocol) ? "https://" : "http://");
- document.write(unescape("%3Cscript src='" + jsapi + "www.google.com/jsapi' type='text/javascript'%3E%3C/script%3E"));
- </script>
+ var jsapi = (("https:" == document.location.protocol) ? "https://" : "http://");
+ document.write(unescape("%3Cscript src='" + jsapi + "www.google.com/jsapi' type='text/javascript'%3E%3C/script%3E"));
}
end
View
141 lib/seer/annotated_timeline.rb
@@ -0,0 +1,141 @@
+module Seer
+
+ # =USAGE
+ #
+ # In your controller:
+ #
+ # @data = Widgets.all # Must be an array, and must respond
+ # # to the data method specified below (in this example, 'quantity')
+ #
+ # @series = @data.map{|w| w.widget_stats} # An array of arrays
+ #
+ # In your view:
+ #
+ # <div id="chart"></div>
+ #
+ # <%= Seer::visualize(
+ # @data,
+ # :as => :annotated_timeline,
+ # :in_element => 'chart',
+ # :series => {
+ # :series_label => 'name',
+ # :data_label => 'date',
+ # :data_method => 'quantity',
+ # :data_series => @series
+ # },
+ # :chart_options => {
+ # :height => 300,
+ # :width => 300,
+ # :axis_font_size => 11,
+ # :colors => ['#7e7587','#990000','#009900'],
+ # :title => "Widget Quantities",
+ # :point_size => 5
+ # }
+ # )
+ # -%>
+ #
+ # For details on the chart options, see the Google API docs at
+ # http://code.google.com/apis/visualization/documentation/gallery/annotated_timeline.html
+ #
+ class AnnotatedTimeline
+
+ include Seer::Chart
+
+ # Graph options
+ attr_accessor :allow_html, :allow_redraw, :all_values_suffix, :annotations_width, :colors, :date_format
+ attr_accessor :display_annotations, :display_annotations_filter, :display_date_bar_separator, :display_exact_values
+ attr_accessor :display_legend_dots, :display_legend_values, :display_range_selector, :display_zoom_buttons
+ attr_accessor :fill, :highlight_dot, :legend_position, :max, :min, :number_formats, :scale_columns, :scale_type
+ attr_accessor :thickness, :wmode, :zoom_end_time, :zoom_start_time
+
+ # Graph data
+ attr_accessor :series_label, :data_label, :data, :data_method, :data_series
+
+ def initialize(args={}) #:nodoc:
+
+ # Standard options
+ args.each{ |method,arg| self.send("#{method}=",arg) if self.respond_to?(method) }
+
+ # Chart options
+ args[:chart_options].each{ |method, arg| self.send("#{method}=",arg) if self.respond_to?(method) }
+
+ # Handle defaults
+ @colors ||= args[:chart_options][:colors] || DEFAULT_COLORS
+ @legend ||= args[:chart_options][:legend] || DEFAULT_LEGEND_LOCATION
+ @height ||= args[:chart_options][:height] || DEFAULT_HEIGHT
+ @width ||= args[:chart_options][:width] || DEFAULT_WIDTH
+
+ @data_table = []
+
+ end
+
+ def data_columns #:nodoc:
+ _data_columns = " data.addRows(#{data_rows.size});\r"
+ _data_columns << " data.addColumn('string', 'Date');\r"
+ data.each do |datum|
+ _data_columns << " data.addColumn('number', '#{datum.send(series_label)}');\r"
+ end
+ _data_columns
+ end
+
+ def data_table #:nodoc:
+ _rows = data_rows
+ _rows.each_with_index do |r,i|
+ @data_table << " data.setCell(#{i}, 0,'#{r}');\r"
+ end
+ data_series.each_with_index do |column,i|
+ column.each_with_index do |c,j|
+ @data_table << " data.setCell(#{j},#{i+1},#{c.send(data_method)});\r"
+ end
+ end
+ @data_table
+ end
+
+ def data_rows
+ data_series.inject([]) do |rows, element|
+ rows |= element.map { |e| e.send(data_label) }
+ end
+ end
+
+ def nonstring_options #:nodoc:
+ [ :allow_html, :allow_redraw, :display_annotations, :display_exact_values, :display_legend_dots, :display_legend_values, :display_range_selector, :display_zoom_buttons, :scale_columns, :annotations_width, :display_date_bar_separator, :display_annotations_filter, :fill, :colors, :max, :min, :thickness, :zoom_end_time, :zoom_start_time]
+ end
+
+ def string_options #:nodoc:
+ [ :all_values_suffix, :date_format, :highlight_dot, :legend_position, :number_formats, :scale_type, :wmode ]
+ end
+
+ def to_js #:nodoc:
+
+ %{
+ google.load('visualization', '1', {'packages':['annotatedtimeline']});
+ google.setOnLoadCallback(drawChart);
+ function drawChart() {
+ var data = new google.visualization.DataTable();
+#{data_columns}
+#{data_table.to_s}
+ var options = {};
+#{options}
+ var container = document.getElementById('#{self.chart_element}');
+ var chart = new google.visualization.AnnotatedTimeline(container);
+ chart.draw(data, options);
+ }
+ }
+ end
+
+ def self.render(data, args) #:nodoc:
+ graph = Seer::AnnotatedTimeline.new(
+ :data => data,
+ :series_label => args[:series][:series_label],
+ :data_series => args[:series][:data_series],
+ :data_label => args[:series][:data_label],
+ :data_method => args[:series][:data_method],
+ :chart_options => args[:chart_options],
+ :chart_element => args[:in_element] || 'chart'
+ )
+ graph.to_js
+ end
+
+ end
+
+end
View
2  lib/seer/area_chart.rb
@@ -104,7 +104,6 @@ def string_options #:nodoc:
def to_js #:nodoc:
%{
- <script type="text/javascript">
google.load('visualization', '1', {'packages':['areachart']});
google.setOnLoadCallback(drawChart);
function drawChart() {
@@ -117,7 +116,6 @@ def to_js #:nodoc:
var chart = new google.visualization.AreaChart(container);
chart.draw(data, options);
}
- </script>
}
end
View
2  lib/seer/bar_chart.rb
@@ -91,7 +91,6 @@ def string_options #:nodoc:
def to_js #:nodoc:
%{
- <script type="text/javascript">
google.load('visualization', '1', {'packages':['barchart']});
google.setOnLoadCallback(drawChart);
function drawChart() {
@@ -104,7 +103,6 @@ def to_js #:nodoc:
var chart = new google.visualization.BarChart(container);
chart.draw(data, options);
}
- </script>
}
end
View
2  lib/seer/column_chart.rb
@@ -91,7 +91,6 @@ def string_options #:nodoc:
def to_js #:nodoc:
%{
- <script type="text/javascript">
google.load('visualization', '1', {'packages':['columnchart']});
google.setOnLoadCallback(drawChart);
function drawChart() {
@@ -104,7 +103,6 @@ def to_js #:nodoc:
var chart = new google.visualization.ColumnChart(container);
chart.draw(data, options);
}
- </script>
}
end
View
2  lib/seer/gauge.rb
@@ -86,7 +86,6 @@ def string_options #:nodoc:
def to_js #:nodoc:
%{
- <script type="text/javascript">
google.load('visualization', '1', {'packages':['gauge']});
google.setOnLoadCallback(drawChart);
function drawChart() {
@@ -99,7 +98,6 @@ def to_js #:nodoc:
var chart = new google.visualization.Gauge(container);
chart.draw(data, options);
}
- </script>
}
end
View
2  lib/seer/geomap.rb
@@ -124,7 +124,6 @@ def string_options #:nodoc:
def to_js
%{
- <script type="text/javascript">
google.load('visualization', '1', {'packages':['geomap']});
google.setOnLoadCallback(drawChart);
function drawChart() {
@@ -137,7 +136,6 @@ def to_js
var geomap = new google.visualization.GeoMap(container);
geomap.draw(data, options);
}
- </script>
}
end
View
2  lib/seer/line_chart.rb
@@ -106,7 +106,6 @@ def string_options #:nodoc:
def to_js #:nodoc:
%{
- <script type="text/javascript">
google.load('visualization', '1', {'packages':['linechart']});
google.setOnLoadCallback(drawChart);
function drawChart() {
@@ -119,7 +118,6 @@ def to_js #:nodoc:
var chart = new google.visualization.LineChart(container);
chart.draw(data, options);
}
- </script>
}
end
View
2  lib/seer/pie_chart.rb
@@ -83,7 +83,6 @@ def string_options #:nodoc:
def to_js #:nodoc:
%{
- <script type="text/javascript">
google.load('visualization', '1', {'packages':['piechart']});
google.setOnLoadCallback(drawChart);
function drawChart() {
@@ -96,7 +95,6 @@ def to_js #:nodoc:
var chart = new google.visualization.PieChart(container);
chart.draw(data, options);
}
- </script>
}
end
View
101 rdoc/files/lib/seer/annotated_timeline_rb.html
@@ -0,0 +1,101 @@
+<?xml version="1.0" encoding="iso-8859-1"?>
+<!DOCTYPE html
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+ <title>File: area_chart.rb</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
+ <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
+ <script type="text/javascript">
+ // <![CDATA[
+
+ function popupCode( url ) {
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
+ }
+
+ function toggleCode( id ) {
+ if ( document.getElementById )
+ elem = document.getElementById( id );
+ else if ( document.all )
+ elem = eval( "document.all." + id );
+ else
+ return false;
+
+ elemStyle = elem.style;
+
+ if ( elemStyle.display != "block" ) {
+ elemStyle.display = "block"
+ } else {
+ elemStyle.display = "none"
+ }
+
+ return true;
+ }
+
+ // Make codeblocks hidden by default
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
+
+ // ]]>
+ </script>
+
+</head>
+<body>
+
+
+
+ <div id="fileHeader">
+ <h1>area_chart.rb</h1>
+ <table class="header-table">
+ <tr class="top-aligned-row">
+ <td><strong>Path:</strong></td>
+ <td>lib/seer/area_chart.rb
+ </td>
+ </tr>
+ <tr class="top-aligned-row">
+ <td><strong>Last Update:</strong></td>
+ <td>Tue Feb 16 17:31:17 -0600 2010</td>
+ </tr>
+ </table>
+ </div>
+ <!-- banner header -->
+
+ <div id="bodyContent">
+
+
+
+ <div id="contextContent">
+
+
+
+ </div>
+
+
+ </div>
+
+
+ <!-- if includes -->
+
+ <div id="section">
+
+
+
+
+
+
+
+
+ <!-- if method_list -->
+
+
+ </div>
+
+
+<div id="validator-badges">
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
+</div>
+
+</body>
+</html>

No commit comments for this range

Something went wrong with that request. Please try again.