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

enum

GanttBarColor

public enum GanttBarColor

The 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
class

GanttBar

public sealed class GanttBar

One 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

NameDescription
GanttBarInitializes a new instance of this class.
Constructor
GanttBar
public GanttBar(double start, double end)

Initializes a new instance of this class.

Properties

NameDescription
StartWhere the bar starts, on the chart's axis.
EndWhere the bar ends, on the chart's axis. Never before Start.
PresetColorThe preset color, when no custom color was set.
CustomColorThe custom CSS color, or null for PresetColor.
LabelThe text drawn beside the bar, or null for none.
TooltipContentWhat the bar shows on hover, or null for nothing.
IsStripedWhether the bar is drawn hatched, for a span that is pending or still running.
TagAny value the caller wants back from OnBarClick.
Property
GanttBar.Start
public double Start { get; }

Where the bar starts, on the chart's axis.

Property
GanttBar.End
public double End { get; }

Where the bar ends, on the chart's axis. Never before Start.

Property
GanttBar.PresetColor
public GanttBarColor PresetColor { get; private set; }

The preset color, when no custom color was set.

Property
GanttBar.CustomColor
public string CustomColor { get; private set; }

The custom CSS color, or null for PresetColor.

Property
GanttBar.Label
public string Label { get; private set; }

The text drawn beside the bar, or null for none.

Property
GanttBar.TooltipContent
public IComponent TooltipContent { get; private set; }

What the bar shows on hover, or null for nothing.

Property
GanttBar.IsStriped
public bool IsStriped { get; private set; }

Whether the bar is drawn hatched, for a span that is pending or still running.

Property
GanttBar.Tag
public object Tag { get; private set; }

Any value the caller wants back from OnBarClick.

Methods

NameDescription
ColorPaints the bar with one of the preset colors.
TextDraws text beside the bar, after its end (or before its start, near the right edge).
TooltipShows text when the bar is hovered.
StripedDraws the bar hatched, for a span that is pending, queued or still running.
SetTagAttaches a value that OnBarClick hands back.
Method
GanttBar.Color
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.
Color(GanttBarColor)
public GanttBar Color(GanttBarColor color)

Paints the bar with one of the preset colors.

Parameters

color GanttBarColor
Color(string)
public GanttBar Color(string cssColor)

Paints the bar with a CSS color; the fill and outline are derived from it.

Parameters

cssColor string
Method
GanttBar.Text
public GanttBar Text(string text)

Draws text beside the bar, after its end (or before its start, near the right edge).

Method
GanttBar.Tooltip
Overload
Tooltip(string)Shows text when the bar is hovered.
Tooltip(IComponent)Shows content when the bar is hovered.
Tooltip(string)
public GanttBar Tooltip(string text)

Shows text when the bar is hovered.

Parameters

text string
Tooltip(IComponent)
public GanttBar Tooltip(IComponent content)

Shows content when the bar is hovered.

Parameters

content IComponent
Method
GanttBar.Striped
public GanttBar Striped(bool striped = true)

Draws the bar hatched, for a span that is pending, queued or still running.

Method
GanttBar.SetTag
public GanttBar SetTag(object tag)

Attaches a value that OnBarClick hands back.

class

GanttRow

public sealed class GanttRow

One row of a GanttChart: a label in the first column and any number of bars on the timeline.

Namespace
Tesserae

Constructors

NameDescription
GanttRowInitializes a new instance of this class with a text label.
Constructor
GanttRow
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.
GanttRow(string, GanttBar[])
public GanttRow(string label, params GanttBar[] bars) : this(TextBlock(label ?? "").Ellipsis().Tooltip(TextBlock(label ?? "")), bars)

Initializes a new instance of this class with a text label.

Parameters

label string
bars GanttBar[]
GanttRow(IComponent, GanttBar[])
public GanttRow(IComponent label, params GanttBar[] bars)

Initializes a new instance of this class with a component as its label.

Parameters

label IComponent
bars GanttBar[]

Properties

NameDescription
LabelComponentWhat the first column shows for this row.
BarsThe row's bars.
IndentLevelHow many levels the label is indented by, to show a row belongs under the one above.
Property
GanttRow.LabelComponent
public IComponent LabelComponent { get; }

What the first column shows for this row.

Property
GanttRow.Bars
public IReadOnlyList<GanttBar> Bars

The row's bars.

Property
GanttRow.IndentLevel
public int IndentLevel { get; private set; }

How many levels the label is indented by, to show a row belongs under the one above.

Methods

NameDescription
AddAdds a bar to the row.
IndentIndents the label by level steps, to nest the row under the one above it.
Method
GanttRow.Add
public GanttRow Add(GanttBar bar)

Adds a bar to the row.

Method
GanttRow.Indent
public GanttRow Indent(int level = 1)

Indents the label by level steps, to nest the row under the one above it.

class

GanttChart

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

NameDescription
GanttChartInitializes a new instance of this class.
Constructor
GanttChart
public GanttChart()

Initializes a new instance of this class.

Methods

NameDescription
TitleSets the heading of the label column. Defaults to "Task".
ColumnsLays 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.
RangePins the numeric axis to start..end. Defaults to the span of the bars.
TicksSets 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.
TickFormatSets how a tick of the numeric axis is written - for example as a duration.
LabelWidthSets the width of the label column. Defaults to 240px.
RowHeightSets the height of each row. Defaults to 44px.
TrackMinWidthSets the narrowest the timeline gets before the chart scrolls sideways. Defaults to 480px.
EmptyMessageSets what the chart says when it has no rows.
OnBarClickCalls onClick with the bar that was clicked.
AddAdds a row.
RowsReplaces every row with rows.
ClearRemoves every row.
RenderRenders the component's root HTML element.
Method
GanttChart.Title
public GanttChart Title(string title)

Sets the heading of the label column. Defaults to "Task".

Method
GanttChart.Columns
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.

Method
GanttChart.Range
public GanttChart Range(double start, double end)

Pins the numeric axis to start..end. Defaults to the span of the bars.

Method
GanttChart.Ticks
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.

Method
GanttChart.TickFormat
public GanttChart TickFormat(Func<double, string> format)

Sets how a tick of the numeric axis is written - for example as a duration.

Method
GanttChart.LabelWidth
public GanttChart LabelWidth(UnitSize width)

Sets the width of the label column. Defaults to 240px.

Method
GanttChart.RowHeight
public GanttChart RowHeight(UnitSize height)

Sets the height of each row. Defaults to 44px.

Method
GanttChart.TrackMinWidth
public GanttChart TrackMinWidth(UnitSize width)

Sets the narrowest the timeline gets before the chart scrolls sideways. Defaults to 480px.

Method
GanttChart.EmptyMessage
public GanttChart EmptyMessage(string message)

Sets what the chart says when it has no rows.

Method
GanttChart.OnBarClick
public GanttChart OnBarClick(Action<GanttBar> onClick)

Calls onClick with the bar that was clicked.

Method
GanttChart.Add
public GanttChart Add(GanttRow row)

Adds a row.

Method
GanttChart.Rows
public GanttChart Rows(params GanttRow[] rows)

Replaces every row with rows.

Method
GanttChart.Clear
public GanttChart Clear()

Removes every row.

Method
GanttChart.Render
public override HTMLElement Render()

Renders the component's root HTML element.

See also