From df77715994bb28b2f5d7b7d87b8048996820d1c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=90=AF=E6=BA=90?= Date: Thu, 20 Aug 2026 17:58:14 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=9D=90=E6=A0=87=E8=BD=B4):=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E7=B4=A7=E5=87=91=E5=A4=9A=E9=81=93=E8=BE=B9=E7=95=8C?= =?UTF-8?q?=E5=88=BB=E5=BA=A6=E9=87=8D=E5=8F=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/core/trackLayoutBuilder.ts | 4 +- .../compactAndSharedHover.test.ts | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/src/components/core/trackLayoutBuilder.ts b/src/components/core/trackLayoutBuilder.ts index f9643bd..af660ec 100644 --- a/src/components/core/trackLayoutBuilder.ts +++ b/src/components/core/trackLayoutBuilder.ts @@ -135,9 +135,7 @@ export function buildTrackLayouts(options: BuildTrackLayoutsOptions): TrackLayou (_, index) => axisStart + ((axisEnd - axisStart) * index) / (tickCount - 1), ) const showAxisEnd = options.displayMode !== 'compact' || cell.row === 0 - const visibleMajorTicks = showAxisEnd - ? majorTicks - : majorTicks.filter((tick) => tick !== axisEnd) + const visibleMajorTicks = showAxisEnd ? majorTicks : majorTicks.slice(0, -1) const tickValues = visibleMajorTicks const { tickTextWidth } = axisTextMetrics( scale.domain() as [number, number], diff --git a/src/components/waveformChartCases/compactAndSharedHover.test.ts b/src/components/waveformChartCases/compactAndSharedHover.test.ts index 8b2214d..c703f57 100644 --- a/src/components/waveformChartCases/compactAndSharedHover.test.ts +++ b/src/components/waveformChartCases/compactAndSharedHover.test.ts @@ -72,6 +72,49 @@ describe('WaveformChart', () => { expect(endTicks[3]).toHaveLength(0) }) + it('removes the later compact row top tick when the Y-axis end has a floating-point tail', async () => { + const yDomain: [number, number] = [-1, 0.2] + const calculatedAxisEnd = + yDomain[0] + ((yDomain[1] - yDomain[0]) * 4) / 4 + expect(calculatedAxisEnd).not.toBe(yDomain[1]) + + const wrapper = await mountSizedChart( + { + kind: 'series', + series: [ + { + name: 'top', + data: { kind: 'points', points: [{ x: 0, y: -0.8 }, { x: 1, y: 0.1 }] }, + }, + { + name: 'bottom', + data: { kind: 'points', points: [{ x: 0, y: -0.7 }, { x: 1, y: 0 }] }, + }, + ], + }, + { displayMode: 'compact', grid: { rowCount: 2, columnCount: 1 }, yDomain }, + ) + + const [topTrack, bottomTrack] = wrapper.findAll('.waveform-chart__track') + const ticksAt = (track: typeof topTrack, position: number) => + track.findAll('.waveform-chart__axis--y .tick').filter((tick) => { + const match = tick.attributes('transform')?.match(/translate\(0,\s*([\d.]+)\)/) + return match ? Math.abs(Number(match[1]) - position) <= 1 : false + }) + const topTrackHeight = Number(topTrack.attributes('data-track-height')) + + expect(ticksAt(topTrack, 0)).toHaveLength(1) + expect(ticksAt(topTrack, 0)[0].text()).toBe('0.2') + expect(ticksAt(bottomTrack, 0)).toHaveLength(0) + expect(Number(bottomTrack.attributes('data-track-top'))).toBeCloseTo( + Number(topTrack.attributes('data-track-top')) + topTrackHeight, + 6, + ) + + const boundaryLabels = [...ticksAt(topTrack, topTrackHeight), ...ticksAt(bottomTrack, 0)] + expect(boundaryLabels).toHaveLength(1) + }) + it('prefixes one shared exponent to the largest visible tick on every compact Y axis', async () => { const wrapper = await mountSizedChart( {