Skip to content
ConsoleMonster
Class

StackedBar

ConsoleMonster.Widgets

Namespace
ConsoleMonster.Widgets
Assembly
ConsoleMonster
Modifiers
sealed

One bar split into proportional segments with a legend (label, value, share). Problem segments take their status colour; healthy and unclassified segments stay neutral. Adjacent indistinguishable fills have a one-cell gap when space allows. An explicit role selects another colour. Without colour, segments use distinct fill glyphs so the split stays readable. Live operations (Key = segment): set (Value), add (Value).

Inheritance

Usage

Explore 36 API references to this type

This type appears in these public API surfaces even when no hand-authored example is attached directly to the page.

Accepted by parameters 18

Constructors

public StackedBar(string widgetId = "stacked") #

Creates a stacked bar.

Parameters

widgetId string = "stacked" optional
The live name (default stacked).

Methods

Add 2 overloads
public StackedBar Add(RichText label, double value, ThemeToken? role = null, string? key = null) #

Adds or updates a segment with a multicolour legend label (its plain text is the key).

Parameters

label ConsoleMonster.Text.RichText required
The rich label.
value double required
The value.
role ConsoleMonster.Styling.ThemeToken? = null optional
The colour role, or null for the next series colour.
key string? = null optional
Stable item identity, or null to use the label.

Returns

StackedBar This instance.
public StackedBar Add(string label, double value, ThemeToken? role = null, string? key = null) #

Adds or updates a segment.

Parameters

label string required
The label.
value double required
The value.
role ConsoleMonster.Styling.ThemeToken? = null optional
The colour role, or null for the next series colour.
key string? = null optional
Stable item identity, or null to use the label.

Returns

StackedBar This instance.
public override void Apply(LiveEvent liveEvent) #

Applies an event to the widget's state.

Parameters

liveEvent ConsoleMonster.Live.LiveEvent required
The event.
public string GetFillMarker(int segmentIndex, RenderContext context) #

Gets the exact unpadded fill glyph used for a segment in the supplied rendering context. Custom legends can use this marker at every colour depth to identify the corresponding bar fill. The built-in bar and legend use this same mapping.

Parameters

segmentIndex int required
Zero-based index in StackedBar.Segments, including zero-valued segments.
context ConsoleMonster.Canvas.RenderContext required
The rendering context, including its glyph set and color capability.

Returns

string The segment's fill glyph, with no surrounding spaces.

Exceptions

  • ArgumentOutOfRangeException โ€“ The index does not identify a segment.
  • ArgumentNullException โ€“ The context is null.
public override Size Measure(Constraints constraints, RenderContext context) #

Returns the size the widget wants within the constraints.

Parameters

constraints ConsoleMonster.Layout.Constraints required
The space offered.
context ConsoleMonster.Canvas.RenderContext required
Profile, theme and glyphs.

Returns

Size The desired size, never larger than the constraints.
public override void Render(Region region, RenderContext context) #

Renders into a region. The region may be smaller or larger than the measured size.

Parameters

region ConsoleMonster.Canvas.Region required
The target region.
context ConsoleMonster.Canvas.RenderContext required
Profile, theme and glyphs.

Properties

public IReadOnlyList<ChartItem> Segments { get; } #

The segments.

public bool ShowLegend { get; set; } #

Whether the legend line is shown (default true).

public int MaxLegendColumns { get; set; } #

The most legend columns per row, or 0 (default) to fit as many as the width allows. Entries fill rows left to right and every row shares one grid fitted to each column, so labels, counts and percentages line up.

public bool ShowTotal { get; set; } #

Whether the total is written after the bar (default true). Turn it off where a title or caption already gives it.

public bool ShowSwatches { get; set; } #

Whether each legend entry starts with a swatch of its bar fill (default true). Without swatches, an entry with a status shows only its coloured status symbol, so every row has one marker; entries without a status, and every entry when there is no colour, keep their swatch.

public bool ColorPassing { get; set; } #

Whether a passing share keeps the pass colour (default false: it is drawn neutral so the problem shares stand out). Turn it on where passing items are coloured elsewhere on the same screen, such as in a cell map.

public ColumnFormat LabelColumn { get; set; } #

Layout of the legend label column (default left-aligned).

public ColumnFormat CountColumn { get; set; } #

Layout of the legend count column (default right-aligned; reserves the digits of the overall total).

public ColumnFormat PercentColumn { get; set; } #

Layout of the legend percentage column (default right-aligned, four cells).

Extension Methods

public static StackedBar ColorPassing(StackedBar stackedBar, bool value = true) #

Sets StackedBar.ColorPassing: Whether a passing share keeps the pass colour (default false: it is drawn neutral so the problem shares stand out). Turn it on where passing items are coloured elsewhere on the same screen, such as in a cell map.

Parameters

stackedBar ConsoleMonster.Widgets.StackedBar required
The instance.
value bool = true optional
The value; true when omitted.

Returns

StackedBar The same instance.

Examples

// C# initializer or property                                              // C# fluent
new global::ConsoleMonster.Widgets.StackedBar { ColorPassing = value };    Ui.StackedBar().ColorPassing(value);
CountColumn 2 overloads
public static StackedBar CountColumn(StackedBar stackedBar, ColumnFormat value) #

Sets StackedBar.CountColumn: Layout of the legend count column (default right-aligned; reserves the digits of the overall total).

