It is not only a fully functional graph visualization library, but also an explorer of data relationships.
!!!###!!!title=advanced-guide——VisActor/VGrammar tutorial documents!!!###!!!!!!###!!!description=VGrammar, as a graphic grammar, provides a very powerful customization capability for users to expand. This tutorial will introduce some customization capabilities.!!!###!!!
Advanced Guide
VGrammar, as a graphic grammar, provides a very powerful customization capability for users to expand. This tutorial will introduce some customization capabilities.
Custom Transform
Implementation
Data transformation transform is actually a pure function. To implement a custom transform, we need to implement a pure function with the following type:
All transforms accept four parameters:
options: configuration
data: data to be transformed
params: configuration data transformation syntax elements, depending on other syntax elements results
view: global VGrammar visualization instance, generally only a few layout algorithms may need to use, not recommended
Take the built-in filter transform implementation as an example:
Registration
To register a transform, just call Factory.registerTransform() for registration.
Example:
Usage
After registration, you can use it like the built-in transform, just pass in the required configuration.
Custom Composite Glyph
VGrammar has some built-in composite glyphs. When basic glyphs and built-in composite glyphs cannot meet the requirements, users can expand them by customizing the composite glyphs.
Registration
Taking the built-in wave composite glyph as an example, when implementing a custom composite glyph, first, we need to register a globally unique name and the types and name of the basic glyphs that make up the glyph. For example, the wave glyph is composed of three area-filled lines, so our implementation code is as follows:
Next, we can set the visual channels that the composite glyph needs to support. VGrammar supports three types of visual channel settings:
registerDefaultEncoder() sets the default graphic attributes of the sub-glyph
registerChannelEncoder() sets the custom graphic channel, users need to implement which sub-glyphs need to update the corresponding graphic attributes when the composite glyph sets this visual channel
registerFunctionEncoder() when multiple graphic attributes of a composite glyph ultimately need to be mapped to a single attribute of a sub-glyph, the function type visual channel parsing function can be registered.
The implementation examples of registerDefaultEncoder() and registerChannelEncoder() are as follows:
The implementation of registerFunctionEncoder() can refer to the implementation of the linkPath composite glyph:
Usage
After the registration of the composite glyph is complete, it can be used like the built-in composite glyph:
Custom Syntax Elements
All VGrammar syntax elements run according to dependency. When the existing syntax elements do not meet the requirements, users can try to implement custom syntax elements. Next, take the vgrammar-projection implementation of the Projection syntax element as an example, explain how to customize the syntax element and use it in the VGrammar visual chart.
Implementation of Syntax Class
When we implement custom syntax elements, we need to inherit the base class GrammarBase and implement the following three main methods:
parse(spec: CustomizedSpec) method for parsing the configuration, the configuration type needs to be defined
evaluate(upstream: any, parameters: any) execution logic, when the syntax element is executed, the upstream dependent data and other dependent parameters will be passed in
output() returns the output object of the syntax element, which will be obtained by the downstream nodes and perform subsequent logic
Example:
Registration
Next, just call the registration method to register the custom syntax element: