Documentation
¶
Overview ¶
Package refract turns one declarative chart specification into any output you need — SVG today, raster, PDF, GPU and browser through additional backends — from the same model, with the same geometry.
The core module is pure Go and depends on nothing but the standard library. The built-in SVG backend needs no rendering engine and no font stack, so a server that only wants a chart as SVG links nothing native and nothing young. Raster output lives in a separate module, github.com/timzifer/refract/backend/gg, which is still CGO-free.
Shape of the API ¶
Build a plot, give it scales, add layers, render it to a target:
src := refract.Float64Columns(map[string][]float64{"t": times, "y": values})
p := refract.New(
refract.Theme(theme.Dark),
refract.Size(800, 500),
refract.Title("Signal"),
)
p.X(scale.Time())
p.Y(scale.Linear(scale.Nice()))
p.Add(geom.Line(src, geom.X("t"), geom.Y("y"), geom.Color(palette.Blue)))
err := p.Render(refract.SVG("signal.svg"))
Status ¶
Pre-alpha. Every release below v1.0.0 may contain breaking changes without a deprecation cycle. See CONCEPT.md for the design and the roadmap.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoLayers = errors.New("refract: plot has no layers and no scales")
ErrNoLayers reports a render of a plot with nothing in it. Rendering empty axes is a legitimate thing to want, so this is only returned when there is also no scale configured — that combination is always a mistake.
Functions ¶
func NewTable ¶
NewTable returns an empty table that can mix numeric and time columns. See data.NewTable.
Types ¶
type Option ¶
type Option func(*Plot)
Option configures a Plot at construction.
func DPR ¶
DPR sets the device pixel ratio. Backends that rasterize multiply the pixel buffer by it; coordinates stay in device-independent units either way. The default is 1.
func Legend ¶
Legend forces the legend on or off. By default a legend appears once a plot has more than one layer: one series does not need to be told apart from anything.
type Plot ¶
type Plot struct {
// contains filtered or unexported fields
}
Plot is a chart specification: size, theme, scales and layers.
A Plot is not safe for concurrent modification. Rendering the same Plot twice is supported and produces the same result, provided the underlying data has not changed.
func (*Plot) Render ¶
Render draws the plot into t.
It opens the target, lowers the chart into the backend it returns, flushes, and closes the target — so a file target has a complete file on disk when Render returns nil.
func (*Plot) X ¶
X sets the horizontal scale. The default is scale.Linear with nicing.
type Source ¶
Source is a columnar data source. See package data.
func Float64Columns ¶
Float64Columns builds a Source over numeric columns, borrowing the slices. See data.Float64Columns.
Directories
¶
| Path | Synopsis |
|---|---|
|
arrow
module
|
|
|
backend
|
|
|
svg
Package svg is refract's built-in, zero-dependency SVG backend.
|
Package svg is refract's built-in, zero-dependency SVG backend. |
|
gg
module
|
|
|
gg/gpu
module
|
|
|
window
module
|
|
|
Package data is refract's data layer: columnar, batch-oriented access to a table of values.
|
Package data is refract's data layer: columnar, batch-oriented access to a table of values. |
|
examples
|
|
|
signal
command
Command signal renders the chart from CONCEPT.md §13.
|
Command signal renders the chart from CONCEPT.md §13. |
|
Package geom holds the visual marks a chart is made of.
|
Package geom holds the visual marks a chart is made of. |
|
internal
|
|
|
fontmetrics
Package fontmetrics answers "how wide is this string" using nothing but the standard library.
|
Package fontmetrics answers "how wide is this string" using nothing but the standard library. |
|
irtest
Package irtest provides a recording ir.Backend for tests.
|
Package irtest provides a recording ir.Backend for tests. |
|
svgdiff
Package svgdiff compares two SVG documents as drawings rather than as bytes.
|
Package svgdiff compares two SVG documents as drawings rather than as bytes. |
|
Package ir defines refract's intermediate representation: a small, backend-agnostic scene description, plus the Backend interface every renderer implements.
|
Package ir defines refract's intermediate representation: a small, backend-agnostic scene description, plus the Backend interface every renderer implements. |
|
Package layout decides where the plot area, titles and legend go.
|
Package layout decides where the plot area, titles and legend go. |
|
Package palette provides colours and colour sequences for charts.
|
Package palette provides colours and colour sequences for charts. |
|
Package render lowers a resolved chart into IR.
|
Package render lowers a resolved chart into IR. |
|
Package scale maps data values onto visual positions and generates the ticks that label them.
|
Package scale maps data values onto visual positions and generates the ticks that label them. |
|
Package theme holds the visual tokens a chart is drawn with: colours, fonts, sizes and spacings.
|
Package theme holds the visual tokens a chart is drawn with: colours, fonts, sizes and spacings. |



