Animate
If you want a more beautiful animation, you can define your own animation.
Animation Register
Animation register is used to achieve the goal of reusing animation functions. After register, you can use it everywhere.
// require registeration class of animation
const Animate = require('@antv/f2/lib/animation/animate');
/**
* @param {String} animationName Animation name, specified by users
* @param {Function} animationFun define specific animations
**/
Animate.registerAnimation('animationName', animationFun); // register a animation called animationName
// use the registered animation
chart.line().animate({
appear: {
animation: 'animationName' // the registered name of the animation
}
})Details on Custom Animation
F2 provides a complete animation customization mechanism. Users can customize animation behavior for any states of graphic element that supports animation. The states here are the four types of animations: appear, enter, leave, update.
The animations in F2 all act on Shape. The animation is performed by changing shape's attributes frame by frame, take the movement of the circle as example:

The animation is very simple, it moves the circle from point A to point B (the coordinate is {x: 230, y: 50}). We need only to call shape.animate() to specify the final state, i.e. graph attributes, of the shape.
See here for graph attributes of various shapes.
Three parameters will be passed to the user-defined animation function, in the order of shape, animateCfg, coord.
Parameters:
shape: The shape instance which animation is acted on.
You can get graph attributes attrs from shape instance and then customize the animation.
The attributes are provided to help users ease the customization:
Attributes
Method To Get
Type
Explanation
attrs
shape.get('attrs')
Object
Get all graph attributes of the shape
className
shape.get('className')
String
Get the type name of the shape
origin
shape.get('origin')
Object
Get the drawing data and corresponding original data record of the shape
index
shape.get('index')
Number
Get the index of the shape, i.e. the order of the data record in data set
In addition, shape.attr(name) can also be used to get graph attribute from shape. More methods of shape are listed in Shape API.
F2 also provides a cacheShape attribute for the shape instance in the update state.This attribute stores the content of the previous state for the shape, so that users can customize the animation for changing. The cacheShape contains the following content:
animateCfg: Object, configuration for animationThe following attributes are contained in animateCfg:
coord: Coordinate object, represents the current coordinate of the chart. The attributes contained in coordinate object are listed in Coordinate API.
Example
The example below shows how to customize the apear animation for bar chart, online demo here:

Last updated