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
AxisLabelColor
Gets or sets the color of Y-axis labels.
public Color AxisLabelColor { get; set; }
Property Value
AxisLabelFormat
Gets or sets the format string for Y-axis labels.
public string AxisLabelFormat { get; set; }
Property Value
BackgroundColor
Gets or sets the background color. When null, inherits from container.
public Color? BackgroundColor { get; set; }
Property Value
BaselineChar
Gets or sets the baseline character.
public char BaselineChar { get; set; }
Property Value
BaselineColor
Gets or sets the baseline color.
public Color BaselineColor { get; set; }
Property Value
BaselinePosition
Gets or sets the baseline position.
public TitlePosition BaselinePosition { get; set; }
Property Value
BorderColor
Gets or sets the border color. When null, uses the foreground color.
public Color? BorderColor { get; set; }
Property Value
BorderStyle
Gets or sets the border style.
public BorderStyle BorderStyle { get; set; }
Property Value
Container
Gets or sets the parent container that hosts this control.
public override IContainer? Container { get; set; }
Property Value
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
GraphHeight
Gets or sets the height of the graph area in lines.
public int GraphHeight { get; set; }
Property Value
HighLabelColor
Gets or sets the color used for the high value label.
public Color HighLabelColor { get; set; }
Property Value
HighLowLabelSide
Gets or sets which side of the graph the high/low labels appear on.
public MarkerSide HighLowLabelSide { get; set; }
Property Value
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
LowLabelColor
Gets or sets the color used for the low value label.
public Color LowLabelColor { get; set; }
Property Value
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
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
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
Mode
Gets or sets the rendering mode (Braille or Ascii).
public LineGraphMode Mode { get; set; }
Property Value
ReferenceLines
Gets the list of reference lines as a read-only snapshot.
public IReadOnlyList<ReferenceLine> ReferenceLines { get; }
Property Value
Series
Gets the list of data series as a read-only snapshot.
public IReadOnlyList<LineGraphSeries> Series { get; }
Property Value
ShowBaseline
Gets or sets whether to show a baseline.
public bool ShowBaseline { get; set; }
Property Value
ShowHighLowLabels
Gets or sets whether to display labels for the highest and lowest data values.
public bool ShowHighLowLabels { get; set; }
Property Value
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
ShowYAxisLabels
Gets or sets whether to show Y-axis labels (min/max values).
public bool ShowYAxisLabels { get; set; }
Property Value
Title
Gets or sets the graph title.
public string? Title { get; set; }
Property Value
TitleColor
Gets or sets the title color. When null, uses the foreground color.
public Color? TitleColor { get; set; }
Property Value
TitlePosition
Gets or sets the title position (Top or Bottom).
public TitlePosition TitlePosition { get; set; }
Property Value
ValueMarkers
Gets the list of value markers as a read-only snapshot.
public IReadOnlyList<ValueMarker> ValueMarkers { get; }
Property Value
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
valuedoubleThe data point value.
AddDataPoint(string, double)
Adds a data point to the specified series.
public void AddDataPoint(string seriesName, double value)
Parameters
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
valuedoubleThe Y-axis value where the line is drawn.
colorColorThe color of the line.
lineCharcharThe character used to draw the line.
labelstringOptional label text.
labelPositionLabelPositionPosition 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
namestringThe series name (must be unique).
lineColorColorThe line color.
gradientColorGradientOptional 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
valuedoubleThe Y-axis value to mark.
labelstringThe label text.
arrowColorColorThe color of the marker arrow.
labelColorColorThe color of the label text.
sideMarkerSideWhich 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
constraintsLayoutConstraintsThe 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
bufferCharacterBufferThe buffer to paint to.
boundsLayoutRectThe absolute bounds where the control should paint.
clipRectLayoutRectThe clipping rectangle (visible area).
defaultFgColordefaultBgColor
RemoveSeries(string)
Removes a series by name.
public bool RemoveSeries(string name)
Parameters
namestringThe 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
dataIEnumerable<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
seriesNamestringThe series name.
dataIEnumerable<double>The data points.