Dependencies Implementation in Vanilla-Gantt
A dependency links a predecessor task (from) to a successor (to), with
one of four types. features/dependencies.feature.js draws the links that
cross the rendered rows as orthogonal arrows, in one SVG layer over the lanes.
A link from row 3 to row 900,000 costs nothing until the view crosses it, and
is drawn when the view sits at row 450,000.
| Type | Leaves | Enters | Satisfied when |
|---|---|---|---|
FS (default) |
the predecessor's end | the successor's start | succ.start >= pred.end |
SS |
the predecessor's start | the successor's start | succ.start >= pred.start |
FF |
the predecessor's end | the successor's end | succ.end >= pred.end |
SF |
the predecessor's start | the successor's end | succ.end >= pred.start |
There is no lag: an end is exclusive, so a task that starts the day its
predecessor ends satisfies FS.
1. Resolving
loadTasksAsync() fetches the dependencies with the tasks
(Data Manager § 1) and resolves each
one (resolveLinksAsync(), yielding every 20,000 links; 790k links take about
0.4 s) before it hands them to VanillaGantt#setModel(): both
ids through the task model's id map (as strings, so 1 and '1' are the same
task), the type to a code. A link with an unknown id, a task linked to
itself, or a type that is not one of the four is skipped; the skipped links
are counted in one warning with the first link's id (or from->to). The
resolved links are typed arrays (from, to task indices, type codes).
vn-gantt-loaded's dependencyCount is the number that resolved.
A link joining a task with no bar (invalid dates) is kept in the index but never drawn: such a task has no bar and no links.
2. The index
The index answers "which links cross the rendered rows" in O(log m + k log m).
It works in the grid's depth-first positions, getTreeRowInfo(key).position
(Tree Rows § 1), not in
render indices and not in the Gantt's own order:
- The grid sorts siblings, so its order follows a column sort of the task list; the Gantt's own children lists don't.
- Positions are stable across expand and collapse. Collapsing hides a
contiguous depth-first range, so the rendered rows
[a, b]are one depth-first range: from rowa's position to rowb's, or to the end ofb's subtree whenbis collapsed or a leaf (windowEnd()). Whenbis expanded its subtree is rows below the view, so it is not included. - A link is the interval
[lo, hi]of its two ends' positions, and crosses the view when that interval overlaps the window.
Structure (buildIndex()): the links sorted by lo (one Float64Array
sort of lo × 2^26 + id), with a max-of-hi segment tree over that order. A
query (queryIndex()) binary-searches the prefix with lo <= windowEnd, then
descends the tree into every subtree whose maximum hi reaches the window's
start.
When it is rebuilt. On every vn-grid-tree-rebuilt: new rows (a load,
including a reload after setDependencies()), a sort, a filter or search
result. Never on expand or collapse, never on a scroll. The rebuild
(buildIndexAsync()) reads the positions of every linked task with one
getTreeRowPositions() call (tasks with no link are not looked up), yields through VanillaGridYield every 20,000
links, and is superseded by a newer rebuild. The event arrives in a microtask
after the rebuilt rows have rendered, so before paint: the layer is cleared
there and stays clear until the new index is done, so links drawn from the old
index in that pass are never painted. While a rebuild runs, a scroll moves the
lanes but draws no links.
A filtered-out end. While a filter or search is active, a task the grid
leaves out has no position (getTreeRowPositions() gives -1, its ancestors
kept as context rows do have one). A link is indexed only when both
ends have a position, so a link with an end the filter leaves out is hidden;
clearing the filter rebuilds the index (reason: 'filter') and brings it back.
Hidden links are not counted in the skipped-links warning, since their ids are
known.
3. Drawing
_renderLinks() runs at the end of every lane pass
(Timeline § 2) and does
nothing when the rendered range, the row height, the entry count and the
layout version are what it last drew. A scroll that keeps the range costs
nothing: the layer is inside the lane block, whose translateY moves it.
For each link the index returns, planLinks():
- Resolves each end to the row it is drawn on: the task itself when visible,
else its nearest visible ancestor (
getNearestVisibleAncestorKey(), O(depth)), and that row's render index (getRenderIndexByKey(), O(1) in tree mode). - Collapsed subtrees. An end inside a collapsed subtree is drawn to the
visible ancestor's summary bar, at the same anchor (start or end) of that
bar, and the link gets
vn-gantt-link-redirected(dashed). A link whose two ends resolve to the same row (both inside one collapsed subtree) is hidden. Two links that resolve to the same bars and anchors are drawn once, violated or redirected if any of them is. - Computes violation on the real tasks (the table above), so a redirected
link shows violated when its hidden task's link is. While a move is
previewed, the dates are the previewed ones, and the links follow the bars
(Task Moving § 2). A violated link gets
vn-gantt-link-violatedand the violated arrowhead. - Routes it (
routePath()): out of the source anchor 8px outward (right of an end, left of a start), vertically to the target row, then into the target anchor from its outer side (from the left into a start, from the right into an end). When the target's approach point is behind the source's, the path detours: half a row toward the target, back, then in. Anchors are the bar's edges (2px minimum width, as drawn); a milestone's start and end are its centre.
A row outside the rendered rows is placed just past the layer's edge
(-rowHeight or (count + 1) × rowHeight), so the vertical run still crosses
the view and the turn into the off-screen bar stays hidden.
DOM. One <svg class="vn-gantt-links" aria-hidden="true"> at the top of
the lane block, as wide as the timeline and as tall as the rendered rows,
above the lanes and transparent to the pointer. Two arrowhead <marker>s, ids
unique per Gantt. One <path class="vn-gantt-link"> per drawn link from a
pool, with data-vn-gantt-from, data-vn-gantt-to (the real tasks' ids) and
data-vn-gantt-type; a path's d and class are written only when they change.
Links are not announced to assistive technology.
4. Cost
| Work | Runs | Cost |
|---|---|---|
| Resolve | per load | O(m) |
| Index rebuild | per vn-grid-tree-rebuilt |
O(m) to mark the linked tasks, one getTreeRowPositions() call (one map lookup per linked task), plus O(m log m) on typed arrays, chunked |
| Window query, plan and draw | per lane pass that changes the range | O(log m + k log m) plus k × (two ancestor lookups, O(depth); two render-index lookups, O(1)) |
k, the links crossing the view, is bounded by the data, not the viewport:
thousands of long links crossing every view draw thousands of paths per pass.
There is no cap. dependencies.feature.js is in GANTT_BUNDLE_FAST_PATH,
and the rebuild makes no per-task call into the grid: one getTreeRowInfo()
per task went through the grid's forwarders, which an obfuscated build keeps
on the heavy profile, and took the rebuild from 0.36 s to 2.3 s at 1,000,000
tasks.
The layer's width. The SVG is as wide as the timeline: 148,800 px at day
zoom over the project-tasks-js plan's ten years. Measured on 2026-10-23
with the sample at 1,000,000 tasks and 792,573 links, scrolling by 37 px per
frame at day zoom in headless Chromium and Firefox: the median frame was the
same with the layer shown and hidden (Chromium 34.6 ms and 34.5 ms, Firefox
17.0 ms both; the frame is the grid's scaled-mode pass without a GPU). A
viewport-sized layer redrawn on horizontal scroll was therefore not needed.
5. Theme tokens
--vn-gantt-link-color, --vn-gantt-link-violated-color,
--vn-gantt-link-width and --vn-gantt-link-redirected-dash (a
stroke-dasharray value), set by each theme
(Themes § 2). The arrowheads take the link
and violated colours through the classes vn-gantt-link-arrow and
vn-gantt-link-arrow-violated.