|
1 |
| -define('dashboard/detail', [ |
2 |
| - 'jquery', |
3 |
| - 'jquery.flot', |
4 |
| - 'dashboard/utils', |
5 |
| -], function ($, plot, utils) { |
6 |
| - $(function () { |
7 |
| - var element = $('#graph'); |
8 |
| - var url = element.data('path') + element.data('metric') + '.json?days=365'; |
9 |
| - var hover = { |
10 |
| - show: function (x, y, message) { |
11 |
| - $('<div id="hover">') |
12 |
| - .html(message) |
13 |
| - .css({ top: y, left: x }) |
14 |
| - .appendTo('body') |
15 |
| - .show(); |
16 |
| - }, |
17 |
| - hide: function () { |
18 |
| - $('#hover').remove(); |
| 1 | +$(function () { |
| 2 | + var element = $('#graph'); |
| 3 | + var url = element.data('path') + element.data('metric') + '.json?days=365'; |
| 4 | + var hover = { |
| 5 | + show: function (x, y, message) { |
| 6 | + $('<div id="hover">') |
| 7 | + .html(message) |
| 8 | + .css({ top: y, left: x }) |
| 9 | + .appendTo('body') |
| 10 | + .show(); |
| 11 | + }, |
| 12 | + hide: function () { |
| 13 | + $('#hover').remove(); |
| 14 | + }, |
| 15 | + }; |
| 16 | + |
| 17 | + $.getJSON(url, function (response) { |
| 18 | + for (var i = 0; i < response.data.length; i++) { |
| 19 | + response.data[i][0] = response.data[i][0] * 1000; |
| 20 | + } |
| 21 | + var options = { |
| 22 | + xaxis: { |
| 23 | + mode: 'time', |
| 24 | + tickColor: 'rgba(0,0,0,0)', |
| 25 | + minTickSize: [1, 'day'], |
19 | 26 | },
|
| 27 | + yaxis: { min: 0, ticks: 4 }, |
| 28 | + grid: { borderWidth: 0, hoverable: true, color: '#0C3C26' }, |
| 29 | + colors: ['#0C4B33'], |
20 | 30 | };
|
21 |
| - |
22 |
| - $.getJSON(url, function (response) { |
23 |
| - for (var i = 0; i < response.data.length; i++) { |
24 |
| - response.data[i][0] = response.data[i][0] * 1000; |
25 |
| - } |
26 |
| - var options = { |
27 |
| - xaxis: { |
28 |
| - mode: 'time', |
29 |
| - tickColor: 'rgba(0,0,0,0)', |
30 |
| - minTickSize: [1, 'day'], |
31 |
| - }, |
32 |
| - yaxis: { min: 0, ticks: 4 }, |
33 |
| - grid: { borderWidth: 0, hoverable: true, color: '#0C3C26' }, |
34 |
| - colors: ['#0C4B33'], |
| 31 | + if (response.period == 'daily') { |
| 32 | + options.bars = { |
| 33 | + show: true, |
| 34 | + barWidth: 22 * 60 * 60 * 1000, |
| 35 | + align: 'center', |
35 | 36 | };
|
36 |
| - if (response.period == 'daily') { |
37 |
| - options.bars = { |
38 |
| - show: true, |
39 |
| - barWidth: 22 * 60 * 60 * 1000, |
40 |
| - align: 'center', |
41 |
| - }; |
42 |
| - } else if (response.period == 'weekly') { |
43 |
| - options.bars = { |
44 |
| - show: true, |
45 |
| - barWidth: 22 * 60 * 60 * 7 * 1000, |
46 |
| - align: 'center', |
47 |
| - }; |
48 |
| - } |
49 |
| - var plot = $.plot(element, [response.data], options); |
50 |
| - |
51 |
| - var format_message = function (timestamp, measurement) { |
52 |
| - var unit = measurement == 1 ? response.unit : response.unit_plural; |
53 |
| - return ( |
54 |
| - utils.formatTimestamp(timestamp, response.period) + |
55 |
| - '<br>' + |
56 |
| - measurement + |
57 |
| - ' ' + |
58 |
| - unit |
59 |
| - ); |
| 37 | + } else if (response.period == 'weekly') { |
| 38 | + options.bars = { |
| 39 | + show: true, |
| 40 | + barWidth: 22 * 60 * 60 * 7 * 1000, |
| 41 | + align: 'center', |
60 | 42 | };
|
| 43 | + } |
| 44 | + var plot = $.plot(element, [response.data], options); |
61 | 45 |
|
62 |
| - var previousPoint = null; |
63 |
| - element.bind('plothover', function (event, pos, item) { |
64 |
| - if (item) { |
65 |
| - if (previousPoint != item.dataIndex) { |
66 |
| - previousPoint = item.dataIndex; |
67 |
| - hover.hide(); |
68 |
| - var x, y; |
69 |
| - var message = format_message.apply(null, item.datapoint); |
70 |
| - if (response.period == 'instant') { |
71 |
| - x = item.pageX + 10; |
72 |
| - y = item.pageY + 10; |
73 |
| - } else { |
74 |
| - // I'd like this hover to be centered over the bar. This |
75 |
| - // simple math sorta works, but it assumes a *lot* about |
76 |
| - // the plot and basically won't scale. Grr. |
77 |
| - x = item.pageX - 40; |
78 |
| - y = item.pageY - 50; |
79 |
| - } |
80 |
| - hover.show(x, y, message); |
81 |
| - } |
82 |
| - } else { |
| 46 | + var format_message = function (timestamp, measurement) { |
| 47 | + var unit = measurement == 1 ? response.unit : response.unit_plural; |
| 48 | + return ( |
| 49 | + formatTimestamp(timestamp, response.period) + |
| 50 | + '<br>' + |
| 51 | + measurement + |
| 52 | + ' ' + |
| 53 | + unit |
| 54 | + ); |
| 55 | + }; |
| 56 | + |
| 57 | + var previousPoint = null; |
| 58 | + element.bind('plothover', function (event, pos, item) { |
| 59 | + if (item) { |
| 60 | + if (previousPoint != item.dataIndex) { |
| 61 | + previousPoint = item.dataIndex; |
83 | 62 | hover.hide();
|
84 |
| - previousPoint = null; |
| 63 | + var x, y; |
| 64 | + var message = format_message.apply(null, item.datapoint); |
| 65 | + if (response.period == 'instant') { |
| 66 | + x = item.pageX + 10; |
| 67 | + y = item.pageY + 10; |
| 68 | + } else { |
| 69 | + // I'd like this hover to be centered over the bar. This |
| 70 | + // simple math sorta works, but it assumes a *lot* about |
| 71 | + // the plot and basically won't scale. Grr. |
| 72 | + x = item.pageX - 40; |
| 73 | + y = item.pageY - 50; |
| 74 | + } |
| 75 | + hover.show(x, y, message); |
85 | 76 | }
|
86 |
| - }); |
| 77 | + } else { |
| 78 | + hover.hide(); |
| 79 | + previousPoint = null; |
| 80 | + } |
87 | 81 | });
|
88 | 82 | });
|
89 | 83 | });
|
0 commit comments