From aeeda29104e51ee0dd778e44669f59bb597bb22d Mon Sep 17 00:00:00 2001 From: xswei Date: Fri, 26 Sep 2025 14:42:55 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20tick=E8=AE=A1=E7=AE=97=E7=B2=BE=E5=BA=A6?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __tests__/unit/tick-methods/d3-ticks.spec.ts | 4 ++++ src/tick-methods/d3-ticks.ts | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/__tests__/unit/tick-methods/d3-ticks.spec.ts b/__tests__/unit/tick-methods/d3-ticks.spec.ts index d4a8c02..98b487d 100644 --- a/__tests__/unit/tick-methods/d3-ticks.spec.ts +++ b/__tests__/unit/tick-methods/d3-ticks.spec.ts @@ -29,4 +29,8 @@ describe('d3 ticks', () => { expect(fn(0, 5, -1)).toStrictEqual(fn(0, 5, 0)); expect(fn(0, 5, -1.2)).toStrictEqual(fn(0, 5, 0)); }); + + test('maximum value accuracy', () => { + expect(fn(0.53, 0.58, 6)).toStrictEqual([0.53, 0.54, 0.55, 0.56, 0.57, 0.58]); + }); }); diff --git a/src/tick-methods/d3-ticks.ts b/src/tick-methods/d3-ticks.ts index 857ccf3..064e065 100644 --- a/src/tick-methods/d3-ticks.ts +++ b/src/tick-methods/d3-ticks.ts @@ -42,7 +42,8 @@ export const d3Ticks: TickMethod = (begin: number, end: number, count: number, b } else { step = -step; start = Math.ceil(start * step); - stop = Math.floor(stop * step); + // 1e-10: Math.floor(0.58 * 100) => 57 + stop = Math.floor(stop * step + 1e-10); ticks = new Array((n = Math.ceil(stop - start + 1))); for (let i = 0; i < n; i += 1) { ticks[i] = (start + i) / step;