Skip to content

Commit

Permalink
Use isNullOrUndef helper for point value checks
Browse files Browse the repository at this point in the history
  • Loading branch information
marisst committed Jan 3, 2025
1 parent 76d2559 commit fe0cd3d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/core/core.interaction.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {_lookupByKey, _rlookupByKey} from '../helpers/helpers.collection.js';
import {getRelativePosition} from '../helpers/helpers.dom.js';
import {_angleBetween, getAngleFromPoint} from '../helpers/helpers.math.js';
import {_isPointInArea} from '../helpers/index.js';
import {_isPointInArea, isNullOrUndef} from '../helpers/index.js';

/**
* @typedef { import('./core.controller.js').default } Chart
Expand Down Expand Up @@ -36,13 +36,13 @@ function binarySearch(metaset, axis, value, intersect) {
.slice(0, result.lo + 1)
.reverse()
.findIndex(
point => point[vScale.axis] || point[vScale.axis] === 0));
point => !isNullOrUndef(point[vScale.axis])));
result.lo -= Math.max(0, distanceToDefinedLo);

const distanceToDefinedHi = (_parsed
.slice(result.hi - 1)
.findIndex(
point => point[vScale.axis] || point[vScale.axis] === 0));
point => !isNullOrUndef(point[vScale.axis])));
result.hi += Math.max(0, distanceToDefinedHi);
}
return result;
Expand Down
5 changes: 3 additions & 2 deletions src/helpers/helpers.extras.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type {ChartMeta, PointElement} from '../types/index.js';

import {_limitValue} from './helpers.math.js';
import {_lookupByKey} from './helpers.collection.js';
import {isNullOrUndef} from './helpers.core.js';

export function fontString(pixelSize: number, fontStyle: string, fontFamily: string) {
return fontStyle + ' ' + pixelSize + 'px ' + fontFamily;
Expand Down Expand Up @@ -107,7 +108,7 @@ export function _getStartAndCountOfVisiblePoints(meta: ChartMeta<'line' | 'scatt
.slice(0, start + 1)
.reverse()
.findIndex(
point => point[vScale.axis] || point[vScale.axis] === 0));
point => !isNullOrUndef(point[vScale.axis])));
start -= Math.max(0, distanceToDefinedLo);
}
start = _limitValue(start, 0, pointCount - 1);
Expand All @@ -122,7 +123,7 @@ export function _getStartAndCountOfVisiblePoints(meta: ChartMeta<'line' | 'scatt
const distanceToDefinedHi = (_parsed
.slice(end - 1)
.findIndex(
point => point[vScale.axis] || point[vScale.axis] === 0));
point => !isNullOrUndef(point[vScale.axis])));
end += Math.max(0, distanceToDefinedHi);
}
count = _limitValue(end, start, pointCount) - start;
Expand Down

0 comments on commit fe0cd3d

Please sign in to comment.