VB Project Planning

<gantt-chart>

HTML-first Gantt chart using native table, progress, and time elements with progressive enhancement to an interactive timeline.

Overview

A web component that progressively enhances a semantic <table> into an interactive Gantt timeline. Without JavaScript, users see a fully readable data table with native <progress> bars and <time> elements. With JavaScript, the component renders a visual timeline with positioned bars, swim lane groups, milestones, progress fill, and a today marker.

Attributes

AttributeValuesDefaultDescription
titlestring—Chart heading (a src JSON "title" sets it)
srcstring—URL of JSON task data ({ title?, tasks: [...] }). Fetched once on connect or when the attribute changes; the fetched tasks replace the child table. A newer value aborts an older in-flight request. Skipped on connect when .tasks was already assigned, and an in-flight request is aborted when .tasks is assigned (.tasks takes precedence)
view"auto", "day", "week", "month", "quarter""auto"Timeline granularity. auto picks day (≤ 3 weeks), week (≤ 90 days), month (≤ 1 year) or quarter
show-todayboolean—Show vertical today marker line
show-progressboolean—Show progress fill inside bars
show-dependenciesboolean—Draw dependency arrows between tasks (row positions are measured, so compact and grouped charts line up)
compactboolean—Reduced row height and spacing

Task Row Attributes

Each <tr> in the table body can carry these data attributes to configure the corresponding task bar.

AttributeOnValuesDescription
data-task-idtrstringUnique task identifier (used by data-depends)
data-grouptrstringSwim lane group; with two or more groups each gets a header row
data-dependstrstringComma-separated task IDs this task depends on (drawn with show-dependencies)
data-statustr"not-started", "in-progress", "done", "blocked"Task status: shown as text in the task list and in the bar's accessible name; also tints the bar
data-assigneetrstringAssignee name (included in the bar's accessible name)
data-milestonetrbooleanRender a diamond marker at the start date instead of a duration bar
data-colortrstringCustom bar colour (any CSS colour)
data-story-idstrstringComma-separated linked user-story IDs (exposed as task.storyIds)
data-item-idstrstringComma-separated linked work-item IDs (exposed as task.itemIds)

How It Works

The component reads task data from the semantic table structure:

  • Task name — from the first <td> text
  • Start/end dates — from <time datetime="YYYY-MM-DD"> elements
  • Progress — from <progress value="..." max="...">
  • Metadata — from data-* attributes on the <tr>

Dates are calendar days in the viewer's local time zone: 2026-04-01 is shown as April 1 everywhere (it is not read as UTC midnight). Positions are measured in whole days, so daylight-saving changes don't shift bars. Each bar is positioned at left: (taskStart - rangeStart) / rangeDays * 100% with width: (taskEnd - taskStart) / rangeDays * 100%; the range runs from the earliest start to the latest end. The timeline granularity auto-adjusts based on the date range, or can be set explicitly via the view attribute; month and quarter ticks fall on the 1st of the month or quarter.

Data Mode

Load task data from JSON via the src attribute. It is fetched once when the element connects (whether src was set before or after) and again only when src changes; moving the element in the DOM does not refetch. The loaded tasks replace any child table, and the component generates a visually hidden table from them for screen readers. A "title" in the JSON sets the title attribute. A newer src aborts an older in-flight request.

Precedence: .tasks wins over src. If .tasks is assigned before the element connects, the initial src is not fetched, and assigning .tasks while a src request is in flight aborts it. Changing src afterwards loads that URL (the most recent source wins). gantt-chart:ready fires once per element; later src loads fire gantt-chart:tasks-changed with source: 'src'.

Events

EventDetailDescription
gantt-chart:upgraded—Once per connect, in a microtask after setup; a safe signal for the first .tasks assignment (fires for an empty chart too)
gantt-chart:ready{ taskCount, dateRange: { start, end } }Once per element: after the first connect render that has tasks (table or .tasks), or else after the first src load. Not re-fired on reconnect or by later src loads (those fire tasks-changed with source 'src'). dateRange values are YYYY-MM-DD
gantt-chart:task-click{ task }When a bar or milestone is clicked or activated with Enter/Space
gantt-chart:tasks-changed{ tasks, source: 'property' | 'src' }After .tasks is assigned (source 'property') or src data loads (source 'src'), with the normalized tasks

Property API (JS-first)

For reactive frameworks, assign .tasks directly instead of templating the source <table>. Each task is a plain object; start/end accept YYYY-MM-DD strings, Dates or timestamps. Tasks without a valid start are dropped.

PropertyTypeDescription
.tasksTask[]Setter replaces the chart contents and re-renders, and regenerates the visually hidden table from the new tasks (the authored table is replaced). Assigned tasks survive moving the element in the DOM. Reading returns the normalized array: start/end are local-midnight timestamps, progress is 0–1, depends/storyIds/itemIds are arrays.

An empty <gantt-chart> (no table, no src) still upgrades and fires gantt-chart:upgraded, so the JS-first pattern above works. A .tasks value assigned before the element is defined is picked up on upgrade.

See the Data API concepts guide for the dual-mode contract.

CSS Custom Properties

VariableDefaultDescription
--gc-task-width180pxLeft panel (task names) width
--gc-row-height36pxRow height for tasks and bars (28px with compact). Dependency arrows follow any value.
--gc-bar-colorvar(--color-interactive)Per-bar color override

Accessibility

  • The task table stays in the DOM (visually hidden) so screen readers get full table semantics with <th>, <time>, and <progress>. For .tasks and src data the component generates that table from the current tasks.
  • Each bar and milestone is a focusable role="button" whose accessible name gives the task name, dates, status, progress and assignee (e.g. “API development: Apr 10, 2026 to May 1, 2026, status: in progress, 40% complete”). Enter or Space activates it and fires gantt-chart:task-click.
  • Status is shown as text in the task list, not by bar colour alone.
  • An aria-live="polite" region announces task selection.
  • Dependency arrows are decorative (aria-hidden); dependencies are not announced.
  • Attribute-driven re-renders crossfade with a View Transition, skipped under prefers-reduced-motion: reduce; bar hover transitions are disabled there too.
  • Print styles show the table and hide the visual chart

Related

↑