Marks visually encode data using geometric primitives.
General JSON format:
A Vega marks
specification includes the following properties:
string
X
Graphical marks type or shape:
points
lines
polys
symbol
object
Database table associated with the marks.
object
X
Visual encoding rules. Valid properties depend on marks type
.
object
Transforms applied to a mark.
Each marks property is associated with the specified data property.
Marks are rendered in marks property array order.
Marks property values can be constants or as data references. You can use the scales property to transform marks property values to the visualization area.
Apply the x
and y
scales to the x
and y
database table columns to scale the data to the visualization area width and height. For example:
Marks must include a type
property that specifies the geometric primitive to use to render the data.
Render marks as points.
Render marks as lines.
Render marks as a polygon.
Render marks as a shape.
Specify x
and y
coordinate values using either constants, or domain and range values of a data
reference. If the from
property is not specified, the x
and y
properties
fields must be constants.
Define a point with size, color, and opacity:
Associate the points
geometric primitive with tweets
data items.
Specifying the data
format
property as lines
causes the rendering engine to assume a lines
database table layout and to extract line-related columns from the table.
Specify x
and y
coordinate values using either constants, or domain and range values of a data
reference. If the from
property is not specified, the x
and y
properties
fields must be constants.
The polys
type renders data as a polygon.
When the data
format property is polys
, the rendering engine assumes a polys
database table layout and extracts the poly-related columns from the table. A polys
database table layout implies that the first data column is the vertex x- and y-positions. The vertices are interleaved x and y values, such that vertex[0] = vert0.x
, vertex[1] = vert0.y
, vertex[2] = vert1.x
, and vertex[3] = vert1.y
, for example. The next three positions of a polys
database table are the triangulated indices, and line loop and drawing information for unpacking multiple, associated polygons that can be packed as a single data item.
The symbol
marks type renders data as one of the supported shapes.
Currently, in symbol
mark types, strokes are not visible beneath other marks, regardless of opacity settings.
Specify x
and y
coordinate values using either constants or domain and range values of a data
reference. If the from
property is not specified, the x
and y
properties
fields must be specified using constant values.
symbol
ExamplesThe following example defines symbol mark types including fill, stroke, and general opacity properties:
The from
field specifies the input database table to use.
data
string
Example
Use the tweets
database table for marks input data.
If from
is not specified, the data source is implicitly a single point with the value defined in the points
properties.
The properties
property specifies type-dependent visual encoding that define the position and appearance of mark instances. The property value is specified using one of the Value Reference options.
Typically, a single mark instance is generated per input data element, except for polys
, which uses multiple data elements to represent a line or area shape.
The following table describes the various marks properties
and lists the types for which the property is valid.
angle
number
symbol
Amount of rotation about the defined center of rotation. The center of rotation depends on the properties that specify the symbol location:
x
and y
: Lower-left corner.
x
and yc
: Left center.
xc
and y
: Bottom center.
xc
and yc
: Center.
Must be a numerical constant or a scale that provides numerical values.
In the following example, the triangle-down symbol is rotated 30 degrees about the downward point:
angleUnit
string
symbol
Optional. Unit of measure for the rotation of a symbol around the center of rotation, defined in angle
. Either degrees
(default) or radians
.
fillColor
color
points, polys, symbol
fillOpacity
number
points, polys, symbol
The fill opacity, from transparent (0
) to opaque (1
). If used with opacity
, the values are multiplied together to determine final opacity.
height
number
symbol
Mark height, in pixels.
lineJoin
string
line, polys, symbol
Line join method:
bevel
- Extension of a line end
miter
- Clipped extension of a line end
round
- Semi-circle at a line end
miterLimit
number
line, polys, symbol
The miter limit at which to bevel a line join, in pixels.
Must be a positive number. Default = 10.0
opacity
number
all
The line opacity as a whole, from transparent (0
) to opaque (1
). If used with fillOpacity
(points
, polys
, symbol
) or strokeOpacity
(lines), the values are multiplied together to determine final opacity.
shape
string
symbol
Shape name:
circle
cross
diamond
hexagon-horiz
hexagon-vert
square
triangle-down
triangle-left
triangle-right
triangle-up
wedge
size
number
points
Graphical primitive size, in pixels. Must be a scale/data reference or a number.
stroke
color
symbol
Stroke color.
strokeColor
color
line, polys
Default color = white
strokeOpacity
number
line, polys, symbol
Stroke opacity, from transparent (0
) to opaque (1
). If used with opacity
, the values are multiplied together to determine final opacity.
strokeWidth
number
line, polys, symbol
Stroke width, in pixels. Must be a scale/data reference or a number.
width
number
symbol
Mark width, in pixels.
x
number
all
x2
number
symbol
xc
number
symbol
y
number
all
y2
number
symbol
yc
number
symbol
z
number
points, symbol
A value reference describes how to specify marks properties
values. The value can be a constant or data object reference:
value
Any
Constant value. If field
is specified, value
is ignored.
field
Perform a lookup on the current data value. The marks from
property determines the source data table and the field
name must be a column defined in the data
property.
scale
Examples:
Statically set the point fillColor
and size
.
For the x
marks property, apply the x
scale transform to the implicit x-coordinate data column.
A field reference is either a string literal or an object. For object values, the following properties are supported:
Property Name
FieldRef
Perform a lookup on the property name. This is the default operation when a field reference is a string.
Typically, color values are specified as a single RGB color value. To specify specific color fields or use a different color space, use one of the following color value reference formats:
field
string
Name of the attribute from the data: sql
field.
colorSpace
string
Space in which the color is defined:
Use r
, g
, and b
property names.
Use h
, s
, and l
property names.
Use l
, a
, and b
property names.
Use h
, c
, and l
property names.
Examples
Set the red and blue channels of an RGB color as constants, and uses a scale transform to determine the green channel:
Use the rgb
color space for the color
field:
The transform
object specifies any Vega projections to be applied to the mark. Each transform is specified as a key:value pair in the transform
object:
The value references an existing Vega object by name.
For example, the following transform references the projection my_mercator_projection
defined in the top-level Vega projections
property.
Currently, the only supported transform is projection
.
``
``
``
``
Name of the data source. The data
name must be defined in the property.
Fill color. Must be a scale/data reference, a string, or a color represented by a 32-bit integer or unsigned integer. See .
Stroke color. Must be a scale/data reference, a string, or a color represented by a 32-bit integer or unsigned integer. See .
Primary x-coordinate, in pixels. Must be a scale/data reference for polys
, or a scale/data reference or a number for points
, lines
, or symbol
. See .
Secondary x-coordinate, in pixels. See .
Center x-coordinate, in pixels. Incompatible with x
and x2
. See .
Primary y-coordinate, in pixels. Must be a scale/data reference for polys
, or a scale/data reference or a number for points
, lines
, or symbol
. See .
Secondary y-coordinate, in pixels. See .
Center y-coordinate, in pixels. Incompatible with y
and y2
. See .
Primary depth-coordinate, in pixels. Must be a scale/data reference or a number. See .
Name of a scale transform to apply to the mark. If the input is an object, it indicates a field value from which to dynamically look up the scale name and follows the format.
Hue-Chroma-Luminance color space. See .
Hue, saturation, and lightness color space. See .
Lab color space. A perceptual color space with distances based on human color judgments. The L dimension represents luminance, the A dimension represents green-red opposition and the B dimension represents blue-yellow opposition. See .
RGB color space. A version of LAB, which uses polar coordinates for the AB plane. See .