data

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package data is refract's data layer: columnar, batch-oriented access to a table of values.

The interface returns whole typed columns, never one value at a time. Scalar access is the single easiest way to make a plotting library slow, and a columnar shape is also what lets a []float64-backed source be borrowed instead of copied.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Source

type Source interface {
	// Len reports the number of rows. Every column has this length.
	Len() int

	// Columns lists the available column names. The order is stable across
	// calls on the same Source.
	Columns() []string

	// Float64Column returns a numeric column by name. ok is false if the
	// column does not exist or is not numeric.
	Float64Column(name string) (data []float64, ok bool)

	// TimeColumn returns a time column by name. ok is false if the column does
	// not exist or is not temporal.
	TimeColumn(name string) (data []time.Time, ok bool)
}

Source exposes columnar, batch access to a table.

Implementations return read-only views: the caller must not mutate a returned slice, and refract never does. An implementation that already holds its data as a Go slice should return that slice directly rather than copying.

func Float64Columns

func Float64Columns(cols map[string][]float64) Source

Float64Columns builds a Source over the given numeric columns.

The slices are borrowed, not copied: the returned Source aliases the caller's memory, and mutating it afterwards mutates what refract will plot. All columns must have the same length; Float64Columns panics otherwise, because a ragged table is a programming error rather than a runtime condition.

type Table

type Table struct {
	// contains filtered or unexported fields
}

Table is a Source that mixes numeric and temporal columns.

It is the general-purpose implementation: use it when a chart plots time against values, which is the common case for the Time scale.

func NewTable

func NewTable() *Table

NewTable returns an empty Table.

func (*Table) Columns

func (t *Table) Columns() []string

Columns lists the column names in insertion order.

func (*Table) Float64

func (t *Table) Float64(name string, v []float64) *Table

Float64 adds a numeric column, borrowing the slice. It returns t so calls can be chained. It panics if the column length disagrees with columns already added, or if the name is already taken.

func (*Table) Float64Column

func (t *Table) Float64Column(name string) ([]float64, bool)

Float64Column returns a numeric column by name.

func (*Table) Len

func (t *Table) Len() int

Len reports the number of rows.

func (*Table) Time

func (t *Table) Time(name string, v []time.Time) *Table

Time adds a temporal column, borrowing the slice. It returns t so calls can be chained. It panics if the column length disagrees with columns already added, or if the name is already taken.

func (*Table) TimeColumn

func (t *Table) TimeColumn(name string) ([]time.Time, bool)

TimeColumn returns a temporal column by name.

Jump to

Keyboard shortcuts

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