Documentation
¶
Overview ¶
Package zuzu draws charts and diagrams from a declarative spec that follows Vega and Vega-Lite. It writes its own SVG, and okage renders the SVG to an image.
The plan is in docs/PLAN.md and the public API in docs/API.md.
Index ¶
- func FromVega(spec *vega.Spec, opts ...Option) (*Chart, Report, error)
- func FromVegaLite(spec *vegalite.Spec, opts ...Option) (*Chart, Report, error)
- func Parse(src []byte, opts ...Option) (*Chart, Report, error)
- type Chart
- func (c *Chart) Image(ctx context.Context, opts ...RenderOption) (*image.RGBA, Report, error)
- func (c *Chart) NewView(ctx context.Context, opts ...RenderOption) (*View, Report, error)
- func (c *Chart) Render(ctx context.Context, opts ...RenderOption) (*scene.Scene, Report, error)
- func (c *Chart) SVG(ctx context.Context, w io.Writer, opts ...RenderOption) (Report, error)
- func (c *Chart) Spec() *vega.Spec
- type Dialect
- type Error
- type IconLoader
- type IconLoaderFunc
- type IconRequest
- type LoadRequest
- type Loader
- type LoaderFunc
- type Option
- type RenderOption
- func WithBackground(c color.Color) RenderOption
- func WithIconLoader(l IconLoader) RenderOption
- func WithIcons(name string, p *icon.Pack) RenderOption
- func WithLoader(l Loader) RenderOption
- func WithLocale(l format.Locale) RenderOption
- func WithLocation(loc *time.Location) RenderOption
- func WithMode(m theme.Mode) RenderOption
- func WithRandom(fn func() rand.Source) RenderOption
- func WithRenderLogger(l *slog.Logger) RenderOption
- func WithResultSet(name string, rs ResultSet) RenderOption
- func WithScheme(s theme.Scheme) RenderOption
- func WithSize(width, height float64) RenderOption
- func WithValues(name string, rows []map[string]any) RenderOption
- type Report
- type ResultSet
- type View
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FromVega ¶
FromVega takes a Vega spec that a program built as Go values. It copies the spec, so a later change by the caller does not reach the Chart.
func FromVegaLite ¶
FromVegaLite takes a Vega-Lite spec that a program built as Go values, and compiles it to Vega. The report names each part that zuzu did not compile, in the loose mode.
Types ¶
type Chart ¶
type Chart struct {
// contains filtered or unexported fields
}
Chart is a parsed spec. It does not change after Parse, so it is safe for concurrent use.
func (*Chart) Image ¶
Image renders the chart and draws it with the direct renderer of okage (D11). The text draws in the bundled IBM Plex Sans (D16), and in no font of the system, so that a chart gives the same pixels on every machine. A character that the bundled font lacks draws nothing. The pixels are premultiplied, as image.RGBA expects.
type Dialect ¶
type Dialect int
Dialect is the language of a spec.
const ( // Vega is a Vega spec. Vega Dialect = iota + 1 // VegaLite is a Vega-Lite spec. VegaLite // DOT is a graph in the DOT language of Graphviz (D31). DOT // Mermaid is a diagram of Mermaid (D31). Mermaid )
The dialects.
func Sniff ¶ added in v0.2.0
Sniff returns the dialect of a source from its first bytes, as a detector of a type of file does: DOT or Mermaid from the first word, and Vega or Vega-Lite from a $schema in the first bytes. It needs no more than the first 512 bytes, and returns false when they do not decide.
type Error ¶
type Error string
Error is an error of the package zuzu.
const ( // ErrUnknownDialect is the error of a spec whose $schema names neither // Vega nor Vega-Lite, and of a spec with no $schema and no WithDialect. ErrUnknownDialect Error = "unknown spec dialect" // ErrNoLoader is the error of a spec that names data by url, when the // render has no loader (D25). ErrNoLoader Error = "no loader for url data" // ErrCycle is the error of a signal, a dataset or a scale that depends // on itself. ErrCycle Error = "cycle in the spec" // ErrUnknownName is the error of a reference to a signal, a dataset or a // scale that the spec does not have. ErrUnknownName Error = "unknown name" )
The errors of the package. The errors of a spec are in the package vega.
type IconLoader ¶
type IconLoader interface {
LoadIcon(ctx context.Context, req IconRequest) (io.ReadCloser, error)
}
IconLoader gives the icons that no pack of WithIcons holds (D31). zuzu asks it once for each icon of a render, by its prefix and its name, and it gives the bytes from wherever it chooses. zuzu itself reads no file and makes no request.
func FSIconLoader ¶
func FSIconLoader(fsys fs.FS) IconLoader
FSIconLoader reads an icon from fsys: the SVG <prefix>/<name>.svg, or else the pack of Iconify <prefix>.json. The caller chooses fsys, so zuzu still reads only what the caller allows.
type IconLoaderFunc ¶
type IconLoaderFunc func(context.Context, IconRequest) (io.ReadCloser, error)
IconLoaderFunc makes an IconLoader of a function.
func (IconLoaderFunc) LoadIcon ¶
func (f IconLoaderFunc) LoadIcon(ctx context.Context, req IconRequest) (io.ReadCloser, error)
LoadIcon calls the function.
type IconRequest ¶
type IconRequest struct {
Prefix, Name string
}
IconRequest names an icon: aws and lambda, for aws:lambda.
type LoadRequest ¶
type LoadRequest struct {
// URL is the url of the spec, as written.
URL string
// Format is csv, tsv, json or topojson, from the spec.
Format string
// Name is the name of the dataset.
Name string
}
LoadRequest says what a spec asks for.
type Loader ¶
type Loader interface {
Load(ctx context.Context, req LoadRequest) (io.ReadCloser, error)
}
Loader reads the data that a spec names by url (D25). zuzu reads no file and makes no request of its own.
type LoaderFunc ¶
type LoaderFunc func(context.Context, LoadRequest) (io.ReadCloser, error)
LoaderFunc makes a Loader of a function.
func (LoaderFunc) Load ¶
func (f LoaderFunc) Load(ctx context.Context, req LoadRequest) (io.ReadCloser, error)
Load calls the function.
type Option ¶
type Option func(*options)
Option is a setting of Parse.
func WithDialect ¶
WithDialect sets the dialect of a spec that has no $schema.
func WithFunction ¶
WithFunction adds a Go function that an expression can call by name. It takes the place of a built in function of the same name.
func WithStrict ¶
WithStrict sets the feature mode (D26). In the strict mode, a feature that zuzu does not support is an error. In the loose mode, the default, zuzu skips it and names it in the report.
type RenderOption ¶
type RenderOption func(*renderOptions)
RenderOption is a setting of a render.
func WithBackground ¶ added in v0.2.0
func WithBackground(c color.Color) RenderOption
WithBackground sets the background of the chart, over the background of the theme and of the spec. A color with an alpha of 0 draws no background, and nil keeps the background of the theme and of the spec. The boxes under the labels of a diagram and the open arrowheads take an opaque color too, so that they match the background.
func WithIconLoader ¶
func WithIconLoader(l IconLoader) RenderOption
WithIconLoader sets how a render loads the icons that no pack holds.
func WithIcons ¶
func WithIcons(name string, p *icon.Pack) RenderOption
WithIcons gives a pack of icons to a render, under a name that replaces the prefix of the pack, as Mermaid does (D31). A diagram names an icon of the pack as name:icon.
func WithLoader ¶
func WithLoader(l Loader) RenderOption
WithLoader sets how the data of a url is read (D25).
func WithLocale ¶
func WithLocale(l format.Locale) RenderOption
WithLocale sets the locale of numbers and dates (D27).
func WithLocation ¶
func WithLocation(loc *time.Location) RenderOption
WithLocation sets the time zone of local time (D27). The default is the zone of the system.
func WithMode ¶
func WithMode(m theme.Mode) RenderOption
WithMode sets the light or the dark mode (D14).
func WithRandom ¶
func WithRandom(fn func() rand.Source) RenderOption
WithRandom sets the function that makes the source of random numbers of a render (D28). Each render calls it once.
func WithRenderLogger ¶
func WithRenderLogger(l *slog.Logger) RenderOption
WithRenderLogger sets where a render logs.
func WithResultSet ¶
func WithResultSet(name string, rs ResultSet) RenderOption
WithResultSet gives the rows of a named dataset, read from the result of a query. zuzu reads it once, and the caller closes it.
func WithScheme ¶
func WithScheme(s theme.Scheme) RenderOption
WithScheme sets the color scheme (D14).
func WithSize ¶
func WithSize(width, height float64) RenderOption
WithSize sets the size of the chart, in place of its width and height.
func WithValues ¶
func WithValues(name string, rows []map[string]any) RenderOption
WithValues gives the rows of a named dataset. They take the place of the values or the url of the dataset in the spec, and its transforms still run.
type Report ¶
Report lists what zuzu did not draw in the loose mode, and what it warns of in either mode (D26).
type ResultSet ¶
type ResultSet interface {
Columns() ([]string, error)
Next() bool
Scan(dest ...any) error
Err() error
}
ResultSet is the result of a query. *sql.Rows satisfies it.
type View ¶
type View struct {
// contains filtered or unexported fields
}
View holds the state of one render. It is not safe for concurrent use.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package dataflow reads the data of a Vega spec and runs its transforms (D6).
|
Package dataflow reads the data of a Vega spec and runs its transforms (D6). |
|
Package expr parses and evaluates the expression language of Vega (D9).
|
Package expr parses and evaluates the expression language of Vega (D9). |
|
Package format formats numbers and times with the syntax of d3-format and d3-time-format, which Vega uses for its axes, its legends and the functions format and timeFormat of its expressions.
|
Package format formats numbers and times with the syntax of d3-format and d3-time-format, which Vega uses for its axes, its legends and the functions format and timeFormat of its expressions. |
|
Package geo holds the cartographic projections of zuzu and the geographic paths that they draw.
|
Package geo holds the cartographic projections of zuzu and the geographic paths that they draw. |
|
Package graph holds the model of a diagram, a graph of nodes, edges and clusters, and its layered layout (D18, D31).
|
Package graph holds the model of a diagram, a graph of nodes, edges and clusters, and its layered layout (D18, D31). |
|
dot
Package dot reads the DOT language of Graphviz into a graph (D31).
|
Package dot reads the DOT language of Graphviz into a graph (D31). |
|
mermaid
Package mermaid reads diagrams of Mermaid 12.3.0 (D31): the flowchart into a graph, and the charts into specs of Vega-Lite and Vega.
|
Package mermaid reads diagrams of Mermaid 12.3.0 (D31): the flowchart into a graph, and the charts into specs of Vega-Lite and Vega. |
|
Package icon reads icons in the JSON format of Iconify, and in SVG, for the nodes of a diagram (D31).
|
Package icon reads icons in the JSON format of Iconify, and in SVG, for the nodes of a diagram (D31). |
|
icons
|
|
|
carbon
Package carbon bundles the icons of Carbon, the design system of IBM, version 11.92.0, under Apache-2.0, as a pack of icons for the diagrams of zuzu (D31).
|
Package carbon bundles the icons of Carbon, the design system of IBM, version 11.92.0, under Apache-2.0, as a pack of icons for the diagrams of zuzu (D31). |
|
fa
Package fa bundles the solid icons of Font Awesome Free, version 7.3.1, under CC BY 4.0, as a pack of icons for the diagrams of zuzu (D31).
|
Package fa bundles the solid icons of Font Awesome Free, version 7.3.1, under CC BY 4.0, as a pack of icons for the diagrams of zuzu (D31). |
|
k8s
Package k8s bundles the icons of Kubernetes, from the pack of Iconify of 2026-10-20, under Apache-2.0, as a pack of icons for the diagrams of zuzu (D31).
|
Package k8s bundles the icons of Kubernetes, from the pack of Iconify of 2026-10-20, under Apache-2.0, as a pack of icons for the diagrams of zuzu (D31). |
|
mdi
Package mdi bundles Material Design Icons of Pictogrammers, from the pack of Iconify of 2025-01-21, under Apache-2.0, as a pack of icons for the diagrams of zuzu (D31).
|
Package mdi bundles Material Design Icons of Pictogrammers, from the pack of Iconify of 2025-01-21, under Apache-2.0, as a pack of icons for the diagrams of zuzu (D31). |
|
internal
|
|
|
color
Package color reads the colors of CSS and converts them between the color spaces of d3: RGB, HSL, CIELAB and HCL.
|
Package color reads the colors of CSS and converts them between the color spaces of d3: RGB, HSL, CIELAB and HCL. |
|
shape
Package shape draws the geometry of the items of a scene as the path data of SVG: the curves of lines and areas, the symbols, the arcs, the trails and the rects with round corners.
|
Package shape draws the geometry of the items of a scene as the path data of SVG: the curves of lines and areas, the symbols, the arcs, the trails and the rects with round corners. |
|
Package layout draws the guides of a chart in the look of zuzu: the axes, the legends and the titles (D12).
|
Package layout draws the guides of a chart in the look of zuzu: the axes, the legends and the titles (D12). |
|
Package raster draws a scene graph as an image with the drawing of okage directly, without the round trip through SVG (D11).
|
Package raster draws a scene graph as an image with the drawing of okage directly, without the round trip through SVG (D11). |
|
Package scale holds the scales of Vega, which map values of the data to values of a chart, such as positions and colors, and the ticks of each scale (D6).
|
Package scale holds the scales of Vega, which map values of the data to values of a chart, such as positions and colors, and the ticks of each scale (D6). |
|
Package scene holds the scene graph of zuzu: the shapes of a chart with their final positions, sizes and colors (D8).
|
Package scene holds the scene graph of zuzu: the shapes of a chart with their final positions, sizes and colors (D8). |
|
Package svg writes a scene graph as SVG (D10).
|
Package svg writes a scene graph as SVG (D10). |
|
Package text measures text for the layout of zuzu (D11).
|
Package text measures text for the layout of zuzu (D11). |
|
Package theme holds the themes of zuzu: a mode, light or dark, and a color scheme, which a caller swaps apart from the mode (D14).
|
Package theme holds the themes of zuzu: a mode, light or dark, and a color scheme, which a caller swaps apart from the mode (D14). |
|
Package vega holds the Go types of a Vega spec, which it reads from JSON and writes back to JSON (D6, D21).
|
Package vega holds the Go types of a Vega spec, which it reads from JSON and writes back to JSON (D6, D21). |
|
Package vegalite holds the Go types of a Vega-Lite spec and the compiler that turns it into a Vega spec (D6, D21).
|
Package vegalite holds the Go types of a Vega-Lite spec and the compiler that turns it into a Vega spec (D6, D21). |