@axdspub/axiom-charts 0.0.13 → 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.
@@ -656,11 +656,12 @@ var AxiomLine = /** @class */ (function (_super) {
656
656
  }
657
657
  var scrubValue = this.xScale.invert(mouseX - this.offset.x);
658
658
  var bisect = bisector(function (row) { return xAccessor(row); }).center;
659
- var i = bisect(this.parsedData, scrubValue);
660
- var bisected = this.parsedData[i];
659
+ var bisectIndex = bisect(this.parsedData, scrubValue);
660
+ var nearestRow = this.getNearestRow(bisectIndex, scrubValue, this.parsedData, xAccessor, yAccessor);
661
+ var bisected = nearestRow;
661
662
  var xValue = xAccessor(bisected);
662
663
  var xPosition = this.xScale(xValue) + this.offset.x;
663
- var yValue = this.parsedData[i].value;
664
+ var yValue = yAccessor(nearestRow);
664
665
  var yPosition = this.yScale(yValue) + this.offset.y;
665
666
  return {
666
667
  xPosition: xPosition,
@@ -669,6 +670,20 @@ var AxiomLine = /** @class */ (function (_super) {
669
670
  yValue: yValue
670
671
  };
671
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
+ };
672
687
  AxiomLine.prototype.drawScrubbing = function (mouseX) {
673
688
  var chart = this.chart;
674
689
  var ctx = chart.getCanvasContext();