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 { 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(); this.appendCrosshairCircles();
} }
@ -278,27 +278,29 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
} }
getClosestIndex(datapoints: [number, number][], xValue: number, yValue: number): number { getClosestIndex(datapoints: [number, number][], xValue: number, yValue: number): number {
let columnIdx; // 1 for y value, 0 for x value let columnIdx; // 0 for x value, 1 for y value,
let value; // xValue ot y Value let value; // xValue to y Value
switch(this.options.crosshair.orientation) { switch(this.options.crosshair.orientation) {
case CrosshairOrientation.HORIZONTAL: case CrosshairOrientation.VERTICAL:
columnIdx = 0; columnIdx = 0;
value = xValue; value = xValue;
break; break;
case CrosshairOrientation.VERTICAL: case CrosshairOrientation.HORIZONTAL:
columnIdx = 1; columnIdx = 1;
value = yValue; value = yValue;
break; break;
case CrosshairOrientation.BOTH: case CrosshairOrientation.BOTH:
// TODO: maybe use voronoi // TODO: maybe use voronoi
columnIdx = 0; columnIdx = 1;
value = yValue; value = yValue;
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 = this.d3.bisector((d: [number, number]) => d[columnIdx]).left; const bisectIndex = this.d3.bisector((d: [number, number]) => d[columnIdx]).left;
let closestIdx = bisectIndex(datapoints, value); let closestIdx = bisectIndex(datapoints, value);
// TODO: refactor corner cases // TODO: refactor corner cases
if(closestIdx < 0) { if(closestIdx < 0) {
return 0; return 0;

Loading…
Cancel
Save