forked from Griesbacher/histou
-
Notifications
You must be signed in to change notification settings - Fork 2
/
flotAddons.js
51 lines (46 loc) · 1.49 KB
/
flotAddons.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
(function ($) {
function init(plot)
{
function fixGaps(plot, series, datapoints)
{
var points = datapoints.points, stepSize = datapoints.pointsize;
var timerangeInMillisec = points[points.length-stepSize]-points[0];
var datapoints = series.data.length;
var avgTimeBetweenPoints = timerangeInMillisec / datapoints;
var indices = [];
for (var i = stepSize; i < points.length; i += stepSize) {
if ((points[i]-points[i-stepSize]) > avgTimeBetweenPoints*2) {
indices.push(i)
}
}
for (var i = indices.length-1; i >= 0; i--) {
var pointIndex = indices[i];
for (var j = 0; j < stepSize; j++) {
points.splice(pointIndex,0,null);
}
}
}
function addHorizontalRuler(plot, options)
{
options.crosshair.mode = 'xy';
}
plot.hooks.processDatapoints.push(fixGaps);
plot.hooks.processOptions.push(addHorizontalRuler);
}
function WaitForjQuery()
{
if (!$.isFunction($.plot)) {
setTimeout(WaitForjQuery, 100);
return;
}
$.plot.plugins.push(
{
init: init,
options: {},
name: "customiseGrafana",
version: "0.1"
}
);
}
WaitForjQuery();
})(jQuery);