logo

G6

  • Docs
  • API
  • Playground
  • Community
  • Productsantv logo arrow
  • 5.0.49
  • Introduction
  • Data
  • Getting Started
    • Quick Start
    • Installation
    • Integration
      • react
      • vue
      • angular
    • Step-by-step guide
  • Graph
    • Extensions En
    • Graph
    • Options
    • extension
  • Element
    • Element Overview
    • Element State
    • Node
      • Node Overview
      • Common Node Configuration
      • Circle Node
      • Diamond Node
      • Donut Node
      • Ellipse Node
      • Hexagon Node
      • HTML Node
      • Image Node
      • Rect Node
      • Star Node
      • Triangle Node
      • Custom Node
      • Define Nodes with React
    • Edge
      • Edge Overview
      • Edge Common Configuration
      • Cubic Bezier Curve Edge
      • CubicHorizontal Bezier Curve Edge
      • CubicVertical Bezier Curve Edge
      • Line Edge
      • Polyline Edge
      • Quadratic Bezier Curve Edge
      • Custom Edge
    • Combo
      • Combo Overview
      • Combo Common Options
      • Circle Combo
      • Rect Combo
      • Custom Combo
    • Shape
      • Shape and KeyShape
      • Atomic Shapes and Their Properties
      • Design and Implementation of Composite Shape
  • Layout
    • Layout Overview
    • Common Layout Configuration Options
    • AntvDagre Layout
    • Circular Layout
    • ComboCombined Layout
    • CompactBox Layout
    • Concentric Layout
    • 3D Force-Directed Layout
    • D3 Force-Directed Layout
    • Dagre Layout
    • Dendrogram Layout
    • Fishbone Layout
    • ForceAtlas2 Force-directed Layout
    • Force-directed Layout
    • Fruchterman Force-directed Layout
    • Grid Layout
    • Indented Tree
    • MDS High-dimensional Data Dimensionality Reduction Layout
    • Mindmap Tree
    • Radial Layout
    • Random Layout
    • Snake Layout
    • Custom Layout
  • Behavior
    • Behavior Overview
    • ZoomCanvas
    • AutoAdaptLabel
    • BrushSelect
    • ClickSelect
    • CollapseExpand
    • CreateEdge
    • DragCanvas
    • DragElement
    • DragElementForce
    • FixElementSize
    • FocusElement
    • HoverActivate
    • LassoSelect
    • OptimizeViewportTransform
    • ScrollCanvas
    • Custom Behavior
  • Plugin
    • Plugin Overview
    • Background
    • BubbleSets
    • Contextmenu
    • EdgeBundling
    • EdgeFilterLens
    • Fisheye
    • Fullscreen
    • GridLine
    • History
    • Hull
    • Legend
    • Minimap
    • Snapline
    • Timebar
    • Toolbar
    • Tooltip
    • Watermark
    • Custom Plugin
  • Transform
    • Data Transformation Overview
    • MapNodeSize
    • PlaceRadialLabels
    • ProcessParallelEdges
    • Custom Transform
  • Theme
    • Theme Overview
    • Custom Theme
    • Palette
    • Custom Palette
  • Animation
    • Animation Overview
    • Custom Animation
  • Further Reading
    • Event
    • renderer
    • coordinate
    • download-image
    • Using Iconfont
    • Use 3D
    • Bundle Project
  • What's new
    • Feature
    • Upgrade To 5.0
  • FAQ
  • contribute

Custom Animation

Previous
Animation Overview
Next
Event

Resource

Ant Design
Galacea Effects
Umi-React Application Framework
Dumi-Component doc generator
ahooks-React Hooks Library

Community

Ant Financial Experience Tech
seeconfSEE Conf-Experience Tech Conference

Help

GitHub
StackOverflow

more productsMore Productions

