heatmap

package
v2.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 6 Imported by: 4

Documentation

Overview

Package heatmap implements a canvas that displays a heatmap, color-mapped data over a grid.

Points are drawn as single canvas cells by default. For an index grid, where X and Y are whole cell numbers, WithCellSize(1, 1) draws each point as a block that fills its share of the plot so the blocks tile it, and WithXLabels / WithYLabels name the columns and rows.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDefaultColorScale

func GetDefaultColorScale() []color.Color

GetDefaultColorScale returns the current default color scale used by all heatmaps.

func SetDefaultColorScale

func SetDefaultColorScale(cs []color.Color) []color.Color

SetDefaultColorScale sets the default color scale used by all heatmaps. Returns the previous color scale.

Types

type HeatPoint

type HeatPoint struct {
	X, Y, V float64
}

HeatPoint has a cartesian X,Y and a Value

func NewHeatPoint

func NewHeatPoint(x, y, value float64) HeatPoint

func NewHeatPointInt

func NewHeatPointInt(x, y int, value float64) HeatPoint

func (HeatPoint) AsFloat64Point

func (p HeatPoint) AsFloat64Point() canvas.Float64Point

type Model

type Model struct {
	linechart.Model

	ColorScale []color.Color // Color gradient user for heatmap

	AutoMinValue bool // AutoMinValue true will automatically adjust minimum data value
	AutoMaxValue bool // AutoMaxValue true will automatically adjust minimum data value
	// contains filtered or unexported fields
}

Model contains state of a heatmap It embeds a linechart.Model, for the graph view, but renders maps instead

func New

func New(w, h int, opts ...Option) Model

New returns a heatmap Model initialized with given width, height and various options. By default, heatmap will automatically scale bars to new maximum data values.

func (*Model) AutoAdjustValueRange

func (m *Model) AutoAdjustValueRange(value float64) (b bool)

AutoAdjustValueRange automatically adjusts the heatmap's value range based on the passed value. It returns whether or not the display range has been adjusted.

func (*Model) ClearData

func (m *Model) ClearData()

Clear will clear heatmap data.

func (*Model) Draw

func (m *Model) Draw()

Draw will display the data on the canvas, then any axis labels. Rows representing the data will be displayed going from from the bottom to the top and coming from the left to the right of the canvas.

func (*Model) DrawPoint

func (m *Model) DrawPoint(pt HeatPoint)

DrawPoint draws a HeatPoint on the heatmap Canvas. It does so by adjusting the background: of one canvas cell, or, when a cell size is set (see WithCellSize), of every canvas cell the data cell covers.

func (Model) Init

func (m Model) Init() tea.Cmd

func (*Model) Push

func (m *Model) Push(p HeatPoint)

Push adds float64 data value to the heat data buffer. Data will be scaled using expected max value and sparkline height.

func (*Model) PushAll

func (m *Model) PushAll(pts []HeatPoint)

PushAll adds all data values the heatmap.

func (*Model) PushAllMatrixRow

func (m *Model) PushAllMatrixRow(dataRows [][]float64)

PushAllMatrixRow adds all data in a matrix to the heatmap, using its X,Y indices Matrix is row-major, with rows representing the data.

func (*Model) Resize

func (m *Model) Resize(w, h int)

Resize will change wavelinechart display width and height. Existing data will be rescaled.

func (*Model) SetValueRange

func (m *Model) SetValueRange(minVal, maxVal float64)

SetValueRange updates the displayed minimum and maximum Y values. Existing data will be rescaled.

func (*Model) SetViewXRange

func (m *Model) SetViewXRange(min, max float64)

SetViewXRange updates the displayed minimum and maximum X values. Existing data will be rescaled.

func (*Model) SetViewXYRange

func (m *Model) SetViewXYRange(minX, maxX, minY, maxY float64)

SetViewXYRange updates the displayed minimum and maximum X and Y values. Existing data will be rescaled.

func (*Model) SetViewYRange

func (m *Model) SetViewYRange(min, max float64)

SetViewYRange updates the displayed minimum and maximum Y values. Existing data will be rescaled.

func (*Model) SetXLabels added in v2.7.1

func (m *Model) SetXLabels(labels []string)

SetXLabels names the cell columns; see WithXLabels.

func (*Model) SetYLabels added in v2.7.1

func (m *Model) SetYLabels(labels []string)

SetYLabels names the cell rows; see WithYLabels.

func (Model) Update

func (m Model) Update(msg tea.Msg) (Model, tea.Cmd)

Update forwards bubbletea Msg to underlying canvas.

func (Model) View

func (m Model) View() string

View returns a string used by the bubbletea framework to display the heatmap.

func (*Model) XLabels added in v2.7.1

func (m *Model) XLabels() []string

XLabels returns the cell column labels.

func (*Model) YLabels added in v2.7.1

func (m *Model) YLabels() []string

YLabels returns the cell row labels.

type Option

type Option func(*Model)

Option is used to set options when initializing a heatmap. Example:

sl := New(width, height, WithMaxValue(someValue), WithNoAuto())

func WithAutoValueRange

func WithAutoValueRange() Option

WithAutoValueRange enables automatically setting the minimum and maximum values if new data values are beyond the current ranges.

func WithCellSize added in v2.7.1

func WithCellSize(w, h float64) Option

WithCellSize sets the size of one data cell in data units and draws each point as a filled block of that size, centred on the point, instead of a single canvas cell. For an index grid (points at whole X and Y) use 1, 1 together with ranges of -0.5..n-0.5 (see WithXLabels) and the cells tile the graph. A size that is not positive restores single-cell points.

func WithCellStyle

func WithCellStyle(style lipgloss.Style) Option

WithCellStyle sets the default cell style

func WithColorScale

func WithColorScale(cs []color.Color) Option

WithColorScale uses the given Color array for the ColorScale.

func WithKeyMap

func WithKeyMap(k canvas.KeyMap) Option

WithKeyMap sets the canvas KeyMap used when processing keyboard event messages in Update().

func WithPoints

func WithPoints(d []HeatPoint) Option

WithPoints adds all data values in []float64 to sparkline data buffer.

func WithStyle

func WithStyle(lm linechart.Model) Option

WithLineChart sets the initial LineChart

func WithUpdateHandler

func WithUpdateHandler(h canvas.UpdateHandler) Option

WithUpdateHandler sets the canvas UpdateHandler used when processing bubbletea Msg events in Update().

func WithValueRange

func WithValueRange(minVal, maxVal float64) Option

WithValueScale sets the minMax/maxValues that for the color mapping

func WithXLabels added in v2.7.1

func WithXLabels(labels []string) Option

WithXLabels names the cell columns: labels[i] is drawn under the column at X = i. The labels define the grid: the X range becomes -0.5..len(labels)-0.5 and is no longer auto-ranged. Draw draws them.

func WithYLabels added in v2.7.1

func WithYLabels(labels []string) Option

WithYLabels names the cell rows: labels[i] is drawn left of the row at Y = i, counting up from the bottom. The labels define the grid: the Y range becomes -0.5..len(labels)-0.5 and is no longer auto-ranged, and the margin left of the graph grows to fit the longest label. Draw draws them.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL