Commit 39b737871f139fa0ee63818c6cdf1763756b41be
1 parent
17ee9571
Exists in
colab
and in
4 other branches
Highcharts replaced by Gruff due to license incompability
Still need to work on the layout
Showing
9 changed files
with
63 additions
and
65 deletions
Show diff stats
Gemfile
@@ -45,6 +45,9 @@ gem "pg", "~> 0.17.0" | @@ -45,6 +45,9 @@ gem "pg", "~> 0.17.0" | ||
45 | # Twitter Bootstrap for layout | 45 | # Twitter Bootstrap for layout |
46 | gem "twitter-bootstrap-rails", "~> 2.2.8" | 46 | gem "twitter-bootstrap-rails", "~> 2.2.8" |
47 | 47 | ||
48 | +# Chart generation | ||
49 | +gem "gruff", "~> 0.5.1" | ||
50 | + | ||
48 | group :doc do | 51 | group :doc do |
49 | # bundle exec rake doc:rails generates the API under doc/api. | 52 | # bundle exec rake doc:rails generates the API under doc/api. |
50 | gem 'sdoc', require: false | 53 | gem 'sdoc', require: false |
Gemfile.lock
@@ -88,6 +88,8 @@ GEM | @@ -88,6 +88,8 @@ GEM | ||
88 | railties (>= 3.0.0) | 88 | railties (>= 3.0.0) |
89 | gherkin (2.12.2) | 89 | gherkin (2.12.2) |
90 | multi_json (~> 1.3) | 90 | multi_json (~> 1.3) |
91 | + gruff (0.5.1) | ||
92 | + rmagick | ||
91 | gyoku (1.1.0) | 93 | gyoku (1.1.0) |
92 | builder (>= 2.1.2) | 94 | builder (>= 2.1.2) |
93 | highline (1.6.20) | 95 | highline (1.6.20) |
@@ -165,6 +167,7 @@ GEM | @@ -165,6 +167,7 @@ GEM | ||
165 | ref (1.0.5) | 167 | ref (1.0.5) |
166 | rest-client (1.6.7) | 168 | rest-client (1.6.7) |
167 | mime-types (>= 1.16) | 169 | mime-types (>= 1.16) |
170 | + rmagick (2.13.2) | ||
168 | rspec-core (2.14.7) | 171 | rspec-core (2.14.7) |
169 | rspec-expectations (2.14.4) | 172 | rspec-expectations (2.14.4) |
170 | diff-lcs (>= 1.1.3, < 2.0) | 173 | diff-lcs (>= 1.1.3, < 2.0) |
@@ -257,6 +260,7 @@ DEPENDENCIES | @@ -257,6 +260,7 @@ DEPENDENCIES | ||
257 | database_cleaner | 260 | database_cleaner |
258 | devise (~> 3.2.0) | 261 | devise (~> 3.2.0) |
259 | factory_girl_rails (~> 4.3.0) | 262 | factory_girl_rails (~> 4.3.0) |
263 | + gruff (~> 0.5.1) | ||
260 | jbuilder (~> 1.2) | 264 | jbuilder (~> 1.2) |
261 | jquery-rails | 265 | jquery-rails |
262 | kalibro_entities (~> 0.0.1.rc6) | 266 | kalibro_entities (~> 0.0.1.rc6) |
README.rdoc
@@ -12,7 +12,7 @@ platform with Mezuro Plugin actived to access Kalibro Web Service. | @@ -12,7 +12,7 @@ platform with Mezuro Plugin actived to access Kalibro Web Service. | ||
12 | 3. <tt>cap deploy:setup</tt> will install the ruby correct ruby version, the gemset and all the directories tree; | 12 | 3. <tt>cap deploy:setup</tt> will install the ruby correct ruby version, the gemset and all the directories tree; |
13 | 4. <tt>cap deploy:migrations</tt> deploys the code and run all the migrations | 13 | 4. <tt>cap deploy:migrations</tt> deploys the code and run all the migrations |
14 | 14 | ||
15 | -* System dependencies | 15 | +* System dependencies (Ubuntu package names) |
16 | 16 | ||
17 | * build-essential | 17 | * build-essential |
18 | 18 | ||
@@ -28,6 +28,12 @@ platform with Mezuro Plugin actived to access Kalibro Web Service. | @@ -28,6 +28,12 @@ platform with Mezuro Plugin actived to access Kalibro Web Service. | ||
28 | 28 | ||
29 | * PhantomJS 1.9.1 (http://phantomjs.org/) | 29 | * PhantomJS 1.9.1 (http://phantomjs.org/) |
30 | 30 | ||
31 | + * imagemagick | ||
32 | + | ||
33 | + * libmagickcore-dev | ||
34 | + | ||
35 | + * libmagickwand-dev | ||
36 | + | ||
31 | * Ruby version | 37 | * Ruby version |
32 | 38 | ||
33 | 2.0.0-p247 | 39 | 2.0.0-p247 |
673 Bytes
app/assets/javascripts/graphics.js
@@ -1,51 +0,0 @@ | @@ -1,51 +0,0 @@ | ||
1 | -function chart_of_the_historic_of_metric (json_params, dinamic_values) | ||
2 | -{ | ||
3 | - container_id = json_params['container_id']; | ||
4 | - metric_name = json_params['metric_name']; | ||
5 | - module_name = json_params['module_name']; | ||
6 | - dates = dinamic_values['dates']; | ||
7 | - metric_values = dinamic_values['values']; | ||
8 | - | ||
9 | - $('#tr_container_' + container_id).hide(); | ||
10 | - $(function () { | ||
11 | - $('#container_'+container_id).highcharts({ | ||
12 | - chart: { | ||
13 | - marginBottom: 80, | ||
14 | - width: 600, | ||
15 | - style: {margin: '0 auto'} | ||
16 | - }, | ||
17 | - title: { | ||
18 | - text: metric_name, | ||
19 | - x: -20 //center | ||
20 | - }, | ||
21 | - subtitle: { | ||
22 | - text: module_name, | ||
23 | - x: -20 | ||
24 | - }, | ||
25 | - xAxis: { | ||
26 | - categories: dates | ||
27 | - }, | ||
28 | - yAxis: { | ||
29 | - title: { | ||
30 | - text: 'Value' | ||
31 | - }, | ||
32 | - labels: { | ||
33 | - align: 'left', | ||
34 | - x: 0, | ||
35 | - y: -2 | ||
36 | - }, | ||
37 | - plotLines: [{ | ||
38 | - value: 0, | ||
39 | - width: 1, | ||
40 | - color: '#808080' | ||
41 | - }] | ||
42 | - }, | ||
43 | - series: [{ | ||
44 | - name: 'Metric value', | ||
45 | - data: metric_values | ||
46 | - }] | ||
47 | - }); | ||
48 | - }); | ||
49 | - | ||
50 | - $('#tr_container_' + container_id).show("slow"); | ||
51 | -} | ||
52 | \ No newline at end of file | 0 | \ No newline at end of file |
@@ -0,0 +1,21 @@ | @@ -0,0 +1,21 @@ | ||
1 | +@Module = { } | ||
2 | + | ||
3 | +class Module.Graphic | ||
4 | + constructor: (@container, @metric_name, @module_id) -> | ||
5 | + $('tr#'+@container).slideDown('slow') | ||
6 | + this.load() | ||
7 | + | ||
8 | + load: -> | ||
9 | + # Those two var are necessary so the jQuery callback can use them | ||
10 | + # Otherwise the scope of the callback function is isolated | ||
11 | + container = @container | ||
12 | + display = this.display | ||
13 | + | ||
14 | + $.get '/modules/metric_history', | ||
15 | + metric_name: @metric_name | ||
16 | + module_id: @module_id | ||
17 | + (data) -> | ||
18 | + display(data,container) | ||
19 | + | ||
20 | + display: (data, container) -> | ||
21 | + $('div#'+container).html('<img src="data:image/png;base64,' + data + '" />') |
app/controllers/modules_controller.rb
1 | -require 'json' | ||
2 | class ModulesController < ApplicationController | 1 | class ModulesController < ApplicationController |
3 | 2 | ||
4 | # GET /modules/metric_history | 3 | # GET /modules/metric_history |
@@ -11,7 +10,25 @@ class ModulesController < ApplicationController | @@ -11,7 +10,25 @@ class ModulesController < ApplicationController | ||
11 | dates.push date | 10 | dates.push date |
12 | values.push metric_history[date] | 11 | values.push metric_history[date] |
13 | end | 12 | end |
14 | - render :json => {dates: dates, values: values}.to_json | 13 | + |
14 | + send_data(Base64.encode64(graphic_for(values, dates)), type: 'image/png', filename: "#{params[:module_id]}-#{params[:metric_name]}.png") | ||
15 | + end | ||
16 | + | ||
17 | + private | ||
18 | + | ||
19 | + def graphic_for(values, dates) | ||
20 | + graphic = Gruff::Line.new(400) | ||
21 | + graphic.hide_title = true | ||
22 | + graphic.hide_legend = true | ||
23 | + graphic.theme = { | ||
24 | + :background_colors => 'transparent' | ||
25 | + } | ||
26 | + | ||
27 | + graphic.labels = Hash[dates.each_with_index.map{ |date, index| [index, date.to_s]}] | ||
28 | + | ||
29 | + graphic.data('Values', values) | ||
30 | + | ||
31 | + graphic.to_blob | ||
15 | end | 32 | end |
16 | 33 | ||
17 | end | 34 | end |
18 | \ No newline at end of file | 35 | \ No newline at end of file |
app/views/repositories/_metric_result.html.erb
@@ -5,22 +5,17 @@ | @@ -5,22 +5,17 @@ | ||
5 | %> | 5 | %> |
6 | <tr> | 6 | <tr> |
7 | <td><%= link_to metric_name, "#metric_#{module_result.id}", | 7 | <td><%= link_to metric_name, "#metric_#{module_result.id}", |
8 | - onclick: "$.get('/modules/metric_history', | ||
9 | - { metric_name: \"#{metric_name}\", | ||
10 | - module_id: \"#{module_result.id}\"} | ||
11 | - ).done(function( data ) { | ||
12 | - json_params = JSON.parse('{\"container_id\": \"#{metric_result.id}\", \"metric_name\": \"#{metric_name}\", \"module_name\": \"#{module_result.module.name}\"}'); | ||
13 | - chart_of_the_historic_of_metric (json_params, data); | ||
14 | - });", | ||
15 | - id: "metric_#{module_result.id}", | ||
16 | - remote: true %></td> | 8 | + onclick: "new Module.Graphic('container#{metric_result.id}', '#{metric_name}', '#{module_result.id}')", |
9 | + id: "metric_#{module_result.id}", | ||
10 | + remote: true %> | ||
11 | + </td> | ||
17 | <td><%= format_grade(metric_result.value) %></td> | 12 | <td><%= format_grade(metric_result.value) %></td> |
18 | <td><%= metric_configuration_snapshot.weight %></td> | 13 | <td><%= metric_configuration_snapshot.weight %></td> |
19 | <td><span style="color: #<%= range_snapshot.color %>"><%= range_snapshot.label %></span></td> | 14 | <td><span style="color: #<%= range_snapshot.color %>"><%= range_snapshot.label %></span></td> |
20 | </tr> | 15 | </tr> |
21 | - <tr id="tr_container_<%= metric_result.id %>" style="display: none"> | 16 | + <tr id="container<%= metric_result.id %>" style="display: none"> |
22 | <td colspan="4"> | 17 | <td colspan="4"> |
23 | - <div id="container_<%= metric_result.id %>"></div> | 18 | + <div id="container<%= metric_result.id %>" class="graphic_container"><%= image_tag 'loader.gif' %> Loading data. Please, wait.</div> |
24 | </td> | 19 | </td> |
25 | </tr> | 20 | </tr> |
26 | <% end %> | 21 | <% end %> |
27 | \ No newline at end of file | 22 | \ No newline at end of file |