From 49c5c3d46273bd4ed65e54bd808a0579eda960ce Mon Sep 17 00:00:00 2001 From: rozetko Date: Wed, 3 Aug 2022 16:14:03 +0300 Subject: [PATCH 1/3] fix non-existing metrics being highlighted on hover --- src/index.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index 70ec9c5..f4861b7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -221,7 +221,7 @@ export class LinePod extends ChartwerkPod { default: throw new Error(`Unknown type of crosshair orientaion: ${this.options.crosshair.orientation}`); } - + // TODO: d3.bisect is not the best way. Use binary search const bisectIndex = d3.bisector((d: [number, number]) => d[columnIdx]).left; let closestIdx = bisectIndex(datapoints, value); @@ -290,14 +290,18 @@ export class LinePod extends ChartwerkPod { let points = []; // datapoints in each metric that is closest to xValue/yValue position this.series.visibleSeries.forEach((serie: LineTimeSerie) => { const closestDatapoint = this.getClosestDatapoint(serie, xValue, yValue); - if(closestDatapoint === undefined) { + if(_.isNil(closestDatapoint)) { this.hideCrosshairCircle(serie.idx); return; } const xPosition = this.state.xScale(closestDatapoint[0]); const yPosition = this.state.yScale(closestDatapoint[1]); - this.moveCrosshairCircle(xPosition, yPosition, serie.idx); + if(!_.isNil(closestDatapoint[0])) { + this.moveCrosshairCircle(xPosition, yPosition, serie.idx); + } else { + this.hideCrosshairCircle(serie.idx); + } points.push({ value: closestDatapoint, @@ -357,7 +361,7 @@ export class LinePod extends ChartwerkPod { this.renderYAxis(); this.renderGrid(); this.onMouseOver(); - + let xAxisMiddleValue: number = this.state.xScale.invert(this.width / 2); let yAxisMiddleValue: number = this.state.yScale.invert(this.height / 2); const centers = { From cf5722484a64a2371aea68bfc3f936720e59bff9 Mon Sep 17 00:00:00 2001 From: rozetko Date: Wed, 3 Aug 2022 16:14:25 +0300 Subject: [PATCH 2/3] 0.6.6 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ab6568c..d1a46a9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@chartwerk/line-pod", - "version": "0.6.5", + "version": "0.6.6", "description": "Chartwerk line chart", "main": "dist/index.js", "scripts": { From a448f62fc94dfb6212a27d62aad8db021924caee Mon Sep 17 00:00:00 2001 From: rozetko Date: Wed, 3 Aug 2022 16:24:07 +0300 Subject: [PATCH 3/3] minor fix --- src/index.ts | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/index.ts b/src/index.ts index f4861b7..8380f35 100644 --- a/src/index.ts +++ b/src/index.ts @@ -290,17 +290,12 @@ export class LinePod extends ChartwerkPod { let points = []; // datapoints in each metric that is closest to xValue/yValue position this.series.visibleSeries.forEach((serie: LineTimeSerie) => { const closestDatapoint = this.getClosestDatapoint(serie, xValue, yValue); - if(_.isNil(closestDatapoint)) { + if(_.isNil(closestDatapoint) || _.isNil(closestDatapoint[0])) { this.hideCrosshairCircle(serie.idx); - return; - } - - const xPosition = this.state.xScale(closestDatapoint[0]); - const yPosition = this.state.yScale(closestDatapoint[1]); - if(!_.isNil(closestDatapoint[0])) { - this.moveCrosshairCircle(xPosition, yPosition, serie.idx); } else { - this.hideCrosshairCircle(serie.idx); + const xPosition = this.state.xScale(closestDatapoint[0]); + const yPosition = this.state.yScale(closestDatapoint[1]); + this.moveCrosshairCircle(xPosition, yPosition, serie.idx); } points.push({