diff --git a/Gemfile b/Gemfile
index 11d744b..f5f28d0 100644
--- a/Gemfile
+++ b/Gemfile
@@ -43,7 +43,7 @@ gem "pg", "~> 0.17.0"
gem "twitter-bootstrap-rails", "~> 2.2.8"
# Chart generation
-gem "gruff", "~> 0.5.1"
+gem "chart-js-rails", "~> 0.0.6"
# JQueryUI
gem 'jquery-ui-rails', '~> 4.1.0'
diff --git a/Gemfile.lock b/Gemfile.lock
index bef8c32..966fa43 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -58,6 +58,8 @@ GEM
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (~> 2.0)
+ chart-js-rails (0.0.6)
+ railties (> 3.1)
cliver (0.3.2)
coderay (1.1.0)
coffee-rails (4.0.1)
@@ -104,8 +106,6 @@ GEM
railties (>= 3.0.0)
gherkin (2.12.2)
multi_json (~> 1.3)
- gruff (0.5.1)
- rmagick
gyoku (1.1.1)
builder (>= 2.1.2)
hike (1.2.3)
@@ -180,7 +180,6 @@ GEM
ref (1.0.5)
rest-client (1.6.7)
mime-types (>= 1.16)
- rmagick (2.13.2)
rspec-core (2.14.7)
rspec-expectations (2.14.4)
diff-lcs (>= 1.1.3, < 2.0)
@@ -276,6 +275,7 @@ DEPENDENCIES
capistrano-bundler
capistrano-rails
capistrano-rvm (~> 0.1.0)
+ chart-js-rails (~> 0.0.6)
coffee-rails (~> 4.0.0)
coveralls
cucumber (~> 1.3.10)
@@ -283,7 +283,6 @@ DEPENDENCIES
database_cleaner
devise (~> 3.2.0)
factory_girl_rails (~> 4.3.0)
- gruff (~> 0.5.1)
jbuilder (~> 2.0.2)
jquery-rails
jquery-ui-rails (~> 4.1.0)
diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js
index 44bbd35..9daa0ce 100644
--- a/app/assets/javascripts/application.js
+++ b/app/assets/javascripts/application.js
@@ -16,4 +16,5 @@
//= require twitter/bootstrap
//= require turbolinks
//= require modules
+//= require Chart
//= require_tree .
diff --git a/app/assets/javascripts/module/graphic.js.coffee b/app/assets/javascripts/module/graphic.js.coffee
index c6c6b56..e89e5a3 100644
--- a/app/assets/javascripts/module/graphic.js.coffee
+++ b/app/assets/javascripts/module/graphic.js.coffee
@@ -4,15 +4,39 @@ class Module.Graphic
this.load()
load: ->
- # Those two var are necessary so the jQuery callback can use them
- # Otherwise the scope of the callback function is isolated
- container = @container
- display = this.display
+ $.post '/modules/' + @module_id + '/metric_history',
+ {
+ metric_name: @metric_name,
+ container: @container
+ }
- $.get '/modules/' + @module_id + '/metric_history',
- metric_name: @metric_name
- (data) ->
- display(data,container)
+ @display: (dates, values, container) ->
+ opts = {bezierCurve: false}
- display: (data, container) ->
- $('div#'+container).html('')
+ #FIXME: Until this gets fixed https://github.com/nnnick/Chart.js/issues/76 this if is necessary
+ min_value = Math.min.apply(null, values)
+ max_value = Math.max.apply(null, values)
+
+ if min_value == max_value
+ opts = {
+ bezierCurve: false,
+ scaleOverride: true,
+ scaleStartValue: (min_value - 2),
+ scaleSteps: 3,
+ scaleStepWidth: 1
+ }
+
+ data = {
+ labels : dates,
+ datasets : [
+ {
+ fillColor : "rgba(220,220,220,0.5)",
+ strokeColor : "rgba(220,220,220,1)",
+ pointColor : "rgba(220,220,220,1)",
+ pointStrokeColor : "#000",
+ data : values
+ }
+ ]
+ }
+
+ graphic = new Chart($('canvas#'+container).get(0).getContext("2d")).Line(data, opts)
diff --git a/app/controllers/modules_controller.rb b/app/controllers/modules_controller.rb
index 1f0ea5c..df03adb 100644
--- a/app/controllers/modules_controller.rb
+++ b/app/controllers/modules_controller.rb
@@ -1,41 +1,15 @@
class ModulesController < ApplicationController
- caches_action :metric_history, cache_path: Proc.new{"#{params[:id]}_#{params[:metric_name]}"}
+ #caches_action :metric_history, cache_path: Proc.new{"#{params[:id]}_#{params[:metric_name]}"}, expires_in: 1.day, layout: false
- # GET /modules/1/metric_history
+ # POST /modules/1/metric_history
def metric_history
module_result = ModuleResult.new({ id: params[:id] })
- metric_history = module_result.metric_history(params[:metric_name]) # pending: sort this hash.
- dates = Array.new
- values = Array.new
- metric_history.keys.each do |date|
- dates.push date
- values.push metric_history[date]
- end
-
- send_data(Base64.encode64(graphic_for(values, dates)), type: 'image/png', filename: "#{params[:module_id]}-#{params[:metric_name]}.png")
+ @container = params[:container]
+ @metric_history = module_result.metric_history(params[:metric_name]) # pending: sort this hash.
end
# POST /modules/1/tree
def load_module_tree
@root_module_result = ModuleResult.find(params[:id].to_i)
end
-
- private
-
- def graphic_for(values, dates)
- graphic = Gruff::Line.new(400)
- graphic.hide_title = true
- graphic.hide_legend = true
- graphic.theme = {
- colors: ['grey'],
- marker_color: 'black',
- background_colors: '#fff'
- }
-
- graphic.labels = Hash[dates.each_with_index.map{ |date, index| [index, date.strftime("%Y/%m/%d")]}]
-
- graphic.data('Values', values)
-
- graphic.to_blob
- end
end
\ No newline at end of file
diff --git a/app/views/modules/_metric_result.html.erb b/app/views/modules/_metric_result.html.erb
index 25c730b..920b9aa 100644
--- a/app/views/modules/_metric_result.html.erb
+++ b/app/views/modules/_metric_result.html.erb
@@ -15,7 +15,7 @@