logo

G6

  • Docs
  • API
  • Playground
  • Community
  • Productsantv logo arrow
  • 5.0.45
  • 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
      • Build-in Node
        • Common Node Configurations
        • Diamond
        • Donut
        • Ellipse
        • Hexagon
        • Html
        • Image
        • Rect
        • Star
        • Triangle
        • Circle
      • Custom Node
      • Define Nodes with React
    • Edge
      • Edge Overview
      • Build-in Edge
        • Common Edge Configurations
        • Cubic Bezier Curve
        • CubicHorizontal Bezier Curve
        • CubicVertical Bezier Curve
        • Line
        • Polyline
        • Quadratic Bezier Curve
      • Custom Edge
    • Combo
      • Combo Overview
      • Build-in Combo
        • Circle
        • Combo Configuration Options
        • Rect
      • Custom Combo
    • Shape
      • Shape Overview
      • Shape Properties
  • Layout
    • Layout Overview
    • Build-in Layout
      • AntvDagre
      • Circular
      • ComboCombined
      • Common Layout Configuration Options
      • CompactBox
      • Concentric
      • D3Force
      • D3Force3D
      • Dagre
      • Dendrogram
      • Fishbone
      • Force
      • ForceAtlas2
      • Fruchterman
      • Grid Layout
      • Indented
      • Mds
      • Mindmap
      • Radial
      • Random
      • Snake
    • Custom Layout
  • Behavior
    • Behavior Overview
    • Build-in Behavior
      • AutoAdaptLabel
      • BrushSelect
      • ClickSelect
      • CollapseExpand
      • CreateEdge
      • DragCanvas
      • DragElement
      • DragElementForce
      • FixElementSize
      • FocusElement
      • HoverActivate
      • LassoSelect
      • OptimizeViewportTransform
      • ScrollCanvas
      • ZoomCanvas
    • Custom Behavior
  • Plugin
    • Plugin Overview
    • Build-in Plugin
      • Background
      • BubbleSets
      • Contextmenu
      • EdgeBundling
      • EdgeFilterLens
      • Fisheye
      • Fullscreen
      • GridLine
      • History
      • Hull
      • Legend
      • Minimap
      • Snapline
      • Timebar
      • Toolbar
      • Tooltip
      • Watermark
    • Custom Plugin
  • Transform
    • Data Transformation Overview
    • Build-in Transform
      • 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

Animation Overview

Previous
Custom Palette
Next
Custom Animation

Resources

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-互动图形解决方案
xtechLiven Experience technology
© Copyright 2025 Ant Group Co., Ltd..备案号:京ICP备15032932号-38

Loading...

Overview

Animation refers to the state changes of elements over a period of time, such as the position, size, and color of nodes. In G6, animations are often used to enhance user experience and improve the coherence and smoothness of the graph update process.

G6 provides a set of animation paradigms to describe element animations and has built-in some common animation effects. Users can achieve different animation effects by configuring animation parameters.

The implementation of an animation paradigm is as follows:

[
{
fields: ['x', 'y'],
},
];

The aforementioned animation paradigm indicates that when the x and y attributes of an element change, an animation will be executed.

Configure Animation

In G6, animation configuration is divided into global configuration and local configuration. Global configuration is mainly used to set whether animations are enabled globally, the duration of animations, and other parameters. Local configuration is primarily used to set the animation effects for elements.

Disabled Global Animation

To disable global animations, you can pass the animation option when instantiating the Graph:

{
animation: false,
}

Configure Global Animation

If you want to enable animations and also configure the default duration for the animations, you can pass the animation option:

{
animation: {
duration: 500,
},
}

Configure Element Animation

For individual elements, you can configure animations at different stages. For example, if you want an element to have a fade-in and fade-out effect when it enters and exits, you can configure it as follows:

{
node: {
animation: {
enter: 'fade',
exit: 'fade'
}
}
}

If you want to update the position of an element with a translation transition, you can configure it as follows:

{
node: {
animation: {
update: 'translate',
}
}
}

If you wish to disable animations for an element, you can configure it as follows:

{
node: {
animation: false,
}
}

Animation Paradigm

The animation configuration mentioned in the previous section actually used the built-in animation paradigm. This section introduces how to customize the animation paradigm.

Tip

Before writing an animation paradigm, it is necessary to understand the compositional structure of an element. For details, please refer to the Element section.

