Permalink
Browse files

graph work

  • Loading branch information...
1 parent 2d14282 commit 8184f798ec645afe233113555a613684811aadc4 @adamgamble adamgamble committed Feb 20, 2012
Showing with 29 additions and 1,150 deletions.
  1. +0 −2 .rspec
  2. +0 −12 app/controllers/application_controller.rb
  3. +0 −1 app/views/admin/weekly_time_report/show.html.haml
  4. +28 −2 app/views/shared/_calendar.html.haml
  5. +1 −0 app/views/shared/_javascripts.html.haml
  6. +0 −4 vendor/gems/gchart/.gitignore
  7. +0 −43 vendor/gems/gchart/CHANGELOG.txt
  8. +0 −31 vendor/gems/gchart/Manifest.txt
  9. +0 −81 vendor/gems/gchart/README.txt
  10. +0 −31 vendor/gems/gchart/Rakefile
  11. +0 −62 vendor/gems/gchart/lib/gchart.rb
  12. +0 −60 vendor/gems/gchart/lib/gchart/bar.rb
  13. +0 −144 vendor/gems/gchart/lib/gchart/base.rb
  14. +0 −7 vendor/gems/gchart/lib/gchart/line.rb
  15. +0 −71 vendor/gems/gchart/lib/gchart/map.rb
  16. +0 −29 vendor/gems/gchart/lib/gchart/meter.rb
  17. +0 −21 vendor/gems/gchart/lib/gchart/pie.rb
  18. +0 −7 vendor/gems/gchart/lib/gchart/pie_3d.rb
  19. +0 −7 vendor/gems/gchart/lib/gchart/scatter.rb
  20. +0 −15 vendor/gems/gchart/lib/gchart/sparkline.rb
  21. +0 −7 vendor/gems/gchart/lib/gchart/venn.rb
  22. +0 −7 vendor/gems/gchart/lib/gchart/xy_line.rb
  23. +0 −3 vendor/gems/gchart/lib/version.rb
  24. +0 −80 vendor/gems/gchart/spec/gchart/bar_spec.rb
  25. +0 −156 vendor/gems/gchart/spec/gchart/base_spec.rb
  26. +0 −7 vendor/gems/gchart/spec/gchart/line_spec.rb
  27. +0 −56 vendor/gems/gchart/spec/gchart/map_spec.rb
  28. +0 −48 vendor/gems/gchart/spec/gchart/meter_spec.rb
  29. +0 −7 vendor/gems/gchart/spec/gchart/pie_3d_spec.rb
  30. +0 −29 vendor/gems/gchart/spec/gchart/pie_spec.rb
  31. +0 −7 vendor/gems/gchart/spec/gchart/scatter_spec.rb
  32. +0 −12 vendor/gems/gchart/spec/gchart/sparkline_spec.rb
  33. +0 −7 vendor/gems/gchart/spec/gchart/venn_spec.rb
  34. +0 −7 vendor/gems/gchart/spec/gchart/xy_line_spec.rb
  35. +0 −69 vendor/gems/gchart/spec/gchart_spec.rb
  36. +0 −11 vendor/gems/gchart/spec/helper.rb
  37. +0 −7 vendor/gems/gchart/spec/spec.opts
