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