Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

initial commit

  • Loading branch information...
commit 9103f06b876878bc72dcef32cfadf8269c148bbb 0 parents
@ryanb ryanb authored
Showing with 8,622 additions and 0 deletions.
  1. +15 −0 README.md
  2. +15 −0 store-after/.gitignore
  3. +40 −0 store-after/Gemfile
  4. +113 −0 store-after/Gemfile.lock
  5. +11 −0 store-after/README.md
  6. +7 −0 store-after/Rakefile
  7. +17 −0 store-after/app/assets/javascripts/application.js
  8. +11 −0 store-after/app/assets/javascripts/orders.js.coffee
  9. +13 −0 store-after/app/assets/stylesheets/application.css
  10. +78 −0 store-after/app/assets/stylesheets/layout.css.scss
  11. +14 −0 store-after/app/assets/stylesheets/orders.css.scss
  12. +3 −0  store-after/app/controllers/application_controller.rb
  13. +5 −0 store-after/app/controllers/orders_controller.rb
  14. +2 −0  store-after/app/helpers/application_helper.rb
  15. +2 −0  store-after/app/helpers/orders_helper.rb
  16. 0  store-after/app/mailers/.gitkeep
  17. 0  store-after/app/models/.gitkeep
  18. +26 −0 store-after/app/models/order.rb
  19. +17 −0 store-after/app/views/layouts/application.html.erb
  20. +22 −0 store-after/app/views/orders/index.html.erb
  21. +4 −0 store-after/config.ru
  22. +62 −0 store-after/config/application.rb
  23. +6 −0 store-after/config/boot.rb
  24. +25 −0 store-after/config/database.yml
  25. +5 −0 store-after/config/environment.rb
  26. +37 −0 store-after/config/environments/development.rb
  27. +67 −0 store-after/config/environments/production.rb
  28. +37 −0 store-after/config/environments/test.rb
  29. +7 −0 store-after/config/initializers/backtrace_silencers.rb
  30. +15 −0 store-after/config/initializers/inflections.rb
  31. +5 −0 store-after/config/initializers/mime_types.rb
  32. +7 −0 store-after/config/initializers/secret_token.rb
  33. +8 −0 store-after/config/initializers/session_store.rb
  34. +14 −0 store-after/config/initializers/wrap_parameters.rb
  35. +5 −0 store-after/config/locales/en.yml
  36. +4 −0 store-after/config/routes.rb
  37. +11 −0 store-after/db/migrate/20120914202335_create_orders.rb
  38. +24 −0 store-after/db/schema.rb
  39. +9 −0 store-after/db/seeds.rb
  40. +2 −0  store-after/doc/README_FOR_APP
  41. 0  store-after/lib/assets/.gitkeep
  42. 0  store-after/lib/tasks/.gitkeep
  43. 0  store-after/log/.gitkeep
  44. +26 −0 store-after/public/404.html
  45. +26 −0 store-after/public/422.html
  46. +25 −0 store-after/public/500.html
  47. 0  store-after/public/favicon.ico
  48. +5 −0 store-after/public/robots.txt
  49. +6 −0 store-after/script/rails
  50. 0  store-after/test/fixtures/.gitkeep
  51. +11 −0 store-after/test/fixtures/orders.yml
  52. 0  store-after/test/functional/.gitkeep
  53. +49 −0 store-after/test/functional/orders_controller_test.rb
  54. 0  store-after/test/integration/.gitkeep
  55. +12 −0 store-after/test/performance/browsing_test.rb
  56. +13 −0 store-after/test/test_helper.rb
  57. 0  store-after/test/unit/.gitkeep
  58. +4 −0 store-after/test/unit/helpers/orders_helper_test.rb
  59. +7 −0 store-after/test/unit/order_test.rb
  60. 0  store-after/vendor/assets/javascripts/.gitkeep
  61. +959 −0 store-after/vendor/assets/javascripts/morris.js
  62. +5,815 −0 store-after/vendor/assets/javascripts/raphael.js
  63. 0  store-after/vendor/assets/stylesheets/.gitkeep
  64. 0  store-after/vendor/plugins/.gitkeep
  65. +15 −0 store-before/.gitignore
  66. +40 −0 store-before/Gemfile
  67. +113 −0 store-before/Gemfile.lock
  68. +11 −0 store-before/README.md
  69. +7 −0 store-before/Rakefile
  70. +15 −0 store-before/app/assets/javascripts/application.js
  71. +3 −0  store-before/app/assets/javascripts/orders.js.coffee
  72. +13 −0 store-before/app/assets/stylesheets/application.css
  73. +78 −0 store-before/app/assets/stylesheets/layout.css.scss
  74. +14 −0 store-before/app/assets/stylesheets/orders.css.scss
  75. +3 −0  store-before/app/controllers/application_controller.rb
  76. +5 −0 store-before/app/controllers/orders_controller.rb
  77. +2 −0  store-before/app/helpers/application_helper.rb
  78. +2 −0  store-before/app/helpers/orders_helper.rb
  79. 0  store-before/app/mailers/.gitkeep
  80. 0  store-before/app/models/.gitkeep
  81. +3 −0  store-before/app/models/order.rb
  82. +17 −0 store-before/app/views/layouts/application.html.erb
  83. +20 −0 store-before/app/views/orders/index.html.erb
  84. +4 −0 store-before/config.ru
  85. +62 −0 store-before/config/application.rb
  86. +6 −0 store-before/config/boot.rb
  87. +25 −0 store-before/config/database.yml
  88. +5 −0 store-before/config/environment.rb
  89. +37 −0 store-before/config/environments/development.rb
  90. +67 −0 store-before/config/environments/production.rb
  91. +37 −0 store-before/config/environments/test.rb
  92. +7 −0 store-before/config/initializers/backtrace_silencers.rb
  93. +15 −0 store-before/config/initializers/inflections.rb
  94. +5 −0 store-before/config/initializers/mime_types.rb
  95. +7 −0 store-before/config/initializers/secret_token.rb
  96. +8 −0 store-before/config/initializers/session_store.rb
  97. +14 −0 store-before/config/initializers/wrap_parameters.rb
  98. +5 −0 store-before/config/locales/en.yml
  99. +4 −0 store-before/config/routes.rb
  100. +11 −0 store-before/db/migrate/20120914202335_create_orders.rb
  101. +24 −0 store-before/db/schema.rb
  102. +9 −0 store-before/db/seeds.rb
  103. +2 −0  store-before/doc/README_FOR_APP
  104. 0  store-before/lib/assets/.gitkeep
  105. 0  store-before/lib/tasks/.gitkeep
  106. 0  store-before/log/.gitkeep
  107. +26 −0 store-before/public/404.html
  108. +26 −0 store-before/public/422.html
  109. +25 −0 store-before/public/500.html
  110. 0  store-before/public/favicon.ico
  111. +5 −0 store-before/public/robots.txt
  112. +6 −0 store-before/script/rails
  113. 0  store-before/test/fixtures/.gitkeep
  114. +11 −0 store-before/test/fixtures/orders.yml
  115. 0  store-before/test/functional/.gitkeep
  116. +49 −0 store-before/test/functional/orders_controller_test.rb
  117. 0  store-before/test/integration/.gitkeep
  118. +12 −0 store-before/test/performance/browsing_test.rb
  119. +13 −0 store-before/test/test_helper.rb
  120. 0  store-before/test/unit/.gitkeep
  121. +4 −0 store-before/test/unit/helpers/orders_helper_test.rb
  122. +7 −0 store-before/test/unit/order_test.rb
  123. 0  store-before/vendor/assets/javascripts/.gitkeep
  124. 0  store-before/vendor/assets/stylesheets/.gitkeep
  125. 0  store-before/vendor/plugins/.gitkeep
