Table of Contents

Class TwGanttChart

Namespace
TwBlazor.Components
Assembly
TwBlazor.dll

A Gantt chart: a horizontal bar per task from its start date to its end date, showing a schedule and where tasks overlap. Tasks can sit under summary tasks, show their progress, depend on each other, and be moved, resized and linked by dragging.

public class TwGanttChart : TwChartBase, IComponent, IHandleEvent, IHandleAfterRender, ITwComponent, IAsyncDisposable
Inheritance
TwGanttChart
Implements
Inherited Members

Remarks

The chart never changes the tasks it is given. Every gesture raises an event (OnTaskChange, OnDependencyCreate) that can be cancelled; store the change and pass the new tasks back in.

Accessibility: each row is a data point whose label gives the task's dates and progress, and the table view lists every task, including those under collapsed summaries. The expand buttons, zoom controls and toolbar buttons are keyboard operable. Dragging is pointer only, so offer another way to change dates, such as a form, when editing matters.

Constructors

TwGanttChart()

public TwGanttChart()

Properties

AllowDrag

Gets or sets whether bars can be dragged to new dates. Default is false.

[Parameter]
public bool AllowDrag { get; set; }

Property Value

bool

AllowLinking

Gets or sets whether dependencies can be drawn by dragging from the dot at either end of a bar to another bar. The ends picked decide the ChartDependencyType. Default is false.

[Parameter]
public bool AllowLinking { get; set; }

Property Value

bool

AllowProgressDrag

Gets or sets whether the grip under a bar can be dragged to set the task's progress. Default is false.

[Parameter]
public bool AllowProgressDrag { get; set; }

Property Value

bool

AllowResize

Gets or sets whether either end of a bar can be dragged to change its start or end. Default is false.

[Parameter]
public bool AllowResize { get; set; }

Property Value

bool

CollapsedIds

Gets or sets the keys of the summary tasks whose tasks are hidden. Bind it with @bind-CollapsedIds to keep the state.

[Parameter]
public IReadOnlySet<string>? CollapsedIds { get; set; }

Property Value

IReadOnlySet<string>

Remarks

The set names the closed summaries, so a task added later starts open.

CollapsedIdsChanged

Raised with the new set of collapsed summaries when one is expanded or collapsed.

[Parameter]
public EventCallback<IReadOnlySet<string>> CollapsedIdsChanged { get; set; }

Property Value

EventCallback<IReadOnlySet<string>>

DateFormat

Gets or sets the .NET date format string used on the axis at Auto, and in tooltips and the table view.

[Parameter]
public string DateFormat { get; set; }

Property Value

string

Remarks

Default is "d MMM", which also shows the time at Hour.

DefaultExpandAll

Gets or sets whether summaries start expanded when CollapsedIds is not set. Default is true.

[Parameter]
public bool DefaultExpandAll { get; set; }

Property Value

bool

Dependencies

Gets or sets the dependencies between tasks, each drawn as an arrow from one task to the other.

[Parameter]
public IReadOnlyList<ChartTaskDependency> Dependencies { get; set; }

Property Value

IReadOnlyList<ChartTaskDependency>

EndLabel

Gets or sets the label for a task's end date. Defaults to the localized Chart_End text ("End").

[Parameter]
public string? EndLabel { get; set; }

Property Value

string

LabelHeader

Gets or sets the heading of the task column in the table view. Defaults to the localized Chart_Task text ("Task").

[Parameter]
public string? LabelHeader { get; set; }

Property Value

string

NonWorkingDays

Gets or sets the days of the week that are shaded as non-working at Day and Hour. If not set, Saturday and Sunday.

[Parameter]
public IReadOnlyCollection<DayOfWeek>? NonWorkingDays { get; set; }

Property Value

IReadOnlyCollection<DayOfWeek>

OnDependencyClick

Raised when a dependency arrow is clicked while AllowLinking is on, for example to remove it.

[Parameter]
public EventCallback<ChartTaskDependency> OnDependencyClick { get; set; }

Property Value

EventCallback<ChartTaskDependency>

OnDependencyCreate

Raised when a dependency is drawn. Add it to Dependencies to keep it, or set Cancel.

[Parameter]
public EventCallback<ChartDependencyRequest> OnDependencyCreate { get; set; }

Property Value

EventCallback<ChartDependencyRequest>

OnTaskChange

Raised when a bar is moved or resized, or its progress is dragged. Store the new values, or set Cancel to leave the bar where it was.

[Parameter]
public EventCallback<ChartTaskChange> OnTaskChange { get; set; }

Property Value

EventCallback<ChartTaskChange>

OnTaskClick

Raised when a task's row is clicked, or Enter or Space is pressed on it.

[Parameter]
public EventCallback<ChartTask> OnTaskClick { get; set; }

Property Value

EventCallback<ChartTask>

RangeEnd

Gets or sets the last date the chart shows. If not set, the chart ends at the latest task.

[Parameter]
public DateTime? RangeEnd { get; set; }

Property Value

DateTime?

