Loading...
{ type: 'view'; options?: FitViewOptions; animation?: ViewportAnimationEffectTiming; } | { type: 'center'; animation?: ViewportAnimationEffectTiming; } | 'view' | 'center'
Whether to automatically fit the canvas. ⚠️ Note: Each time render
is executed, it will adapt according to autoFit
.
Two basic adaptation modes:
'view'
- Automatically scale to ensure all content is visible within the view'center'
- Center the content without changing the zoom levelMore precise adaptation control can be achieved through object form:
const graph = new Graph({autoFit: {type: 'view', // Adaptation type: 'view' or 'center'options: {// Only applicable to 'view' typewhen: 'overflow', // When to adapt: 'overflow' (only when content overflows) or 'always' (always adapt)direction: 'x', // Adaptation direction: 'x', 'y', or 'both'},animation: {// Adaptation animation effectduration: 1000, // Animation duration (milliseconds)easing: 'ease-in-out', // Animation easing function},},});
Property | Description | Type | Default | Required |
---|---|---|---|---|
when | Adaptation occurs under the following conditions - 'overflow' adapt only when content overflows - 'always' always adapt | 'overflow' | 'always' | 'always' | |
direction | Adapt only in the specified direction - 'x' adapt only in x direction - 'y' adapt only in y direction - 'both' adapt in both x and y directions | 'x' | 'y' | 'both' | 'both' |
type ViewportAnimationEffectTiming =| boolean // true to enable default animation, false to disable animation| {easing?: string; // Animation easing function: 'ease-in-out', 'ease-in', 'ease-out', 'linear'duration?: number; // Animation duration (milliseconds)};
boolean Default:
false
Whether to automatically resize the canvas.
Implemented based on the window.onresize
event. When the browser window size changes, the canvas will automatically resize to fit the container.
string
Canvas background color.
This color is used as the background color when exporting images. Any valid CSS color value can be used, such as hexadecimal, RGB, RGBA, etc.
Canvas configuration. Related configuration items under GraphOptions (such as container
, width
, height
, devicePixelRatio
, background
, cursor
) are shortcut configuration items and will be converted to canvas configuration items.
Property | Description | Type | Default | Required |
---|---|---|---|---|
container | Canvas container | string | HTMLElement | - | |
devicePixelRatio | Device pixel ratio | number | - | |
width | Canvas width | number | - | |
height | Canvas height | number | - | |
cursor | Cursor style, same as GraphOptions.cursor | string | - | |
background | Canvas background color | string | - | |
renderer | Renderer, same as GraphOptions.renderer | (layer: 'background' | 'main' | 'label' | 'transient' ) => IRenderer | - | |
enableMultiLayer | Whether to enable multi-layer. Non-dynamic parameter, effective only during initialization | boolean | - |
string | HTMLElement | Canvas
Canvas container, can be one of the following three assignments:
'container'
document.getElementById('container')
new Canvas(options)
, where options
is of type CanvasConfig.string
Cursor style, controls the cursor shape when hovering over the canvas. Any valid CSS cursor value can be used.
Supported values include: 'auto'
, 'default'
, 'none'
, 'context-menu'
, 'help'
, 'pointer'
, 'progress'
, 'wait'
, 'cell'
, 'crosshair'
, 'text'
, 'vertical-text'
, 'alias'
, 'copy'
, 'move'
, 'no-drop'
, 'not-allowed'
, 'grab'
, 'grabbing'
, 'all-scroll'
, 'col-resize'
, 'row-resize'
, 'n-resize'
, 'e-resize'
, 's-resize'
, 'w-resize'
, 'ne-resize'
, 'nw-resize'
, 'se-resize'
, 'sw-resize'
, 'ew-resize'
, 'ns-resize'
, 'nesw-resize'
, 'nwse-resize'
, 'zoom-in'
, `'zoom-out'.
Cursor values are referenced from MDN - cursor.
number
Device pixel ratio.
Used for high-definition screens, the default is window.devicePixelRatio.
number
Canvas width. If not set, the container width will be automatically obtained.
number
Canvas height. If not set, the container height will be automatically obtained.
(layer: 'background' | 'main' | 'label' | 'transient') => IRenderer
Manually specify the renderer
G6 uses a layered rendering approach, divided into four layers: background
, main
, label
, transient
. Users can set the renderer for each layer of the canvas through this configuration item.
Example: Use SVG renderer for rendering
import { Renderer as SVGRenderer } from '@antv/g-svg';import { Graph } from '@antv/g6';const graph = new Graph({renderer: () => new SVGRenderer(),});
number | number[]
Canvas padding
Usually, during adaptation, it will be adapted according to the padding. It can be a single value (same padding on all sides) or an array form (specify the padding for top, right, bottom, left in order).
Example:
// Single valueconst graph1 = new Graph({padding: 20, // 20 pixels of padding on all sides});// Array formconst graph2 = new Graph({padding: [20, 40, 20, 40], // Padding for top, right, bottom, left});
number Default:
0
Rotation angle (in radians)
number
Viewport x coordinate, sets the initial horizontal position of the viewport.
number
Viewport y coordinate, sets the initial vertical position of the viewport.
number Default:
1
Sets the initial zoom level of the viewport, 1 means 100% (original size).
[number, number] Default:
[0.01, 10]
Zoom range, limits the minimum and maximum scale that users can zoom.
boolean | AnimationEffectTiming
Enable or disable global animation
When configured as an animation option, animation will be enabled, and this animation configuration will be used as the base configuration for global animation.
Property | Description | Type | Default | Required |
---|---|---|---|---|
delay | Animation delay time | number | - | |
direction | Animation direction | 'alternate' | 'alternate-reverse' | 'normal' | 'reverse' | 'forward' | |
duration | Animation duration | number | - | |
easing | Animation easing function | string | - | |
fill | Fill mode after animation ends | 'auto' | 'backwards' | 'both' | 'forwards' | 'none' | 'none' | |
iterations | Animation iteration count | number | - |
Example:
// Simple enableconst graph1 = new Graph({animation: true,});// Detailed configurationconst graph2 = new Graph({animation: {duration: 500, // Animation duration (milliseconds)easing: 'ease-in-out', // Easing function},});
Data.
Property | Description | Type | Default | Required |
---|---|---|---|---|
id | Unique identifier for the node, used to distinguish different nodes | string | - | ✓ |
type | Node type, built-in node type name or custom node name | string | - | |
data | Node data, used to store custom data for the node, such as node name, description, etc. Can be accessed in style mapping through callback functions | object | - | |
style | Node style, including visual attributes such as position, size, color, etc. | object | - | |
states | Initial state of the node, such as selected, activated, hovered, etc. | string[] | - | |
combo | ID of the combo to which it belongs, used to organize the hierarchical relationship of nodes, if none, it is null | string | null | - | |
children | Collection of child node IDs, used only in tree graph scenarios | string[] | - |
Property | Description | Type | Default | Required |
---|---|---|---|---|
source | Starting node ID of the edge | string | - | ✓ |
target | Target node ID of the edge | string | - | ✓ |
id | Unique identifier for the edge | string | - | |
type | Edge type, built-in edge type name or custom edge name | string | - | |
data | Edge data, used to store custom data for the edge, can be accessed in style mapping through callback functions | object | - | |
style | Edge style, including visual attributes such as line color, width, arrow, etc. | object | - | |
states | Initial state of the edge | string[] | - |
Property | Description | Type | Default | Required |
---|---|---|---|---|
id | Unique identifier for the combo | string | - | ✓ |
type | Combo type, built-in combo type name or custom combo name | string | - | |
data | Combo data, used to store custom data for the combo, can be accessed in style mapping through callback functions | object | - | |
style | Combo style | object | - | |
states | Initial state of the combo | string[] | - | |
combo | Parent combo ID. If there is no parent combo, it is null | string | null | - |
Example:
const graph = new Graph({data: {nodes: [{ id: 'node1', style: { x: 100, y: 100 } },{ id: 'node2', style: { x: 200, y: 200 } },],edges: [{ id: 'edge1', source: 'node1', target: 'node2' }],combos: [{ id: 'combo1', style: { x: 150, y: 150 } }],},});
Node configuration options.
Property | Description | Type | Default | Required |
---|---|---|---|---|
type | Node type, built-in node type name or custom node name | Type | circle | |
style | Node style, including color, size, etc. | Style | - | |
state | Define the style of the node in different states | State | - | |
palette | Define the color palette of the node, used to map colors based on different data | Palette | - | |
animation | Define the animation effect of the node | Animation | - |
See Node for details
Example:
const graph = new Graph({node: {type: 'circle', // Node typestyle: {fill: '#e6f7ff', // Fill colorstroke: '#91d5ff', // Border colorlineWidth: 1, // Border widthr: 20, // RadiuslabelText: (d) => d.id, // Label text},// Node state stylestate: {hover: {lineWidth: 2,stroke: '#69c0ff',},selected: {fill: '#bae7ff',stroke: '#1890ff',lineWidth: 2,},},},});
Edge configuration options
Property | Description | Type | Default | Required |
---|---|---|---|---|
type | Edge type, built-in edge type name or custom edge name | Type | line | |
style | Edge style, including color, size, etc. | Style | - | |
state | Define the style of the edge in different states | State | - | |
palette | Define the color palette of the edge, used to map colors based on different data | Palette | - | |
animation | Define the animation effect of the edge | Animation | - |
See Edge for details
Example:
const graph = new Graph({edge: {type: 'polyline', // Edge typestyle: {stroke: '#91d5ff', // Edge colorlineWidth: 2, // Edge widthendArrow: true, // Whether there is an arrow},// Edge state stylestate: {selected: {stroke: '#1890ff',lineWidth: 3,},},},});
Combo configuration options
Property | Description | Type | Default | Required |
---|---|---|---|---|
type | Combo type, built-in combo type name or custom combo name | Type | circle | |
style | Combo style, including color, size, etc. | Style | - | |
state | Define the style of the combo in different states | State | - | |
palette | Define the color palette of the combo, used to map colors based on different data | Palette | - | |
animation | Define the animation effect of the combo | Animation | - |
See Combo for details
Example:
const graph = new Graph({combo: {type: 'circle', // Combo typestyle: {fill: '#f0f0f0', // Background colorstroke: '#d9d9d9', // Border colorlineWidth: 1, // Border width},// Combo state stylestate: {selected: {stroke: '#1890ff',lineWidth: 2,},},},});
CustomLayoutOptions | CustomLayoutOptions[]
Layout configuration options, can be an object (normal layout) or an array (pipeline layout).
Example:
const graph = new Graph({container: 'container',layout: {type: 'force', // Force-directed layoutpreventOverlap: true, // Prevent node overlapnodeStrength: -50, // Repulsion between nodesedgeStrength: 0.5, // Elastic coefficient of edgesiterations: 200, // Number of iterationsanimation: true, // Enable layout animation},});
false | 'light' | 'dark' | string
Set the theme of the chart, can be the built-in 'light'
, 'dark'
theme, or the name of a custom theme. Set to false
to use no theme.
(string | CustomExtensionOptions | ((this:Graph) =>CustomExtensionOptions))[]
Configure the interaction behaviors of the chart, can be a string (using default configuration), an object (custom configuration), or a function (dynamic configuration, the graph instance can be accessed within the function).
Example:
const graph = new Graph({behaviors: ['drag-canvas', // Enable canvas dragging with default configuration'zoom-canvas', // Enable canvas zooming with default configuration{type: 'drag-element', // Custom configuration for dragging elementskey: 'drag-node-only',enable: (event) => event.targetType === 'node', // Only allow dragging nodes},function () {console.log(this); // Output graph instancereturn {type: 'hover-activate',};},],});
(string | CustomExtensionOptions | ((this:Graph) =>CustomExtensionOptions))[]
Set the plugins of the chart, can be a string (using default configuration), an object (custom configuration), or a function (dynamic configuration, the graph instance can be accessed within the function).
Example:
const graph = new Graph({container: 'container',plugins: ['minimap', // Enable minimap with default configuration{type: 'grid', // Enable grid backgroundkey: 'grid-plugin',line: {stroke: '#d9d9d9',lineWidth: 1,},},{type: 'toolbar', // Enable toolbarkey: 'graph-toolbar',position: 'top-right', // Position},],});
(string | CustomExtensionOptions | ((this:Graph) =>CustomExtensionOptions))[]
Configure data processing, used to process data before rendering, does not affect the original data. Can be a string (using default configuration), an object (custom configuration), or a function (dynamic configuration, the graph instance can be accessed within the function).
Example:
const graph = new Graph({transforms: ['process-parallel-edges', // Process parallel edges with default configuration{type: 'map-node-size', // Map node size based on node datafield: 'value', // Use the value of the fieldmax: 50, // Maximum radiusmin: 20, // Minimum radius},],});
interface CustomExtensionOption extends Record<string, any> {/** Extension type */type: string;/** Extension key, i.e., unique identifier */key?: string;}