Skip to content

Commit 10435a4

Browse files
committed
Fix animation configuration (fixes #86)
This adds the animation configuration to all options. It now also supports easing options. This closes #74 because it makes it obsolete. The callbacks can only be done after #70 but they're added as todo comments.
1 parent fc15ef6 commit 10435a4

File tree

7 files changed

+82
-16
lines changed

7 files changed

+82
-16
lines changed

src/ChartJs.Blazor/ChartJS/Common/BaseConfigOptions.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ public class BaseConfigOptions
4646
/// </summary>
4747
public Tooltips Tooltips { get; set; }
4848

49+
/// <summary>
50+
/// Gets or sets the animation-configuration for this chart.
51+
/// </summary>
52+
public Animation Animation { get; set; }
53+
4954
public IClickHandler OnClick { get; set; }
5055

5156
public Hover Hover { get; set; }
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace ChartJs.Blazor.ChartJS.Common.Enums
6+
{
7+
/// <summary>
8+
/// Represents an easing function supported by chart.js. Details about the different
9+
/// functions can be found here: <a href="https://easings.net"/>
10+
/// <para>
11+
/// As per documentation here: <a href="https://www.chartjs.org/docs/latest/configuration/animations.html#easing"/>
12+
/// </para>
13+
/// </summary>
14+
public sealed class Easing : StringEnum
15+
{
16+
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
17+
public static Easing Linear => new Easing("linear");
18+
public static Easing EaseInQuad => new Easing("easeInQuad");
19+
public static Easing EaseOutQuad => new Easing("easeOutQuad");
20+
public static Easing EaseInOutQuad => new Easing("easeInOutQuad");
21+
public static Easing EaseInCubic => new Easing("easeInCubic");
22+
public static Easing EaseOutCubic => new Easing("easeOutCubic");
23+
public static Easing EaseInOutCubic => new Easing("easeInOutCubic");
24+
public static Easing EaseInQuart => new Easing("easeInQuart");
25+
public static Easing EaseOutQuart => new Easing("easeOutQuart");
26+
public static Easing EaseInOutQuart => new Easing("easeInOutQuart");
27+
public static Easing EaseInQuint => new Easing("easeInQuint");
28+
public static Easing EaseOutQuint => new Easing("easeOutQuint");
29+
public static Easing EaseInOutQuint => new Easing("easeInOutQuint");
30+
public static Easing EaseInSine => new Easing("easeInSine");
31+
public static Easing EaseOutSine => new Easing("easeOutSine");
32+
public static Easing EaseInOutSine => new Easing("easeInOutSine");
33+
public static Easing EaseInExpo => new Easing("easeInExpo");
34+
public static Easing EaseOutExpo => new Easing("easeOutExpo");
35+
public static Easing EaseInOutExpo => new Easing("easeInOutExpo");
36+
public static Easing EaseInCirc => new Easing("easeInCirc");
37+
public static Easing EaseOutCirc => new Easing("easeOutCirc");
38+
public static Easing EaseInOutCirc => new Easing("easeInOutCirc");
39+
public static Easing EaseInElastic => new Easing("easeInElastic");
40+
public static Easing EaseOutElastic => new Easing("easeOutElastic");
41+
public static Easing EaseInOutElastic => new Easing("easeInOutElastic");
42+
public static Easing EaseInBack => new Easing("easeInBack");
43+
public static Easing EaseOutBack => new Easing("easeOutBack");
44+
public static Easing EaseInOutBack => new Easing("easeInOutBack");
45+
public static Easing EaseInBounce => new Easing("easeInBounce");
46+
public static Easing EaseOutBounce => new Easing("easeOutBounce");
47+
public static Easing EaseInOutBounce => new Easing("easeInOutBounce");
48+
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
49+
50+
private Easing(string stringRep) : base(stringRep) { }
51+
}
52+
}
Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
1-
namespace ChartJs.Blazor.ChartJS.Common.Properties
1+
using ChartJs.Blazor.ChartJS.Common.Enums;
2+
3+
namespace ChartJs.Blazor.ChartJS.Common.Properties
24
{
35
/// <summary>
4-
/// Defines some animation configurations
6+
/// The animation-subconfig of <see cref="BaseConfigOptions"/>.
7+
/// Specifies options for the animations in this chart.
58
/// </summary>
69
public class Animation
710
{
811
/// <summary>
9-
/// Defines the duration of the animation
12+
/// Gets or sets the number of milliseconds an animation takes.
1013
/// </summary>
11-
public long Duration { get; set; }
14+
public long? Duration { get; set; }
15+
16+
/// <summary>
17+
/// Gets or sets the easing function to use.
18+
/// See <a href="https://easings.net"/> for reference.
19+
/// </summary>
20+
public Easing Easing { get; set; }
21+
22+
// TODO OnProgress Callback called on each step of an animation.
23+
// TODO OnComplete Callback called at the end of an animation.
1224
}
1325
}

src/ChartJs.Blazor/ChartJS/Common/Properties/ArcAnimation.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@
33
/// <summary>
44
/// The animation-subconfig of the options for a radial chart.
55
/// </summary>
6-
public class ArcAnimation
6+
public class ArcAnimation : Animation
77
{
88
/// <summary>
9-
/// If true, the chart will animate in with a rotation animation.
9+
/// Gets or sets a value indicating whether the chart will
10+
/// load in with a rotation animation or not.
1011
/// </summary>
11-
public bool AnimateRotate { get; set; } = true;
12+
public bool? AnimateRotate { get; set; }
1213

1314
/// <summary>
14-
/// If true, will animate scaling the chart from the center outwards.
15+
/// Gets or sets a value indicating whether the chart will
16+
/// load in with a scaling animation (from the center outwards) or not.
1517
/// </summary>
16-
public bool AnimateScale { get; set; } = false;
18+
public bool? AnimateScale { get; set; }
1719
}
1820
}

src/ChartJs.Blazor/ChartJS/LineChart/LineOptions.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ namespace ChartJs.Blazor.ChartJS.LineChart
99
/// </summary>
1010
public class LineOptions : BaseConfigOptions
1111
{
12-
/// <summary>
13-
/// General animation time
14-
/// </summary>
15-
public Animation Animation { get; set; }
16-
1712
/// <summary>
1813
/// Hover options for hovering over an item
1914
/// </summary>

src/ChartJs.Blazor/ChartJS/PieChart/PieOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public PieOptions(bool doughnutCutout = false)
2727
/// <summary>
2828
/// Gets or sets the animation-configuration for this chart.
2929
/// </summary>
30-
public ArcAnimation Animation { get; set; }
30+
public new ArcAnimation Animation { get; set; }
3131

3232
/// <summary>
3333
/// Gets or sets the starting angle to draw arcs from.

src/ChartJs.Blazor/ChartJS/PolarAreaChart/PolarAreaOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class PolarAreaOptions : BaseConfigOptions
1818
/// <summary>
1919
/// Gets or sets the animation-configuration for this chart.
2020
/// </summary>
21-
public ArcAnimation Animation { get; set; }
21+
public new ArcAnimation Animation { get; set; }
2222

2323
/// <summary>
2424
/// The scale (axis) for this chart.

0 commit comments

Comments
 (0)