Skip to content

Commit d95545b

Browse files
committed
feat(graph tooltip): refactoring PR grafana#3063
1 parent 34804bd commit d95545b

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

public/app/plugins/panel/graph/graph_tooltip.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ function ($, _) {
4141
};
4242

4343
this.getMultiSeriesPlotHoverInfo = function(seriesList, pos) {
44-
var value, i, series, hoverIndex, hoverDistance;
44+
var value, i, series, hoverIndex, hoverDistance, pointTime;
4545
var results = [];
46-
var seriesTimes = new Array(seriesList.length);
4746

4847
//now we know the current X (j) position for X and Y values
4948
var last_value = 0; //needed for stacked values
@@ -62,13 +61,8 @@ function ($, _) {
6261
}
6362

6463
hoverIndex = this.findHoverIndexFromData(pos.x, series);
65-
66-
// Store distance for each highlighted point
6764
hoverDistance = Math.abs(pos.x - series.data[hoverIndex][0]);
68-
seriesTimes[i] = {
69-
time: series.data[hoverIndex][0],
70-
distance: hoverDistance
71-
};
65+
pointTime = series.data[hoverIndex][0];
7266

7367
if (series.stack) {
7468
if (panel.tooltip.value_type === 'individual') {
@@ -88,15 +82,22 @@ function ($, _) {
8882
// stacked and steppedLine plots can have series with different length.
8983
// Stacked series can increase its length on each new stacked serie if null points found,
9084
// to speed the index search we begin always on the last found hoverIndex.
91-
var newhoverIndex = this.findHoverIndexFromDataPoints(pos.x, series, hoverIndex);
92-
results.push({ value: value, hoverIndex: newhoverIndex, color: series.color, label: series.label });
93-
} else {
94-
results.push({ value: value, hoverIndex: hoverIndex, color: series.color, label: series.label });
85+
hoverIndex = this.findHoverIndexFromDataPoints(pos.x, series, hoverIndex);
86+
hoverDistance = Math.abs(pos.x - series.data[hoverIndex][0]);
9587
}
88+
89+
results.push({
90+
value: value,
91+
hoverIndex: hoverIndex,
92+
color: series.color,
93+
label: series.label,
94+
time: pointTime,
95+
distance: hoverDistance
96+
});
9697
}
9798

9899
// Find point which closer to pointer
99-
results.time = _.min(seriesTimes, 'distance').time;
100+
results.time = _.min(results, 'distance').time;
100101

101102
return results;
102103
};

0 commit comments

Comments
 (0)