Grammar Elements
VGrammar visual scenes consist of grammar elements with different meanings.
Currently, VGrammar supports grammar elements including:
- Semaphore Signal
- Data Data
- Mapping Scale
- Coordinate System Coordinate
- Graphic Mark
In addition, developers can register their own grammar elements through the registerGrammar
interface.
Semaphore Signal
Semaphore (signal) grammar elements describe a variable in the visual scene. Signals can be simple values or generated by specific calculation logic, and dynamically affect the calculation of the visual scene.
VGrammar provides some built-in semaphores, including:
- width & height: Width and height of the visual scene
- viewWidth & viewHeight: Width and height excluding padding
- viewBox: Bounding box excluding padding
- padding: Inner padding of the visual scene
- autoFit: Whether the visual scene adapts to the container width and height
Spec form Signal element usage example:
API form Signal element usage example:
Data Data
Data (data) grammar elements are used to manage a set of data, and VGrammar provides built-in data transformations to support data analysis logic.
In VGrammar visualization scenes, graphic element rendering is based on data-driven logic; except for special components and Group graphics, other graphic types are based on data elements to perform corresponding data mapping (data join) calculations.
Spec form Data element usage example:
API form Data element usage example:
Mapping Scale
Mapping (scale) grammar element is responsible for mapping data to visual channels, such as mapping ['A', 'B']
data to color channel ['red', 'blue']
.
Currently, VGrammar provides several different types of Scale grammar elements, such as LinearScale linear mapping, OrdinalScale sequential mapping, etc.
Developers can freely choose the mapping method, configure mapping parameters, and apply the declared scale element to the visual encoding calculation of the mark:
Spec form Scale element usage example:
API form Scale element usage example:
Coordinate System Coordinate
Coordinate (coordinate) grammar elements describe specific coordinate system transformation logic, converting coordinate positions from the canvas coordinate system to the target coordinate system.
Coordinate system functions include conversion between different coordinate system categories (such as Cartesian coordinate system to polar coordinate system conversion) and additional coordinate system transformation logic (such as translation, rotation, scaling, transposition). Semantic graphic elements adapt their presentation based on their corresponding coordinate system.
Currently, VGrammar provides two types of coordinate systems:
- Cartesian coordinate system: The Cartesian coordinate system provided by VGrammar consists of two perpendicular x and y axes.
- Polar coordinate system: The polar coordinate system provided by VGrammar consists of angle theta and radius r.
Spec form Coordinate element usage example:
API form Coordinate element usage example:
Graphic Mark
Graphic (mark) grammar elements describe a group of graphical elements with the same data mapping and visual encoding logic. Developers can create data-driven graphics content through mark elements.
Spec form Mark element usage example:
API form Mark element usage example:
Inter-reference of grammar elements
All grammar elements can reference each other
In Spec mode, grammar elements can reference another grammar element through the dependency
configuration:
In API mode, you can use the depend
API to reference another grammar element:
Note that each grammar element provides semantic configurations to depend on specific grammar elements; the effect and depend()
, dependency
are consistent, and when declaring specific configurations using custom callbacks, all dependent grammar elements can be accessed through their globally unique id
;