15 README.md
@@ -0,0 +1,15 @@
+# RailsCasts Episode #223: Charts & Graphs (revised)
+
+http://railscasts.com/episodes/223-charts-graphs-revised
+
+Requires Ruby 1.9.2 or higher.
+
+
+### Commands used in console
+
+```ruby
+Order.group("date(purchased_at)").select("purchased_at, sum(price) as total_price")
+o = _
+o.purchased_at
+o.total_price
+```
15 store-after/.gitignore
@@ -0,0 +1,15 @@
+# See http://help.github.com/ignore-files/ for more about ignoring files.
+#
+# If you find yourself ignoring temporary files generated by your text editor
+# or operating system, you probably want to add a global ignore instead:
+# git config --global core.excludesfile ~/.gitignore_global
+
+# Ignore bundler config
+/.bundle
+
+# Ignore the default SQLite database.
+/db/*.sqlite3
+
+# Ignore all logfiles and tempfiles.
+/log/*.log
+/tmp
40 store-after/Gemfile
@@ -0,0 +1,40 @@
+source 'https://rubygems.org'
+
+gem 'rails', '3.2.8'
+
+# Bundle edge Rails instead:
+# gem 'rails', :git => 'git://github.com/rails/rails.git'
+
+gem 'sqlite3'
+
+
+# Gems used only for assets and not required
+# in production environments by default.
+group :assets do
+ gem 'sass-rails', '~> 3.2.3'
+ gem 'coffee-rails', '~> 3.2.1'
+
+ # See https://github.com/sstephenson/execjs#readme for more supported runtimes
+ # gem 'therubyracer', :platforms => :ruby
+
+ gem 'uglifier', '>= 1.0.3'
+end
+
+gem 'jquery-rails'
+
+# To use ActiveModel has_secure_password
+# gem 'bcrypt-ruby', '~> 3.0.0'
+
+# To use Jbuilder templates for JSON
+# gem 'jbuilder'
+
+# Use unicorn as the app server
+# gem 'unicorn'
+
+# Deploy with Capistrano
+# gem 'capistrano'
+
+# To use debugger
+# gem 'debugger'
+
+gem 'will_paginate'
113 store-after/Gemfile.lock
@@ -0,0 +1,113 @@
+GEM
+ remote: https://rubygems.org/
+ specs:
+ actionmailer (3.2.8)
+ actionpack (= 3.2.8)
+ mail (~> 2.4.4)
+ actionpack (3.2.8)
+ activemodel (= 3.2.8)
+ activesupport (= 3.2.8)
+ builder (~> 3.0.0)
+ erubis (~> 2.7.0)
+ journey (~> 1.0.4)
+ rack (~> 1.4.0)
+ rack-cache (~> 1.2)
+ rack-test (~> 0.6.1)
+ sprockets (~> 2.1.3)
+ activemodel (3.2.8)
+ activesupport (= 3.2.8)
+ builder (~> 3.0.0)
+ activerecord (3.2.8)
+ activemodel (= 3.2.8)
+ activesupport (= 3.2.8)
+ arel (~> 3.0.2)
+ tzinfo (~> 0.3.29)
+ activeresource (3.2.8)
+ activemodel (= 3.2.8)
+ activesupport (= 3.2.8)
+ activesupport (3.2.8)
+ i18n (~> 0.6)
+ multi_json (~> 1.0)
+ arel (3.0.2)
+ builder (3.0.3)
+ coffee-rails (3.2.2)
+ coffee-script (>= 2.2.0)
+ railties (~> 3.2.0)
+ coffee-script (2.2.0)
+ coffee-script-source
+ execjs
+ coffee-script-source (1.3.3)
+ erubis (2.7.0)
+ execjs (1.4.0)
+ multi_json (~> 1.0)
+ hike (1.2.1)
+ i18n (0.6.1)
+ journey (1.0.4)
+ jquery-rails (2.1.2)
+ railties (>= 3.1.0, < 5.0)
+ thor (~> 0.14)
+ json (1.7.5)
+ mail (2.4.4)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ mime-types (1.19)
+ multi_json (1.3.6)
+ polyglot (0.3.3)
+ rack (1.4.1)
+ rack-cache (1.2)
+ rack (>= 0.4)
+ rack-ssl (1.3.2)
+ rack
+ rack-test (0.6.1)
+ rack (>= 1.0)
+ rails (3.2.8)
+ actionmailer (= 3.2.8)
+ actionpack (= 3.2.8)
+ activerecord (= 3.2.8)
+ activeresource (= 3.2.8)
+ activesupport (= 3.2.8)
+ bundler (~> 1.0)
+ railties (= 3.2.8)
+ railties (3.2.8)
+ actionpack (= 3.2.8)
+ activesupport (= 3.2.8)
+ rack-ssl (~> 1.3.2)
+ rake (>= 0.8.7)
+ rdoc (~> 3.4)
+ thor (>= 0.14.6, < 2.0)
+ rake (0.9.2.2)
+ rdoc (3.12)
+ json (~> 1.4)
+ sass (3.2.1)
+ sass-rails (3.2.5)
+ railties (~> 3.2.0)
+ sass (>= 3.1.10)
+ tilt (~> 1.3)
+ sprockets (2.1.3)
+ hike (~> 1.2)
+ rack (~> 1.0)
+ tilt (~> 1.1, != 1.3.0)
+ sqlite3 (1.3.6)
+ thor (0.16.0)
+ tilt (1.3.3)
+ treetop (1.4.10)
+ polyglot
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.33)
+ uglifier (1.3.0)
+ execjs (>= 0.3.0)
+ multi_json (~> 1.0, >= 1.0.2)
+ will_paginate (3.0.3)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ coffee-rails (~> 3.2.1)
+ jquery-rails
+ rails (= 3.2.8)
+ sass-rails (~> 3.2.3)
+ sqlite3
+ uglifier (>= 1.0.3)
+ will_paginate
11 store-after/README.md
@@ -0,0 +1,11 @@
+# RailsCasts Example Application
+
+Run these commands to try it out.
+
+```
+bundle
+rake db:setup
+rails s
+```
+
+Requires Ruby 1.9.2 or later to run.
7 store-after/Rakefile
@@ -0,0 +1,7 @@
+#!/usr/bin/env rake
+# Add your own tasks in files placed in lib/tasks ending in .rake,
+# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
+
+require File.expand_path('../config/application', __FILE__)
+
+Store::Application.load_tasks
17 store-after/app/assets/javascripts/application.js
@@ -0,0 +1,17 @@
+// This is a manifest file that'll be compiled into application.js, which will include all the files
+// listed below.
+//
+// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
+// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
+//
+// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
+// the compiled file.
+//
+// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
+// GO AFTER THE REQUIRES BELOW.
+//
+//= require jquery
+//= require jquery_ujs
+//= require raphael
+//= require morris
+//= require_tree .
11 store-after/app/assets/javascripts/orders.js.coffee
@@ -0,0 +1,11 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
+jQuery ->
+ Morris.Line
+ element: 'orders_chart'
+ data: $('#orders_chart').data('orders')
+ xkey: 'purchased_at'
+ ykeys: ['price', 'shipping_price', 'download_price']
+ labels: ['Total Price', 'Shipping Price', 'Download Price']
+ preUnits: '$'
13 store-after/app/assets/stylesheets/application.css
@@ -0,0 +1,13 @@
+/*
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
+ * listed below.
+ *
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
+ *
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
+ * compiled file, but it's generally better to create a new file per style scope.
+ *
+ *= require_self
+ *= require_tree .
+ */
78 store-after/app/assets/stylesheets/layout.css.scss
@@ -0,0 +1,78 @@
+html, body {
+ background-color: #4B7399;
+ font-family: Verdana, Helvetica, Arial;
+ font-size: 14px;
+}
+
+a {
+ color: #0000FF;
+ img { border: none; }
+}
+
+.clear {
+ clear: both;
+ height: 0;
+ overflow: hidden;
+}
+
+#container {
+ width: 80%;
+ margin: 0 auto;
+ background-color: #FFF;
+ padding: 20px 40px;
+ border: solid 1px black;
+ margin-top: 20px;
+}
+
+#flash_notice, #flash_alert {
+ padding: 5px 8px;
+ margin: 10px 0;
+}
+
+#flash_notice {
+ background-color: #CFC;
+ border: solid 1px #6C6;
+}
+
+#flash_alert {
+ background-color: #FCC;
+ border: solid 1px #C66;
+}
+
+.error_messages, #error_explanation {
+ width: 400px;
+ border: 2px solid #CF0000;
+ padding: 0px;
+ padding-bottom: 12px;
+ margin-bottom: 20px;
+ background-color: #f0f0f0;
+ font-size: 12px;
+
+ h2 {
+ text-align: left;
+ font-weight: bold;
+ padding: 5px 10px;
+ font-size: 12px;
+ margin: 0;
+ background-color: #c00;
+ color: #fff;
+ }
+
+ p { margin: 8px 10px; }
+ ul { margin-bottom: 0; }
+}
+
+.field_with_errors {
+ display: inline;
+}
+
+form .field, form .actions {
+ margin: 12px 0;
+}
+
+.pagination {
+ margin: 8px 0;
+ a, em, .disabled { padding: 4px; }
+ em { font-style: normal; }
+ .disabled { color: #999; }
+}
14 store-after/app/assets/stylesheets/orders.css.scss
@@ -0,0 +1,14 @@
+// Place all the styles related to the orders controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
+#orders {
+ border-collapse: collapse;
+ margin: 20px 0;
+ td, th {
+ padding: 4px 10px;
+ border: solid 1px #CCC;
+ }
+ td:last-child {
+ text-align: right;
+ }
+}
3  store-after/app/controllers/application_controller.rb
@@ -0,0 +1,3 @@
+class ApplicationController < ActionController::Base
+ protect_from_forgery
+end
5 store-after/app/controllers/orders_controller.rb
@@ -0,0 +1,5 @@
+class OrdersController < ApplicationController
+ def index
+ @orders = Order.order("purchased_at desc").page(params[:page]).per_page(10)
+ end
+end
2  store-after/app/helpers/application_helper.rb
@@ -0,0 +1,2 @@
+module ApplicationHelper
+end
2  store-after/app/helpers/orders_helper.rb
@@ -0,0 +1,2 @@
+module OrdersHelper
+end
0  store-after/app/mailers/.gitkeep
No changes.
0  store-after/app/models/.gitkeep
No changes.
26 store-after/app/models/order.rb
@@ -0,0 +1,26 @@
+class Order < ActiveRecord::Base
+ attr_accessible :price, :purchased_at, :shipping
+
+ def self.chart_data(start = 3.weeks.ago)
+ total_prices = prices_by_day(start)
+ shipping_prices = where(shipping: true).prices_by_day(start)
+ download_prices = where(shipping: false).prices_by_day(start)
+ (start.to_date..Date.today).map do |date|
+ {
+ purchased_at: date,
+ price: total_prices[date] || 0,
+ shipping_price: shipping_prices[date] || 0,
+ download_price: download_prices[date] || 0
+ }
+ end
+ end
+
+ def self.prices_by_day(start)
+ orders = where(purchased_at: start.beginning_of_day..Time.zone.now)
+ orders = orders.group("date(purchased_at)")
+ orders = orders.select("purchased_at, sum(price) as total_price")
+ orders.each_with_object({}) do |order, prices|
+ prices[order.purchased_at.to_date] = order.total_price
+ end
+ end
+end
17 store-after/app/views/layouts/application.html.erb
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Orders</title>
+ <%= stylesheet_link_tag "application", media: "all" %>
+ <%= javascript_include_tag "application" %>
+ <%= csrf_meta_tag %>
+ </head>
+ <body>
+ <div id="container">
+ <% flash.each do |name, msg| %>
+ <%= content_tag :div, msg, id: "flash_#{name}" %>
+ <% end %>
+ <%= yield %>
+ </div>
+ </body>
+</html>
22 store-after/app/views/orders/index.html.erb
@@ -0,0 +1,22 @@
+<h1>Orders</h1>
+
+<%= content_tag :div, "", id: "orders_chart", data: {orders: Order.chart_data} %>
+
+<table id="orders">
+ <tr>
+ <th>Number</th>
+ <th>Purchased</th>
+ <th>Shipping</th>
+ <th>Total Price</th>
+ </tr>
+ <% @orders.each do |order| %>
+ <tr>
+ <td><%= order.id %></td>
+ <td><%= order.purchased_at.strftime("%B %e, %Y %H:%M") %></td>
+ <td><%= order.shipping ? "Yes" : "No" %></td>
+ <td><%= number_to_currency order.price %></td>
+ </tr>
+ <% end %>
+</table>
+
+<%= will_paginate @orders %>
4 store-after/config.ru
@@ -0,0 +1,4 @@
+# This file is used by Rack-based servers to start the application.
+
+require ::File.expand_path('../config/environment', __FILE__)
+run Store::Application
62 store-after/config/application.rb
@@ -0,0 +1,62 @@
+require File.expand_path('../boot', __FILE__)
+
+require 'rails/all'
+
+if defined?(Bundler)
+ # If you precompile assets before deploying to production, use this line
+ Bundler.require(*Rails.groups(:assets => %w(development test)))
+ # If you want your assets lazily compiled in production, use this line
+ # Bundler.require(:default, :assets, Rails.env)
+end
+
+module Store
+ class Application < Rails::Application
+ # Settings in config/environments/* take precedence over those specified here.
+ # Application configuration should go into files in config/initializers
+ # -- all .rb files in that directory are automatically loaded.
+
+ # Custom directories with classes and modules you want to be autoloadable.
+ # config.autoload_paths += %W(#{config.root}/extras)
+
+ # Only load the plugins named here, in the order given (default is alphabetical).
+ # :all can be used as a placeholder for all plugins not explicitly named.
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
+
+ # Activate observers that should always be running.
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
+
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
+ # config.time_zone = 'Central Time (US & Canada)'
+
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
+ # config.i18n.default_locale = :de
+
+ # Configure the default encoding used in templates for Ruby 1.9.
+ config.encoding = "utf-8"
+
+ # Configure sensitive parameters which will be filtered from the log file.
+ config.filter_parameters += [:password]
+
+ # Enable escaping HTML in JSON.
+ config.active_support.escape_html_entities_in_json = true
+
+ # Use SQL instead of Active Record's schema dumper when creating the database.
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
+ # like if you have constraints or database-specific column types
+ # config.active_record.schema_format = :sql
+
+ # Enforce whitelist mode for mass assignment.
+ # This will create an empty whitelist of attributes available for mass-assignment for all models
+ # in your app. As such, your models will need to explicitly whitelist or blacklist accessible
+ # parameters by using an attr_accessible or attr_protected declaration.
+ config.active_record.whitelist_attributes = true
+
+ # Enable the asset pipeline
+ config.assets.enabled = true
+
+ # Version of your assets, change this if you want to expire all your assets
+ config.assets.version = '1.0'
+ end
+end
6 store-after/config/boot.rb
@@ -0,0 +1,6 @@
+require 'rubygems'
+
+# Set up gems listed in the Gemfile.
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
+
+require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
25 store-after/config/database.yml
@@ -0,0 +1,25 @@
+# SQLite version 3.x
+# gem install sqlite3
+#
+# Ensure the SQLite 3 gem is defined in your Gemfile
+# gem 'sqlite3'
+development:
+ adapter: sqlite3
+ database: db/development.sqlite3
+ pool: 5
+ timeout: 5000
+
+# Warning: The database defined as "test" will be erased and
+# re-generated from your development database when you run "rake".
+# Do not set this db to the same as development or production.
+test:
+ adapter: sqlite3
+ database: db/test.sqlite3
+ pool: 5
+ timeout: 5000
+
+production:
+ adapter: sqlite3
+ database: db/production.sqlite3
+ pool: 5
+ timeout: 5000
5 store-after/config/environment.rb
@@ -0,0 +1,5 @@
+# Load the rails application
+require File.expand_path('../application', __FILE__)
+
+# Initialize the rails application
+Store::Application.initialize!
37 store-after/config/environments/development.rb
@@ -0,0 +1,37 @@
+Store::Application.configure do
+ # Settings specified here will take precedence over those in config/application.rb
+
+ # In the development environment your application's code is reloaded on
+ # every request. This slows down response time but is perfect for development
+ # since you don't have to restart the web server when you make code changes.
+ config.cache_classes = false
+
+ # Log error messages when you accidentally call methods on nil.
+ config.whiny_nils = true
+
+ # Show full error reports and disable caching
+ config.consider_all_requests_local = true
+ config.action_controller.perform_caching = false
+
+ # Don't care if the mailer can't send
+ config.action_mailer.raise_delivery_errors = false
+
+ # Print deprecation notices to the Rails logger
+ config.active_support.deprecation = :log
+
+ # Only use best-standards-support built into browsers
+ config.action_dispatch.best_standards_support = :builtin
+
+ # Raise exception on mass assignment protection for Active Record models
+ config.active_record.mass_assignment_sanitizer = :strict
+
+ # Log the query plan for queries taking more than this (works
+ # with SQLite, MySQL, and PostgreSQL)
+ config.active_record.auto_explain_threshold_in_seconds = 0.5
+
+ # Do not compress assets
+ config.assets.compress = false
+
+ # Expands the lines which load the assets
+ config.assets.debug = true
+end
67 store-after/config/environments/production.rb
@@ -0,0 +1,67 @@
+Store::Application.configure do
+ # Settings specified here will take precedence over those in config/application.rb
+
+ # Code is not reloaded between requests
+ config.cache_classes = true
+
+ # Full error reports are disabled and caching is turned on
+ config.consider_all_requests_local = false
+ config.action_controller.perform_caching = true
+
+ # Disable Rails's static asset server (Apache or nginx will already do this)
+ config.serve_static_assets = false
+
+ # Compress JavaScripts and CSS
+ config.assets.compress = true
+
+ # Don't fallback to assets pipeline if a precompiled asset is missed
+ config.assets.compile = false
+
+ # Generate digests for assets URLs
+ config.assets.digest = true
+
+ # Defaults to nil and saved in location specified by config.assets.prefix
+ # config.assets.manifest = YOUR_PATH
+
+ # Specifies the header that your server uses for sending files
+ # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
+
+ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
+ # config.force_ssl = true
+
+ # See everything in the log (default is :info)
+ # config.log_level = :debug
+
+ # Prepend all log lines with the following tags
+ # config.log_tags = [ :subdomain, :uuid ]
+
+ # Use a different logger for distributed setups
+ # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
+
+ # Use a different cache store in production
+ # config.cache_store = :mem_cache_store
+
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server
+ # config.action_controller.asset_host = "http://assets.example.com"
+
+ # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
+ # config.assets.precompile += %w( search.js )
+
+ # Disable delivery errors, bad email addresses will be ignored
+ # config.action_mailer.raise_delivery_errors = false
+
+ # Enable threaded mode
+ # config.threadsafe!
+
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
+ # the I18n.default_locale when a translation can not be found)
+ config.i18n.fallbacks = true
+
+ # Send deprecation notices to registered listeners
+ config.active_support.deprecation = :notify
+
+ # Log the query plan for queries taking more than this (works
+ # with SQLite, MySQL, and PostgreSQL)
+ # config.active_record.auto_explain_threshold_in_seconds = 0.5
+end
37 store-after/config/environments/test.rb
@@ -0,0 +1,37 @@
+Store::Application.configure do
+ # Settings specified here will take precedence over those in config/application.rb
+
+ # The test environment is used exclusively to run your application's
+ # test suite. You never need to work with it otherwise. Remember that
+ # your test database is "scratch space" for the test suite and is wiped
+ # and recreated between test runs. Don't rely on the data there!
+ config.cache_classes = true
+
+ # Configure static asset server for tests with Cache-Control for performance
+ config.serve_static_assets = true
+ config.static_cache_control = "public, max-age=3600"
+
+ # Log error messages when you accidentally call methods on nil
+ config.whiny_nils = true
+
+ # Show full error reports and disable caching
+ config.consider_all_requests_local = true
+ config.action_controller.perform_caching = false
+
+ # Raise exceptions instead of rendering exception templates
+ config.action_dispatch.show_exceptions = false
+
+ # Disable request forgery protection in test environment
+ config.action_controller.allow_forgery_protection = false
+
+ # Tell Action Mailer not to deliver emails to the real world.
+ # The :test delivery method accumulates sent emails in the
+ # ActionMailer::Base.deliveries array.
+ config.action_mailer.delivery_method = :test
+
+ # Raise exception on mass assignment protection for Active Record models
+ config.active_record.mass_assignment_sanitizer = :strict
+
+ # Print deprecation notices to the stderr
+ config.active_support.deprecation = :stderr
+end
7 store-after/config/initializers/backtrace_silencers.rb
@@ -0,0 +1,7 @@
+# Be sure to restart your server when you modify this file.
+
+# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
+# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
+
+# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
+# Rails.backtrace_cleaner.remove_silencers!
15 store-after/config/initializers/inflections.rb
@@ -0,0 +1,15 @@
+# Be sure to restart your server when you modify this file.
+
+# Add new inflection rules using the following format
+# (all these examples are active by default):
+# ActiveSupport::Inflector.inflections do |inflect|
+# inflect.plural /^(ox)$/i, '\1en'
+# inflect.singular /^(ox)en/i, '\1'
+# inflect.irregular 'person', 'people'
+# inflect.uncountable %w( fish sheep )
+# end
+#
+# These inflection rules are supported but not enabled by default:
+# ActiveSupport::Inflector.inflections do |inflect|
+# inflect.acronym 'RESTful'
+# end
5 store-after/config/initializers/mime_types.rb
@@ -0,0 +1,5 @@
+# Be sure to restart your server when you modify this file.
+
+# Add new mime types for use in respond_to blocks:
+# Mime::Type.register "text/richtext", :rtf
+# Mime::Type.register_alias "text/html", :iphone
7 store-after/config/initializers/secret_token.rb
@@ -0,0 +1,7 @@
+# Be sure to restart your server when you modify this file.
+
+# Your secret key for verifying the integrity of signed cookies.
+# If you change this key, all old signed cookies will become invalid!
+# Make sure the secret is at least 30 characters and all random,
+# no regular words or you'll be exposed to dictionary attacks.
+Store::Application.config.secret_token = '624d8588042ddfd605d1f983d84edcbce025ca1466329ac1b287d1c6704909389f554debff2bf2dfaec7593ae240d02f211a087ee27c345e4434c0c5f5b687ec'
8 store-after/config/initializers/session_store.rb
@@ -0,0 +1,8 @@
+# Be sure to restart your server when you modify this file.
+
+Store::Application.config.session_store :cookie_store, key: '_store_session'
+
+# Use the database for sessions instead of the cookie-based default,
+# which shouldn't be used to store highly confidential information
+# (create the session table with "rails generate session_migration")
+# Store::Application.config.session_store :active_record_store
14 store-after/config/initializers/wrap_parameters.rb
@@ -0,0 +1,14 @@
+# Be sure to restart your server when you modify this file.
+#
+# This file contains settings for ActionController::ParamsWrapper which
+# is enabled by default.
+
+# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
+ActiveSupport.on_load(:action_controller) do
+ wrap_parameters format: [:json]
+end
+
+# Disable root element in JSON by default.
+ActiveSupport.on_load(:active_record) do
+ self.include_root_in_json = false
+end
5 store-after/config/locales/en.yml
@@ -0,0 +1,5 @@
+# Sample localization file for English. Add more files in this directory for other locales.
+# See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
+
+en:
+ hello: "Hello world"
4 store-after/config/routes.rb
@@ -0,0 +1,4 @@
+Store::Application.routes.draw do
+ resources :orders
+ root to: 'orders#index'
+end
11 store-after/db/migrate/20120914202335_create_orders.rb
@@ -0,0 +1,11 @@
+class CreateOrders < ActiveRecord::Migration
+ def change
+ create_table :orders do |t|
+ t.decimal :price, :precision => 2, :scale => 8
+ t.datetime :purchased_at
+ t.boolean :shipping
+
+ t.timestamps
+ end
+ end
+end
24 store-after/db/schema.rb
@@ -0,0 +1,24 @@
+# encoding: UTF-8
+# This file is auto-generated from the current state of the database. Instead
+# of editing this file, please use the migrations feature of Active Record to
+# incrementally modify your database, and then regenerate this schema definition.
+#
+# Note that this schema.rb definition is the authoritative source for your
+# database schema. If you need to create the application database on another
+# system, you should be using db:schema:load, not running all the migrations
+# from scratch. The latter is a flawed and unsustainable approach (the more migrations
+# you'll amass, the slower it'll run and the greater likelihood for issues).
+#
+# It's strongly recommended to check this file into your version control system.
+
+ActiveRecord::Schema.define(:version => 20120914202335) do
+
+ create_table "orders", :force => true do |t|
+ t.decimal "price", :precision => 2, :scale => 8
+ t.datetime "purchased_at"
+ t.boolean "shipping"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
+end
9 store-after/db/seeds.rb
@@ -0,0 +1,9 @@
+Order.delete_all
+generator = proc do |start_time, end_time, shipping|
+ time = Time.at(rand(end_time.to_i - start_time.to_i) + start_time.to_i)
+ dollars = rand(200) + 10
+ Order.create!(price: dollars, purchased_at: time, shipping: rand(shipping))
+end
+200.times { generator.call(10.days.ago, Time.zone.now.end_of_day, 1) }
+500.times { generator.call(1.month.ago, Time.zone.now.end_of_day, 2) }
+Order.create!(price: 10, purchased_at: 1.month.ago.beginning_of_day, shipping: true)
2  store-after/doc/README_FOR_APP
@@ -0,0 +1,2 @@
+Use this README file to introduce your application and point to useful places in the API for learning more.
+Run "rake doc:app" to generate API documentation for your models, controllers, helpers, and libraries.
0  store-after/lib/assets/.gitkeep
No changes.
0  store-after/lib/tasks/.gitkeep
No changes.
0  store-after/log/.gitkeep
No changes.
26 store-after/public/404.html
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>The page you were looking for doesn't exist (404)</title>
+ <style type="text/css">
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
+ div.dialog {
+ width: 25em;
+ padding: 0 4em;
+ margin: 4em auto 0 auto;
+ border: 1px solid #ccc;
+ border-right-color: #999;
+ border-bottom-color: #999;
+ }
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
+ </style>
+</head>
+
+<body>
+ <!-- This file lives in public/404.html -->
+ <div class="dialog">
+ <h1>The page you were looking for doesn't exist.</h1>
+ <p>You may have mistyped the address or the page may have moved.</p>
+ </div>
+</body>
+</html>
26 store-after/public/422.html
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>The change you wanted was rejected (422)</title>
+ <style type="text/css">
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
+ div.dialog {
+ width: 25em;
+ padding: 0 4em;
+ margin: 4em auto 0 auto;
+ border: 1px solid #ccc;
+ border-right-color: #999;
+ border-bottom-color: #999;
+ }
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
+ </style>
+</head>
+
+<body>
+ <!-- This file lives in public/422.html -->
+ <div class="dialog">
+ <h1>The change you wanted was rejected.</h1>
+ <p>Maybe you tried to change something you didn't have access to.</p>
+ </div>
+</body>
+</html>
25 store-after/public/500.html
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>We're sorry, but something went wrong (500)</title>
+ <style type="text/css">
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
+ div.dialog {
+ width: 25em;
+ padding: 0 4em;
+ margin: 4em auto 0 auto;
+ border: 1px solid #ccc;
+ border-right-color: #999;
+ border-bottom-color: #999;
+ }
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
+ </style>
+</head>
+
+<body>
+ <!-- This file lives in public/500.html -->
+ <div class="dialog">
+ <h1>We're sorry, but something went wrong.</h1>
+ </div>
+</body>
+</html>
0  store-after/public/favicon.ico
No changes.
5 store-after/public/robots.txt
@@ -0,0 +1,5 @@
+# See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
+#
+# To ban all spiders from the entire site uncomment the next two lines:
+# User-Agent: *
+# Disallow: /
6 store-after/script/rails
@@ -0,0 +1,6 @@
+#!/usr/bin/env ruby
+# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
+
+APP_PATH = File.expand_path('../../config/application', __FILE__)
+require File.expand_path('../../config/boot', __FILE__)
+require 'rails/commands'
0  store-after/test/fixtures/.gitkeep
No changes.
11 store-after/test/fixtures/orders.yml
@@ -0,0 +1,11 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+one:
+ price: 9.99
+ purchased_at: 2012-09-14 13:23:36
+ shipping: false
+
+two:
+ price: 9.99
+ purchased_at: 2012-09-14 13:23:36
+ shipping: false
0  store-after/test/functional/.gitkeep
No changes.
49 store-after/test/functional/orders_controller_test.rb
@@ -0,0 +1,49 @@
+require 'test_helper'
+
+class OrdersControllerTest < ActionController::TestCase
+ setup do
+ @order = orders(:one)
+ end
+
+ test "should get index" do
+ get :index
+ assert_response :success
+ assert_not_nil assigns(:orders)
+ end
+
+ test "should get new" do
+ get :new
+ assert_response :success
+ end
+
+ test "should create order" do
+ assert_difference('Order.count') do
+ post :create, order: { price: @order.price, purchased_at: @order.purchased_at, shipping: @order.shipping }
+ end
+
+ assert_redirected_to order_path(assigns(:order))
+ end
+
+ test "should show order" do
+ get :show, id: @order
+ assert_response :success
+ end
+
+ test "should get edit" do
+ get :edit, id: @order
+ assert_response :success
+ end
+
+ test "should update order" do
+ put :update, id: @order, order: { price: @order.price, purchased_at: @order.purchased_at, shipping: @order.shipping }
+ assert_redirected_to order_path(assigns(:order))
+ end
+
+ test "should destroy order" do
+ assert_difference('Order.count', -1) do
+ delete :destroy, id: @order
+ end
+
+ assert_redirected_to orders_path
+ end
+end
0  store-after/test/integration/.gitkeep
No changes.
12 store-after/test/performance/browsing_test.rb
@@ -0,0 +1,12 @@
+require 'test_helper'
+require 'rails/performance_test_help'
+
+class BrowsingTest < ActionDispatch::PerformanceTest
+ # Refer to the documentation for all available options
+ # self.profile_options = { :runs => 5, :metrics => [:wall_time, :memory]
+ # :output => 'tmp/performance', :formats => [:flat] }
+
+ def test_homepage
+ get '/'
+ end
+end
13 store-after/test/test_helper.rb
@@ -0,0 +1,13 @@
+ENV["RAILS_ENV"] = "test"
+require File.expand_path('../../config/environment', __FILE__)
+require 'rails/test_help'
+
+class ActiveSupport::TestCase
+ # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
+ #
+ # Note: You'll currently still have to declare fixtures explicitly in integration tests
+ # -- they do not yet inherit this setting
+ fixtures :all
+
+ # Add more helper methods to be used by all tests here...
+end
0  store-after/test/unit/.gitkeep
No changes.
4 store-after/test/unit/helpers/orders_helper_test.rb
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class OrdersHelperTest < ActionView::TestCase
+end
7 store-after/test/unit/order_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class OrderTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
0  store-after/vendor/assets/javascripts/.gitkeep
No changes.
959 store-after/vendor/assets/javascripts/morris.js
@@ -0,0 +1,959 @@
+(function() {
+ var $, Morris, minutesSpecHelper, secondsSpecHelper,
+ __slice = [].slice,
+ __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
+ __hasProp = {}.hasOwnProperty,
+ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
+
+ Morris = window.Morris = {};
+
+ $ = jQuery;
+
+ Morris.EventEmitter = (function() {
+
+ function EventEmitter() {}
+
+ EventEmitter.prototype.on = function(name, handler) {
+ if (this.handlers == null) {
+ this.handlers = {};
+ }
+ if (this.handlers[name] == null) {
+ this.handlers[name] = [];
+ }
+ return this.handlers[name].push(handler);
+ };
+
+ EventEmitter.prototype.fire = function() {
+ var args, handler, name, _i, _len, _ref, _results;
+ name = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
+ if ((this.handlers != null) && (this.handlers[name] != null)) {
+ _ref = this.handlers[name];
+ _results = [];
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ handler = _ref[_i];
+ _results.push(handler.apply(null, args));
+ }
+ return _results;
+ }
+ };
+
+ return EventEmitter;
+
+ })();
+
+ Morris.commas = function(num) {
+ var absnum, intnum, ret, strabsnum;
+ if (num === null) {
+ return "n/a";
+ } else {
+ ret = num < 0 ? "-" : "";
+ absnum = Math.abs(num);
+ intnum = Math.floor(absnum).toFixed(0);
+ ret += intnum.replace(/(?=(?:\d{3})+$)(?!^)/g, ',');
+ strabsnum = absnum.toString();
+ if (strabsnum.length > intnum.length) {
+ ret += strabsnum.slice(intnum.length);
+ }
+ return ret;
+ }
+ };
+
+ Morris.pad2 = function(number) {
+ return (number < 10 ? '0' : '') + number;
+ };
+
+ Morris.Donut = (function() {
+
+ Donut.prototype.colors = ['#0B62A4', '#3980B5', '#679DC6', '#95BBD7', '#B0CCE1', '#095791', '#095085', '#083E67', '#052C48', '#042135'];
+
+ function Donut(options) {
+ this.select = __bind(this.select, this);
+ if (!(this instanceof Morris.Donut)) {
+ return new Morris.Donut(options);
+ }
+ if (typeof options.element === 'string') {
+ this.el = $(document.getElementById(options.element));
+ } else {
+ this.el = $(options.element);
+ }
+ if (options.colors != null) {
+ this.colors = options.colors;
+ }
+ if (this.el === null || this.el.length === 0) {
+ throw new Error("Graph placeholder not found.");
+ }
+ if (options.data === void 0 || options.data.length === 0) {
+ return;
+ }
+ this.data = options.data;
+ this.el.addClass('graph-initialised');
+ this.r = new Raphael(this.el[0]);
+ this.draw();
+ }
+
+ Donut.prototype.draw = function() {
+ var C, cx, cy, d, idx, last, max_value, min, next, seg, total, w, x, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2, _results;
+ cx = this.el.width() / 2;
+ cy = this.el.height() / 2;
+ w = (Math.min(cx, cy) - 10) / 3;
+ total = 0;
+ _ref = this.data;
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ x = _ref[_i];
+ total += x.value;
+ }
+ min = 5 / (2 * w);
+ C = 1.9999 * Math.PI - min * this.data.length;
+ last = 0;
+ idx = 0;
+ this.segments = [];
+ _ref1 = this.data;
+ for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
+ d = _ref1[_j];
+ next = last + min + C * (d.value / total);
+ seg = new Morris.DonutSegment(cx, cy, w * 2, w, last, next, this.colors[idx % this.colors.length], d);
+ seg.render(this.r);
+ this.segments.push(seg);
+ seg.on('hover', this.select);
+ last = next;
+ idx += 1;
+ }
+ this.text1 = this.r.text(cx, cy - 10, '').attr({
+ 'font-size': 15,
+ 'font-weight': 800
+ });
+ this.text2 = this.r.text(cx, cy + 10, '').attr({
+ 'font-size': 14
+ });
+ max_value = Math.max.apply(null, (function() {
+ var _k, _len2, _ref2, _results;
+ _ref2 = this.data;
+ _results = [];
+ for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
+ d = _ref2[_k];
+ _results.push(d.value);
+ }
+ return _results;
+ }).call(this));
+ idx = 0;
+ _ref2 = this.data;
+ _results = [];
+ for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
+ d = _ref2[_k];
+ if (d.value === max_value) {
+ this.select(this.segments[idx]);
+ break;
+ }
+ _results.push(idx += 1);
+ }
+ return _results;
+ };
+
+ Donut.prototype.select = function(segment) {
+ var s, _i, _len, _ref;
+ _ref = this.segments;
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ s = _ref[_i];
+ s.deselect();
+ }
+ segment.select();
+ return this.setLabels(segment.data.label, Morris.commas(segment.data.value));
+ };
+
+ Donut.prototype.setLabels = function(label1, label2) {
+ var inner, maxHeightBottom, maxHeightTop, maxWidth, text1bbox, text1scale, text2bbox, text2scale;
+ inner = (Math.min(this.el.width() / 2, this.el.height() / 2) - 10) * 2 / 3;
+ maxWidth = 1.8 * inner;
+ maxHeightTop = inner / 2;
+ maxHeightBottom = inner / 3;
+ this.text1.attr({
+ text: label1,
+ transform: ''
+ });
+ text1bbox = this.text1.getBBox();
+ text1scale = Math.min(maxWidth / text1bbox.width, maxHeightTop / text1bbox.height);
+ this.text1.attr({
+ transform: "S" + text1scale + "," + text1scale + "," + (text1bbox.x + text1bbox.width / 2) + "," + (text1bbox.y + text1bbox.height)
+ });
+ this.text2.attr({
+ text: label2,
+ transform: ''
+ });
+ text2bbox = this.text2.getBBox();
+ text2scale = Math.min(maxWidth / text2bbox.width, maxHeightBottom / text2bbox.height);
+ return this.text2.attr({
+ transform: "S" + text2scale + "," + text2scale + "," + (text2bbox.x + text2bbox.width / 2) + "," + text2bbox.y
+ });
+ };
+
+ return Donut;
+
+ })();
+
+ Morris.DonutSegment = (function(_super) {
+
+ __extends(DonutSegment, _super);
+
+ function DonutSegment(cx, cy, inner, outer, p0, p1, color, data) {
+ this.cx = cx;
+ this.cy = cy;
+ this.inner = inner;
+ this.outer = outer;
+ this.color = color;
+ this.data = data;
+ this.deselect = __bind(this.deselect, this);
+
+ this.select = __bind(this.select, this);
+
+ this.sin_p0 = Math.sin(p0);
+ this.cos_p0 = Math.cos(p0);
+ this.sin_p1 = Math.sin(p1);
+ this.cos_p1 = Math.cos(p1);
+ this.long = (p1 - p0) > Math.PI ? 1 : 0;
+ this.path = this.calcSegment(this.inner + 3, this.inner + this.outer - 5);
+ this.selectedPath = this.calcSegment(this.inner + 3, this.inner + this.outer);
+ this.hilight = this.calcArc(this.inner);
+ }
+
+ DonutSegment.prototype.calcArcPoints = function(r) {
+ return [this.cx + r * this.sin_p0, this.cy + r * this.cos_p0, this.cx + r * this.sin_p1, this.cy + r * this.cos_p1];
+ };
+
+ DonutSegment.prototype.calcSegment = function(r1, r2) {
+ var ix0, ix1, iy0, iy1, ox0, ox1, oy0, oy1, _ref, _ref1;
+ _ref = this.calcArcPoints(r1), ix0 = _ref[0], iy0 = _ref[1], ix1 = _ref[2], iy1 = _ref[3];
+ _ref1 = this.calcArcPoints(r2), ox0 = _ref1[0], oy0 = _ref1[1], ox1 = _ref1[2], oy1 = _ref1[3];
+ return ("M" + ix0 + "," + iy0) + ("A" + r1 + "," + r1 + ",0," + this.long + ",0," + ix1 + "," + iy1) + ("L" + ox1 + "," + oy1) + ("A" + r2 + "," + r2 + ",0," + this.long + ",1," + ox0 + "," + oy0) + "Z";
+ };
+
+ DonutSegment.prototype.calcArc = function(r) {
+ var ix0, ix1, iy0, iy1, _ref;
+ _ref = this.calcArcPoints(r), ix0 = _ref[0], iy0 = _ref[1], ix1 = _ref[2], iy1 = _ref[3];
+ return ("M" + ix0 + "," + iy0) + ("A" + r + "," + r + ",0," + this.long + ",0," + ix1 + "," + iy1);
+ };
+
+ DonutSegment.prototype.render = function(r) {
+ var _this = this;
+ this.arc = r.path(this.hilight).attr({
+ stroke: this.color,
+ 'stroke-width': 2,
+ opacity: 0
+ });
+ return this.seg = r.path(this.path).attr({
+ fill: this.color,
+ stroke: 'white',
+ 'stroke-width': 3
+ }).hover(function() {
+ return _this.fire('hover', _this);
+ });
+ };
+
+ DonutSegment.prototype.select = function() {
+ if (!this.selected) {
+ this.seg.animate({
+ path: this.selectedPath
+ }, 150, '<>');
+ this.arc.animate({
+ opacity: 1
+ }, 150, '<>');
+ return this.selected = true;
+ }
+ };
+
+ DonutSegment.prototype.deselect = function() {
+ if (this.selected) {
+ this.seg.animate({
+ path: this.path
+ }, 150, '<>');
+ this.arc.animate({
+ opacity: 0
+ }, 150, '<>');
+ return this.selected = false;
+ }
+ };
+
+ return DonutSegment;
+
+ })(Morris.EventEmitter);
+
+ Morris.Line = (function() {
+
+ function Line(options) {
+ this.updateHilight = __bind(this.updateHilight, this);
+
+ this.hilight = __bind(this.hilight, this);
+
+ this.updateHover = __bind(this.updateHover, this);
+
+ this.transY = __bind(this.transY, this);
+
+ this.transX = __bind(this.transX, this);
+
+ var touchHandler,
+ _this = this;
+ if (!(this instanceof Morris.Line)) {
+ return new Morris.Line(options);
+ }
+ if (typeof options.element === 'string') {
+ this.el = $(document.getElementById(options.element));
+ } else {
+ this.el = $(options.element);
+ }
+ if (this.el === null || this.el.length === 0) {
+ throw new Error("Graph placeholder not found.");
+ }
+ this.options = $.extend({}, this.defaults, options);
+ if (typeof this.options.units === 'string') {
+ this.options.postUnits = options.units;
+ }
+ if (this.options.data === void 0 || this.options.data.length === 0) {
+ return;
+ }
+ this.el.addClass('graph-initialised');
+ this.r = new Raphael(this.el[0]);
+ this.pointGrow = Raphael.animation({
+ r: this.options.pointSize + 3
+ }, 25, 'linear');
+ this.pointShrink = Raphael.animation({
+ r: this.options.pointSize
+ }, 25, 'linear');
+ this.elementWidth = null;
+ this.elementHeight = null;
+ this.dirty = false;
+ this.prevHilight = null;
+ this.el.mousemove(function(evt) {
+ return _this.updateHilight(evt.pageX);
+ });
+ if (this.options.hideHover) {
+ this.el.mouseout(function(evt) {
+ return _this.hilight(null);
+ });
+ }
+ touchHandler = function(evt) {
+ var touch;
+ touch = evt.originalEvent.touches[0] || evt.originalEvent.changedTouches[0];
+ _this.updateHilight(touch.pageX);
+ return touch;
+ };
+ this.el.bind('touchstart', touchHandler);
+ this.el.bind('touchmove', touchHandler);
+ this.el.bind('touchend', touchHandler);
+ this.seriesLabels = this.options.labels;
+ this.setData(this.options.data);
+ }
+
+ Line.prototype.defaults = {
+ lineWidth: 3,
+ pointSize: 4,
+ lineColors: ['#0b62a4', '#7A92A3', '#4da74d', '#afd8f8', '#edc240', '#cb4b4b', '#9440ed'],
+ ymax: 'auto',
+ ymin: 'auto 0',
+ marginTop: 25,
+ marginRight: 25,
+ marginBottom: 30,
+ marginLeft: 25,
+ numLines: 5,
+ gridLineColor: '#aaa',
+ gridTextColor: '#888',
+ gridTextSize: 12,
+ gridStrokeWidth: 0.5,
+ hoverPaddingX: 10,
+ hoverPaddingY: 5,
+ hoverMargin: 10,
+ hoverFillColor: '#fff',
+ hoverBorderColor: '#ccc',
+ hoverBorderWidth: 2,
+ hoverOpacity: 0.95,
+ hoverLabelColor: '#444',
+ hoverFontSize: 12,
+ smooth: true,
+ hideHover: false,
+ parseTime: true,
+ preUnits: '',
+ postUnits: '',
+ dateFormat: function(x) {
+ return new Date(x).toString();
+ },
+ xLabels: 'auto',
+ xLabelFormat: null
+ };
+
+ Line.prototype.setData = function(data, redraw) {
+ var d, series_data, ykey, ymax, ymin, _i, _j, _k, _len, _len1, _ref, _ref1, _ref2, _results,
+ _this = this;
+ if (redraw == null) {
+ redraw = true;
+ }
+ this.options.data = data.slice(0);
+ this.options.data.sort(function(a, b) {
+ return (a[_this.options.xkey] < b[_this.options.xkey]) - (b[_this.options.xkey] < a[_this.options.xkey]);
+ });
+ this.columnLabels = $.map(this.options.data, function(d) {
+ return d[_this.options.xkey];
+ });
+ this.series = [];
+ _ref = this.options.ykeys;
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ ykey = _ref[_i];
+ series_data = [];
+ _ref1 = this.options.data;
+ for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
+ d = _ref1[_j];
+ series_data.push((function() {
+ switch (typeof d[ykey]) {
+ case 'number':
+ return d[ykey];
+ case 'string':
+ return parseFloat(d[ykey]);
+ default:
+ return null;
+ }
+ })());
+ }
+ this.series.push(series_data);
+ }
+ if (this.options.parseTime) {
+ this.xvals = $.map(this.columnLabels, function(x) {
+ return Morris.parseDate(x);
+ });
+ } else {
+ this.xvals = (function() {
+ _results = [];
+ for (var _k = _ref2 = this.columnLabels.length - 1; _ref2 <= 0 ? _k <= 0 : _k >= 0; _ref2 <= 0 ? _k++ : _k--){ _results.push(_k); }
+ return _results;
+ }).apply(this);
+ }
+ if (this.options.parseTime) {
+ this.columnLabels = $.map(this.columnLabels, function(d) {
+ if (typeof d === 'number') {
+ return _this.options.dateFormat(d);
+ } else {
+ return d;
+ }
+ });
+ }
+ this.xmin = Math.min.apply(null, this.xvals);
+ this.xmax = Math.max.apply(null, this.xvals);
+ if (this.xmin === this.xmax) {
+ this.xmin -= 1;
+ this.xmax += 1;
+ }
+ if (typeof this.options.ymax === 'string' && this.options.ymax.slice(0, 4) === 'auto') {
+ ymax = Math.max.apply(null, Array.prototype.concat.apply([], this.series));
+ if (this.options.ymax.length > 5) {
+ this.ymax = Math.max(parseInt(this.options.ymax.slice(5), 10), ymax);
+ } else {
+ this.ymax = ymax;
+ }
+ } else if (typeof this.options.ymax === 'string') {
+ this.ymax = parseInt(this.options.ymax, 10);
+ } else {
+ this.ymax = this.options.ymax;
+ }
+ if (typeof this.options.ymin === 'string' && this.options.ymin.slice(0, 4) === 'auto') {
+ ymin = Math.min.apply(null, Array.prototype.concat.apply([], this.series));
+ if (this.options.ymin.length > 5) {
+ this.ymin = Math.min(parseInt(this.options.ymin.slice(5), 10), ymin);
+ } else {
+ this.ymin = ymin;
+ }
+ } else if (typeof this.options.ymin === 'string') {
+ this.ymin = parseInt(this.options.ymin, 10);
+ } else {
+ this.ymin = this.options.ymin;
+ }
+ if (this.ymin === this.ymax) {
+ this.ymin -= 1;
+ this.ymax += 1;
+ }
+ this.yInterval = (this.ymax - this.ymin) / (this.options.numLines - 1);
+ if (this.yInterval > 0 && this.yInterval < 1) {
+ this.precision = -Math.floor(Math.log(this.yInterval) / Math.log(10));
+ } else {
+ this.precision = 0;
+ }
+ this.dirty = true;
+ if (redraw) {
+ return this.redraw();
+ }
+ };
+
+ Line.prototype.calc = function() {
+ var h, s, scoords, w, x, _i, _len, _ref,
+ _this = this;
+ w = this.el.width();
+ h = this.el.height();
+ if (this.elementWidth !== w || this.elementHeight !== h || this.dirty) {
+ this.elementWidth = w;
+ this.elementHeight = h;
+ this.dirty = false;
+ this.maxYLabelWidth = Math.max(this.measureText(this.yLabelFormat(this.ymin), this.options.gridTextSize).width, this.measureText(this.yLabelFormat(this.ymax), this.options.gridTextSize).width);
+ this.left = this.maxYLabelWidth + this.options.marginLeft;
+ this.width = this.el.width() - this.left - this.options.marginRight;
+ this.height = this.el.height() - this.options.marginTop - this.options.marginBottom;
+ this.dx = this.width / (this.xmax - this.xmin);
+ this.dy = this.height / (this.ymax - this.ymin);
+ this.columns = (function() {
+ var _i, _len, _ref, _results;
+ _ref = this.xvals;
+ _results = [];
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ x = _ref[_i];
+ _results.push(this.transX(x));
+ }
+ return _results;
+ }).call(this);
+ this.seriesCoords = [];
+ _ref = this.series;
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ s = _ref[_i];
+ scoords = [];
+ $.each(s, function(i, y) {
+ if (y === null) {
+ return scoords.push(null);
+ } else {
+ return scoords.push({
+ x: _this.columns[i],
+ y: _this.transY(y)
+ });
+ }
+ });
+ this.seriesCoords.push(scoords);
+ }
+ return this.hoverMargins = $.map(this.columns.slice(1), function(x, i) {
+ return (x + _this.columns[i]) / 2;
+ });
+ }
+ };
+
+ Line.prototype.transX = function(x) {
+ if (this.xvals.length === 1) {
+ return this.left + this.width / 2;
+ } else {
+ return this.left + (x - this.xmin) * this.dx;
+ }
+ };
+
+ Line.prototype.transY = function(y) {
+ return this.options.marginTop + this.height - (y - this.ymin) * this.dy;
+ };
+
+ Line.prototype.redraw = function() {
+ this.r.clear();
+ this.calc();
+ this.drawGrid();
+ this.drawSeries();
+ this.drawHover();
+ return this.hilight(this.options.hideHover ? null : 0);
+ };
+
+ Line.prototype.drawGrid = function() {
+ var drawLabel, firstY, i, l, labelText, lastY, lineY, prevLabelMargin, v, xLabelMargin, y, ypos, _i, _j, _k, _len, _ref, _ref1, _ref2, _results, _results1,
+ _this = this;
+ firstY = this.ymin;
+ lastY = this.ymax;
+ for (lineY = _i = firstY, _ref = this.yInterval; firstY <= lastY ? _i <= lastY : _i >= lastY; lineY = _i += _ref) {
+ v = parseFloat(lineY.toFixed(this.precision));
+ y = this.transY(v);
+ this.r.text(this.left - this.options.marginLeft / 2, y, this.yLabelFormat(v)).attr('font-size', this.options.gridTextSize).attr('fill', this.options.gridTextColor).attr('text-anchor', 'end');
+ this.r.path("M" + this.left + "," + y + "H" + (this.left + this.width)).attr('stroke', this.options.gridLineColor).attr('stroke-width', this.options.gridStrokeWidth);
+ }
+ ypos = this.options.marginTop + this.height + this.options.marginBottom / 2;
+ xLabelMargin = 50;
+ prevLabelMargin = null;
+ drawLabel = function(labelText, xpos) {
+ var label, labelBox;
+ label = _this.r.text(_this.transX(xpos), ypos, labelText).attr('font-size', _this.options.gridTextSize).attr('fill', _this.options.gridTextColor);
+ labelBox = label.getBBox();
+ if ((prevLabelMargin === null || prevLabelMargin <= labelBox.x) && labelBox.x >= 0 && (labelBox.x + labelBox.width) < _this.el.width()) {
+ return prevLabelMargin = labelBox.x + labelBox.width + xLabelMargin;
+ } else {
+ return label.remove();
+ }
+ };
+ if (this.options.parseTime) {
+ if (this.columnLabels.length === 1 && this.options.xLabels === 'auto') {
+ return drawLabel(this.columnLabels[0], this.xvals[0]);
+ } else {
+ _ref1 = Morris.labelSeries(this.xmin, this.xmax, this.width, this.options.xLabels, this.options.xLabelFormat);
+ _results = [];
+ for (_j = 0, _len = _ref1.length; _j < _len; _j++) {
+ l = _ref1[_j];
+ _results.push(drawLabel(l[0], l[1]));
+ }
+ return _results;
+ }
+ } else {
+ _results1 = [];
+ for (i = _k = 0, _ref2 = this.columnLabels.length; 0 <= _ref2 ? _k <= _ref2 : _k >= _ref2; i = 0 <= _ref2 ? ++_k : --_k) {
+ labelText = this.columnLabels[this.columnLabels.length - i - 1];
+ _results1.push(drawLabel(labelText, i));
+ }
+ return _results1;
+ }
+ };
+
+ Line.prototype.drawSeries = function() {
+ var c, circle, coords, i, path, _i, _j, _ref, _ref1, _results;
+ for (i = _i = _ref = this.seriesCoords.length - 1; _ref <= 0 ? _i <= 0 : _i >= 0; i = _ref <= 0 ? ++_i : --_i) {
+ coords = $.map(this.seriesCoords[i], function(c) {
+ return c;
+ });
+ if (coords.length > 1) {
+ path = this.createPath(coords, this.options.marginTop, this.left, this.options.marginTop + this.height, this.left + this.width);
+ this.r.path(path).attr('stroke', this.options.lineColors[i]).attr('stroke-width', this.options.lineWidth);
+ }
+ }
+ this.seriesPoints = (function() {
+ var _j, _ref1, _results;
+ _results = [];
+ for (i = _j = 0, _ref1 = this.seriesCoords.length - 1; 0 <= _ref1 ? _j <= _ref1 : _j >= _ref1; i = 0 <= _ref1 ? ++_j : --_j) {
+ _results.push([]);
+ }
+ return _results;
+ }).call(this);
+ _results = [];
+ for (i = _j = _ref1 = this.seriesCoords.length - 1; _ref1 <= 0 ? _j <= 0 : _j >= 0; i = _ref1 <= 0 ? ++_j : --_j) {
+ _results.push((function() {
+ var _k, _len, _ref2, _results1;
+ _ref2 = this.seriesCoords[i];
+ _results1 = [];
+ for (_k = 0, _len = _ref2.length; _k < _len; _k++) {
+ c = _ref2[_k];
+ if (c === null) {
+ circle = null;
+ } else {
+ circle = this.r.circle(c.x, c.y, this.options.pointSize).attr('fill', this.options.lineColors[i]).attr('stroke-width', 1).attr('stroke', '#ffffff');
+ }
+ _results1.push(this.seriesPoints[i].push(circle));
+ }
+ return _results1;
+ }).call(this));
+ }
+ return _results;
+ };
+
+ Line.prototype.createPath = function(coords, top, left, bottom, right) {
+ var c, g, grads, i, ix, lc, lg, path, x1, x2, y1, y2, _i, _ref;
+ path = "";
+ if (this.options.smooth) {
+ grads = this.gradients(coords);
+ for (i = _i = 0, _ref = coords.length - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; i = 0 <= _ref ? ++_i : --_i) {
+ c = coords[i];
+ if (i === 0) {
+ path += "M" + c.x + "," + c.y;
+ } else {
+ g = grads[i];
+ lc = coords[i - 1];
+ lg = grads[i - 1];
+ ix = (c.x - lc.x) / 4;
+ x1 = lc.x + ix;
+ y1 = Math.min(bottom, lc.y + ix * lg);
+ x2 = c.x - ix;
+ y2 = Math.min(bottom, c.y - ix * g);
+ path += "C" + x1 + "," + y1 + "," + x2 + "," + y2 + "," + c.x + "," + c.y;
+ }
+ }
+ } else {
+ path = "M" + $.map(coords, function(c) {
+ return "" + c.x + "," + c.y;
+ }).join("L");
+ }
+ return path;
+ };
+
+ Line.prototype.gradients = function(coords) {
+ return $.map(coords, function(c, i) {
+ if (i === 0) {
+ return (coords[1].y - c.y) / (coords[1].x - c.x);
+ } else if (i === (coords.length - 1)) {
+ return (c.y - coords[i - 1].y) / (c.x - coords[i - 1].x);
+ } else {
+ return (coords[i + 1].y - coords[i - 1].y) / (coords[i + 1].x - coords[i - 1].x);
+ }
+ });
+ };
+
+ Line.prototype.drawHover = function() {
+ var i, yLabel, _i, _ref, _results;
+ this.hoverHeight = this.options.hoverFontSize * 1.5 * (this.series.length + 1);
+ this.hover = this.r.rect(-10, -this.hoverHeight / 2 - this.options.hoverPaddingY, 20, this.hoverHeight + this.options.hoverPaddingY * 2, 10).attr('fill', this.options.hoverFillColor).attr('stroke', this.options.hoverBorderColor).attr('stroke-width', this.options.hoverBorderWidth).attr('opacity', this.options.hoverOpacity);
+ this.xLabel = this.r.text(0, (this.options.hoverFontSize * 0.75) - this.hoverHeight / 2, '').attr('fill', this.options.hoverLabelColor).attr('font-weight', 'bold').attr('font-size', this.options.hoverFontSize);
+ this.hoverSet = this.r.set();
+ this.hoverSet.push(this.hover);
+ this.hoverSet.push(this.xLabel);
+ this.yLabels = [];
+ _results = [];
+ for (i = _i = 0, _ref = this.series.length - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; i = 0 <= _ref ? ++_i : --_i) {
+ yLabel = this.r.text(0, this.options.hoverFontSize * 1.5 * (i + 1.5) - this.hoverHeight / 2, '').attr('fill', this.options.lineColors[i]).attr('font-size', this.options.hoverFontSize);
+ this.yLabels.push(yLabel);
+ _results.push(this.hoverSet.push(yLabel));
+ }
+ return _results;
+ };
+
+ Line.prototype.updateHover = function(index) {
+ var i, maxLabelWidth, xloc, yloc, _i, _ref,
+ _this = this;
+ this.hoverSet.show();
+ this.xLabel.attr('text', this.columnLabels[index]);
+ for (i = _i = 0, _ref = this.series.length - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; i = 0 <= _ref ? ++_i : --_i) {
+ this.yLabels[i].attr('text', "" + this.seriesLabels[i] + ": " + (this.yLabelFormat(this.series[i][index])));
+ }
+ maxLabelWidth = Math.max.apply(null, $.map(this.yLabels, function(l) {
+ return l.getBBox().width;
+ }));
+ maxLabelWidth = Math.max(maxLabelWidth, this.xLabel.getBBox().width);
+ this.hover.attr('width', maxLabelWidth + this.options.hoverPaddingX * 2);
+ this.hover.attr('x', -this.options.hoverPaddingX - maxLabelWidth / 2);
+ yloc = Math.min.apply(null, $.map(this.series, function(s) {
+ return _this.transY(s[index]);
+ }));
+ if (yloc > this.hoverHeight + this.options.hoverPaddingY * 2 + this.options.hoverMargin + this.options.marginTop) {
+ yloc = yloc - this.hoverHeight / 2 - this.options.hoverPaddingY - this.options.hoverMargin;
+ } else {
+ yloc = yloc + this.hoverHeight / 2 + this.options.hoverPaddingY + this.options.hoverMargin;
+ }
+ yloc = Math.max(this.options.marginTop + this.hoverHeight / 2 + this.options.hoverPaddingY, yloc);
+ yloc = Math.min(this.options.marginTop + this.height - this.hoverHeight / 2 - this.options.hoverPaddingY, yloc);
+ xloc = Math.min(this.left + this.width - maxLabelWidth / 2 - this.options.hoverPaddingX, this.columns[index]);
+ xloc = Math.max(this.left + maxLabelWidth / 2 + this.options.hoverPaddingX, xloc);
+ return this.hoverSet.attr('transform', "t" + xloc + "," + yloc);
+ };
+
+ Line.prototype.hideHover = function() {
+ return this.hoverSet.hide();
+ };
+
+ Line.prototype.hilight = function(index) {
+ var i, _i, _j, _ref, _ref1;
+ if (this.prevHilight !== null && this.prevHilight !== index) {
+ for (i = _i = 0, _ref = this.seriesPoints.length - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; i = 0 <= _ref ? ++_i : --_i) {
+ if (this.seriesPoints[i][this.prevHilight]) {
+ this.seriesPoints[i][this.prevHilight].animate(this.pointShrink);
+ }
+ }
+ }
+ if (index !== null && this.prevHilight !== index) {
+ for (i = _j = 0, _ref1 = this.seriesPoints.length - 1; 0 <= _ref1 ? _j <= _ref1 : _j >= _ref1; i = 0 <= _ref1 ? ++_j : --_j) {
+ if (this.seriesPoints[i][index]) {
+ this.seriesPoints[i][index].animate(this.pointGrow);
+ }
+ }
+ this.updateHover(index);
+ }
+ this.prevHilight = index;
+ if (index === null) {
+ return this.hideHover();
+ }
+ };
+
+ Line.prototype.updateHilight = function(x) {
+ var hoverIndex, _i, _ref, _results;
+ x -= this.el.offset().left;
+ _results = [];
+ for (hoverIndex = _i = _ref = this.hoverMargins.length; _ref <= 0 ? _i <= 0 : _i >= 0; hoverIndex = _ref <= 0 ? ++_i : --_i) {
+ if (hoverIndex === 0 || this.hoverMargins[hoverIndex - 1] > x) {
+ this.hilight(hoverIndex);
+ break;
+ } else {
+ _results.push(void 0);
+ }
+ }
+ return _results;
+ };
+
+ Line.prototype.measureText = function(text, fontSize) {
+ var ret, tt;
+ if (fontSize == null) {
+ fontSize = 12;
+ }
+ tt = this.r.text(100, 100, text).attr('font-size', fontSize);
+ ret = tt.getBBox();
+ tt.remove();
+ return ret;
+ };
+
+ Line.prototype.yLabelFormat = function(label) {
+ return "" + this.options.preUnits + (Morris.commas(label)) + this.options.postUnits;
+ };
+
+ return Line;
+
+ })();
+
+ Morris.parseDate = function(date) {
+ var isecs, m, msecs, n, o, offsetmins, p, q, r, ret, secs;
+ if (typeof date === 'number') {
+ return date;
+ }
+ m = date.match(/^(\d+) Q(\d)$/);
+ n = date.match(/^(\d+)-(\d+)$/);
+ o = date.match(/^(\d+)-(\d+)-(\d+)$/);
+ p = date.match(/^(\d+) W(\d+)$/);
+ q = date.match(/^(\d+)-(\d+)-(\d+)[ T](\d+):(\d+)(Z|([+-])(\d\d):?(\d\d))?$/);
+ r = date.match(/^(\d+)-(\d+)-(\d+)[ T](\d+):(\d+):(\d+(\.\d+)?)(Z|([+-])(\d\d):?(\d\d))?$/);
+ if (m) {
+ return new Date(parseInt(m[1], 10), parseInt(m[2], 10) * 3 - 1, 1).getTime();
+ } else if (n) {
+ return new Date(parseInt(n[1], 10), parseInt(n[2], 10) - 1, 1).getTime();
+ } else if (o) {
+ return new Date(parseInt(o[1], 10), parseInt(o[2], 10) - 1, parseInt(o[3], 10)).getTime();
+ } else if (p) {
+ ret = new Date(parseInt(p[1], 10), 0, 1);
+ if (ret.getDay() !== 4) {
+ ret.setMonth(0, 1 + ((4 - ret.getDay()) + 7) % 7);
+ }
+ return ret.getTime() + parseInt(p[2], 10) * 604800000;
+ } else if (q) {
+ if (!q[6]) {
+ return new Date(parseInt(q[1], 10), parseInt(q[2], 10) - 1, parseInt(q[3], 10), parseInt(q[4], 10), parseInt(q[5], 10)).getTime();
+ } else {
+ offsetmins = 0;
+ if (q[6] !== 'Z') {
+ offsetmins = parseInt(q[8], 10) * 60 + parseInt(q[9], 10);
+ if (q[7] === '+') {
+ offsetmins = 0 - offsetmins;
+ }
+ }
+ return Date.UTC(parseInt(q[1], 10), parseInt(q[2], 10) - 1, parseInt(q[3], 10), parseInt(q[4], 10), parseInt(q[5], 10) + offsetmins);
+ }
+ } else if (r) {
+ secs = parseFloat(r[6]);
+ isecs = Math.floor(secs);
+ msecs = Math.round((secs - isecs) * 1000);
+ if (!r[8]) {
+ return new Date(parseInt(r[1], 10), parseInt(r[2], 10) - 1, parseInt(r[3], 10), parseInt(r[4], 10), parseInt(r[5], 10), isecs, msecs).getTime();
+ } else {
+ offsetmins = 0;
+ if (r[8] !== 'Z') {
+ offsetmins = parseInt(r[10], 10) * 60 + parseInt(r[11], 10);
+ if (r[9] === '+') {
+ offsetmins = 0 - offsetmins;
+ }
+ }
+ return Date.UTC(parseInt(r[1], 10), parseInt(r[2], 10) - 1, parseInt(r[3], 10), parseInt(r[4], 10), parseInt(r[5], 10) + offsetmins, isecs, msecs);
+ }
+ } else {
+ return new Date(parseInt(date, 10), 0, 1).getTime();
+ }
+ };
+
+ Morris.labelSeries = function(dmin, dmax, pxwidth, specName, xLabelFormat) {
+ var d, d0, ddensity, name, ret, s, spec, t, _i, _len, _ref;
+ ddensity = 200 * (dmax - dmin) / pxwidth;
+ d0 = new Date(dmin);
+ spec = Morris.LABEL_SPECS[specName];
+ if (spec === void 0) {
+ _ref = Morris.AUTO_LABEL_ORDER;
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ name = _ref[_i];
+ s = Morris.LABEL_SPECS[name];
+ if (ddensity >= s.span) {
+ spec = s;
+ break;
+ }
+ }
+ }
+ if (spec === void 0) {
+ spec = Morris.LABEL_SPECS["second"];
+ }
+ if (xLabelFormat) {
+ spec = $.extend({}, spec, {
+ fmt: xLabelFormat
+ });
+ }
+ d = spec.start(d0);
+ ret = [];
+ while ((t = d.getTime()) <= dmax) {
+ if (t >= dmin) {
+ ret.push([spec.fmt(d), t]);
+ }
+ spec.incr(d);
+ }
+ return ret;
+ };
+
+ minutesSpecHelper = function(interval) {
+ return {
+ span: interval * 60 * 1000,
+ start: function(d) {
+ return new Date(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours());
+ },
+ fmt: function(d) {
+ return "" + (Morris.pad2(d.getHours())) + ":" + (Morris.pad2(d.getMinutes()));
+ },
+ incr: function(d) {
+ return d.setMinutes(d.getMinutes() + interval);
+ }
+ };
+ };
+
+ secondsSpecHelper = function(interval) {
+ return {
+ span: interval * 1000,
+ start: function(d) {
+ return new Date(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), d.getMinutes());
+ },
+ fmt: function(d) {
+ return "" + (Morris.pad2(d.getHours())) + ":" + (Morris.pad2(d.getMinutes())) + ":" + (Morris.pad2(d.getSeconds()));
+ },
+ incr: function(d) {
+ return d.setSeconds(d.getSeconds() + interval);
+ }
+ };
+ };
+
+ Morris.LABEL_SPECS = {
+ "year": {
+ span: 17280000000,
+ start: function(d) {
+ return new Date(d.getFullYear(), 0, 1);
+ },
+ fmt: function(d) {
+ return "" + (d.getFullYear());
+ },
+ incr: function(d) {
+ return d.setFullYear(d.getFullYear() + 1);
+ }
+ },
+ "month": {
+ span: 2419200000,
+ start: function(d) {
+ return new Date(d.getFullYear(), d.getMonth(), 1);
+ },
+ fmt: function(d) {
+ return "" + (d.getFullYear()) + "-" + (Morris.pad2(d.getMonth() + 1));
+ },
+ incr: function(d) {
+ return d.setMonth(d.getMonth() + 1);
+ }
+ },
+ "day": {
+ span: 86400000,
+ start: function(d) {
+ return new Date(d.getFullYear(), d.getMonth(), d.getDate());
+ },
+ fmt: function(d) {
+ return "" + (d.getFullYear()) + "-" + (Morris.pad2(d.getMonth() + 1)) + "-" + (Morris.pad2(d.getDate()));
+ },
+ incr: function(d) {
+ return d.setDate(d.getDate() + 1);
+ }
+ },
+ "hour":