windowsforms-117077-controls-and-libraries-chart-control-examples-end-user-interaction-how-to-implement-a-custom-pie-animation.md
To implement a custom bar animation, design a class inheriting the PieAnimationBase class and override the PieAnimationBase.ApplyState method which determines the transformations applied to an individual pie segment.
using DevExpress.XtraCharts;
using System.Drawing;
namespace AnimationExample {
class GripPieAnimation : PieAnimationBase {
public static PointF CalculateOffset(RectangleF pointBounds, float progress) {
float offsetX = (pointBounds.Width / 2 + pointBounds.X) * progress;
float offsetY = (pointBounds.Height / 2 + pointBounds.Y) * progress;
return new PointF(offsetX, offsetY);
}
public override void ApplyState(
SceneModifier modifier,
RectangleF diagramBounds,
PieSeriesPointLayoutParameters pieParameters,
float progress
) {
float pieCenterX = pieParameters.PieCenter.X;
float pieCenterY = pieParameters.PieCenter.Y;
float scale = (progress <= 0.5)
? 1 - 0.2f * progress
: 0.8f + 0.2f * progress;
// Note that methods requiered for correct transform are called in inverse order.
// This is a feature of affine transformations.
modifier.Translate(pieCenterX, pieCenterY);
modifier.Scale(scale, scale);
modifier.Translate(-pieCenterX, -pieCenterY);
}
protected override ChartElement CreateObjectForClone() {
return new GripPieAnimation();
}
}
}
protected override void OnLoad(EventArgs e) {
base.OnLoad(e);
view.Animation = new GripPieAnimation {
BeginTime = new TimeSpan(0, 0, 0, 0),
PointDelay = new TimeSpan(0, 0, 0, 0, 250),
Duration = new TimeSpan(0, 0, 0, 1, 500),
EasingFunction = new LinearEasingFunction {
EasingMode = EasingMode.Out
}
};
chartControl.AnimationStartMode = ChartAnimationMode.OnLoad;
}
private void buttonOnClick(object sender, EventArgs e) {
chartControl.Animate();
}
Imports DevExpress.XtraCharts
Imports System.Drawing
Namespace AnimationExample
Friend Class GripPieAnimation
Inherits PieAnimationBase
Public Shared Function CalculateOffset(ByVal pointBounds As RectangleF, ByVal progress As Single) As PointF
Dim offsetX As Single = (pointBounds.Width / 2 + pointBounds.X) * progress
Dim offsetY As Single = (pointBounds.Height / 2 + pointBounds.Y) * progress
Return New PointF(offsetX, offsetY)
End Function
Public Overrides Sub ApplyState(ByVal modifier As SceneModifier, ByVal diagramBounds As RectangleF, ByVal pieParameters As PieSeriesPointLayoutParameters, ByVal progress As Single)
Dim pieCenterX As Single = pieParameters.PieCenter.X
Dim pieCenterY As Single = pieParameters.PieCenter.Y
Dim scale As Single = If(progress <= 0.5, 1 - 0.2F * progress, 0.8F + 0.2F * progress)
' Note that methods requiered for correct transform are called in inverse order.
' This is a feature of affine transformations.
modifier.Translate(pieCenterX, pieCenterY)
modifier.Scale(scale, scale)
modifier.Translate(-pieCenterX, -pieCenterY)
End Sub
Protected Overrides Function CreateObjectForClone() As ChartElement
Return New GripPieAnimation()
End Function
End Class
End Namespace
Protected Overrides Sub OnLoad(ByVal e As EventArgs)
MyBase.OnLoad(e)
view.Animation = New GripPieAnimation With { _
.BeginTime = New TimeSpan(0, 0, 0, 0), .PointDelay = New TimeSpan(0, 0, 0, 0, 250), .Duration = New TimeSpan(0, 0, 0, 1, 500), .EasingFunction = New LinearEasingFunction With {.EasingMode = EasingMode.Out} _
}
chartControl.AnimationStartMode = ChartAnimationMode.OnLoad
End Sub
Private Sub buttonOnClick(ByVal sender As Object, ByVal e As EventArgs) Handles btnAnimate.Click
chartControl.Animate()
End Sub