Commit 7806b739f9e39af398d11f6f5b462dca31c33a2d
Exists in
colab
and in
4 other branches
Merge pull request #226 from mezuro/fix-pain-chart
Fixed and refactored graphic for Metric Results
Showing
6 changed files
with
40 additions
and
20 deletions
Show diff stats
app/assets/javascripts/module/graphic.js.coffee
| 1 | 1 | class Module.Graphic |
| 2 | 2 | constructor: (@container, @metric_name, @module_id) -> |
| 3 | - $('tr#'+@container).slideToggle('slow') | |
| 4 | - this.load() | |
| 3 | + drawer = $('tr#'+@container) | |
| 4 | + if drawer.is(":hidden") | |
| 5 | + drawer.slideDown('slow') | |
| 6 | + this.load() | |
| 7 | + else | |
| 8 | + drawer.slideUp('slow') | |
| 5 | 9 | |
| 6 | 10 | load: -> |
| 7 | 11 | $.post '/modules/' + @module_id + '/metric_history', |
| ... | ... | @@ -11,7 +15,13 @@ class Module.Graphic |
| 11 | 15 | } |
| 12 | 16 | |
| 13 | 17 | @display: (dates, values, container) -> |
| 14 | - opts = {bezierCurve: false} | |
| 18 | + canvas = $('canvas#'+container).get(0) | |
| 19 | + | |
| 20 | + opts = { | |
| 21 | + bezierCurve: false, | |
| 22 | + responsive: true, | |
| 23 | + maintainAspectRatio: false | |
| 24 | + } | |
| 15 | 25 | |
| 16 | 26 | data = { |
| 17 | 27 | labels : dates, |
| ... | ... | @@ -26,4 +36,8 @@ class Module.Graphic |
| 26 | 36 | ] |
| 27 | 37 | } |
| 28 | 38 | |
| 29 | - graphic = new Chart($('canvas#'+container).get(0).getContext("2d")).Line(data, opts) | |
| 39 | + if canvas.hasOwnProperty("chart") && canvas.chart != null | |
| 40 | + canvas.chart.destroy() | |
| 41 | + canvas.chart = null | |
| 42 | + | |
| 43 | + canvas.chart = new Chart(canvas.getContext("2d")).Line(data, opts) | ... | ... |
app/assets/stylesheets/boilerplate/graphic.css
| ... | ... | @@ -0,0 +1,13 @@ |
| 1 | +table.metric_results { | |
| 2 | + table-layout: fixed; | |
| 3 | +} | |
| 4 | + | |
| 5 | +.metric_results div.graphic_container { | |
| 6 | + width: 100%; | |
| 7 | + max-height: 20em; | |
| 8 | +} | |
| 9 | + | |
| 10 | +.metric_results div.graphic_container > canvas { | |
| 11 | + width: 100%; | |
| 12 | + height: 100%; | |
| 13 | +} | |
| 0 | 14 | \ No newline at end of file | ... | ... |
app/views/modules/_metric_result.html.erb
| ... | ... | @@ -17,7 +17,6 @@ |
| 17 | 17 | <td colspan="4"> |
| 18 | 18 | <span id="loader_container<%= metric_result.id %>"><%= image_tag 'loader.gif' %> <%= t('loading_data') %></span> |
| 19 | 19 | <canvas id="container<%= metric_result.id %>" class="graphic_container" style="display: none"></canvas> |
| 20 | - <span id="container<%= metric_result.id %>" style="display: none"><%= t('only_point_printed_chart') %></span> | |
| 21 | 20 | </td> |
| 22 | 21 | </tr> |
| 23 | 22 | <% end %> | ... | ... |
app/views/modules/_metric_results.html.erb
| 1 | -<table class="table table-hover"> | |
| 1 | +<table class="table table-hover metric_results"> | |
| 2 | 2 | <thead> |
| 3 | - <th><%= t('activemodel.attributes.metric_result.metric') %></th> | |
| 4 | - <th><%= t('activemodel.attributes.metric_result.value') %></th> | |
| 5 | - <th><%= t('activemodel.attributes.metric_result.weight') %></th> | |
| 6 | - <th><%= t('activemodel.attributes.metric_result.threshold') %></th> | |
| 3 | + <tr> | |
| 4 | + <th><%= t('activemodel.attributes.metric_result.metric') %></th> | |
| 5 | + <th><%= t('activemodel.attributes.metric_result.value') %></th> | |
| 6 | + <th><%= t('activemodel.attributes.metric_result.weight') %></th> | |
| 7 | + <th><%= t('activemodel.attributes.metric_result.threshold') %></th> | |
| 8 | + </tr> | |
| 7 | 9 | </thead> |
| 8 | 10 | |
| 9 | 11 | <tbody> | ... | ... |
app/views/modules/metric_history.js.erb
| ... | ... | @@ -10,11 +10,6 @@ |
| 10 | 10 | <% end %> |
| 11 | 11 | |
| 12 | 12 | $("#loader_<%= @container %>").hide(); |
| 13 | - if (dates.length > 1) { | |
| 14 | - $("canvas#<%= @container %>").show(); | |
| 15 | - Module.Graphic.display(dates, values, '<%= @container %>'); | |
| 16 | - } | |
| 17 | - else { | |
| 18 | - $('span#<%= @container %>').show(); | |
| 19 | - } | |
| 13 | + $("canvas#<%= @container %>").show(); | |
| 14 | + Module.Graphic.display(dates, values, '<%= @container %>'); | |
| 20 | 15 | <% end %> |
| 21 | 16 | \ No newline at end of file | ... | ... |