Ant DesignAnt Design-Enterprise UI design language
yuqueYuque-Knowledge creation and Sharing tool
EggEgg-Enterprise-class Node development framework
kitchenKitchen-Sketch Tool set
GalaceanGalacean-Interactive solution
xtechLiven Experience technology
© Copyright 2025 Ant Group Co., Ltd..备案号:京ICP备15032932号-38

Loading...

Overview

Implement Animation

For circular node (Circle) elements, the main shape is a circle. Now, let's create an animation for it so that when the size of the node changes, it transitions with a scaling animation:

[
{
fields: ['r'],
shape: 'key',
},
];

Now let's create a graph instance and update the element size to trigger the update animation:

const graph = new Graph({
container: 'container',
width: 50,
height: 50,
data: {
nodes: [{ id: 'node-1', style: { x: 25, y: 25, size: 20 } }],
},
node: {
animation: {
update: [{ fields: ['r'], shape: 'key' }],
},
},
});
graph.draw().then(() => {
graph.updateNodeData([{ id: 'node-1', style: { size: 40 } }]);
graph.draw();
});

⬇️ Move the pointer to the graph below and click the play button on the left to replay

import { Graph } from '@antv/g6';
const graph = new Graph({
width: 50,
height: 50,
container,
data: {
nodes: [{ id: 'node-1', style: { x: 25, y: 25, size: 20 } }],
},
node: {
animation: {
update: [
{
fields: ['r'],
shape: 'key',
},
],
},
},
});
graph.draw().then(() => {
graph.updateNodeData([{ id: 'node-1', style: { size: 40 } }]);
graph.draw();
});

Principle Analysis

When animating an element, the element converts its animation frame parameters into animation frame parameters for its individual sub-graphics and executes the corresponding animations.

In the example above, by updating the node size, an animation was performed on the node, and its animation frame parameters were:

[{ "size": 20 }, { "size": 40 }]

After obtaining the attribute, the node element converts it into animation frame parameters for the main shape (circle):

[{ "r": 10 }, { "r": 20 }]

Therefore, what is ultimately happening here is that a transition animation is being performed on the circle, changing its radius from 10 to 20.

Composite Animation

By directly combining the position change animation with the size change animation into a single animation paradigm, you can obtain a composite animation paradigm:

[
{
fields: ['x', 'y'],
},
{
fields: ['r'],
shape: 'key',
},
];

And update both the position and size of the node simultaneously:

graph.updateNodeData([{ id: 'node-1', style: { x: 175, size: 40 } }]);
graph.draw();

⬇️ Move the pointer to the graph below and click the play button on the left to replay

import { Graph } from '@antv/g6';
const graph = new Graph({
container: 'container',
width: 200,
height: 50,
data: {
nodes: [{ id: 'node-1', style: { x: 25, y: 25, size: 20 } }],
},
node: {
animation: {
update: [
{
fields: ['x', 'y'],
},
{ fields: ['r'], shape: 'key' },
],
},
},
});
graph.draw().then(() => {
graph.updateNodeData([{ id: 'node-1', style: { x: 175, size: 40 } }]);
graph.draw();
});

Add color transition:

[
{
fields: ['x', 'y'],
},
{
fields: ['r', 'fill'],
shape: 'key',
},
];

Execute node update:

graph.updateNodeData([{ id: 'node-1', style: { x: 175, size: 40, fill: 'pink' } }]);
graph.draw();

⬇️ Move the pointer to the graph below and click the play button on the left to replay

import { Graph } from '@antv/g6';
const graph = new Graph({
container: 'container',
width: 200,
height: 50,
data: {
nodes: [{ id: 'node-1', style: { x: 25, y: 25, size: 20 } }],
},
node: {
animation: {
update: [
{
fields: ['x', 'y'],
},
{ fields: ['r', 'fill'], shape: 'key' },
],
},
},
});
graph.draw().then(() => {
graph.updateNodeData([{ id: 'node-1', style: { x: 175, size: 40, fill: 'pink' } }]);
graph.draw();
});