View
2 .rspec
@@ -1,3 +1 @@
--color
---format nested
---drb
@@ -1,5 +1,3 @@
-require File.expand_path('../../../vendor/gems/gchart/lib/gchart', __FILE__)
-
class ApplicationController < ActionController::Base
include RefurlHelper
before_filter :initialize_site_settings
@@ -28,16 +26,6 @@ def external_hours_chart_url(users, options = {})
hours = WorkUnit.for_users(users).scheduled_between(start_date,end_date).all
internal_hours, external_hours, max_hours = determine_daily_hours(hours, start_date, end_date)
-
- GChart.bar(:title => title,
- :orientation => :vertical,
- :axis => [["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"], [0, max_hours]],
- :colors => ['ff0000', '00ff00'],
- :size => width,
- :data => [internal_hours,external_hours],
- :legend => ["Int","Ext"],
- :extras => {"chf" => "bg,s,00000000"} # Makes fill transparent
- ).to_url
end
private
@@ -4,7 +4,6 @@
- if @users.any?
= render :partial => 'week_pagination', :locals => { :start_date => @start_date }
- = image_tag external_hours_chart_url(@users, :width => "500x200", :title => "Cumulative Hours Worked")
- @users.each do |user|
%h3= user
= render :partial => 'shared/calendar', :locals => { :start_date => @start_date, :user => user, :work_units => user.work_units_between(@start_date, @start_date + 6.days)}
@@ -34,12 +34,38 @@
%li#target_hours= "#{t(:target_hours_offset)}: #{user.target_hours_offset(last_effective_date(start_date))}"
- if @site_settings.client && work_units.present?
%li#external_percentage= "#{t(:external_percentage)}: #{external_work_percentage(user, start_date.beginning_of_week, start_date.end_of_week)}%"
- %td.span2
- = image_tag external_hours_chart_url(user, :date => start_date, :width => "260x100", :title => "Hours Worked")
+ %td.span2{:id => "#{user.id}_chart"}
- if request.xhr?
:javascript
$('a[rel=twipsy]').twipsy({ placement: 'below'} );
- else
- content_for :javascripts do
:javascript
$('a[rel=twipsy]').twipsy({ placement: 'below'} );
+
+ google.load('visualization', '1.0', {'packages':['corechart']});
+ google.setOnLoadCallback(drawChart);
+
+ function drawChart() {
+
+ // Create the data table.
+ var data = new google.visualization.DataTable();
+ data.addColumn('string', 'Topping');
+ data.addColumn('number', 'Slices');
+ data.addRows([
+ ['Mushrooms', 3],
+ ['Onions', 1],
+ ['Olives', 1],
+ ['Zucchini', 1],
+ ['Pepperoni', 2]
+ ]);
+
+ // Set chart options
+ var options = {'title':'How Much Pizza I Ate Last Night',
+ 'width':100,
+ 'height':100};
+
+ // Instantiate and draw our chart, passing in some options.
+ var chart = new google.visualization.BarChart(document.getElementById("#{user.id}_chart"));
+ chart.draw(data, options);
+ }
@@ -2,4 +2,5 @@
:javascript
calendar_expansion_default = true;
= javascript_include_tag 'application'
+= javascript_include_tag "https://www.google.com/jsapi"
= yield :javascripts
@@ -1,4 +0,0 @@
-.DS_Store
-doc
-pkg
-
@@ -1,43 +0,0 @@
-== 0.5.0 (2008-04-17)
-
- * Support for Map charts
- * Support for Sparkline charts
- * Initial support for Google-o-meter
-
-== UNRELEASED
-
- * Freeze GChart::VERSION.
-
-== 0.4.2 (2008-01-09)
-
- * Encoding a flatlined chart doesn't asplode [Jack Danger Canty]
-
-== 0.4.1 (2008-01-02)
-
- * (bug #16756 fixed) Example in the README is incorrect
-
-== 0.4.0 (2007-12-28)
-
- * New committer, Abhay Kumar
- * Implement all three encodings. Fix extended encoding calculation.
- * Support bar thickness/spacing for bar charts
- * (bug #16565 fixed) GChart now tells you when your chart is too big.
- * Pushed some bar chart params logic down where it belongs
- * Enforce pie chart spec: pie charts only take one set of data
-
-== 0.3.0 (2007-12-24)
-
- * Breaking change: labels --> legend
- * Switched to RSpec, added skeletal specs for all types
- * Extensive refactoring, pulled chart types into GChart::Base subclasses
- * (bug) Errors in the static helpers should report a reasonable file and line
-
-== 0.2.0 (2007-12-12)
-
- * Support for basic :labels
- * Support for pie3d
- * Minor doc cleanups
-
-== 0.1.0 (2007-12-10)
-
- * Birthday!
@@ -1,31 +0,0 @@
-CHANGELOG.txt
-Manifest.txt
-README.txt
-Rakefile
-lib/gchart.rb
-lib/gchart/bar.rb
-lib/gchart/base.rb
-lib/gchart/line.rb
-lib/gchart/map.rb
-lib/gchart/meter.rb
-lib/gchart/pie.rb
-lib/gchart/pie_3d.rb
-lib/gchart/scatter.rb
-lib/gchart/sparkline.rb
-lib/gchart/venn.rb
-lib/gchart/xy_line.rb
-lib/version.rb
-spec/gchart/bar_spec.rb
-spec/gchart/base_spec.rb
-spec/gchart/line_spec.rb
-spec/gchart/map_spec.rb
-spec/gchart/meter_spec.rb
-spec/gchart/pie_3d_spec.rb
-spec/gchart/pie_spec.rb
-spec/gchart/scatter_spec.rb
-spec/gchart/sparkline_spec.rb
-spec/gchart/venn_spec.rb
-spec/gchart/xy_line_spec.rb
-spec/gchart_spec.rb
-spec/helper.rb
-spec/spec.opts
@@ -1,81 +0,0 @@
-= GChart
-
-== DESCRIPTION
-
-GChart exposes the Google Chart API (http://code.google.com/apis/chart) via
-a friendly Ruby interface. It can generate the URL for a given chart
-(for webpage use), or download the generated PNG (for offline use).
-
-== PROBLEMS/TODO
-
-* Add support fills (area or background), grid lines, shape markers, range markers
-* Support shorthand colors and color names
-* Make venn data specification friendlier
-
-There are lots of missing features. Until they're implemented, you can directly specify
-query parameters using the :extras key, e.g.,
-
- # provides a legend for each data set
- g = GChart.line(:data => [[1, 2], [3, 4]], :extras => { "chdl" => "First|Second"})
-
-== SYNOPSIS
-
- # line chart
- g = GChart.line(:data => [0, 10, 100])
-
- # bar chart
- g = GChart.bar(:data => [100, 1000, 10000])
-
- # pie chart (pie3d for a fancier look)
- g = GChart.pie(:data => [33, 33, 34])
-
- # venn diagram (asize, bsize, csize, ab%, bc%, ca%, abc%)
- g = GChart.venn(:data => [100, 80, 60, 30, 30, 30, 10])
-
- # scatter plot (x coords, y coords [, sizes])
- g = GChart.scatter(:data => [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [1, 2, 3, 4, 5]])
-
- # map chart
- g = GChart.map(:area => 'usa', :data => {'NY'=>1,'VA'=>3,'CA'=>2})
-
- # meter
- g = GChart.meter(:data => 70, :label => "70%")
-
- # chart title
- g = GChart.line(:title => "Awesomeness over Time", :data => [0, 10, 100])
-
- # data set legend
- g = GChart.line(:data => [[1, 2], [3, 4]], :legend => ["Monkeys", "Ferrets"])
-
- # data set colors
- g = GChart.line(:data => [[0, 10, 100], [100, 10, 0]], :colors => ["ff0000", "0000ff"])
-
- g.to_url # generate the chart's URL, or
- g.fetch # get the bytes, or
- g.write("foo.png") # write to a file (defaults to "chart.png")
- g.write(stream) # write to anything that quacks like IO
-
-== LICENSE
-
-(The MIT License)
-
-Copyright 2007-2008 John Barnette (jbarnette@rubyforge.org)
-
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of this software and associated documentation files (the
-'Software'), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
-CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,31 +0,0 @@
-require "rubygems"
-require "hoe"
-require "spec/rake/spectask"
-
-require "./lib/version.rb"
-
-hoe = Hoe.new("gchart", GChart::VERSION) do |p|
- p.rubyforge_name = "gchart"
- p.author = "John Barnette"
- p.email = "jbarnette@rubyforge.org"
- p.summary = "GChart uses the Google Chart API to create pretty pictures."
- p.description = p.paragraphs_of("README.txt", 2..5).join("\n\n")
- p.url = "http://gchart.rubyforge.org"
- p.changes = p.paragraphs_of("CHANGELOG.txt", 0..1).join("\n\n")
-end
-
-desc "Run all specs"
-Spec::Rake::SpecTask.new do |t|
- t.spec_files = FileList["spec/**/*_spec.rb"]
- t.spec_opts = ["--options", "spec/spec.opts"]
-end
-
-desc "Run all specs and get coverage statistics"
-Spec::Rake::SpecTask.new('spec:rcov') do |t|
- t.spec_files = FileList["spec/**/*_spec.rb"]
- t.rcov = true
- t.spec_opts = ["--options", "spec/spec.opts"]
-end
-
-Rake::Task[:default].prerequisites.clear
-task :default => :spec
@@ -1,62 +0,0 @@
-require File.expand_path(File.dirname(__FILE__) + "/version")
-
-%w(base bar line map meter pie pie_3d scatter sparkline venn xy_line).each do |type|
- require File.expand_path(File.dirname(__FILE__) + "/gchart/#{type}")
-end
-
-module GChart
- URL = "http://chart.apis.google.com/chart"
- SIMPLE_CHARS = ('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a
- EXTENDED_CHARS = ('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a + %w[- .]
- EXTENDED_PAIRS = EXTENDED_CHARS.collect { |first| EXTENDED_CHARS.collect { |second| first + second } }.flatten
-
- class << self
- # Convenience constructor for GChart::Line.
- def line(*args, &block); Line.new(*args, &block) end
-
- # Convenience constructor for GChart::XYLine.
- def xyline(*args, &block); XYLine.new(*args, &block) end
-
- # Convenience constructor for GChart::Bar.
- def bar(*args, &block); Bar.new(*args, &block) end
-
- # Convenience constructor for GChart::Map.
- def map(*args, &block); Map.new(*args, &block) end
-
- # Convenience constructor for GChart::Meter.
- def meter(*args, &block); Meter.new(*args, &block) end
-
- # Convenience constructor for GChart::Pie.
- def pie(*args, &block); Pie.new(*args, &block) end
-
- # Convenience constructor for GChart::Pie3D.
- def pie3d(*args, &block); Pie3D.new(*args, &block) end
-
- # Convenience constructor for GChart::Line.
- def sparkline(*args, &block); Sparkline.new(*args, &block) end
-
- # Convenience constructor for GChart::Venn.
- def venn(*args, &block); Venn.new(*args, &block) end
-
- # Convenience constructor for GChart::Scatter.
- def scatter(*args, &block); Scatter.new(*args, &block) end
-
- # Encode +n+ as a string. +n+ is normalized based on +max+.
- # +encoding+ can currently only be :extended.
- def encode(encoding, n, max)
- case encoding
- when :simple
- return "_" if n.nil?
- SIMPLE_CHARS[((n/max.to_f) * (SIMPLE_CHARS.size - 1)).round]
- when :text
- return "-1" if n.nil?
- ((((n/max.to_f) * 1000.0).round)/10.0).to_s
- when :extended
- return "__" if n.nil?
- EXTENDED_PAIRS[max.zero? ? 0 : ((n/max.to_f) * (EXTENDED_PAIRS.size - 1)).round]
- else
- raise ArgumentError, "unsupported encoding: #{encoding.inspect}"
- end
- end
- end
-end
Oops, something went wrong.

0 comments on commit 8184f79

Please sign in to comment.