Commit f54ae5f3656f7adab6a06421a0dc29fc281f0e25

Authored by Guilherme Rojas V. de Lima
Committed by Rafael Manzo
1 parent 0980581e

Chart generated using ajax.

pending: tests for module_result_controller; find a way to send the all the data required to generate chart using just one json parameter; configurate the highchart to show gridlines.
app/assets/javascripts/graphics.js
1 -function chart_of_the_historic_of_metric (container_id, metric_name, module_name, date_list, metric_values_list) 1 +function chart_of_the_historic_of_metric (json_params, dinamic_values)
2 { 2 {
3 - date_list = date_list.split(',');  
4 - metric_values_list = metric_values_list.split(',');  
5 - for(var i = 0; i < metric_values_list.length; i++) {  
6 - metric_values_list[i] = parseInt(metric_values_list[i]);  
7 - }  
8 - $('#tr_container_' + container_id).hide(); 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'];
9 8
  9 + $('#tr_container_' + container_id).hide();
10 $(function () { 10 $(function () {
11 $('#container_'+container_id).highcharts({ 11 $('#container_'+container_id).highcharts({
  12 + chart: {
  13 + marginBottom: 80
  14 + },
12 title: { 15 title: {
13 text: metric_name, 16 text: metric_name,
14 x: -20 //center 17 x: -20 //center
@@ -18,27 +21,26 @@ function chart_of_the_historic_of_metric (container_id, metric_name, module_name @@ -18,27 +21,26 @@ function chart_of_the_historic_of_metric (container_id, metric_name, module_name
18 x: -20 21 x: -20
19 }, 22 },
20 xAxis: { 23 xAxis: {
21 - categories: date_list 24 + categories: dates
22 }, 25 },
23 yAxis: { 26 yAxis: {
24 title: { 27 title: {
25 text: 'Value' 28 text: 'Value'
26 }, 29 },
27 - plotLines: [{  
28 - value: 0,  
29 - width: 1,  
30 - color: '#808080'  
31 - }] 30 + labels: {
  31 + align: 'left',
  32 + x: 0,
  33 + y: -2
32 }, 34 },
33 - legend: {  
34 - layout: 'vertical',  
35 - align: 'right',  
36 - verticalAlign: 'middle',  
37 - borderWidth: 0 35 + plotLines: [{
  36 + value: 0,
  37 + width: 1,
  38 + color: '#808080'
  39 + }]
38 }, 40 },
39 series: [{ 41 series: [{
40 name: 'Metric value', 42 name: 'Metric value',
41 - data: metric_values_list 43 + data: metric_values
42 }] 44 }]
43 }); 45 });
44 }); 46 });
app/controllers/modules_controller.rb
@@ -3,7 +3,15 @@ class ModulesController &lt; ApplicationController @@ -3,7 +3,15 @@ class ModulesController &lt; ApplicationController
3 3
4 # GET /modules/metric_history 4 # GET /modules/metric_history
5 def metric_history 5 def metric_history
6 - render :json => {mk: "monkey"}.to_json 6 + module_result = ModuleResult.new({ id: params[:module_id] })
  7 + metric_history = module_result.metric_history(params[:metric_name]) # pending: sort this hash.
  8 + dates = Array.new
  9 + values = Array.new
  10 + metric_history.keys.each do |date|
  11 + dates.push date
  12 + values.push metric_history[date]
  13 + end
  14 + render :json => {dates: dates, values: values}.to_json
7 end 15 end
8 16
9 end 17 end
10 \ No newline at end of file 18 \ No newline at end of file
app/views/repositories/_metric_result.html.erb
1 <% metric_configuration_snapshot = metric_result.metric_configuration_snapshot %> 1 <% metric_configuration_snapshot = metric_result.metric_configuration_snapshot %>
2 <% unless metric_configuration_snapshot.range_snapshot.nil? %> 2 <% unless metric_configuration_snapshot.range_snapshot.nil? %>
3 - <% range_snapshot = find_range_snapshot(metric_result) %> 3 + <% range_snapshot = find_range_snapshot(metric_result)
  4 + metric_name = metric_configuration_snapshot.metric.name
  5 + %>
4 <tr> 6 <tr>
5 - <td><%= link_to metric_configuration_snapshot.metric.name, "#metric_#{module_result.id}",  
6 - onclick: "$.get('/modules/metric_history', function( data ) { alert( data['mk'] ); });", 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 + });",
7 id: "metric_#{module_result.id}", 15 id: "metric_#{module_result.id}",
8 remote: true %></td> 16 remote: true %></td>
9 <td><%= format_grade(metric_result.value) %></td> 17 <td><%= format_grade(metric_result.value) %></td>