mirror of
https://github.com/grafana/grafana.git
synced 2025-08-01 07:32:12 +08:00
TimeSeries: Simplify hover proximity code (#81518)
This commit is contained in:
@ -397,7 +397,7 @@
|
|||||||
"tinycolor2": "1.6.0",
|
"tinycolor2": "1.6.0",
|
||||||
"tslib": "2.6.2",
|
"tslib": "2.6.2",
|
||||||
"tween-functions": "^1.2.0",
|
"tween-functions": "^1.2.0",
|
||||||
"uplot": "1.6.29",
|
"uplot": "1.6.30",
|
||||||
"uuid": "9.0.1",
|
"uuid": "9.0.1",
|
||||||
"visjs-network": "4.25.0",
|
"visjs-network": "4.25.0",
|
||||||
"webpack-assets-manifest": "^5.1.0",
|
"webpack-assets-manifest": "^5.1.0",
|
||||||
|
@ -58,7 +58,7 @@
|
|||||||
"string-hash": "^1.1.3",
|
"string-hash": "^1.1.3",
|
||||||
"tinycolor2": "1.6.0",
|
"tinycolor2": "1.6.0",
|
||||||
"tslib": "2.6.2",
|
"tslib": "2.6.2",
|
||||||
"uplot": "1.6.29",
|
"uplot": "1.6.30",
|
||||||
"xss": "^1.0.14"
|
"xss": "^1.0.14"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
@ -106,7 +106,7 @@
|
|||||||
"slate-react": "0.22.10",
|
"slate-react": "0.22.10",
|
||||||
"tinycolor2": "1.6.0",
|
"tinycolor2": "1.6.0",
|
||||||
"tslib": "2.6.2",
|
"tslib": "2.6.2",
|
||||||
"uplot": "1.6.29",
|
"uplot": "1.6.30",
|
||||||
"uuid": "9.0.1"
|
"uuid": "9.0.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
@ -61,13 +61,18 @@ exports[`GraphNG utils preparePlotConfigBuilder 1`] = `
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
"cursor": {
|
"cursor": {
|
||||||
"dataIdx": [Function],
|
|
||||||
"drag": {
|
"drag": {
|
||||||
"setScale": false,
|
"setScale": false,
|
||||||
},
|
},
|
||||||
"focus": {
|
"focus": {
|
||||||
"prox": 30,
|
"prox": 30,
|
||||||
},
|
},
|
||||||
|
"hover": {
|
||||||
|
"prox": [Function],
|
||||||
|
"skip": [
|
||||||
|
null,
|
||||||
|
],
|
||||||
|
},
|
||||||
"points": {
|
"points": {
|
||||||
"fill": [Function],
|
"fill": [Function],
|
||||||
"size": [Function],
|
"size": [Function],
|
||||||
|
@ -561,51 +561,16 @@ export const preparePlotConfigBuilder: UPlotConfigPrepFn<{
|
|||||||
const hoverProximityPx = 15;
|
const hoverProximityPx = 15;
|
||||||
|
|
||||||
let cursor: Partial<uPlot.Cursor> = {
|
let cursor: Partial<uPlot.Cursor> = {
|
||||||
// this scans left and right from cursor position to find nearest data index with value != null
|
hover: {
|
||||||
// TODO: do we want to only scan past undefined values, but halt at explicit null values?
|
prox: (self, seriesIdx, hoveredIdx) => {
|
||||||
dataIdx: (self, seriesIdx, hoveredIdx, cursorXVal) => {
|
const yVal = self.data[seriesIdx][hoveredIdx];
|
||||||
let seriesData = self.data[seriesIdx];
|
if (yVal === null) {
|
||||||
|
return hoverProximityPx;
|
||||||
if (seriesData[hoveredIdx] == null) {
|
|
||||||
let nonNullLft = null,
|
|
||||||
nonNullRgt = null,
|
|
||||||
i;
|
|
||||||
|
|
||||||
i = hoveredIdx;
|
|
||||||
while (nonNullLft == null && i-- > 0) {
|
|
||||||
if (seriesData[i] != null) {
|
|
||||||
nonNullLft = i;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
i = hoveredIdx;
|
return null;
|
||||||
while (nonNullRgt == null && i++ < seriesData.length) {
|
},
|
||||||
if (seriesData[i] != null) {
|
skip: [null],
|
||||||
nonNullRgt = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let xVals = self.data[0];
|
|
||||||
|
|
||||||
let curPos = self.valToPos(cursorXVal, 'x');
|
|
||||||
let rgtPos = nonNullRgt == null ? Infinity : self.valToPos(xVals[nonNullRgt], 'x');
|
|
||||||
let lftPos = nonNullLft == null ? -Infinity : self.valToPos(xVals[nonNullLft], 'x');
|
|
||||||
|
|
||||||
let lftDelta = curPos - lftPos;
|
|
||||||
let rgtDelta = rgtPos - curPos;
|
|
||||||
|
|
||||||
if (lftDelta <= rgtDelta) {
|
|
||||||
if (lftDelta <= hoverProximityPx) {
|
|
||||||
hoveredIdx = nonNullLft!;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (rgtDelta <= hoverProximityPx) {
|
|
||||||
hoveredIdx = nonNullRgt!;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return hoveredIdx;
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
14
yarn.lock
14
yarn.lock
@ -3276,7 +3276,7 @@ __metadata:
|
|||||||
tinycolor2: "npm:1.6.0"
|
tinycolor2: "npm:1.6.0"
|
||||||
tslib: "npm:2.6.2"
|
tslib: "npm:2.6.2"
|
||||||
typescript: "npm:5.3.3"
|
typescript: "npm:5.3.3"
|
||||||
uplot: "npm:1.6.29"
|
uplot: "npm:1.6.30"
|
||||||
xss: "npm:^1.0.14"
|
xss: "npm:^1.0.14"
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
react: ^17.0.0 || ^18.0.0
|
react: ^17.0.0 || ^18.0.0
|
||||||
@ -3864,7 +3864,7 @@ __metadata:
|
|||||||
tinycolor2: "npm:1.6.0"
|
tinycolor2: "npm:1.6.0"
|
||||||
tslib: "npm:2.6.2"
|
tslib: "npm:2.6.2"
|
||||||
typescript: "npm:5.3.3"
|
typescript: "npm:5.3.3"
|
||||||
uplot: "npm:1.6.29"
|
uplot: "npm:1.6.30"
|
||||||
uuid: "npm:9.0.1"
|
uuid: "npm:9.0.1"
|
||||||
webpack: "npm:5.90.0"
|
webpack: "npm:5.90.0"
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
@ -17680,7 +17680,7 @@ __metadata:
|
|||||||
tslib: "npm:2.6.2"
|
tslib: "npm:2.6.2"
|
||||||
tween-functions: "npm:^1.2.0"
|
tween-functions: "npm:^1.2.0"
|
||||||
typescript: "npm:5.3.3"
|
typescript: "npm:5.3.3"
|
||||||
uplot: "npm:1.6.29"
|
uplot: "npm:1.6.30"
|
||||||
uuid: "npm:9.0.1"
|
uuid: "npm:9.0.1"
|
||||||
visjs-network: "npm:4.25.0"
|
visjs-network: "npm:4.25.0"
|
||||||
webpack: "npm:5.90.0"
|
webpack: "npm:5.90.0"
|
||||||
@ -29633,10 +29633,10 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"uplot@npm:1.6.29":
|
"uplot@npm:1.6.30":
|
||||||
version: 1.6.29
|
version: 1.6.30
|
||||||
resolution: "uplot@npm:1.6.29"
|
resolution: "uplot@npm:1.6.30"
|
||||||
checksum: 0cda54a89cbe7f1ff5eb4a3e75bafa145a6af79e534cef6e8e4a1ace042b18a63ea56b25407d87fc7f073711ebb947a59de8068aa3576bc86b2514f1d058c187
|
checksum: 08ad2f9441b8cfa26d9219362cdbb6f2dc6e5ec9403382df71798ed3e9d3666e7712c8a245e652ebb4a25c5d911cbdc614b52dfd891c0f7ce8705320d2eff81f
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user