RangeStart

Gets or sets the first date the chart shows. If not set, the chart starts at the earliest task.

[Parameter]
public DateTime? RangeStart { get; set; }

Property Value

DateTime?

RollUpSummaries

Gets or sets whether a summary task's dates and progress are worked out from the tasks under it.

[Parameter]
public bool RollUpSummaries { get; set; }

Property Value

bool

Remarks

Default is true: a summary spans its tasks, and its progress is theirs weighted by length. Turn it off when a summary keeps dates of its own, such as an agreed baseline.

RowHeight

Gets or sets the height of each row in pixels, so the chart grows with its tasks. If not set, the rows share the chart's Height.

[Parameter]
public int? RowHeight { get; set; }

Property Value

int?

ScrollToToday

Gets or sets whether a scrolling plot first scrolls to today, when today is in the chart's range. Default is true.

[Parameter]
public bool ScrollToToday { get; set; }

Property Value

bool

ShowDependencies

Gets or sets whether the dependency arrows are drawn. Default is true.

[Parameter]
public bool ShowDependencies { get; set; }

Property Value

bool

ShowNonWorkingDays

Gets or sets whether non-working days are shaded. Default is true.

[Parameter]
public bool ShowNonWorkingDays { get; set; }

Property Value

bool

ShowTaskLabels

Gets or sets whether each bar is labelled with its task's name. Default is false.

[Parameter]
public bool ShowTaskLabels { get; set; }

Property Value

bool

ShowToday

Gets or sets whether a line marks today, when today is in the chart's range. Default is true.

[Parameter]
public bool ShowToday { get; set; }

Property Value

bool

ShowToolbar

Gets or sets whether the toolbar with the zoom controls, expand and collapse buttons and today button is shown. Default is true.

[Parameter]
public bool ShowToolbar { get; set; }

Property Value

bool

ShowZoomControls

Gets or sets whether the toolbar has zoom controls. Default is true.

[Parameter]
public bool ShowZoomControls { get; set; }

Property Value

bool

SlotWidth

Gets or sets the width of one column in pixels at any zoom level other than Auto. If not set, each level has its own width, from 40 pixels a day to 88 a year.

[Parameter]
public int? SlotWidth { get; set; }

Property Value

int?

SnapToSlot

Gets or sets whether dragged dates snap to the nearest column (or to midnight at Auto). Default is true.

[Parameter]
public bool SnapToSlot { get; set; }

Property Value

bool

StartLabel

Gets or sets the label for a task's start date. Defaults to the localized Chart_Start text ("Start").

[Parameter]
public string? StartLabel { get; set; }

Property Value

string

Tasks

Gets or sets the tasks to plot, in the order they should be listed. Tasks with a ParentId are listed under their summary task.

[Parameter]
public IReadOnlyList<ChartTask> Tasks { get; set; }

Property Value

IReadOnlyList<ChartTask>

Today

Gets or sets the moment the today line marks. If not set, the current time.

[Parameter]
public DateTime? Today { get; set; }

Property Value

DateTime?

Zoom

Gets or sets how much time the chart shows. Bind it with @bind-Zoom to follow the zoom controls.

[Parameter]
public GanttZoom Zoom { get; set; }

Property Value

GanttZoom

Remarks

Default is Auto: the whole schedule fits the chart's width. Any other level gives each day, week, month, quarter or year a column of SlotWidth pixels and scrolls the plot when it is wider than the chart, keeping the task names in view.

ZoomChanged

Raised when the zoom level changes from the zoom controls or SetZoomAsync(GanttZoom).

[Parameter]
public EventCallback<GanttZoom> ZoomChanged { get; set; }

Property Value

EventCallback<GanttZoom>

datumClass

Gets extra classes for every data point, such as a pointer cursor when datumsActivatable is set.

protected override string? datumClass { get; }

Property Value

string

datumsActivatable

Gets whether clicking a data point, or pressing Enter or Space on it, calls OnDatumActivatedAsync(int).

protected override bool datumsActivatable { get; }

Property Value

bool

plotHeight

Gets the height of the plot in pixels, replacing the height set by Height.

protected override double? plotHeight { get; }

Property Value

double?

plotMinWidth

Gets the minimum width of the plot in pixels. When set, a plot wider than its container scrolls horizontally while the labels on its left stay in view.

protected override double? plotMinWidth { get; }

Property Value

double?

plotOverlay

Gets content layered over the plot, above the data points. Positions inside it are percentages of the plot.

protected override RenderFragment? plotOverlay { get; }

Property Value

RenderFragment

plotScrollerClass

Gets the classes for the element that scrolls the plot when plotMinWidth is set. It needs to scroll horizontally, such as with overflow-x-auto.

protected override string? plotScrollerClass { get; }

Property Value

string

toolbarContent

Gets content shown at the start of the toolbar, before the legend, such as controls that change the view.

protected override RenderFragment? toolbarContent { get; }

Property Value

RenderFragment

yAxisClass

