From f54ae5f3656f7adab6a06421a0dc29fc281f0e25 Mon Sep 17 00:00:00 2001 From: Guilherme Rojas V. de Lima Date: Mon, 11 Nov 2013 20:46:52 -0200 Subject: [PATCH] Chart generated using ajax. --- app/assets/javascripts/graphics.js | 40 +++++++++++++++++++++------------------- app/controllers/modules_controller.rb | 10 +++++++++- app/views/repositories/_metric_result.html.erb | 14 +++++++++++--- 3 files changed, 41 insertions(+), 23 deletions(-) diff --git a/app/assets/javascripts/graphics.js b/app/assets/javascripts/graphics.js index 240392c..0433b2d 100644 --- a/app/assets/javascripts/graphics.js +++ b/app/assets/javascripts/graphics.js @@ -1,14 +1,17 @@ -function chart_of_the_historic_of_metric (container_id, metric_name, module_name, date_list, metric_values_list) +function chart_of_the_historic_of_metric (json_params, dinamic_values) { - date_list = date_list.split(','); - metric_values_list = metric_values_list.split(','); - for(var i = 0; i < metric_values_list.length; i++) { - metric_values_list[i] = parseInt(metric_values_list[i]); - } - $('#tr_container_' + container_id).hide(); + container_id = json_params['container_id']; + metric_name = json_params['metric_name']; + module_name = json_params['module_name']; + dates = dinamic_values['dates']; + metric_values = dinamic_values['values']; + $('#tr_container_' + container_id).hide(); $(function () { $('#container_'+container_id).highcharts({ + chart: { + marginBottom: 80 + }, title: { text: metric_name, x: -20 //center @@ -18,27 +21,26 @@ function chart_of_the_historic_of_metric (container_id, metric_name, module_name x: -20 }, xAxis: { - categories: date_list + categories: dates }, yAxis: { title: { text: 'Value' }, - plotLines: [{ - value: 0, - width: 1, - color: '#808080' - }] + labels: { + align: 'left', + x: 0, + y: -2 }, - legend: { - layout: 'vertical', - align: 'right', - verticalAlign: 'middle', - borderWidth: 0 + plotLines: [{ + value: 0, + width: 1, + color: '#808080' + }] }, series: [{ name: 'Metric value', - data: metric_values_list + data: metric_values }] }); }); diff --git a/app/controllers/modules_controller.rb b/app/controllers/modules_controller.rb index cb5c101..f931d8a 100644 --- a/app/controllers/modules_controller.rb +++ b/app/controllers/modules_controller.rb @@ -3,7 +3,15 @@ class ModulesController < ApplicationController # GET /modules/metric_history def metric_history - render :json => {mk: "monkey"}.to_json + module_result = ModuleResult.new({ id: params[:module_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 + render :json => {dates: dates, values: values}.to_json end end \ No newline at end of file diff --git a/app/views/repositories/_metric_result.html.erb b/app/views/repositories/_metric_result.html.erb index b590fea..b50d9da 100644 --- a/app/views/repositories/_metric_result.html.erb +++ b/app/views/repositories/_metric_result.html.erb @@ -1,9 +1,17 @@ <% metric_configuration_snapshot = metric_result.metric_configuration_snapshot %> <% unless metric_configuration_snapshot.range_snapshot.nil? %> - <% range_snapshot = find_range_snapshot(metric_result) %> + <% range_snapshot = find_range_snapshot(metric_result) + metric_name = metric_configuration_snapshot.metric.name + %> - <%= link_to metric_configuration_snapshot.metric.name, "#metric_#{module_result.id}", - onclick: "$.get('/modules/metric_history', function( data ) { alert( data['mk'] ); });", + <%= link_to metric_name, "#metric_#{module_result.id}", + onclick: "$.get('/modules/metric_history', + { metric_name: \"#{metric_name}\", + module_id: \"#{module_result.id}\"} + ).done(function( data ) { + json_params = JSON.parse('{\"container_id\": \"#{metric_result.id}\", \"metric_name\": \"#{metric_name}\", \"module_name\": \"#{module_result.module.name}\"}'); + chart_of_the_historic_of_metric (json_params, data); + });", id: "metric_#{module_result.id}", remote: true %> <%= format_grade(metric_result.value) %> -- libgit2 0.21.2