From fe0cd3d24044d2b563e1fd08027e284735bd1c81 Mon Sep 17 00:00:00 2001 From: Mariss Tubelis Date: Fri, 3 Jan 2025 15:23:51 +0100 Subject: [PATCH] Use isNullOrUndef helper for point value checks --- src/core/core.interaction.js | 6 +++--- src/helpers/helpers.extras.ts | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/core/core.interaction.js b/src/core/core.interaction.js index 1c75447206e..8a716023651 100644 --- a/src/core/core.interaction.js +++ b/src/core/core.interaction.js @@ -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 @@ -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; diff --git a/src/helpers/helpers.extras.ts b/src/helpers/helpers.extras.ts index beabb6d96f3..798e10c1e86 100644 --- a/src/helpers/helpers.extras.ts +++ b/src/helpers/helpers.extras.ts @@ -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; @@ -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); @@ -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;