Gets extra classes for the labels along the left of the plot, such as a different maximum width. A scrolling plot (plotMinWidth) sits in a taller cell than the plot itself, so these classes should then keep the labels to the top of it.

protected override string? yAxisClass { get; }

Property Value

string

Methods

BuildScene(ChartSceneBuilder)

Describes what the chart draws by adding marks, data points, axes, legend entries and a table to builder. Add nothing to show the empty state.

protected override void BuildScene(ChartSceneBuilder builder)

Parameters

builder ChartSceneBuilder

The builder that collects the scene.

CollapseAllAsync()

Hides the tasks under every summary.

public Task CollapseAllAsync()

Returns

Task

A task that completes once the change is reported.

CommitBarDrag(string, string, double, double)

Takes the dates a bar was dragged to. Called by the gesture script; not for app code.

[JSInvokable]
public Task<bool> CommitBarDrag(string key, string kind, double startPosition, double endPosition)

Parameters

key string

The task's key.

kind string

"move", "resize-start" or "resize-end".

startPosition double

Where the bar now starts, from 0 to 100 across the plot.

endPosition double

Where the bar now ends, from 0 to 100 across the plot.

Returns

Task<bool>

true if the change was accepted.

Takes a dependency drawn between two bars. Called by the gesture script; not for app code.

[JSInvokable]
public Task<bool> CommitLink(string fromKey, string fromAnchor, string toKey, string toAnchor)

Parameters

fromKey string

The key of the task the line was drawn from.

fromAnchor string

"start" or "end": which end of that bar it was drawn from.

toKey string

The key of the task the line was drawn to.

toAnchor string

"start" or "end": which end of that bar it was drawn to.

Returns

Task<bool>

true if the dependency was accepted.

CommitProgressDrag(string, double)

Takes the progress a bar's grip was dragged to. Called by the gesture script; not for app code.

[JSInvokable]
public Task<bool> CommitProgressDrag(string key, double progress)

Parameters

key string

The task's key.

progress double

The new progress, from 0 to 1.

Returns

Task<bool>

true if the change was accepted.

DisposeCoreAsync()

Releases what a chart type holds, such as references handed to script. Called by DisposeAsync().

protected override ValueTask DisposeCoreAsync()

Returns

ValueTask

ExpandAllAsync()

Shows the tasks under every summary.

public Task ExpandAllAsync()

Returns

Task

A task that completes once the change is reported.

GoToTodayAsync()

Scrolls a zoomed-in plot to today.

public Task GoToTodayAsync()

Returns

Task

A task that completes once the plot has scrolled.

OnAfterRenderAsync(bool)

Method invoked after each time the component has been rendered interactively and the UI has finished updating (for example, after elements have been added to the browser DOM). Any ElementReference fields will be populated by the time this runs.

This method is not invoked during prerendering or server-side rendering, because those processes are not attached to any live browser DOM and are already complete before the DOM is updated.

Note that the component does not automatically re-render after the completion of any returned Task, because that would cause an infinite render loop.

protected override Task OnAfterRenderAsync(bool firstRender)

Parameters

firstRender bool

Set to true if this is the first time OnAfterRender(bool) has been invoked on this component instance; otherwise false.

Returns

Task

A Task representing any asynchronous operation.

Remarks

The OnAfterRender(bool) and OnAfterRenderAsync(bool) lifecycle methods are useful for performing interop, or interacting with values received from @ref. Use the firstRender parameter to ensure that initialization work is only performed once.

OnDatumActivatedAsync(int)

Called when a data point is clicked, or Enter or Space is pressed on it, while datumsActivatable is true.

protected override Task OnDatumActivatedAsync(int index)

Parameters

index int

The zero-based position of the data point.

Returns

Task

OnParametersSet()

Invoked when the component's parameters have been set. Ensures that the component has a unique identifier by generating one if none is provided.

protected override void OnParametersSet()

Remarks

If the component's identifier is not set, a unique ID is generated based on the component's type name (with a 'Tw' prefix removed if present) and a GUID. This helps ensure that each component instance can be uniquely identified, which is useful for scenarios such as associating labels with form elements or targeting elements in client-side scripts.

RenderYTick(ChartTick, int)

Gets content to show for a label along the left of the plot instead of its text. Return null to show the text. Content that holds controls makes the labels readable by assistive technology, so it should repeat the label's text.

protected override RenderFragment? RenderYTick(ChartTick tick, int index)

Parameters

tick ChartTick

The label.

index int

The zero-based position of the label.

Returns

RenderFragment

ScrollToAsync(DateTime)

Scrolls a zoomed-in plot so a date is near its start. Does nothing at Auto, where the whole schedule is in view.

public Task ScrollToAsync(DateTime value)

Parameters

value DateTime

The date to scroll to.

Returns

Task

A task that completes once the plot has scrolled.

SetZoomAsync(GanttZoom)

Changes the zoom level and raises ZoomChanged.

public Task SetZoomAsync(GanttZoom value)

Parameters

value GanttZoom

The new zoom level.

Returns

Task

A task that completes once the change is reported.