This is an automated email from the ASF dual-hosted git repository. sushuang pushed a commit to branch PR/plainheart_fix/alignTicks-precision in repository https://gitbox.apache.org/repos/asf/echarts.git
commit b16d96c39fb3fd366f31f3ab510acd183891bd64 Author: 100pah <[email protected]> AuthorDate: Fri Feb 20 15:43:27 2026 +0800 chore: Tweak the usage of isFinite. --- src/component/axisPointer/axisTrigger.ts | 3 ++- src/coord/axisAlignTicks.ts | 3 ++- src/data/helper/sourceHelper.ts | 3 ++- src/layout/barGrid.ts | 6 +++--- src/scale/breakImpl.ts | 2 +- src/scale/scaleMapper.ts | 8 ++++---- src/util/format.ts | 4 ++-- src/util/number.ts | 10 ++++++++++ 8 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/component/axisPointer/axisTrigger.ts b/src/component/axisPointer/axisTrigger.ts index 082b61c0d..326786d1a 100644 --- a/src/component/axisPointer/axisTrigger.ts +++ b/src/component/axisPointer/axisTrigger.ts @@ -26,6 +26,7 @@ import { Dictionary, Payload, CommonAxisPointerOption, HighlightPayload, Downpla import AxisPointerModel, { AxisPointerOption } from './AxisPointerModel'; import { each, curry, bind, extend, Curry1 } from 'zrender/src/core/util'; import { ZRenderType } from 'zrender/src/zrender'; +import { isNullableNumberFinite } from '../../util/number'; const inner = makeInner<{ axisPointerLastHighlights: Dictionary<BatchItem> @@ -288,7 +289,7 @@ function buildPayloadsBySeries(value: AxisValue, axisInfo: CollectedAxisInfo) { seriesNestestValue = series.getData().get(dataDim[0], dataIndices[0]); } - if (seriesNestestValue == null || !isFinite(seriesNestestValue)) { + if (!isNullableNumberFinite(seriesNestestValue)) { return; } diff --git a/src/coord/axisAlignTicks.ts b/src/coord/axisAlignTicks.ts index b400e4db8..0fb54eedd 100644 --- a/src/coord/axisAlignTicks.ts +++ b/src/coord/axisAlignTicks.ts @@ -19,6 +19,7 @@ import { getAcceptableTickPrecision, + isNullableNumberFinite, mathAbs, mathCeil, mathFloor, mathMax, mathRound, nice, NICE_MODE_MIN, quantity, round } from '../util/number'; import IntervalScale from '../scale/Interval'; @@ -243,7 +244,7 @@ export function scaleCalcAlign( intervalPrecision = getAcceptableTickPrecision([max, min], pxSpan, 0.5 / alignToNiceSegCount); updateMinNiceFromMinT0Interval(); updateMaxNiceFromMaxT1Interval(); - if (isFinite(intervalPrecision)) { + if (isNullableNumberFinite(intervalPrecision)) { interval = round(interval, intervalPrecision); } } diff --git a/src/data/helper/sourceHelper.ts b/src/data/helper/sourceHelper.ts index a4c47721a..67668666a 100644 --- a/src/data/helper/sourceHelper.ts +++ b/src/data/helper/sourceHelper.ts @@ -450,7 +450,8 @@ function doGuessOrdinal( const beStr = isString(val); // Consider usage convenience, '1', '2' will be treated as "number". // `Number('')` (or any whitespace) is `0`. - if (val != null && Number.isFinite(Number(val)) && val !== '') { + // `Number(val)` prevents error for BigInt. + if (val != null && isFinite(Number(val)) && val !== '') { return beStr ? BE_ORDINAL.Might : BE_ORDINAL.Not; } else if (beStr && val !== '-') { diff --git a/src/layout/barGrid.ts b/src/layout/barGrid.ts index dcba7aa30..88c033600 100644 --- a/src/layout/barGrid.ts +++ b/src/layout/barGrid.ts @@ -18,7 +18,7 @@ */ import { each, defaults, hasOwn, assert } from 'zrender/src/core/util'; -import { mathAbs, mathMax, mathMin, parsePercent } from '../util/number'; +import { isNullableNumberFinite, mathAbs, mathMax, mathMin, parsePercent } from '../util/number'; import { isDimensionStacked } from '../data/helper/dataStackHelper'; import createRenderPlanner from '../chart/helper/createRenderPlanner'; import Axis2D from '../coord/cartesian/Axis2D'; @@ -340,7 +340,7 @@ function createLayoutInfoListOnAxis( const linearScaleSpan = getScaleLinearSpanForMapping(axisScale); // `linearScaleSpan` may be `0` or `Infinity` or `NaN`, since normalizers like // `intervalScaleEnsureValidExtent` may not have been called yet. - if (axisPre.linearMinGap && linearScaleSpan && isFinite(linearScaleSpan)) { + if (axisPre.linearMinGap && linearScaleSpan && isNullableNumberFinite(linearScaleSpan)) { singular = false; bandWidth = pxSpan / linearScaleSpan * axisPre.linearMinGap; pxToDataRatio = linearScaleSpan / pxSpan; @@ -759,7 +759,7 @@ function calcShapeOverflowSupplement( const linearSpan = getScaleLinearSpanForMapping(scale); linearSupplement = [-linearSpan * SINGULAR_SUPPLEMENT_RATIO, linearSpan * SINGULAR_SUPPLEMENT_RATIO]; } - else if (pxToDataRatio != null && isFinite(pxToDataRatio)) { + else if (isNullableNumberFinite(pxToDataRatio)) { // Convert from pixel domain to data domain, since the `barsBoundPx` is calculated based on // `minGap` and extent on data domain. linearSupplement = [barsBoundPx[0] * pxToDataRatio, barsBoundPx[1] * pxToDataRatio]; diff --git a/src/scale/breakImpl.ts b/src/scale/breakImpl.ts index 6fe9c2620..f0f2e5ba2 100644 --- a/src/scale/breakImpl.ts +++ b/src/scale/breakImpl.ts @@ -436,7 +436,7 @@ function addBreaksToTicks( // The input ticks should be in accending order. ticks: ScaleTick[], breaks: ParsedAxisBreakList, - scaleExtent: [number, number], + scaleExtent: number[], // Keep the break ends at the same level to avoid an awkward appearance. getTimeProps?: (clampedBrk: ParsedAxisBreak) => ScaleTick['time'], ): void { diff --git a/src/scale/scaleMapper.ts b/src/scale/scaleMapper.ts index 5dd02a687..57b06e161 100644 --- a/src/scale/scaleMapper.ts +++ b/src/scale/scaleMapper.ts @@ -204,7 +204,7 @@ export interface ScaleMapperGeneric<This> { * An extent is always in an increase order. * It always returns an array - never be a null/undefined. */ - getExtent(this: This): [number, number]; + getExtent(this: This): number[]; /** * [NOTICE]: @@ -215,7 +215,7 @@ export interface ScaleMapperGeneric<This> { kind: ScaleExtentKind, // NullUndefined means the outermost space. depth: ScaleMapperDepthOpt['depth'] | NullUndefined - ): [number, number] | NullUndefined; + ): number[] | NullUndefined; /** * [NOTICE]: @@ -413,11 +413,11 @@ const linearScaleMapperMethods: ScaleMapperGeneric<LinearScaleMapper> = { }, getExtent() { - return this._extents[SCALE_EXTENT_KIND_EFFECTIVE].slice() as [number, number]; + return this._extents[SCALE_EXTENT_KIND_EFFECTIVE].slice(); }, getExtentUnsafe(kind) { - return this._extents[kind] as [number, number]; + return this._extents[kind]; }, setExtent(start, end) { diff --git a/src/util/format.ts b/src/util/format.ts index afe9625b4..637807232 100644 --- a/src/util/format.ts +++ b/src/util/format.ts @@ -19,7 +19,7 @@ import * as zrUtil from 'zrender/src/core/util'; import { encodeHTML } from 'zrender/src/core/dom'; -import { parseDate, isNumeric, numericToNumber } from './number'; +import { parseDate, isNumeric, numericToNumber, isNullableNumberFinite } from './number'; import { TooltipRenderMode, ColorString, ZRColor, DimensionType } from './types'; import { Dictionary } from 'zrender/src/core/types'; import { GradientObject } from 'zrender/src/graphic/Gradient'; @@ -72,7 +72,7 @@ export function makeValueReadable( return (str && zrUtil.trim(str)) ? str : '-'; } function isNumberUserReadable(num: number): boolean { - return !!(num != null && !isNaN(num) && isFinite(num)); + return isNullableNumberFinite(num); } const isTypeTime = valueType === 'time'; diff --git a/src/util/number.ts b/src/util/number.ts index 84a802dd1..accab98a0 100644 --- a/src/util/number.ts +++ b/src/util/number.ts @@ -802,3 +802,13 @@ export function getLeastCommonMultiple(a: number, b: number) { } return a * b / getGreatestCommonDividor(a, b); } + +/** + * NOTICE: Assume the input `val` is number or null/undefined, no type check. + * Therefore, it is NOT suitable for processing user input, but sufficient for + * internal usage in most cases. + * For platform-agnosticism, `Number.isFinite` is not used. + */ +export function isNullableNumberFinite(val: number | NullUndefined) { + return val != null && isFinite(val); +} --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
