Data Manager Implementation in Vanilla-Gantt
The Gantt's DataManager is its only data source. <vn-gantt> fetches the
tasks and dependencies from it, builds the task model, and feeds the same task
objects to the embedded grid through an internal StaticDataManager.
1. The contract
VanillaGanttDataManager (data-managers/gantt-data-manager.js) is the base
class. It follows the shape of the grid's DataManager
(Data Manager): an async
fetch that honours an AbortSignal, onConfigChanged, reset() and
destroy(). It is not that class: a second top-level class DataManager on a
page that loads the grid would throw, and the grid's row-and-filter contract
has no tasks, links or writes.
| Member | Base behaviour |
|---|---|
fetchTasks({ signal }) |
Resolves []. Every task, parents and children, in any order |
fetchDependencies({ signal }) |
Resolves []. Every { id?, from, to, type? } link; how they are resolved and drawn is in Dependencies |
updateTasks(changes) |
Rejects: read-only. Stores { id, start, end } changes atomically and resolves with the stored tasks |
reset(), destroy() |
No-ops |
onConfigChanged |
null; <vn-gantt> sets it (auto-reload) |
_notifyConfigChanged(reason) |
Calls onConfigChanged, for subclasses' setters |
The contract is async with an abort signal and a batch write, so a server manager fits without changing the element.
2. The static manager
VanillaGanttStaticDataManager holds tasks and dependencies in memory.
fetchTasks()andfetchDependencies()resolve with the stored objects themselves, in a new array, and reject with anAbortErrorwhen the signal is already aborted. The Gantt and its grid therefore show the objects the manager holds.setTasks()andsetDependencies()replace the data and fireonConfigChanged('setTasks')/('setDependencies').updateTasks(changes)checks every id first and rejects, changing nothing, when one is unknown; otherwise it writesstartandendonto the stored objects and resolves with them, in the order ofchanges. Ids compare as strings and the first task with an id wins, as in the Gantt. The id map is built on the first call aftersetTasks().
3. The task model
VanillaGanttTasks.buildTaskModel(tasks, { signal })
(features/tasks.feature.js) builds, in O(n):
- Ids.
String(id)to index; a duplicate is left out after the first, and a task without an id is skipped. - Dates into two
Int32Arrays of UTC day numbers, through the grid'sVanillaGridDateTimeFeature.parseDateValue()with adatecolumn (Date and Time Types): a'YYYY-MM-DD'string is its UTC midnight; epoch ms and aDateare floored to their UTC day.endis exclusive, soend == startis a milestone. - Parents from
parentId(null,undefinedor''is a root). - Cycles, cut by one walk of each parent chain.
- Children bucketed by parent in input order (CSR arrays).
- Depth-first order, iterative, roots and siblings in input order.
- Roll-up, bottom-up over the reversed order: a summary spans the earliest start and the latest end of its children that have a bar; a summary with none has no bar.
- Span: the earliest start and latest end over every bar, for the range.
The passes that touch every task object (the ids, the dates, the parents)
yield through VanillaGridYield every 20,000 tasks, about 20 ms of work at
1M tasks, and stop with an AbortError when the load's signal aborted
meanwhile; the others are loops over typed arrays. Over 1M tasks the build
takes about 1.4 s in headless Chromium, with the page painting between the
slices.
Display order is the grid's, never this one: the grid sorts siblings
(Tree Rows § 4).
writeSummaryDates() then writes each summary's rolled-up dates onto its task
object as 'YYYY-MM-DD', so the grid's start and end cells show the span the
bar does, yielding every 20,000 tasks like the build. A summary's own input
dates are ignored.
4. Bad data: the Gantt's tree wins
| Data | Result |
|---|---|
Duplicate id |
The first task wins; the others are left out of both panes |
Unknown parentId |
The task is a root |
A parentId cycle, including a task that is its own parent |
Every task in the cycle is a root; their other children keep them as parent |
Unparsable start or end on a leaf, or end before start |
The row renders with no bar, and the leaf is left out of its parent's roll-up |
Each kind is warned once per load, with a count and the first id.
The grid builds its tree by different rules: it cuts a cycle at one row
chosen by the sorted order, and shows every duplicate row
(Tree Rows § 3). Left alone,
the two trees would differ, and a summary bar would span children the grid
shows elsewhere. So the grid never sees bad data: it gets the model's rows (no
duplicate) and tree.parentKeyGetter, which returns the parent the model
resolved (VanillaGanttTasks.parentKeyOf()), as String(id), or null for a
root. The getter is VanillaGanttTasks.parentKeyGetterOf(gantt), which reads
the Gantt's current model on each call: it is created in the task model's
fast-profile chunk, not the element, since the tree build calls it per row. It therefore sees no cycle and no unknown parent, and the two panes show
the same tree by construction whatever the sort. Cost: one Map lookup per
row per tree build.