Table of Contents

Class LineGraphControl

Namespace
SharpConsoleUI.Controls
Assembly
SharpConsoleUI.dll

A line graph control for visualizing time-series data using braille or ASCII rendering. Supports multiple named series rendered as connected lines.

public class LineGraphControl : BaseControl, IWindowControl, IDisposable, IDOMPaintable, INotifyPropertyChanged
Inheritance
LineGraphControl
Implements
Inherited Members
Extension Methods

Properties

AutoFitDataPoints

Gets or sets whether MaxDataPoints is automatically adjusted to match the rendered width.

public bool AutoFitDataPoints { get; set; }

Property Value

bool

AxisLabelColor

Gets or sets the color of Y-axis labels.

public Color AxisLabelColor { get; set; }

Property Value

Color

AxisLabelFormat

Gets or sets the format string for Y-axis labels.

public string AxisLabelFormat { get; set; }

Property Value

string

BackgroundColor

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

public Color? BackgroundColor { get; set; }

Property Value

Color?

BaselineChar

Gets or sets the baseline character.

public char BaselineChar { get; set; }

Property Value

char

BaselineColor

Gets or sets the baseline color.

public Color BaselineColor { get; set; }

Property Value

Color

BaselinePosition

Gets or sets the baseline position.

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.

public BorderStyle BorderStyle { get; set; }

Property Value

BorderStyle

Container

Gets or sets the parent container that hosts this control.

public override IContainer? Container { get; set; }

Property Value

IContainer

ContentWidth

Gets the minimum width needed to display the control's content, including margins. Returns null if width cannot be determined. This is calculated based on content (text length, child controls, etc.) and represents the natural/intrinsic size.

public override int? ContentWidth { get; }

Property Value

int?

ForegroundColor

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

public Color? ForegroundColor { get; set; }

Property Value

Color?

GraphHeight

Gets or sets the height of the graph area in lines.

public int GraphHeight { get; set; }

Property Value

int

HighLabelColor

Gets or sets the color used for the high value label.

public Color HighLabelColor { get; set; }

Property Value

Color

HighLowLabelSide

Gets or sets which side of the graph the high/low labels appear on.

public MarkerSide HighLowLabelSide { get; set; }

Property Value

MarkerSide

InlineTitleWithBaseline

Gets or sets whether the title is rendered inline with the baseline. Only applies when TitlePosition and BaselinePosition are the same.

public bool InlineTitleWithBaseline { get; set; }

Property Value

bool

LowLabelColor

Gets or sets the color used for the low value label.

public Color LowLabelColor { get; set; }

Property Value

Color

MaxDataPoints

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

public int MaxDataPoints { get; set; }

Property Value

int

MaxValue

Gets or sets the fixed maximum value for the Y axis. When null, auto-scales from data.

public double? MaxValue { get; set; }

Property Value

double?

MinValue

Gets or sets the fixed minimum value for the Y axis. When null, auto-scales from data.

public double? MinValue { get; set; }

Property Value

double?

Mode

Gets or sets the rendering mode (Braille or Ascii).

public LineGraphMode Mode { get; set; }

Property Value

LineGraphMode

ReferenceLines

Gets the list of reference lines as a read-only snapshot.

public IReadOnlyList<ReferenceLine> ReferenceLines { get; }

Property Value

IReadOnlyList<ReferenceLine>

Series

Gets the list of data series as a read-only snapshot.

public IReadOnlyList<LineGraphSeries> Series { get; }

Property Value

IReadOnlyList<LineGraphSeries>

ShowBaseline

Gets or sets whether to show a baseline.

public bool ShowBaseline { get; set; }

Property Value

bool

ShowHighLowLabels

Gets or sets whether to display labels for the highest and lowest data values.

public bool ShowHighLowLabels { get; set; }

Property Value

bool

ShowLegend

Gets or sets whether to show a legend displaying series names and colors. The legend is rendered on the title row, right-aligned.

