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 ¶
- func GetDefaultColorScale() []color.Color
- func SetDefaultColorScale(cs []color.Color) []color.Color
- type HeatPoint
- type Model
- func (m *Model) AutoAdjustValueRange(value float64) (b bool)
- func (m *Model) ClearData()
- func (m *Model) Draw()
- func (m *Model) DrawPoint(pt HeatPoint)
- func (m Model) Init() tea.Cmd
- func (m *Model) Push(p HeatPoint)
- func (m *Model) PushAll(pts []HeatPoint)
- func (m *Model) PushAllMatrixRow(dataRows [][]float64)
- func (m *Model) Resize(w, h int)
- func (m *Model) SetValueRange(minVal, maxVal float64)
- func (m *Model) SetViewXRange(min, max float64)
- func (m *Model) SetViewXYRange(minX, maxX, minY, maxY float64)
- func (m *Model) SetViewYRange(min, max float64)
- func (m *Model) SetXLabels(labels []string)
- func (m *Model) SetYLabels(labels []string)
- func (m Model) Update(msg tea.Msg) (Model, tea.Cmd)
- func (m Model) View() string
- func (m *Model) XLabels() []string
- func (m *Model) YLabels() []string
- type Option
- func WithAutoValueRange() Option
- func WithCellSize(w, h float64) Option
- func WithCellStyle(style lipgloss.Style) Option
- func WithColorScale(cs []color.Color) Option
- func WithKeyMap(k canvas.KeyMap) Option
- func WithPoints(d []HeatPoint) Option
- func WithStyle(lm linechart.Model) Option
- func WithUpdateHandler(h canvas.UpdateHandler) Option
- func WithValueRange(minVal, maxVal float64) Option
- func WithXLabels(labels []string) Option
- func WithYLabels(labels []string) Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetDefaultColorScale ¶
GetDefaultColorScale returns the current default color scale used by all heatmaps.
Types ¶
type HeatPoint ¶
type HeatPoint struct {
X, Y, V float64
}
HeatPoint has a cartesian X,Y and a Value
func NewHeatPoint ¶
func NewHeatPointInt ¶
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 ¶
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 ¶
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) 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 ¶
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) Push ¶
Push adds float64 data value to the heat data buffer. Data will be scaled using expected max value and sparkline height.
func (*Model) PushAllMatrixRow ¶
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 ¶
Resize will change wavelinechart display width and height. Existing data will be rescaled.
func (*Model) SetValueRange ¶
SetValueRange updates the displayed minimum and maximum Y values. Existing data will be rescaled.
func (*Model) SetViewXRange ¶
SetViewXRange updates the displayed minimum and maximum X values. Existing data will be rescaled.
func (*Model) SetViewXYRange ¶
SetViewXYRange updates the displayed minimum and maximum X and Y values. Existing data will be rescaled.
func (*Model) SetViewYRange ¶
SetViewYRange updates the displayed minimum and maximum Y values. Existing data will be rescaled.
func (*Model) SetXLabels ¶ added in v2.7.1
SetXLabels names the cell columns; see WithXLabels.
func (*Model) SetYLabels ¶ added in v2.7.1
SetYLabels names the cell rows; see WithYLabels.
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
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 ¶
WithCellStyle sets the default cell style
func WithColorScale ¶
WithColorScale uses the given Color array for the ColorScale.
func WithKeyMap ¶
WithKeyMap sets the canvas KeyMap used when processing keyboard event messages in Update().
func WithPoints ¶
WithPoints adds all data values in []float64 to sparkline data buffer.
func WithUpdateHandler ¶
func WithUpdateHandler(h canvas.UpdateHandler) Option
WithUpdateHandler sets the canvas UpdateHandler used when processing bubbletea Msg events in Update().
func WithValueRange ¶
WithValueScale sets the minMax/maxValues that for the color mapping
func WithXLabels ¶ added in v2.7.1
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
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.