|
@@ -2,7 +2,7 @@ define([
|
|
|
'jquery',
|
|
'jquery',
|
|
|
'lodash'
|
|
'lodash'
|
|
|
],
|
|
],
|
|
|
-function ($, _) {
|
|
|
|
|
|
|
+function ($) {
|
|
|
'use strict';
|
|
'use strict';
|
|
|
|
|
|
|
|
function GraphTooltip(elem, dashboard, scope, getSeriesFn) {
|
|
function GraphTooltip(elem, dashboard, scope, getSeriesFn) {
|
|
@@ -21,7 +21,10 @@ function ($, _) {
|
|
|
var initial = last*ps;
|
|
var initial = last*ps;
|
|
|
var len = series.datapoints.points.length;
|
|
var len = series.datapoints.points.length;
|
|
|
for (var j = initial; j < len; j += ps) {
|
|
for (var j = initial; j < len; j += ps) {
|
|
|
- if (series.datapoints.points[j] > posX) {
|
|
|
|
|
|
|
+ // Special case of a non stepped line, highlight the very last point just before a null point
|
|
|
|
|
+ if ((series.datapoints.points[initial] != null && series.datapoints.points[j] == null && ! series.lines.steps)
|
|
|
|
|
+ //normal case
|
|
|
|
|
+ || series.datapoints.points[j] > posX) {
|
|
|
return Math.max(j - ps, 0)/ps;
|
|
return Math.max(j - ps, 0)/ps;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -51,23 +54,35 @@ function ($, _) {
|
|
|
//now we know the current X (j) position for X and Y values
|
|
//now we know the current X (j) position for X and Y values
|
|
|
var last_value = 0; //needed for stacked values
|
|
var last_value = 0; //needed for stacked values
|
|
|
|
|
|
|
|
|
|
+ var minDistance, minTime;
|
|
|
|
|
+
|
|
|
for (i = 0; i < seriesList.length; i++) {
|
|
for (i = 0; i < seriesList.length; i++) {
|
|
|
series = seriesList[i];
|
|
series = seriesList[i];
|
|
|
|
|
|
|
|
if (!series.data.length || (panel.legend.hideEmpty && series.allIsNull)) {
|
|
if (!series.data.length || (panel.legend.hideEmpty && series.allIsNull)) {
|
|
|
|
|
+ // Init value & yaxis so that it does not brake series sorting
|
|
|
results.push({ hidden: true, value: 0, yaxis: 0 });
|
|
results.push({ hidden: true, value: 0, yaxis: 0 });
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (!series.data.length || (panel.legend.hideZero && series.allIsZero)) {
|
|
if (!series.data.length || (panel.legend.hideZero && series.allIsZero)) {
|
|
|
|
|
+ // Init value & yaxis so that it does not brake series sorting
|
|
|
results.push({ hidden: true, value: 0, yaxis: 0 });
|
|
results.push({ hidden: true, value: 0, yaxis: 0 });
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
hoverIndex = this.findHoverIndexFromData(pos.x, series);
|
|
hoverIndex = this.findHoverIndexFromData(pos.x, series);
|
|
|
- hoverDistance = Math.abs(pos.x - series.data[hoverIndex][0]);
|
|
|
|
|
|
|
+ hoverDistance = pos.x - series.data[hoverIndex][0];
|
|
|
pointTime = series.data[hoverIndex][0];
|
|
pointTime = series.data[hoverIndex][0];
|
|
|
|
|
|
|
|
|
|
+ // Take the closest point before the cursor, or if it does not exist, the closest after
|
|
|
|
|
+ if (! minDistance
|
|
|
|
|
+ || (hoverDistance >=0 && (hoverDistance < minDistance || minDistance < 0))
|
|
|
|
|
+ || (hoverDistance < 0 && hoverDistance > minDistance)) {
|
|
|
|
|
+ minDistance = hoverDistance;
|
|
|
|
|
+ minTime = pointTime;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
if (series.stack) {
|
|
if (series.stack) {
|
|
|
if (panel.tooltip.value_type === 'individual') {
|
|
if (panel.tooltip.value_type === 'individual') {
|
|
|
value = series.data[hoverIndex][1];
|
|
value = series.data[hoverIndex][1];
|
|
@@ -89,6 +104,7 @@ function ($, _) {
|
|
|
hoverIndex = this.findHoverIndexFromDataPoints(pos.x, series, hoverIndex);
|
|
hoverIndex = this.findHoverIndexFromDataPoints(pos.x, series, hoverIndex);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // Be sure we have a yaxis so that it does not brake series sorting
|
|
|
yaxis = 0;
|
|
yaxis = 0;
|
|
|
if (series.yaxis) {
|
|
if (series.yaxis) {
|
|
|
yaxis = series.yaxis.n;
|
|
yaxis = series.yaxis.n;
|
|
@@ -106,8 +122,8 @@ function ($, _) {
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // Find point which closer to pointer
|
|
|
|
|
- results.time = _.min(results, 'distance').time;
|
|
|
|
|
|
|
+ // Time of the point closer to pointer
|
|
|
|
|
+ results.time = minTime;
|
|
|
|
|
|
|
|
return results;
|
|
return results;
|
|
|
};
|
|
};
|
|
@@ -153,6 +169,8 @@ function ($, _) {
|
|
|
|
|
|
|
|
seriesHtml = '';
|
|
seriesHtml = '';
|
|
|
|
|
|
|
|
|
|
+ absoluteTime = dashboard.formatDate(seriesHoverInfo.time, tooltipFormat);
|
|
|
|
|
+
|
|
|
// Dynamically reorder the hovercard for the current time point if the
|
|
// Dynamically reorder the hovercard for the current time point if the
|
|
|
// option is enabled, sort by yaxis by default.
|
|
// option is enabled, sort by yaxis by default.
|
|
|
if (panel.tooltip.sort === 2) {
|
|
if (panel.tooltip.sort === 2) {
|
|
@@ -169,8 +187,6 @@ function ($, _) {
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- var distance, time;
|
|
|
|
|
-
|
|
|
|
|
for (i = 0; i < seriesHoverInfo.length; i++) {
|
|
for (i = 0; i < seriesHoverInfo.length; i++) {
|
|
|
hoverInfo = seriesHoverInfo[i];
|
|
hoverInfo = seriesHoverInfo[i];
|
|
|
|
|
|
|
@@ -178,11 +194,6 @@ function ($, _) {
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (! distance || hoverInfo.distance < distance) {
|
|
|
|
|
- distance = hoverInfo.distance;
|
|
|
|
|
- time = hoverInfo.time;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
var highlightClass = '';
|
|
var highlightClass = '';
|
|
|
if (item && i === item.seriesIndex) {
|
|
if (item && i === item.seriesIndex) {
|
|
|
highlightClass = 'graph-tooltip-list-item--highlight';
|
|
highlightClass = 'graph-tooltip-list-item--highlight';
|
|
@@ -198,7 +209,6 @@ function ($, _) {
|
|
|
plot.highlight(hoverInfo.index, hoverInfo.hoverIndex);
|
|
plot.highlight(hoverInfo.index, hoverInfo.hoverIndex);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- absoluteTime = dashboard.formatDate(time, tooltipFormat);
|
|
|
|
|
self.showTooltip(absoluteTime, seriesHtml, pos);
|
|
self.showTooltip(absoluteTime, seriesHtml, pos);
|
|
|
}
|
|
}
|
|
|
// single series tooltip
|
|
// single series tooltip
|