public bool ShowLegend { get; set; }

Property Value

bool

ShowYAxisLabels

Gets or sets whether to show Y-axis labels (min/max values).

public bool ShowYAxisLabels { get; set; }

Property Value

bool

Title

Gets or sets the graph title.

public string? Title { get; set; }

Property Value

string

TitleColor

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

public Color? TitleColor { get; set; }

Property Value

Color?

TitlePosition

Gets or sets the title position (Top or Bottom).

public TitlePosition TitlePosition { get; set; }

Property Value

TitlePosition

ValueMarkers

Gets the list of value markers as a read-only snapshot.

public IReadOnlyList<ValueMarker> ValueMarkers { get; }

Property Value

IReadOnlyList<ValueMarker>

Width

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

public override int? Width { get; set; }

Property Value

int?

Methods

AddDataPoint(double)

Adds a data point to a single-series graph. Auto-creates a default series if none exist.

public void AddDataPoint(double value)

Parameters

value double

The data point value.

AddDataPoint(string, double)

Adds a data point to the specified series.

public void AddDataPoint(string seriesName, double value)

Parameters

seriesName string

The series name.

value double

The data point value.

AddReferenceLine(double, Color, char, string?, LabelPosition)

Adds a horizontal reference line at the specified Y-axis value.

public void AddReferenceLine(double value, Color color, char lineChar = '─', string? label = null, LabelPosition labelPosition = LabelPosition.None)

Parameters

value double

The Y-axis value where the line is drawn.

color Color

The color of the line.

lineChar char

The character used to draw the line.

label string

Optional label text.

labelPosition LabelPosition

Position of the label relative to the line.

AddSeries(string, Color, ColorGradient?)

Adds a new named data series to the graph.

public LineGraphSeries AddSeries(string name, Color lineColor, ColorGradient? gradient = null)

Parameters

name string

The series name (must be unique).

lineColor Color

The line color.

gradient ColorGradient

Optional color gradient.

Returns

LineGraphSeries

The created series.

AddValueMarker(double, string, Color, Color, MarkerSide)

Adds a labeled value marker pointing at the specified Y-axis value.

public void AddValueMarker(double value, string label, Color arrowColor, Color labelColor, MarkerSide side = MarkerSide.Right)

Parameters

value double

The Y-axis value to mark.

label string

The label text.

arrowColor Color

The color of the marker arrow.

labelColor Color

The color of the label text.

side MarkerSide

Which side of the graph the marker appears on.

ClearAllData()

Clears all data from all series.

public void ClearAllData()

ClearReferenceLines()

Removes all reference lines from the graph.

public void ClearReferenceLines()

ClearValueMarkers()

Removes all value markers from the graph.

public void ClearValueMarkers()

GetLogicalContentSize()

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

public override Size GetLogicalContentSize()

Returns

Size

The size representing the content's natural dimensions.

MeasureDOM(LayoutConstraints)

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

public override LayoutSize MeasureDOM(LayoutConstraints constraints)

Parameters

constraints LayoutConstraints

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

Returns

LayoutSize

The desired size of the control.

OnDisposing()

Called during Dispose() before Container is set to null. Override to perform control-specific cleanup (null events, close portals, clear data, etc.).

protected override void OnDisposing()

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

Paints the control's content directly to a CharacterBuffer.

public override 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

RemoveSeries(string)

Removes a series by name.

public bool RemoveSeries(string name)

Parameters

name string

The series name to remove.

Returns

bool

True if the series was found and removed.

SetDataPoints(IEnumerable<double>)

Sets data points for a single-series graph. Auto-creates a default series if none exist.

public void SetDataPoints(IEnumerable<double> data)

Parameters

data IEnumerable<double>

The data points.

SetDataPoints(string, IEnumerable<double>)

Sets all data points for the specified series, replacing existing data.

public void SetDataPoints(string seriesName, IEnumerable<double> data)

Parameters

seriesName string

The series name.

data IEnumerable<double>

The data points.