Table of Contents

Class SparklineControl

Namespace
SharpConsoleUI.Controls
Assembly
SharpConsoleUI.dll

A vertical column/sparkline graph control for visualizing time-series data. Displays vertical bars showing historical values over time.

public class SparklineControl : IWindowControl, IDisposable, IDOMPaintable
Inheritance
SparklineControl
Implements
Inherited Members
Extension Methods

Constructors

SparklineControl()

Initializes a new instance of the SparklineControl class.

public SparklineControl()

Properties

ActualWidth

Gets the actual rendered width of the control, or null if not yet rendered.

public int? ActualWidth { get; }

Property Value

int?

BackgroundColor

Gets or sets the background color of the control. When null, inherits from the container.

public Color? BackgroundColor { get; set; }

Property Value

Color?

BarColor

Gets or sets the color for the bars.

public Color BarColor { get; set; }

Property Value

Color

BaselineChar

Gets or sets the character used for the baseline (default: ┈).

public char BaselineChar { get; set; }

Property Value

char

BaselineColor

Gets or sets the color of the baseline (default: Grey50).

public Color BaselineColor { get; set; }

Property Value

Color

BaselinePosition

Gets or sets the position of the baseline (Top or Bottom, default: Bottom). When set to Top, baseline appears above the graph.

public TitlePosition BaselinePosition { get; set; }

Property Value

TitlePosition

BorderColor

Gets or sets the border color. When null, uses the foreground color.

public Color? BorderColor { get; set; }

Property Value

Color?

BorderStyle

Gets or sets the border style around the graph.

public BorderStyle BorderStyle { get; set; }

Property Value

BorderStyle

Container

Gets or sets the parent container that hosts this control.

public IContainer? Container { get; set; }

Property Value

IContainer

DataPoints

Gets the data points collection.

public IReadOnlyList<double> DataPoints { get; }

Property Value

IReadOnlyList<double>

ForegroundColor

Gets or sets the foreground color for labels. When null, inherits from the container.

public Color? ForegroundColor { get; set; }

Property Value

Color?

Gradient

Gets or sets the color gradient for vertical color interpolation. When set, each bar column gets a color based on its height. When null, uses the solid BarColor.

public ColorGradient? Gradient { get; set; }

Property Value

ColorGradient

GraphHeight

Gets or sets the height of the graph in lines.

public int GraphHeight { get; set; }

Property Value

int

HorizontalAlignment

Gets or sets the horizontal alignment of the control within its container.

public HorizontalAlignment HorizontalAlignment { get; set; }

Property Value

HorizontalAlignment

InlineTitleWithBaseline

Gets or sets whether to show the title inline with the baseline. Only applies when TitlePosition and BaselinePosition are the same (both Top or both Bottom). Format: "Title ┈┈┈┈┈┈┈┈┈" (title followed by baseline fill).

public bool InlineTitleWithBaseline { get; set; }

Property Value

bool

Margin

Gets or sets the margin (spacing) around the control.

public Margin Margin { get; set; }

Property Value

Margin

MaxDataPoints

Gets or sets the maximum number of data points to display. When exceeded, oldest points are removed.

public int MaxDataPoints { get; set; }

Property Value

int

MaxValue

Gets or sets the maximum value for the graph scale. When null, uses the maximum data point value.

public double? MaxValue { get; set; }

Property Value

double?

MinValue

Gets or sets the minimum value for the graph scale. When null, uses the minimum data point value (or 0 if all positive).

public double? MinValue { get; set; }

Property Value

double?

Mode

Gets or sets the rendering mode for sparkline bars. Block mode uses 9-level block characters, Braille mode uses 5-level braille patterns.

public SparklineMode Mode { get; set; }

Property Value

SparklineMode

Name

Gets or sets the unique name identifier for this control, used for lookup.

public string? Name { get; set; }

Property Value

string

SecondaryBarColor

Gets or sets the color for the secondary bars (in bidirectional mode).

public Color SecondaryBarColor { get; set; }

Property Value

Color

SecondaryDataPoints

Gets the secondary data points collection (for bidirectional mode).

public IReadOnlyList<double> SecondaryDataPoints { get; }

Property Value

IReadOnlyList<double>

SecondaryGradient

