Custom Animation
Previously, we introduced how to configure basic animations and animation arrangements in VChart. In addition, if you have more specific needs or better animation ideas, you can achieve them through the ability to customize animations. Custom animation methods can be used not only in VChart, but also in the entire VisActor series of visualization solutions.
This chapter will introduce how to customize animations in VChart, including custom animation attribute interpolation functions and custom animation classes. Before you begin, please make sure you are familiar with and can use VChart's basic chart animation capabilities. In the last section (Complex Animation Configuration and Choreography), we introduced the concept of TimeSlice, each TimeSlice can define multiple animation effects (effect
), and we will focus on effect.custom
to introduce custom animation methods.
Custom Animation Attribute Interpolation Function
Custom animation attribute interpolation functions are mainly used to provide visual channels before and after the animation is executed to achieve some animation effects. effect.custom
can be configured as a custom interpolation function:
You need to create an animation function that implements the IAnimationChannelInterpolator
type, with the following function parameters:
ratio
: The progress ratio of the animation, a decimal value between 0 and 1.from
: The visual channel attribute of the graphic element at the start of the animation.to
: The visual channel attribute of the graphic element at the start of the animation.nextAttributes
: The attribute values for the next frame, which can be calculated and modified in the function.datum
: The original data associated with the current graphic element.element
: The current graphic element.parameters
: Custom animation parameters that can be passed when creating the animation.
Here is an example of a custom animation:
Custom Animation Class
In VChart, custom animations are accomplished by implementing the ICustomAnimate
interface. The following is the definition of the ICustomAnimate
interface:
The interface defines some basic animation properties and lifecycle functions that can be used to create, update, and destroy custom animations. Detailed documentation can be found in VRender Custom Animation.
The following example uses the built-in StreamLight
custom animation class from VRender
to implement the bar chart streamer effect:
Writing Your Own Custom Animation Class
In VChart, you can inherit the ACustomAnimate class to write your own custom animation class. For example, the following code writes an animation that translates a column from a certain point.
Then pass this class to the custom field of the custom function in the spec