Extension is an important concept in G6, it is a general term for all expandable parts in G6, including the following types:
G6 provides the register
function for registering extensions, for example:
import { register, ExtensionCategory } from '@antv/g6';import { CustomNode } from './my-custom-node';// # Registering Nodesregister(ExtensionCategory.NODE, 'custom-node', CustomNode);
The first parameter of the register
function is the type of the extension, the second parameter is the name of the extension, and the third parameter is the implementation of the extension.
Different types of extensions can use the same extension name, but when registering extensions of the same type, only the first registration will take effect.
For detailed parameter signatures, see: API Documentation
// ✅register(ExtensionCategory.NODE, 'custom-name', CustomNode);register(ExtensionCategory.COMBO, 'custom-name', CustomCombo);// ❌register(ExtensionCategory.NODE, 'custom-name', CustomNode);register(ExtensionCategory.NODE, 'custom-name', CustomNode);
The configuration location for different types of extensions varies, but all are used by specifying the name that was used during registration, for example:
options.node.type
options.edge.type
options.combo.type
options.behaviors
options.layout.type
options.plugins
options.theme
options.transform
options.node.palette
, options.edge.palette
, etc.options.node.animate
, options.edge.animate
, etc.G6 provides the getExtension
and getExtensions
methods to obtain a single extension and all extensions of a specified type, respectively, for example:
import { getExtension, getExtensions, ExtensionCategory } from '@antv/g6';// To get the implementation of the node extension registered with the name 'custom-node'getExtension(ExtensionCategory.NODE, 'custom-node');// Retrieve all registered node extension implementationsgetExtensions(ExtensionCategory.NODE);