Timeline and Virtualization Implementation in Vanilla-Gantt

The timeline is virtualized on both axes. Vertically it has no scroller of its own: the task grid owns vertical scrolling and its row pool, and the timeline draws one lane per row the grid renders. Horizontally it is a native scroller with a custom scrollbar, and draws only the ticks near the view.

1. Following the grid

features/scroll-sync.feature.js adds a listener with the grid's addViewportListener() (Row Virtualization § 1.18). The grid calls it at the end of every render pass that changes the state, synchronously and before paint, and asks it only to write. So the lane writes happen in the listener itself (_onViewportState() → _renderLanes()), and read no layout: horizontal values come from the last horizontal pass.

Lane k shows render entry startIndex + k, at offsetTop + k × rowHeight: one translateY(offsetTop) on the lane block, and translateY(k × rowHeight) on each lane. These are the grid's own offsets, so the scaled-mode mapping (one DOM pixel spanning several logical ones, § 1.5) is never reproduced, and the lanes stay level in natural and scaled mode alike. The lanes take the state's measured rowHeight; the timeline body takes its viewportHeight, which snapViewportToRows may round. A state whose phase is not 'rows' (loading skeleton, empty, error) hides every lane.

Re-orders. The listener compares geometry only, so a sort, filter or reload that keeps the range (a sort at scroll top) calls no listener while the rows under the lanes change. The Gantt runs only in tree mode, where the grid fires vn-grid-tree-rebuilt after every rebuild of the tree (rows, sort, filter), once rendered (Tree Rows § 6). On it every lane is rewritten from getRenderEntry(i). A rebuild that also moved the range rewrites lanes the listener just wrote: one extra O(pool) pass per sort, filter or reload. Expand and collapse change entryCount, so the listener sees them.

2. The lane pool

features/rendering.feature.js. The pool grows to the grid's pool size and never past it. Each pass:

  1. Rotates the pool by the change in startIndex (when smaller than the pool), so a lane keeps the entry it already shows: a 5-row scroll rewrites 5 lanes, as the grid's pool rotation re-renders 5 rows.
  2. Writes each lane's translateY and height only when they changed, and its data-vn-gantt-entry and the vn-gantt-lane-alt class (odd entries) when its entry index changed.
  3. Rewrites a lane's bar only when its row key or the layout version changed, or on a forced pass. The layout version moves with a new model, a zoom, a range change, a move's preview and an applied move, which move bars without changing any row.

The pass then redraws the links and syncs the hover. Bars carry no tabindex and are never focused, so a pass hands no focus around: the timeline is its pane's only focus target (Task Moving § 4). While a move is previewed, a bar is drawn at its previewed dates.

The lane block also holds the dependency link layer, so it moves with the lanes; each lane pass ends by redrawing the links when the rendered range changed (Dependencies § 3).

A lane's bar comes from the model's typed arrays (Data Manager § 3):

Task Bar
Leaf left = (start - range.start) × pxPerDay, width = (end - start) × pxPerDay, at least 2px so a one-day task stays visible at year zoom
Summary (has children) vn-gantt-bar-summary: a thin bracket over the children's span, its ends turned down
Milestone (end == start, no children) vn-gantt-bar-milestone: a diamond centred on its date
No valid dates No bar; the lane still marks the row

Each bar is role="img" with a title from taskLabel (Name - Oct 12, 2026 to Oct 15, 2026, dates in the locale's medium format), or from milestoneLabel (Name - on Oct 21, 2026) when the task starts and ends on the same day: the tooltip, and, with no aria-label, the accessible name for browse mode. The timeline itself is role="group", named by the timelineLabel message, with a visually hidden live region that reads the selected bar's label after a keyboard selection change (Task Moving § 4). Lanes have no role: the grid's body is a plain table, so there are no row semantics to mirror. A row a filter keeps only as context (getTreeRowInfo(key).isContext) gets vn-gantt-lane-context, which dims its bar. The selected task's lane gets vn-gantt-lane-selected, the grid's selected-row tint (--vn-gantt-row-selected-bg, Themes § 2), over the stripes: _writeLane() sets it from the selected key, so a lane rotated by the pool keeps it with its task, and a selection change toggles it on the rendered lanes without rewriting them (Task Moving § 4). The same class rings the lane's bar (--vn-gantt-bar-focus-ring), so the selected task shows in the timeline however it was selected. A selected task with no rendered row (scrolled away, under a collapsed parent, hidden by the search or a filter) has no lane, so nothing is tinted until it shows again; a selected context row is both tinted and dimmed. Lanes are see-through, so the tick lines under them stay visible.

Hover across the panes. A hovered task reads as one row too: the mouse or a pen over a task's grid row tints its lane (vn-gantt-lane-hover), and over its lane or bar tints its grid row (vn-grid-row-hover, painted by the grid's base stylesheet as a hovered row: Themes § 4.2). Both take the hover tint, which wins over the selection tint as it does in every grid theme; the selected task's grid row keeps the grid's selection marker, the bar on its inline-start edge that no hover covers (Selection § 6.3), so the selection still shows under the pointer. The lane has no marker; hover paints the lane, not the bar, so the selected bar's ring shows under the pointer too. Each task row reaches the splitter, as its lane reaches the timeline's edge: past its last column the grid's row filler takes the rest of the task list's width (Row Virtualization § 1.2), so the pointer there is over the row (it marks both panes, and a click selects the task) and the row's tints fill it. pointerover on the grid's viewport and on the timeline's body records the hovered row or lane, and pointerleave of either clears it (features/scroll-sync.feature.js); a touch tap marks nothing. The same events record which pane a mouse or pen pointer is over (_pointerPane), the gate of the row keys (Task Moving § 4). _syncHover() reads the task from that element each time, rather than keeping the key, so an expand, a collapse or a search that rewrites the row under a still pointer moves both marks to the task it now shows. It runs on a hover change and at the end of every lane pass, which follows the grid's row writes, so a rotated pool row never keeps a stale mark into a paint: it walks the lane pool, and finds the grid row through getRenderIndexByKey() and the pool row's data-vn-grid-entry-index. A scroll under a still pointer needs nothing more: Chromium and Firefox fire pointerover on the row or lane that ends up under it. Under forced colors neither mark shows, as :hover doesn't.