The Element section mentioned that elements in G6 are composed of one or more atomic graphics. Therefore, the animation of an element is essentially a combination of these atomic shape animations.

Thus, the animation paradigm is an array that describes the animation effects of each atomic shape within the element. For the element itself, it is also a special composite shape and thus has basic shape attributes such as x, y, etc.

Therefore, you can directly write an animation paradigm for the element itself:

[
{
fields: ['x', 'y'],
},
];

Custom Animation

If the built-in animations do not meet your requirements, you can create custom animations. For details, please refer to Custom Animation.

Animation Priority

Animation priority refers to the precedence between global animation configuration and element-specific animation configuration. It can be summarized as follows:

Global Animation ConfigLocal Animation ConfigWhether to Execute Animation
✅ true✅ true✅ Execute animation with default configuration
✅ true❌ false❌ Won't execute animation
✅ true✅ Custom Animation✅ Execute animation with local animation configuration
❌ false✅ true❌ Won't execute animation
❌ false❌ false❌ Won't execute animation
❌ false✅ Custom Animation❌ Won't execute animation
✅ Custom Animation✅ true✅ Execute animation with global animation configuration
✅ Custom Animation✅ Custom Animation✅ Execute animation, local animation configuration overrides the global animation configuration
✅ Custom Animation❌ false❌ Won't execute animation

Persistent Animation

If you want elements to have persistent animations, such as the undulating effect of nodes or the ant line effect of edges, this can be achieved by customizing the elements. Below is an implementation of an edge with an Ant Line animation provided:

import { Line } from '@antv/g6';
class AntLine extends Line {
onCreate() {
this.shapeMap.key.animate([{ lineDashOffset: -20 }, { lineDashOffset: 0 }], {
duration: 500,
iterations: Infinity,
});
}
}

The onCreate is a lifecycle hook used to execute animations when an element is created.

Configure the edge style in the options as follows:

{
edge: {
type: 'ant-line',
style:{
lineDash: [10, 10]
}
}
}

(() => {
const { register, Line, Graph } = window.g6;
class AntLine extends Line {
onCreate() {
this.shapeMap.key.animate([{ lineDashOffset: 20 }, { lineDashOffset: 0 }], {
duration: 500,
iterations: Infinity,
});
}
}
register('edge', 'ant-line', AntLine);
const container = createContainer({ width: 200, height: 50 });
const graph = new Graph({
container,
width: 200,
height: 50,
data: {
nodes: [
{ id: 'node-1', style: { x: 25, y: 25 } },
{ id: 'node-2', style: { x: 175, y: 25 } },
],
edges: [{ source: 'node-1', target: 'node-2', style: { lineDash: [10, 10] } }],
},
edge: {
type: 'ant-line',
},
});
graph.draw();
return container;
})();

The lineDash is an array for lineDashOffset, and the AntLine effect is achieved by continuously varying the lineDashOffset.

Similarly, you can also create a breathing effect for nodes:

import { Circle } from '@antv/g6';
class BreathingCircle extends Circle {
onCreate() {}
}

The lineDashOffset is the offset for lineDash, and the AntLine effect is achieved by continuously varying the lineDashOffset.

Similarly, you can also create a breathing effect for nodes:

import { Circle } from '@antv/g6';
class BreathingCircle extends Circle {
onCreate() {
this.shapeMap.halo.animate([{ lineWidth: 5 }, { lineWidth: 10 }], {
duration: 1000,
iterations: Infinity,
direction: 'alternate',
});
}
}

Node Style Configuration:

{
node: {
type: 'breathing-circle',
style: {
halo: true,
haloLineWidth: 5,
},
},
}

(() => {
const { register, Circle, Graph } = window.g6;
class BreathingCircle extends Circle {
onCreate() {
this.shapeMap.halo.animate([{ lineWidth: 5 }, { lineWidth: 10 }], {
duration: 1000,
iterations: Infinity,
direction: 'alternate',
});
}
}
register('node', 'breathing-circle', BreathingCircle);
const container = createContainer({ width: 50, height: 50 });
const graph = new Graph({
container,
width: 50,
height: 50,
data: {
nodes: [{ id: 'node-1', style: { x: 25, y: 25 } }],
},
node: {
type: 'breathing-circle',
style: {
halo: true,
haloLineWidth: 5,
},
},
});
graph.draw();
return container;
})();