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 ¶
- func Comparator(fields []*Accessor, orders []string) func(a, b Row) int
- func ParseTypes(rows []Row, f Format, loc *time.Location) error
- func SplitField(name string) []string
- func Supported(typ string) bool
- func TimeFloor(units []string, step int, loc *time.Location) func(time.Time) time.Time
- type Accessor
- type Env
- type Error
- type Format
- type Hierarchy
- type HierarchyEnv
- type IconEnv
- type MarkEnv
- type ProjectionEnv
- type Row
- type TextEnv
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Comparator ¶
Comparator returns a function that compares rows by fields, each in the order ascending or descending. A missing order is ascending.
func ParseTypes ¶
ParseTypes converts the fields of rows to the types that a format gives. It changes the rows.
func SplitField ¶
SplitField splits a field name in the syntax of Vega into the names of its path.
func TimeFloor ¶
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 ¶
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.
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.
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 ¶
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 ¶
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 ¶
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 ¶
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.
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.