Browse Source

fx points

merge-requests/10/head
Alexey Velikiy 3 years ago
parent
commit
8d41aad0d0
  1. 2
      dist/index.js
  2. 14
      src/index.ts

2
dist/index.js vendored

File diff suppressed because one or more lines are too long

14
src/index.ts

@ -181,7 +181,7 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
}
updateCrosshair(): void {
// Base don't know anything about crosshair circles, It is only for line pod
// Core doesn't know anything about crosshair circles, It is only for line pod
this.appendCrosshairCircles();
}
@ -278,27 +278,29 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
}
getClosestIndex(datapoints: [number, number][], xValue: number, yValue: number): number {
let columnIdx; // 1 for y value, 0 for x value
let value; // xValue ot y Value
let columnIdx; // 0 for x value, 1 for y value,
let value; // xValue to y Value
switch(this.options.crosshair.orientation) {
case CrosshairOrientation.HORIZONTAL:
case CrosshairOrientation.VERTICAL:
columnIdx = 0;
value = xValue;
break;
case CrosshairOrientation.VERTICAL:
case CrosshairOrientation.HORIZONTAL:
columnIdx = 1;
value = yValue;
break;
case CrosshairOrientation.BOTH:
// TODO: maybe use voronoi
columnIdx = 0;
columnIdx = 1;
value = yValue;
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 = this.d3.bisector((d: [number, number]) => d[columnIdx]).left;
let closestIdx = bisectIndex(datapoints, value);
// TODO: refactor corner cases
if(closestIdx < 0) {
return 0;

Loading…
Cancel
Save