Commit 8de19b7110c676af508d7950dde8eb678b9ab9b0

Authored by Guilherme Rojas V. de Lima
Committed by Rafael Manzo
1 parent 5d225698

Any metric links generate a sample graphic.

application.html.erb should include highcharts.js just in Repositories controller.

Signed-off By: Diego Araújo <diegoamc@gmail.com>
app/assets/javascripts/graphics.js 0 → 100644
... ... @@ -0,0 +1,44 @@
  1 +function generate_graphic(metric_name, module_name, date_list, metric_values_list)
  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 +
  9 + $(function () {
  10 + $('#container').highcharts({
  11 + title: {
  12 + text: metric_name,
  13 + x: -20 //center
  14 + },
  15 + subtitle: {
  16 + text: module_name,
  17 + x: -20
  18 + },
  19 + xAxis: {
  20 + categories: date_list
  21 + },
  22 + yAxis: {
  23 + title: {
  24 + text: 'Value'
  25 + },
  26 + plotLines: [{
  27 + value: 0,
  28 + width: 1,
  29 + color: '#808080'
  30 + }]
  31 + },
  32 + legend: {
  33 + layout: 'vertical',
  34 + align: 'right',
  35 + verticalAlign: 'middle',
  36 + borderWidth: 0
  37 + },
  38 + series: [{
  39 + name: 'Tokyo',
  40 + data: metric_values_list
  41 + }]
  42 + });
  43 + });
  44 +}
0 45 \ No newline at end of file
... ...
app/views/layouts/application.html.erb
... ... @@ -40,6 +40,8 @@
40 40  
41 41 <%= javascript_include_tag "application" %>
42 42  
  43 + <%= javascript_include_tag "http://code.highcharts.com/highcharts.js" %>
  44 +
43 45 <%= csrf_meta_tags %>
44 46 </head>
45 47 <body>
... ...
app/views/repositories/_metric_result.html.erb
... ... @@ -2,7 +2,7 @@
2 2 <% unless metric_configuration_snapshot.range_snapshot.nil? %>
3 3 <% range_snapshot = find_range_snapshot(metric_result) %>
4 4 <tr>
5   - <td><%= link_to metric_configuration_snapshot.metric.name %></td>
  5 + <td><%= link_to metric_configuration_snapshot.metric.name, "#", onclick: "generate_graphic('metrica', 'modulo', '12/09/2012,21/10/2013,30/05/2013','12.7,13,20')" %></td>
6 6 <td><%= format_grade(metric_result.value) %></td>
7 7 <td><%= metric_configuration_snapshot.weight %></td>
8 8 <td><span style="color: #<%= range_snapshot.color %>"><%= range_snapshot.label %></span></td>
... ...
app/views/repositories/show.html.erb
... ... @@ -87,6 +87,8 @@
87 87  
88 88 <hr/>
89 89  
  90 +<div id="container"></div>
  91 +
90 92 <%= link_to 'Back', project_path(@repository.project_id), class: 'btn btn-default' %>
91 93 <% if project_owner? @repository.project_id %>
92 94 <%= link_to 'Destroy', project_repository_path(@repository.project_id, @repository.id), method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger' %>
... ...