GanttChart
Description
Labelled rows of bars on a shared horizontal axis
GanttChart lists rows in a label column and draws each row's bars on one axis shared by every row, so when things happen and what overlaps what can be read at a glance. Use it for schedules, the steps of a process, or any set of spans over time.
The axis is either a set of named, equal-width columns (Columns(...)) or a numeric range with evenly spaced ticks. Without Columns, the axis spans the bars, or the range set with Range(...). The label column stays in place while the timeline scrolls sideways once it is narrower than its minimum width (TrackMinWidth, 480px by default).
Create a chart with GanttChart(), add rows with Add(GanttRow(label, bars...)), and create bars with GanttBar(start, end) in the axis's unit. With named columns, column i spans i to i + 1, so GanttBar(0, 2) covers the first two columns.
Samples
Named columns
Columns(...) splits the axis into equal columns. Color(GanttBarColor) picks one of the preset hues and Tooltip(...) sets the hover text.
A numeric axis
Without columns the axis is numeric. TickFormat(...) writes the ticks, Text(...) puts a label beside a bar, Indent(...) nests a row under the one above, and Striped() marks a span that was waiting. OnBarClick(...) receives the clicked bar.
Several bars on one row
A row holds any number of bars. Color(string) takes any CSS color and derives the fill and the outline from it. Range(...) and Ticks(...) pin the axis, and EmptyMessage(...) is shown while the chart has no rows.
API reference
public enum GanttBarColorThe preset colors a GanttBar can be painted with. Each one is a pastel fill under a stronger outline of the same hue, which reads the same in light and dark mode.
- Namespace
- Tesserae
public sealed class GanttBarOne bar on a GanttChart row: a span from Start to End, in whatever unit the chart's axis is in (days, seconds, milliseconds since an origin, …).
- Namespace
- Tesserae
Constructors
| Name | Description |
|---|---|
| GanttBar | Initializes a new instance of this class. |
Properties
| Name | Description |
|---|---|
| Start | Where the bar starts, on the chart's axis. |
| End | Where the bar ends, on the chart's axis. Never before Start. |
| PresetColor | The preset color, when no custom color was set. |
| CustomColor | The custom CSS color, or null for PresetColor. |
| Label | The text drawn beside the bar, or null for none. |
| TooltipContent | What the bar shows on hover, or null for nothing. |
| IsStriped | Whether the bar is drawn hatched, for a span that is pending or still running. |
| Tag | Any value the caller wants back from OnBarClick. |
public double End { get; }Where the bar ends, on the chart's axis. Never before Start.
public GanttBarColor PresetColor { get; private set; }The preset color, when no custom color was set.
public string CustomColor { get; private set; }The custom CSS color, or null for PresetColor.
public string Label { get; private set; }The text drawn beside the bar, or null for none.
public IComponent TooltipContent { get; private set; }What the bar shows on hover, or null for nothing.
public bool IsStriped { get; private set; }Whether the bar is drawn hatched, for a span that is pending or still running.
Methods
| Name | Description |
|---|---|
| Color | Paints the bar with one of the preset colors. |
| Text | Draws text beside the bar, after its end (or before its start, near the right edge). |
| Tooltip | Shows text when the bar is hovered. |
| Striped | Draws the bar hatched, for a span that is pending, queued or still running. |
| SetTag | Attaches a value that OnBarClick hands back. |
| Overload | |
|---|---|
| Color(GanttBarColor) | Paints the bar with one of the preset colors. |
| Color(string) | Paints the bar with a CSS color; the fill and outline are derived from it. |
public GanttBar Text(string text)Draws text beside the bar, after its end (or before its start, near the right edge).
| Overload | |
|---|---|
| Tooltip(string) | Shows text when the bar is hovered. |
| Tooltip(IComponent) | Shows content when the bar is hovered. |
public GanttBar Striped(bool striped = true)Draws the bar hatched, for a span that is pending, queued or still running.
public sealed class GanttRowOne row of a GanttChart: a label in the first column and any number of bars on the timeline.
- Namespace
- Tesserae
Constructors
| Name | Description |
|---|---|
| GanttRow | Initializes a new instance of this class with a text label. |
| Overload | |
|---|---|
| GanttRow(string, GanttBar[]) | Initializes a new instance of this class with a text label. |
| GanttRow(IComponent, GanttBar[]) | Initializes a new instance of this class with a component as its label. |
Properties
| Name | Description |
|---|---|
| LabelComponent | What the first column shows for this row. |
| Bars | The row's bars. |
| IndentLevel | How many levels the label is indented by, to show a row belongs under the one above. |
public IComponent LabelComponent { get; }What the first column shows for this row.
public sealed class GanttChart : ComponentBase<GanttChart, HTMLElement>A timeline of labelled rows, each holding one or more bars laid out on a shared horizontal axis - a schedule of tasks over days, or the steps of a process over seconds. The axis is either a set of named, equal-width columns (Columns) or a numeric range with evenly spaced ticks (Range, TickFormat).
Remarks
The label column stays put while the timeline scrolls sideways once it is narrower than TrackMinWidth. Without an explicit range the axis spans the bars.
- Namespace
- Tesserae
- Inheritance
- ComponentBase<GanttChart, HTMLElement> → GanttChart
Constructors
| Name | Description |
|---|---|
| GanttChart | Initializes a new instance of this class. |
Methods
| Name | Description |
|---|---|
| Title | Sets the heading of the label column. Defaults to "Task". |
| Columns | Lays the axis out as named, equal-width columns - days of a week, sprints, phases. Column i spans i to i + 1 on the axis, so a bar from 0 to 2 covers the first two. |
| Range | Pins the numeric axis to start..end. Defaults to the span of the bars. |
| Ticks | Sets roughly how many ticks the numeric axis shows; the step is rounded to 1, 2 or 5 times a power of ten. Defaults to 6. |
| TickFormat | Sets how a tick of the numeric axis is written - for example as a duration. |
| LabelWidth | Sets the width of the label column. Defaults to 240px. |
| RowHeight | Sets the height of each row. Defaults to 44px. |
| TrackMinWidth | Sets the narrowest the timeline gets before the chart scrolls sideways. Defaults to 480px. |
| EmptyMessage | Sets what the chart says when it has no rows. |
| OnBarClick | Calls onClick with the bar that was clicked. |
| Add | Adds a row. |
| Rows | Replaces every row with rows. |
| Clear | Removes every row. |
| Render | Renders the component's root HTML element. |
public GanttChart Title(string title)Sets the heading of the label column. Defaults to "Task".
public GanttChart Columns(params string[] columns)Lays the axis out as named, equal-width columns - days of a week, sprints, phases. Column i spans i to i + 1 on the axis, so a bar from 0 to 2 covers the first two.
public GanttChart Range(double start, double end)Pins the numeric axis to start..end. Defaults to the span of the bars.
public GanttChart Ticks(int approximateCount)Sets roughly how many ticks the numeric axis shows; the step is rounded to 1, 2 or 5 times a power of ten. Defaults to 6.
public GanttChart TickFormat(Func<double, string> format)Sets how a tick of the numeric axis is written - for example as a duration.
public GanttChart LabelWidth(UnitSize width)Sets the width of the label column. Defaults to 240px.
public GanttChart RowHeight(UnitSize height)Sets the height of each row. Defaults to 44px.
public GanttChart TrackMinWidth(UnitSize width)Sets the narrowest the timeline gets before the chart scrolls sideways. Defaults to 480px.
public GanttChart EmptyMessage(string message)Sets what the chart says when it has no rows.
public GanttChart OnBarClick(Action<GanttBar> onClick)Calls onClick with the bar that was clicked.