From 4359c51014263e7e79c11edacf8751d4a65219df Mon Sep 17 00:00:00 2001 From: Shreyag02 Date: Mon, 16 Nov 2026 01:31:48 +0530 Subject: [PATCH 1/2] fix: [data-view] label every tick at exact spacing boundaries buildAxis takes the ceiling of the label floor over the unit width. The call site divides the unit width by scaling, so a width on an exact multiple of the floor can land a hair under it (29.4 / 1.05 = 27.999999999999996) and thin one step too far. Subtract a small epsilon before the ceiling. --- .../data-view/__tests__/timeline.test.tsx | 50 ++++++++++++++++++- .../components/data-view/utils/time-scale.tsx | 16 ++++-- 2 files changed, 61 insertions(+), 5 deletions(-) diff --git a/packages/react/components/data-view/__tests__/timeline.test.tsx b/packages/react/components/data-view/__tests__/timeline.test.tsx index 3d0d1b64d..bf9cbdf55 100644 --- a/packages/react/components/data-view/__tests__/timeline.test.tsx +++ b/packages/react/components/data-view/__tests__/timeline.test.tsx @@ -2,6 +2,7 @@ import { act, fireEvent, render, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { afterEach, beforeAll, describe, expect, it, vi } from 'vitest'; import { Theme } from '../../theme'; +import { SCALINGS } from '../../theme/settings'; // biome-ignore lint/suspicious/noShadowRestrictedNames: legitimate export name import { DataView } from '../data-view'; @@ -13,7 +14,12 @@ import type { TimelineActions } from '../data-view.types'; import { useDataView } from '../hooks/useDataView'; -import { buildAxis, createTimeScale, toTimestamp } from '../utils/time-scale'; +import { + buildAxis, + createTimeScale, + TIMELINE_DEFAULT_UNIT_WIDTH, + toTimestamp +} from '../utils/time-scale'; beforeAll(() => { // jsdom doesn't implement ResizeObserver, and the timeline observes its scroll @@ -198,6 +204,41 @@ describe('buildAxis', () => { expect(roomy.every(t => t.showLabel)).toBe(true); }); + it('labels at exact multiples of the label spacing despite float error', () => { + // The call site divides by scaling: 29.4 / 1.05 = 27.999999999999996. + expect( + buildAxis(januaryScale, 'day', 29.4 / 1.05).ticks.every(t => t.showLabel) + ).toBe(true); + const half = buildAxis(januaryScale, 'day', 14.7 / 1.05).ticks; + expect(half.map(t => t.showLabel).slice(0, 4)).toEqual([ + true, + false, + true, + false + ]); + }); + + it('keeps the default label spacing at every scaling', () => { + for (const s of SCALINGS) { + const scaling = Number(s); + const every = (['day', 'week', 'month', 'quarter'] as const).map( + scale => { + const unitWidth = TIMELINE_DEFAULT_UNIT_WIDTH[scale] * scaling; + const scaleForUnit = createTimeScale({ + minTime: new Date(2025, 0, 1).getTime(), + maxTime: new Date(2027, 0, 1).getTime(), + scale, + unitWidth, + padUnits: 0 + }); + const { ticks } = buildAxis(scaleForUnit, scale, unitWidth / scaling); + return ticks.findIndex((t, i) => i > 0 && t.showLabel); + } + ); + expect(every).toEqual([2, 1, 1, 1]); + } + }); + it('labels every Nth unit when labelEvery is passed', () => { const roomyScale = createTimeScale({ minTime: new Date(2025, 0, 1).getTime(), @@ -2225,7 +2266,7 @@ describe('DataView.Timeline theme scaling', () => { ]; function renderScaled( - scaling: '1' | '1.1', + scaling: '1' | '1.05' | '1.1', props: Partial> = {}, data: Order[] = scaledOrders ) { @@ -2319,6 +2360,11 @@ describe('DataView.Timeline theme scaling', () => { expect(lefts(scaled.container, 'data-view-timeline-axis-tick')[1]).toBe(42); }); + it('labels every tick when unitWidth equals the scaled label floor', () => { + const { container } = renderScaled('1.05', { unitWidth: 29.4 }); + expect(labels(container)).toHaveLength(32); + }); + it('scales the gap between cards sharing a lane', () => { // At scaling 1, b starts 7.5px after a ends, under the 8px card gap. const nearlyTouching: Order[] = [ diff --git a/packages/react/components/data-view/utils/time-scale.tsx b/packages/react/components/data-view/utils/time-scale.tsx index 29759c3c2..dd8a4458c 100644 --- a/packages/react/components/data-view/utils/time-scale.tsx +++ b/packages/react/components/data-view/utils/time-scale.tsx @@ -37,6 +37,13 @@ export const TIMELINE_DEFAULT_UNIT_WIDTH: Record = { /** Minimum px between rendered tick labels. Denser ticks skip labels. */ const TICK_LABEL_MIN_SPACE = 28; +/** + * Absorbs float error in the spacing ratio. The call site divides the unit + * width by scaling, so a width on an exact multiple of the floor can come out + * a hair under it (29.4 / 1.05 = 27.999999999999996). + */ +const LABEL_SPACING_EPSILON = 1e-9; + /** Coerce a consumer-provided date (Date | epoch ms | parseable string | object with a numeric `valueOf`) to ms. */ export function toTimestamp(value: unknown): number | null { return toInstant(value)?.getTime() ?? null; @@ -167,8 +174,9 @@ function tickLabel(date: Date, scale: TimelineScale): string { * year in its label ("Jan 2025", then "Feb"). * * `labelEvery` labels every Nth unit, counted from the domain start. The - * collision floor (labels never closer than `TICK_LABEL_MIN_SPACE`) still - * applies, so a too-dense request degrades instead of overlapping. + * collision floor (labels never closer than `TICK_LABEL_MIN_SPACE`, within + * float error) still applies, so a too-dense request degrades instead of + * overlapping. * * Cost note: this materializes one tick per `scale` unit across the whole * domain on every rebuild, since `virtualized` culls what renders, not what gets @@ -184,7 +192,9 @@ export function buildAxis( ): { ticks: TimelineTick[]; bands: TimelineBand[] } { const autoLabelEvery = Math.max( 1, - Math.ceil(TICK_LABEL_MIN_SPACE / Math.max(1, unitWidth)) + Math.ceil( + TICK_LABEL_MIN_SPACE / Math.max(1, unitWidth) - LABEL_SPACING_EPSILON + ) ); const effectiveLabelEvery = Math.max( autoLabelEvery, From 2fa8d2d0ef7e6cc1c73c881bcc75fcce5a482d3e Mon Sep 17 00:00:00 2001 From: Shreyag02 Date: Mon, 16 Nov 2026 10:50:57 +0530 Subject: [PATCH 2/2] fix: [data-view] scale timeline demo card heights with theme The default estimatedRowHeight scales with the theme's scaling, but the demo cards had a fixed 64px height. At a larger scaling the card content grew while the card did not. Scale the card height with --rs-scaling and document this on the timeline page. --- apps/www/src/app/examples/timeline-stress/page.tsx | 9 +++++---- apps/www/src/components/dataview-demo.tsx | 3 ++- apps/www/src/content/docs/dataview/timeline.mdx | 2 ++ 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/apps/www/src/app/examples/timeline-stress/page.tsx b/apps/www/src/app/examples/timeline-stress/page.tsx index 770c01d52..99d237bf0 100644 --- a/apps/www/src/app/examples/timeline-stress/page.tsx +++ b/apps/www/src/app/examples/timeline-stress/page.tsx @@ -100,9 +100,10 @@ const STATUS_COLOR: Record = { }; /** - * Card height is fixed at 64 to sit inside the 66px lane pitch. Under - * `virtualized` the lane height is exactly `estimatedRowHeight`, so a taller - * card would overflow into the lane below instead of growing its own. + * Card height is fixed at 64 × scaling to sit inside the default lane height + * of 66 × scaling. Under `virtualized` the lane height is exactly + * `estimatedRowHeight`, so a taller card would overflow toward the lane below + * instead of growing its own. */ function TaskCard({ task, @@ -114,7 +115,7 @@ function TaskCard({ return (