@axdspub/axiom-charts 0.0.12 → 0.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  import { RequestItem } from '@axdspub/axiom-ui-data-services';
2
- import { extent, bisectCenter, sum } from 'd3-array';
2
+ import { extent, bisector, sum } from 'd3-array';
3
3
  import { groupBy, debounce } from 'lodash';
4
4
  import { create } from 'd3-selection';
5
5
  import { scaleUtc, scaleLinear, scaleRadial } from 'd3-scale';
@@ -646,20 +646,44 @@ var AxiomLine = /** @class */ (function (_super) {
646
646
  });
647
647
  };
648
648
  AxiomLine.prototype.getScrubPosition = function (mouseX) {
649
- if (this.xScale === undefined || this.yScale === undefined || this.parsedData === undefined || this.offset === undefined)
649
+ if (this.xScale === undefined || this.yScale === undefined || this.parsedData === undefined || this.offset === undefined) {
650
650
  return undefined;
651
- var newDate = this.xScale.invert(mouseX - this.offset.x);
652
- var i = bisectCenter(this.parsedData.map(function (row) { return row.time; }), newDate);
653
- var lineX = this.xScale(this.parsedData[i].time) + this.offset.x;
654
- var yValue = this.parsedData[i].value;
655
- var yPx = this.yScale(yValue) + this.offset.y;
651
+ }
652
+ var xAccessor = this.getAccessorAtAxis('x');
653
+ var yAccessor = this.getAccessorAtAxis('y');
654
+ if (xAccessor === undefined || yAccessor === undefined) {
655
+ return undefined;
656
+ }
657
+ var scrubValue = this.xScale.invert(mouseX - this.offset.x);
658
+ var bisect = bisector(function (row) { return xAccessor(row); }).center;
659
+ var bisectIndex = bisect(this.parsedData, scrubValue);
660
+ var nearestRow = this.getNearestRow(bisectIndex, scrubValue, this.parsedData, xAccessor, yAccessor);
661
+ var bisected = nearestRow;
662
+ var xValue = xAccessor(bisected);
663
+ var xPosition = this.xScale(xValue) + this.offset.x;
664
+ var yValue = yAccessor(nearestRow);
665
+ var yPosition = this.yScale(yValue) + this.offset.y;
656
666
  return {
657
- xPosition: lineX,
658
- xValue: newDate,
659
- yPosition: yPx,
667
+ xPosition: xPosition,
668
+ xValue: xValue,
669
+ yPosition: yPosition,
660
670
  yValue: yValue
661
671
  };
662
672
  };
673
+ AxiomLine.prototype.getNearestRow = function (bisectIndex, scrubValue, parsedData, xAccessor, yAccessor) {
674
+ var nonEmptyRows = parsedData.filter(function (row) { return yAccessor(row) !== null && yAccessor(row) !== undefined; });
675
+ var minDistance = Number.MAX_VALUE;
676
+ var nearestRow = parsedData[bisectIndex];
677
+ for (var i = 0; i < nonEmptyRows.length; i += 1) {
678
+ var current = xAccessor(nonEmptyRows[i]);
679
+ var distance = Math.abs(+current - +scrubValue);
680
+ if (distance < minDistance) {
681
+ minDistance = distance;
682
+ nearestRow = nonEmptyRows[i];
683
+ }
684
+ }
685
+ return nearestRow;
686
+ };
663
687
  AxiomLine.prototype.drawScrubbing = function (mouseX) {
664
688
  var chart = this.chart;
665
689
  var ctx = chart.getCanvasContext();
@@ -1217,7 +1241,9 @@ var AxiomChart = /** @class */ (function (_super) {
1217
1241
  var _this = this;
1218
1242
  if (this.plotImplementations === undefined)
1219
1243
  return;
1220
- var plotsWithScrubbingEnabled = this.plotImplementations.filter(function (plot) { var _a; return ((_a = plot.scrubbing) !== null && _a !== void 0 ? _a : false) && plot.type === EPlotTypes.line; });
1244
+ var plotsWithScrubbingEnabled = this.plotImplementations.filter(function (plot) {
1245
+ return plot.scrubbing !== undefined && plot.scrubbing && plot.type === EPlotTypes.line;
1246
+ });
1221
1247
  var plotScrubPositions = this.getScrubPositions(cursorX, plotsWithScrubbingEnabled);
1222
1248
  // console.log(plotScrubPositions)
1223
1249
  if (this.onScrub !== undefined) {