Commit 39b737871f139fa0ee63818c6cdf1763756b41be

Authored by Rafael Manzo
1 parent 17ee9571

Highcharts replaced by Gruff due to license incompability

Still need to work on the layout
Gemfile
... ... @@ -45,6 +45,9 @@ gem "pg", "~> 0.17.0"
45 45 # Twitter Bootstrap for layout
46 46 gem "twitter-bootstrap-rails", "~> 2.2.8"
47 47  
  48 +# Chart generation
  49 +gem "gruff", "~> 0.5.1"
  50 +
48 51 group :doc do
49 52 # bundle exec rake doc:rails generates the API under doc/api.
50 53 gem 'sdoc', require: false
... ...
Gemfile.lock
... ... @@ -88,6 +88,8 @@ GEM
88 88 railties (>= 3.0.0)
89 89 gherkin (2.12.2)
90 90 multi_json (~> 1.3)
  91 + gruff (0.5.1)
  92 + rmagick
91 93 gyoku (1.1.0)
92 94 builder (>= 2.1.2)
93 95 highline (1.6.20)
... ... @@ -165,6 +167,7 @@ GEM
165 167 ref (1.0.5)
166 168 rest-client (1.6.7)
167 169 mime-types (>= 1.16)
  170 + rmagick (2.13.2)
168 171 rspec-core (2.14.7)
169 172 rspec-expectations (2.14.4)
170 173 diff-lcs (>= 1.1.3, < 2.0)
... ... @@ -257,6 +260,7 @@ DEPENDENCIES
257 260 database_cleaner
258 261 devise (~> 3.2.0)
259 262 factory_girl_rails (~> 4.3.0)
  263 + gruff (~> 0.5.1)
260 264 jbuilder (~> 1.2)
261 265 jquery-rails
262 266 kalibro_entities (~> 0.0.1.rc6)
... ...
README.rdoc
... ... @@ -12,7 +12,7 @@ platform with Mezuro Plugin actived to access Kalibro Web Service.
12 12 3. <tt>cap deploy:setup</tt> will install the ruby correct ruby version, the gemset and all the directories tree;
13 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 17 * build-essential
18 18  
... ... @@ -28,6 +28,12 @@ platform with Mezuro Plugin actived to access Kalibro Web Service.
28 28  
29 29 * PhantomJS 1.9.1 (http://phantomjs.org/)
30 30  
  31 + * imagemagick
  32 +
  33 + * libmagickcore-dev
  34 +
  35 + * libmagickwand-dev
  36 +
31 37 * Ruby version
32 38  
33 39 2.0.0-p247
... ...
app/assets/images/loader.gif 0 → 100644

673 Bytes

app/assets/javascripts/graphics.js
... ... @@ -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 0 \ No newline at end of file
app/assets/javascripts/module/graphic.js.coffee 0 → 100644
... ... @@ -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/assets/stylesheets/boilerplate/graphic.css 0 → 100644
... ... @@ -0,0 +1,3 @@
  1 +div.graphic_container {
  2 + text-align: center;
  3 +}
0 4 \ No newline at end of file
... ...
app/controllers/modules_controller.rb
1   -require 'json'
2 1 class ModulesController < ApplicationController
3 2  
4 3 # GET /modules/metric_history
... ... @@ -11,7 +10,25 @@ class ModulesController &lt; ApplicationController
11 10 dates.push date
12 11 values.push metric_history[date]
13 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 32 end
16 33  
17 34 end
18 35 \ No newline at end of file
... ...
app/views/repositories/_metric_result.html.erb
... ... @@ -5,22 +5,17 @@
5 5 %>
6 6 <tr>
7 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 12 <td><%= format_grade(metric_result.value) %></td>
18 13 <td><%= metric_configuration_snapshot.weight %></td>
19 14 <td><span style="color: #<%= range_snapshot.color %>"><%= range_snapshot.label %></span></td>
20 15 </tr>
21   - <tr id="tr_container_<%= metric_result.id %>" style="display: none">
  16 + <tr id="container<%= metric_result.id %>" style="display: none">
22 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 19 </td>
25 20 </tr>
26 21 <% end %>
27 22 \ No newline at end of file
... ...