heatmap

package
v2.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

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

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. Columns 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.

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) 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.

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

Jump to

Keyboard shortcuts

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