Commit 00aef830ba0dc71d3ca8ef7f01b362fd1e6ab113
1 parent
48a6cd84
Exists in
colab
and in
4 other branches
Fixed graphic for Metric Results not displaying correctly
The graphic for Metric results previously did not have a set size. Changed it so that it fills the whole space available, and made it responsive to window resizing. That broke some particular cases of histories with few changes and number of points that wasn't very small. In addition, made the graphic display a single point instead of an unhelpful message.
Showing
6 changed files
with
34 additions
and
16 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
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 | ... | ... |