Gets or sets the color gradient for the secondary series in bidirectional mode. When null in bidirectional mode, uses SecondaryBarColor or the primary Gradient.

public ColorGradient? SecondaryGradient { get; set; }

Property Value

ColorGradient

SecondaryMaxValue

Gets or sets the maximum value for the secondary data series scale. When null, uses the same scale as the primary series or the max secondary data value.

public double? SecondaryMaxValue { get; set; }

Property Value

double?

ShowBaseline

Gets or sets whether to show a dotted baseline at the bottom of the graph.

public bool ShowBaseline { get; set; }

Property Value

bool

StickyPosition

Gets or sets whether this control should stick to the top or bottom during scrolling.

public StickyPosition StickyPosition { get; set; }

Property Value

StickyPosition

Tag

Gets or sets an arbitrary object value that can be used to store custom data.

public object? Tag { get; set; }

Property Value

object

Title

Gets or sets the optional title displayed at the top of the graph (inside border if present).

public string? Title { get; set; }

Property Value

string

TitleColor

Gets or sets the color for the title text. When null, uses the foreground color.

public Color? TitleColor { get; set; }

Property Value

Color?

TitlePosition

Gets or sets the position of the title relative to the sparkline graph. Default is Top (title above the graph).

public TitlePosition TitlePosition { get; set; }

Property Value

TitlePosition

VerticalAlignment

Gets or sets the vertical alignment of the control within its container.

public VerticalAlignment VerticalAlignment { get; set; }

Property Value

VerticalAlignment

Visible

Gets or sets whether this control is visible.

public bool Visible { get; set; }

Property Value

bool

Width

Gets or sets the explicit width of the control, or null for automatic sizing.

public int? Width { get; set; }

Property Value

int?

Methods

AddDataPoint(double)

Adds a new data point to the graph. If the maximum number of points is exceeded, the oldest point is removed.

public void AddDataPoint(double value)

Parameters

value double

AddSecondaryDataPoint(double)

Adds a new secondary data point (for bidirectional mode). If the maximum number of points is exceeded, the oldest point is removed.

public void AddSecondaryDataPoint(double value)

Parameters

value double

ClearDataPoints()

Clears all data points from the graph.

public void ClearDataPoints()

ClearSecondaryDataPoints()

Clears all secondary data points from the graph.

public void ClearSecondaryDataPoints()

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

GetLogicalContentSize()

Gets the logical size of the control's content without rendering.

public Size GetLogicalContentSize()

Returns

Size

The size representing the content's natural dimensions.

Invalidate()

Marks this control as needing to be re-rendered.

public void Invalidate()

MeasureDOM(LayoutConstraints)

Measures the control's desired size given the available constraints.

public LayoutSize MeasureDOM(LayoutConstraints constraints)

Parameters

constraints LayoutConstraints

The layout constraints (min/max width/height).

Returns

LayoutSize

The desired size of the control.

PaintDOM(CharacterBuffer, LayoutRect, LayoutRect, Color, Color)

Paints the control's content directly to a CharacterBuffer.

public void PaintDOM(CharacterBuffer buffer, LayoutRect bounds, LayoutRect clipRect, Color defaultFg, Color defaultBg)

Parameters

buffer CharacterBuffer

The buffer to paint to.

bounds LayoutRect

The absolute bounds where the control should paint.

clipRect LayoutRect

The clipping rectangle (visible area).

defaultFg Color
defaultBg Color

SetBidirectionalData(IEnumerable<double>, IEnumerable<double>)

Sets both primary and secondary data points at once (for bidirectional mode). More efficient than calling SetDataPoints and SetSecondaryDataPoints separately.

public void SetBidirectionalData(IEnumerable<double> primaryData, IEnumerable<double> secondaryData)

Parameters

primaryData IEnumerable<double>
secondaryData IEnumerable<double>

SetDataPoints(IEnumerable<double>)

Sets the data points for the graph, replacing any existing points.

public void SetDataPoints(IEnumerable<double> dataPoints)

Parameters

dataPoints IEnumerable<double>

SetSecondaryDataPoints(IEnumerable<double>)

Sets the secondary data points for bidirectional mode, replacing any existing points.

public void SetSecondaryDataPoints(IEnumerable<double> dataPoints)

Parameters

dataPoints IEnumerable<double>