Skip to content

LineGraph

Each terminal cell encodes a 2×4 braille dot grid, giving ~4× the vertical resolution of normal block characters. This produces smooth curves even at small component sizes.

When SetYRange is not called, the Y axis auto-scales to the min/max of all series. Call SetYRange(min, max) to pin the scale — useful when comparing across time windows.

SetShowCursor(true) adds a vertical cursor that follows the mouse or can be positioned programmatically. Use SetOnCursorMove to read the X position and show values in a tooltip.

LineGraph preview

LineGraph renders line charts using braille characters

Constructor func NewLineGraph() *LineGraph

Usage

graph := components.NewLineGraph().
SetTitle("CPU usage").
SetStyle(components.LineGraphSolid).
SetSeries(
components.DataSeries{Label: "core0", Values: []float64{12, 18, 9, 22, 30}, Color: tcell.ColorGreen},
components.DataSeries{Label: "core1", Values: []float64{5, 8, 14, 11, 19}},
).
SetRange(0, 100).
SetShowLegend(true).
SetYAxis(components.AxisConfig{Show: true, Format: "%.0f%%"})
fmt.Println(graph != nil)

Methods

Method Signature Description
AddSeries func (g *LineGraph) AddSeries(s DataSeries) *LineGraph AddSeries appends a data series
AddValue func (g *LineGraph) AddValue(value float64, maxLen int) *LineGraph AddValue appends a value to the first series with rolling window
Clear func (g *LineGraph) Clear() *LineGraph Clear removes all data
GetFieldHeight func (g *LineGraph) GetFieldHeight() int GetFieldHeight returns preferred height
GetRange func (g *LineGraph) GetRange() (min, max float64) GetRange returns the current Y-axis range
GetSeries func (g *LineGraph) GetSeries() []DataSeries GetSeries returns all series
SetAutoScale func (g *LineGraph) SetAutoScale(enabled bool) *LineGraph SetAutoScale enables/disables automatic range calculation
SetCursorFrac func (g *LineGraph) SetCursorFrac(frac float64) *LineGraph SetCursorFrac positions a vertical scrub cursor at fractional X (0..1 across the plot). A negative value (the default) hides it. Drawn beneath the series so the line stays visible on top, letting callers correlate a selected point across stacked graphs.
SetCursorLabel func (g *LineGraph) SetCursorLabel(lines []string) *LineGraph SetCursorLabel sets the plain-text lines shown in a floating card beside the scrub cursor. Pass nil to hide the card. Drawn on top of the plot, flipping to the cursor's left when there isn't room on the right.
SetGridColor func (g *LineGraph) SetGridColor(color tcell.Color) *LineGraph SetGridColor sets the grid line color
SetOnHover func (g *LineGraph) SetOnHover(fn func(seriesIdx, pointIdx int, value float64)) *LineGraph SetOnHover sets the hover callback
SetRange func (g *LineGraph) SetRange(min, max float64) *LineGraph SetRange sets fixed Y-axis range (disables auto-scale)
SetSeries func (g *LineGraph) SetSeries(series ...DataSeries) *LineGraph SetSeries sets all data series
SetShowGrid func (g *LineGraph) SetShowGrid(show bool) *LineGraph SetShowGrid enables/disables the background grid
SetShowLegend func (g *LineGraph) SetShowLegend(show bool) *LineGraph SetShowLegend enables/disables the legend
SetStyle func (g *LineGraph) SetStyle(style LineGraphStyle) *LineGraph SetStyle sets the line rendering style
SetTitle func (g *LineGraph) SetTitle(title string) *LineGraph SetTitle sets the graph title
SetValues func (g *LineGraph) SetValues(values []float64) *LineGraph SetValues sets values for a single series (convenience for single-line graphs)
SetXAxis func (g *LineGraph) SetXAxis(config AxisConfig) *LineGraph SetXAxis configures the X axis
SetYAxis func (g *LineGraph) SetYAxis(config AxisConfig) *LineGraph SetYAxis configures the Y axis

Types

type AxisConfig struct AxisConfig controls Y-axis display. LabelCount 0 auto-selects a reasonable density based on component height. Format uses fmt.Sprintf syntax.
FieldTypeDescription
Show bool
LabelCount int Number of labels on Y axis (0 = auto)
Format string Printf format for labels (default "%.1f")
type DataSeries struct DataSeries is a named set of float64 values plotted as a single line. Color 0 falls back to the theme accent; set it explicitly for multi-series charts.
FieldTypeDescription
Label string
Values []float64
Color tcell.Color 0 = use theme accent
type LineGraphStyle LineGraphStyle configures the graph appearance
ConstantDescription
LineGraphDots
LineGraphSolid
LineGraphFilled