dataflow

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 28 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package dataflow reads the data of a Vega spec and runs its transforms (D6). It runs each dataset once, from its source to its last transform, since zuzu draws a static chart (D7). The view gives it the signals, the other datasets and the expressions through an Env.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Comparator

func Comparator(fields []*Accessor, orders []string) func(a, b Row) int

Comparator returns a function that compares rows by fields, each in the order ascending or descending. A missing order is ascending.

func ParseTypes

func ParseTypes(rows []Row, f Format, loc *time.Location) error

ParseTypes converts the fields of rows to the types that a format gives. It changes the rows.

func SplitField

func SplitField(name string) []string

SplitField splits a field name in the syntax of Vega into the names of its path.

func Supported

func Supported(typ string) bool

Supported reports whether zuzu runs a transform type.

func TimeFloor

func TimeFloor(units []string, step int, loc *time.Location) func(time.Time) time.Time

TimeFloor returns a function that floors a time to a set of units, as the timeunit transform of Vega documents. The fields of the units stay, and every other field takes the start of its range, with the year 2012 when the units have no year. With day, the date is the day of the week of the first week of 2012, which starts on a Sunday. With step, the smallest unit floors to a multiple of step.

Types

type Accessor

type Accessor struct {
	// Name is the name of the field, which names the output of a transform,
	// such as sum_price.
	Name string
	// contains filtered or unexported fields
}

Accessor reads a value from a row.

func FieldAccessor

func FieldAccessor(name string) *Accessor

FieldAccessor returns an accessor of a field name in the syntax of Vega: a dot reads a nested field, as in a.b, brackets read an index or a quoted name, as in a[0] and a["b c"], and a backslash makes the next character plain, as in a\.b.

func (*Accessor) Get

func (a *Accessor) Get(r Row) any

Get reads the value from a row.

type Env

type Env interface {
	// Compile compiles an expression, which can read signals.
	Compile(src string) (*expr.Program, error)
	// Scope returns the scope that an expression of the view runs in, with
	// a datum.
	Scope(datum any) *expr.Scope
	// Data returns the rows of a dataset, after its transforms.
	Data(name string) ([]Row, error)
	// SetSignal sets a signal that a transform writes, such as the signal of
	// an extent.
	SetSignal(name string, v any)
	// Location is the time zone of local time (D27).
	Location() *time.Location
	// Random returns a random number from 0 to 1, from the source of the
	// render (D28).
	Random() float64
}

Env is what a transform reads from the view.

type Error

type Error string

Error is an error of the package dataflow.

const (
	// ErrParam is the error of a parameter of a transform that is missing
	// or has a value that the transform cannot use.
	ErrParam Error = "invalid transform parameter"
	// ErrFormat is the error of data that does not read in its format.
	ErrFormat Error = "invalid data"
)

The errors of the package.

func (Error) Error

func (err Error) Error() string

Error satisfies the error interface.

type Format

type Format struct {
	// Type is json, csv, tsv or dsv. The default is json.
	Type string
	// Delimiter is the delimiter of dsv.
	Delimiter string
	// Header names the columns of delimited text that has no header line.
	Header []string
	// Property is the field of JSON that holds the rows.
	Property string
	// Parse gives the type of each field: boolean, integer, number, date,
	// string, or date:'spec' and utc:'spec' with a format spec of
	// d3-time-format.
	Parse map[string]string
	// Auto infers the type of each field.
	Auto bool
	// Feature names the object of a TopoJSON topology whose geometries
	// are the rows, and Mesh names the object whose arcs, joined into
	// lines, are the row.
	Feature, Mesh string
	// Filter keeps the arcs of a mesh between two geometries, for
	// "interior", or the arcs of one geometry alone, for "exterior".
	Filter string
}

Format says how to read data, with its signals resolved.

type Hierarchy

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

Hierarchy is the tree that a stratify transform builds, which the transforms after it read, in its dataset and in the datasets that derive from it. It holds the fields that name each node and its parent, so that a transform builds the tree again from its own rows.

type HierarchyEnv

type HierarchyEnv interface {
	Hierarchy() *Hierarchy
}

HierarchyEnv is an Env that keeps the hierarchy of a view across its datasets. An Env without it keeps the hierarchy for one run of transforms.

type IconEnv

type IconEnv interface {
	// Icon returns an icon by its name, pack:name, or an error for an icon
	// that no pack and no loader gives.
	Icon(name string) (*icon.Icon, error)
	// Image returns an image by its url, as a URL of data, with its size.
	Image(url string) (string, float64, float64, error)
	// IconColor returns the color of an icon of one color.
	IconColor() string
	// Issue handles a feature that does not draw: an error in the strict
	// mode, and an issue of the report in the loose mode.
	Issue(err error, path, format string, args ...any) error
}

IconEnv is an Env that gives the icons and the images of the nodes of a diagram (D31). The transform zuzu.icon needs it.

type MarkEnv

type MarkEnv interface {
	// MarkShapes returns the type of a mark and a row for each of its
	// items, with x, y, x2, y2, width, height and bounds, and whether the
	// view has the mark.
	MarkShapes(name string) (string, []Row, bool)
}

MarkEnv is an Env that gives the items of the marks of a view, by name. The transform label needs it for the marks that it avoids.

type ProjectionEnv

type ProjectionEnv interface {
	Projection(name string) (*geo.Projection, error)
}

ProjectionEnv is an Env that holds the projections of a view, by name. The geographic transforms need it.

type Row

type Row = map[string]any

Row is a row of a dataset. Its values are the values of expressions: float64, string, bool, nil, time.Time, []any and map[string]any.

func Ingest

func Ingest(v any) []Row

Ingest turns values that JSON gave into rows. An array gives one row for each element, and any other value gives one row.

func Read

func Read(src []byte, f Format, loc *time.Location) ([]Row, error)

Read reads rows from the text of data in a format. A value that is not an object becomes the row {"data": value}, as Vega reads it.

func ReadTopoJSON

func ReadTopoJSON(v any, f Format) ([]Row, error)

ReadTopoJSON reads the rows of a TopoJSON topology: a row for each geometry of the object that Feature names, or one row, the MultiLineString of the mesh of the object that Mesh names.

func Run

func Run(env Env, rows []Row, ts []vega.Transform, path string) ([]Row, error)

Run runs transforms over rows, in order, and returns the rows of the last. A transform that zuzu does not run is an error that wraps vega.ErrUnsupportedTransform. path is the JSON pointer of the list of transforms in the spec, for the errors.

type TextEnv

type TextEnv interface {
	// TextSize returns the width and the height of a text, which is a
	// string or a list of lines, in a font, a size and a weight. An empty
	// font or a size of 0 means that of the theme.
	TextSize(text any, font string, size float64, weight string) (float64, float64)
}

TextEnv is an Env that measures text as the writer draws it. The transform label needs it.

Jump to

Keyboard shortcuts

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