3. Scale and zoom

features/timeline-scale.feature.js holds the day arithmetic as pure functions (the Node suite loads it directly). A date is a UTC day number, whole days since 1970-01-01, so every day is exactly one day wide and a 23- or 25-hour local day can't shift a bar.

Zoom px per day Upper tier Lower tier 10 years wide
day 40 month (October 2026) day (12) 146,000 px
week 20 month ISO week (W42) 73,000 px
month 5 year month (Oct) 18,000 px
quarter 2 year quarter (Q4) 7,300 px
year 0.5 none year 1,800 px

scrollToDate(date) centres the timeline on a date. scrollToTask(id) calls the grid's revealRow() (expanding the task's ancestors) and scrollToRow(key, { align: 'center' }), then scrolls the bar into view horizontally when any of it is outside the view (_scrollBarIntoView(): the bar's start lands two header tiers from the left edge); it returns false for an unknown id (and, on the element, before initializeGantt()). The same horizontal scroll follows every selection change but a bar press (Task Moving § 4). Focus doesn't move, unless scrollToTask(id, { focus: true }): the task is then selected (no setSelectedKeys() and no event when it already is) and the timeline takes focus, from wherever focus was, even for a task without a bar or whose row the search or a filter hides. <vn-gantt-toolbar>'s scrollToSelectedTask command calls it that way (Gantt Toolbar).

4. Header, ticks and pane geometry

The header's two tiers hold ticks from small pools, virtualized horizontally: _renderTicks() covers the visible span plus one viewport each side (up to the canvas's edge, past the range's end when the canvas is wider), and does nothing while the visible span stays inside the window it last drew, so it rewrites the pools about once per viewport width of scrolling. The tick lines in the body share the lower tier's positions. A tick's label is position: sticky; left: 0 inside the tick, so a long month keeps its label in view while scrolled; the tiers therefore don't clip their overflow, which would make them the label's scroll container.

Pane geometry. The lanes start level with the grid's rows because the header is sized to end exactly where the grid's viewport begins. The body and the timeline are overflow: clip (hidden as the fallback): a hidden overflow can still be scrolled by scrollIntoView(), find-in-page or script, which would shift every lane off its row for good. _scheduleGeometrySync() measures, in the scheduler's read phase, the grid viewport's top against the timeline scroller's top, the scroller's width, and the layout-relative edges the task grid's vertical scrollbar is placed by (§ 6.2) with the task list's and the layout's widths; the write phase sizes the header (split into its two tiers), places the body and the message, writes the scrollbar's offsets and the splitter's ARIA values (Web Component § 8). It runs on a ResizeObserver of the timeline and the grid's viewport, and after both stylesheets have loaded. initializeGantt() measures once synchronously too (_syncGeometryNow()), right after the grid has its header, so the first painted frame already has the header level with the grid's instead of growing by the grid's border a frame later. The markup gives the header, its two tiers (24px each) and the message their sizes from the start, so no frame paints the two tiers' ticks on top of each other. The timeline's width is also read once, synchronously, when the Gantt is built, so the first tick pass and the scrollbar don't wait a frame for it; with no width (a hidden element) the tick pass does nothing until the observer fires.

5. Input

Input over the timeline Goes to
Vertical wheel (more vertical than horizontal, no Shift) The grid's forwardWheel(event): the same normalization, speed multiplier and momentum guard as a wheel over the grid, so both panes scroll at one speed
Horizontal wheel, Shift+wheel The scroller, natively
Vertical touch drag The grid's scrollTopBy(dy) per move. The scroller is touch-action: pan-x, so the browser pans horizontally and leaves vertical drags to the Gantt
Horizontal touch drag The scroller, natively

Touch momentum. The grid pane's native momentum has no counterpart for a drag the Gantt forwards, so the Gantt runs its own: the drag's velocity is an exponential average of the last moves (weight 0.3 for the newest); on release within 80 ms of the last move, above 0.1 px/ms, it decays as exp(-t / 325 ms) over animation frames through scrollTopBy(). It stops below 0.02 px/ms, at either end of the scroll range (a frame that doesn't move), and on the next touch, wheel, scrollbar drag or key over the Gantt.

During a native touch fling of the grid pane itself the compositor moves the grid first, so the timeline may trail by a frame; wheel, keyboard and scrollbar scrolling set scrollTop on the main thread and the panes move in the same frame. gantt-scroll-performance.spec.js samples what was painted after each of 120 wheel frames at 1M tasks and finds no lane off its row. A native touch fling could not be measured: headless Chromium does not scroll the grid on a synthesized touch gesture. It is a check on a real device.

6. The scrollbars

6.1 The horizontal scrollbar

features/scrollbar.feature.js hides the scroller's native scrollbar and draws an overlay with the grid's mechanics and look (Row Virtualization § 2.5 to 2.9). The grid's code is VanillaGrid.prototype methods bound to grid state, so it is copied, reduced to one axis:

Every size comes from cached values (canvas width, visible width, scrollLeft), so an update reads no layout. A horizontal scroll reads scrollLeft once in the scheduler's read phase, then redraws the ticks and the thumb in its write phase (_scheduleScrollRead()). Only an explicit scroll writes scrollLeft (scrollToDate(), scrollToTask(), the zoom anchor, the scrollbar, ArrowLeft / ArrowRight on the timeline, a drag's edge auto-scroll). A change that can move it without one (a new timeline width, a new range on a load) leaves it to the browser, which clamps it, and re-reads it the same way: writing the cached value back would undo a scroll the handler had not seen yet. The scheduler runs a write queued by a read in the next frame, so an explicit scroll can land between the two; every explicit scroll bumps a counter, and a read the counter has moved past is dropped instead of cached over the newer value.

6.2 The task grid's vertical scrollbar, at the timeline's right edge

The grid's own vertical scrollbar (Row Virtualization § 2) is moved by the Gantt's stylesheet from the task list's right edge, between the panes, to the timeline's right edge. It stays the grid's: it measures itself (clientHeight, getBoundingClientRect()), so thumb size, drag, track paging, the mid-drag re-anchor and the row-range label work unchanged, and its events bubble through the grid, never the timeline's bar drag or keys.

7. Performance

Work Runs Cost
Lane pass per grid render pass that changes the state O(pool) cheap writes, plus one bar rewrite per lane whose row changed
Lane rewrite per vn-grid-tree-rebuilt O(pool)
Tick pass when the visible span leaves the drawn window O(visible ticks)
Horizontal scroll per scroll frame one read, a range check, a thumb transform
Touch momentum per animation frame while flinging one scrollTopBy()
Link layer per lane pass that changes the range the window query and the links crossing the view (Dependencies § 4)

None of it depends on the task count: at 1M tasks the DOM holds as many lanes as the grid's pool and the ticks of three viewport widths. tests/playwright/gantt-virtualization.spec.js checks both bounds on the sample at 1M tasks. rendering.feature.js, scroll-sync.feature.js and timeline-scale.feature.js are in GANTT_BUNDLE_FAST_PATH (build.js).

Measured on 2026-10-23 by tests/playwright/gantt-scroll-performance.spec.js (in PERF_SPECS), headless Chromium, the project-tasks-js sample at 1,000,000 tasks and 792,573 links (scaled mode), 240 wheel-driven frames over the timeline:

Figure Measured Asserted
Layouts per frame 1.00, as with the timeline hidden at most 1.1: the lane pass reads no layout
The lane pass (lanes and links) about 1.0 ms at most 3 ms on average
Main-thread time per frame (CDP TaskDuration) 36 to 39 ms, against 32 to 33 ms with the timeline hidden (the grid's own scaled-mode frame, about 21 ms on the machine Row Virtualization § 1.5 was measured on) at most 10 ms over the timeline-hidden figure of the same run
Painted frames with a lane off its row (120 frames) 0 0
Navigation to vn-gantt-loaded about 5 s, generating the plan included reported

The timing figures are relative to the same run, so they hold on a slower machine. The obfuscated build (npm run build:obfuscate) of the sample at 1M tasks loads, scrolls from top to bottom and moves tasks without hanging; it was checked by hand against dist/, not by a spec, since the suite serves the sources.