Browse Source

Merge branch 'do-not-highlight-nil-metric' into 'main'

fix non-existing metrics being highlighted on hover

See merge request chartwerk/line-pod!25
pull/1/head
rozetko 2 years ago
parent
commit
fa632d35a9
  1. 2
      package.json
  2. 15
      src/index.ts

2
package.json

@ -1,6 +1,6 @@
{ {
"name": "@chartwerk/line-pod", "name": "@chartwerk/line-pod",
"version": "0.6.5", "version": "0.6.6",
"description": "Chartwerk line chart", "description": "Chartwerk line chart",
"main": "dist/index.js", "main": "dist/index.js",
"scripts": { "scripts": {

15
src/index.ts

@ -221,7 +221,7 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
default: default:
throw new Error(`Unknown type of crosshair orientaion: ${this.options.crosshair.orientation}`); throw new Error(`Unknown type of crosshair orientaion: ${this.options.crosshair.orientation}`);
} }
// TODO: d3.bisect is not the best way. Use binary search // TODO: d3.bisect is not the best way. Use binary search
const bisectIndex = d3.bisector((d: [number, number]) => d[columnIdx]).left; const bisectIndex = d3.bisector((d: [number, number]) => d[columnIdx]).left;
let closestIdx = bisectIndex(datapoints, value); let closestIdx = bisectIndex(datapoints, value);
@ -290,15 +290,14 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
let points = []; // datapoints in each metric that is closest to xValue/yValue position let points = []; // datapoints in each metric that is closest to xValue/yValue position
this.series.visibleSeries.forEach((serie: LineTimeSerie) => { this.series.visibleSeries.forEach((serie: LineTimeSerie) => {
const closestDatapoint = this.getClosestDatapoint(serie, xValue, yValue); const closestDatapoint = this.getClosestDatapoint(serie, xValue, yValue);
if(closestDatapoint === undefined) { if(_.isNil(closestDatapoint) || _.isNil(closestDatapoint[0])) {
this.hideCrosshairCircle(serie.idx); this.hideCrosshairCircle(serie.idx);
return; } else {
const xPosition = this.state.xScale(closestDatapoint[0]);
const yPosition = this.state.yScale(closestDatapoint[1]);
this.moveCrosshairCircle(xPosition, yPosition, serie.idx);
} }
const xPosition = this.state.xScale(closestDatapoint[0]);
const yPosition = this.state.yScale(closestDatapoint[1]);
this.moveCrosshairCircle(xPosition, yPosition, serie.idx);
points.push({ points.push({
value: closestDatapoint, value: closestDatapoint,
color: serie.color, color: serie.color,
@ -357,7 +356,7 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
this.renderYAxis(); this.renderYAxis();
this.renderGrid(); this.renderGrid();
this.onMouseOver(); this.onMouseOver();
let xAxisMiddleValue: number = this.state.xScale.invert(this.width / 2); let xAxisMiddleValue: number = this.state.xScale.invert(this.width / 2);
let yAxisMiddleValue: number = this.state.yScale.invert(this.height / 2); let yAxisMiddleValue: number = this.state.yScale.invert(this.height / 2);
const centers = { const centers = {

Loading…
Cancel
Save