Parameters

stackedBar ConsoleMonster.Widgets.StackedBar required
The instance.
value ConsoleMonster.Layout.ColumnFormat required
The value.

Returns

StackedBar The same instance.

Examples

// C# initializer or property                                             // C# fluent
new global::ConsoleMonster.Widgets.StackedBar { CountColumn = value };    Ui.StackedBar().CountColumn(value);
public static StackedBar CountColumn(StackedBar stackedBar, Action<ColumnFormat> configure) #

Configures StackedBar.CountColumn in place: Layout of the legend count column (default right-aligned; reserves the digits of the overall total).

Parameters

stackedBar ConsoleMonster.Widgets.StackedBar required
The instance.
configure System.Action<ConsoleMonster.Layout.ColumnFormat> required
Configures the value.

Returns

StackedBar The same instance.
LabelColumn 2 overloads
public static StackedBar LabelColumn(StackedBar stackedBar, ColumnFormat value) #

Sets StackedBar.LabelColumn: Layout of the legend label column (default left-aligned).

Parameters

stackedBar ConsoleMonster.Widgets.StackedBar required
The instance.
value ConsoleMonster.Layout.ColumnFormat required
The value.

Returns

StackedBar The same instance.

Examples

// C# initializer or property                                             // C# fluent
new global::ConsoleMonster.Widgets.StackedBar { LabelColumn = value };    Ui.StackedBar().LabelColumn(value);
public static StackedBar LabelColumn(StackedBar stackedBar, Action<ColumnFormat> configure) #

Configures StackedBar.LabelColumn in place: Layout of the legend label column (default left-aligned).

Parameters

stackedBar ConsoleMonster.Widgets.StackedBar required
The instance.
configure System.Action<ConsoleMonster.Layout.ColumnFormat> required
Configures the value.

Returns

StackedBar The same instance.
public static StackedBar MaxLegendColumns(StackedBar stackedBar, int value) #

Sets StackedBar.MaxLegendColumns: The most legend columns per row, or 0 (default) to fit as many as the width allows. Entries fill rows left to right and every row shares one grid fitted to each column, so labels, counts and percentages line up.

Parameters

stackedBar ConsoleMonster.Widgets.StackedBar required
The instance.
value int required
The value.

Returns

StackedBar The same instance.

Examples

// C# initializer or property                                                  // C# fluent
new global::ConsoleMonster.Widgets.StackedBar { MaxLegendColumns = value };    Ui.StackedBar().MaxLegendColumns(value);
PercentColumn 2 overloads
public static StackedBar PercentColumn(StackedBar stackedBar, ColumnFormat value) #

Sets StackedBar.PercentColumn: Layout of the legend percentage column (default right-aligned, four cells).

Parameters

stackedBar ConsoleMonster.Widgets.StackedBar required
The instance.
value ConsoleMonster.Layout.ColumnFormat required
The value.

Returns

StackedBar The same instance.

Examples

// C# initializer or property                                               // C# fluent
new global::ConsoleMonster.Widgets.StackedBar { PercentColumn = value };    Ui.StackedBar().PercentColumn(value);
public static StackedBar PercentColumn(StackedBar stackedBar, Action<ColumnFormat> configure) #

Configures StackedBar.PercentColumn in place: Layout of the legend percentage column (default right-aligned, four cells).

Parameters

stackedBar ConsoleMonster.Widgets.StackedBar required
The instance.
configure System.Action<ConsoleMonster.Layout.ColumnFormat> required
Configures the value.

Returns

StackedBar The same instance.
public static StackedBar ShowLegend(StackedBar stackedBar, bool value = true) #

Sets StackedBar.ShowLegend: Whether the legend line is shown (default true).

Parameters

stackedBar ConsoleMonster.Widgets.StackedBar required
The instance.
value bool = true optional
The value; true when omitted.

Returns

StackedBar The same instance.

Examples

// C# initializer or property                                            // C# fluent
new global::ConsoleMonster.Widgets.StackedBar { ShowLegend = value };    Ui.StackedBar().ShowLegend(value);
public static StackedBar ShowSwatches(StackedBar stackedBar, bool value = true) #

Sets StackedBar.ShowSwatches: Whether each legend entry starts with a swatch of its bar fill (default true). Without swatches, an entry with a status shows only its coloured status symbol, so every row has one marker; entries without a status, and every entry when there is no colour, keep their swatch.

Parameters

stackedBar ConsoleMonster.Widgets.StackedBar required
The instance.
value bool = true optional
The value; true when omitted.

Returns

StackedBar The same instance.

Examples

// C# initializer or property                                              // C# fluent
new global::ConsoleMonster.Widgets.StackedBar { ShowSwatches = value };    Ui.StackedBar().ShowSwatches(value);
public static StackedBar ShowTotal(StackedBar stackedBar, bool value = true) #

Sets StackedBar.ShowTotal: Whether the total is written after the bar (default true). Turn it off where a title or caption already gives it.

Parameters

stackedBar ConsoleMonster.Widgets.StackedBar required
The instance.
value bool = true optional
The value; true when omitted.

Returns

StackedBar The same instance.

Examples

// C# initializer or property                                           // C# fluent
new global::ConsoleMonster.Widgets.StackedBar { ShowTotal = value };    Ui.StackedBar().ShowTotal(value);