Documentation
¶
Overview ¶
Package expr parses and evaluates the expression language of Vega (D9).
An expression is a subset of JavaScript expressions, such as datum.price * 2 or datum.open < datum.close ? 'up' : 'down'. Compile parses an expression into a Program, and a Program evaluates against a Scope: the datum, the signals and the functions that the runtime gives it. The rules for +, == and truth follow JavaScript, as Vega does. docs/EXPRESSIONS.md holds the design.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Undefined any = undefined{}
Undefined is the value undefined of JavaScript.
Functions ¶
func Ascending ¶
Ascending compares two values in the natural order that the sorts of Vega use: null and undefined first, then numbers, dates and strings by their values. NaN is equal to everything, as it is not ordered.
Types ¶
type Color ¶
type Color struct {
// contains filtered or unexported fields
}
Color is a color that the functions rgb, hsl, lab and hcl make. An expression reads its channels as properties, such as .r of an RGB color or .h of an HSL color, and writes it as rgb() or rgba(), as d3 does.
type Error ¶
type Error string
Error is an error of the package expr.
const ( // ErrSyntax is the error of an expression that does not parse. ErrSyntax Error = "syntax error" // ErrUnknownFunction is the error of a call to a function that the // scope does not hold. ErrUnknownFunction Error = "unknown function" // ErrNotAllowed is the error of a construct that Vega does not allow in // an expression, such as an assignment. ErrNotAllowed Error = "not allowed in an expression" )
The errors of the package expr.
const ErrArgument Error = "invalid argument"
ErrArgument is the error of a function called with an argument that it cannot use, such as a format spec that does not parse.
const ErrUnknownName Error = "unknown name"
ErrUnknownName is the error of a name that is neither datum, parent, a constant nor a signal.
type Func ¶
Func is a function that an expression can call. It takes the scope of the call, so that a function of the runtime, such as scale, reaches the view.
type Program ¶
type Program struct {
// contains filtered or unexported fields
}
Program is a parsed expression.
type RegExp ¶
RegExp is a regular expression, which the function regexp makes. Go reads the pattern, so a pattern that only JavaScript reads, such as one with a lookahead, is an error.
type Scope ¶
type Scope struct {
// Datum is the row that the expression reads as datum.
Datum any
// Parent is the datum of the enclosing group, which it reads as parent.
Parent any
// Signals holds the signals of the view. It can be nil.
Signals Signals
// Functions holds functions beyond the built in ones, such as the
// functions that read the data and the scales of a view, and those that a
// caller adds. A function here takes the place of a built in one of the
// same name.
Functions map[string]Func
// Location is the time zone of the functions of local time (D27). Nil is
// time.Local.
Location *time.Location
// Rand is the source of random numbers (D28). Nil is a source seeded
// from the system.
Rand *rand.Rand
// Locale holds the names and symbols of the formats (D27). Nil is US
// English.
Locale *format.Locale
}
Scope is what an expression reads when it runs.