diff --git a/Documentation~/en/api.md b/Documentation~/en/api.md
index 8a063e9d..db32d020 100644
--- a/Documentation~/en/api.md
+++ b/Documentation~/en/api.md
@@ -13,6 +13,7 @@ slug: /api
- [AnimationAddition](#animationaddition)
- [AnimationChange](#animationchange)
- [AnimationEasing](#animationeasing)
+- [AnimationExchange](#animationexchange)
- [AnimationFadeIn](#animationfadein)
- [AnimationFadeOut](#animationfadeout)
- [AnimationHiding](#animationhiding)
@@ -70,6 +71,7 @@ slug: /api
- [ColorUtil](#colorutil)
- [Comment](#comment)
- [CommentItem](#commentitem)
+- [CommentLayer](#commentlayer)
- [CommentMarkStyle](#commentmarkstyle)
- [ComponentHandlerAttribute](#componenthandlerattribute)
- [ComponentHelper](#componenthelper)
@@ -360,6 +362,14 @@ Options:
- `Linear`:
+## AnimationExchange
+
+class in XCharts.Runtime / Inherits from: [AnimationInfo](#animationinfo)
+
+> Since `v3.15.0`
+
+Data exchange animation. Generally used for animation of data sorting.
+
## AnimationFadeIn
class in XCharts.Runtime / Inherits from: [AnimationInfo](#animationinfo)
@@ -386,7 +396,7 @@ Data hiding animation.
## AnimationInfo
-class in XCharts.Runtime / Subclasses: [AnimationFadeIn](#animationfadein),[AnimationFadeOut](#animationfadeout),[AnimationChange](#animationchange),[AnimationAddition](#animationaddition),[AnimationHiding](#animationhiding),[AnimationInteraction](#animationinteraction)
+class in XCharts.Runtime / Subclasses: [AnimationFadeIn](#animationfadein),[AnimationFadeOut](#animationfadeout),[AnimationChange](#animationchange),[AnimationAddition](#animationaddition),[AnimationHiding](#animationhiding),[AnimationInteraction](#animationinteraction),[AnimationExchange](#animationexchange)
> Since `v3.8.0`
@@ -531,7 +541,7 @@ public float GetWidth(float width)
class in XCharts.Runtime / Inherits from: [ChildComponent](#childcomponent)
-the animation of serie. support animation type: fadeIn, fadeOut, change, addition.
+the animation of serie. support animation type: fadeIn, fadeOut, change, addition, exchange.
### AnimationStyle.addition
@@ -548,6 +558,11 @@ Update data animation configuration.
public bool enable
Whether to enable animation.
+### AnimationStyle.exchange
+
+public AnimationExchange exchange
+Exchange animation configuration. Valid in sort bar chart.
+
### AnimationStyle.fadeIn
public AnimationFadeIn fadeIn
@@ -639,6 +654,10 @@ public int GetCurrIndex()
public float GetCurrRate()
+### AnimationStyle.GetExchangeDuration
+
+public float GetExchangeDuration()
+
### AnimationStyle.GetInteractionDuration
public float GetInteractionDuration()
@@ -1097,7 +1116,7 @@ public static float GetAxisValueDistance(GridCoord grid, Axis axis, float scaleW
### AxisHelper.GetAxisValueLength
-public static float GetAxisValueLength(GridCoord grid, Axis axis, float scaleWidth, double value)
+public static float GetAxisValueLength(GridCoord grid, Axis axis, float scaleWidth, double value, float gap = 0)
获得数值value在坐标轴上对应的长度
### AxisHelper.GetAxisValuePosition
@@ -1674,6 +1693,10 @@ Global parameter setting component.
public ThemeStyle theme
+### BaseChart.topPainter
+
+public Painter topPainter
+
### BaseChart.typeListForComponent
public Dictionary<Type, FieldInfo> typeListForComponent
@@ -3428,13 +3451,20 @@ Convert the html string to color.
class in XCharts.Runtime / Inherits from: [MainComponent](#maincomponent),[IPropertyChanged](#ipropertychanged)
-comment of chart.
+> Since `v3.15.0`
+
+comment of chart. Used to annotate special information in the chart.
### Comment.items
public List<CommentItem> items
The items of comment.
+### Comment.layer
+
+public CommentLayer layer
+The layer of comment.
+
### Comment.show
public bool show
@@ -3443,10 +3473,12 @@ Set this to false to prevent the comment from showing.
### Comment.GetLabelStyle
public LabelStyle GetLabelStyle(int index)
+Get the label style of comment item.
### Comment.GetMarkStyle
public CommentMarkStyle GetMarkStyle(int index)
+Get the mark style of comment item.
### Comment.OnChanged
@@ -3478,6 +3510,17 @@ the mark rect style.
public bool show
Set this to false to prevent this comment item from showing.
+## CommentLayer
+
+class in XCharts.Runtime
+
+The layer of comment.
+
+Options:
+
+- `Lower`: The comment is display under the serie.
+- `Upper`: The comment is display above the serie.
+
## CommentMarkStyle
class in XCharts.Runtime / Inherits from: [ChildComponent](#childcomponent)
@@ -7257,6 +7300,10 @@ class in XCharts.Runtime
public void Reset()
+### SerieDataContext.UpdateExchangePosition
+
+public void UpdateExchangePosition(ref float x, ref float y, float totalTime)
+
## SerieDataExtraFieldAttribute
class in XCharts.Runtime / Inherits from: [Attribute](https://docs.unity3d.com/ScriptReference/30_search.html?q=attribute)
@@ -7685,6 +7732,10 @@ public override void RefreshLabelInternal()
public override void RefreshLabelNextFrame()
+### SerieHandler<T>.RefreshTitleLabelInternal
+
+public void RefreshTitleLabelInternal()
+
### SerieHandler<T>.RemoveComponent
public override void RemoveComponent()
diff --git a/Documentation~/en/configuration.md b/Documentation~/en/configuration.md
index 21d57578..9a04162c 100644
--- a/Documentation~/en/configuration.md
+++ b/Documentation~/en/configuration.md
@@ -176,6 +176,7 @@ slug: /configuration
- [AnimationAddition](#animationaddition)
- [AnimationChange](#animationchange)
+- [AnimationExchange](#animationexchange)
- [AnimationFadeIn](#animationfadein)
- [AnimationFadeOut](#animationfadeout)
- [AnimationHiding](#animationhiding)
@@ -234,6 +235,14 @@ class in XCharts.Runtime / Inherits from: [AnimationInfo](#animationinfo)
Data change animation.
+## AnimationExchange
+
+class in XCharts.Runtime / Inherits from: [AnimationInfo](#animationinfo)
+
+> Since `v3.15.0`
+
+Data exchange animation. Generally used for animation of data sorting.
+
## AnimationFadeIn
class in XCharts.Runtime / Inherits from: [AnimationInfo](#animationinfo)
@@ -260,7 +269,7 @@ Data hiding animation.
## AnimationInfo
-class in XCharts.Runtime / Subclasses: [AnimationFadeIn](#animationfadein), [AnimationFadeOut](#animationfadeout), [AnimationChange](#animationchange), [AnimationAddition](#animationaddition), [AnimationHiding](#animationhiding), [AnimationInteraction](#animationinteraction)
+class in XCharts.Runtime / Subclasses: [AnimationFadeIn](#animationfadein), [AnimationFadeOut](#animationfadeout), [AnimationChange](#animationchange), [AnimationAddition](#animationaddition), [AnimationHiding](#animationhiding), [AnimationInteraction](#animationinteraction), [AnimationExchange](#animationexchange)
> Since `v3.8.0`
@@ -326,7 +335,7 @@ the mlvalue of width.
class in XCharts.Runtime / Inherits from: [ChildComponent](#childcomponent)
-the animation of serie. support animation type: fadeIn, fadeOut, change, addition.
+the animation of serie. support animation type: fadeIn, fadeOut, change, addition, exchange.
### AnimationStyle.addition
@@ -356,6 +365,12 @@ Options:
Whether to enable animation.
+### AnimationStyle.exchange
+
+[AnimationExchange](#animationexchange) `v3.15.0`
+
+Exchange animation configuration. Valid in sort bar chart.
+
### AnimationStyle.fadeIn
[AnimationFadeIn](#animationfadein) `v3.8.0`
@@ -1247,7 +1262,9 @@ class in XCharts.Runtime / Subclasses: [AnimationStyle](#animationstyle), [AxisA
class in XCharts.Runtime / Inherits from: [MainComponent](#maincomponent), [IPropertyChanged](#ipropertychanged)
-comment of chart.
+> Since `v3.15.0`
+
+comment of chart. Used to annotate special information in the chart.
### Comment.items
@@ -1261,6 +1278,17 @@ The items of comment.
The text style of all comments.
+### Comment.layer
+
+[CommentLayer](#commentlayer) `v3.15.0`
+
+The layer of comment.
+
+Options:
+
+- `Lower`: The comment is display under the serie.
+- `Upper`: The comment is display above the serie.
+
### Comment.markStyle
[CommentMarkStyle](#commentmarkstyle)
@@ -2238,6 +2266,12 @@ class in XCharts.Runtime / Inherits from: [ChildComponent](#childcomponent), [IS
数据项背景颜色。
+### ItemStyle.backgroundGap
+
+`float` `v3.15.0`
+
+the gap between background and data item.
+
### ItemStyle.backgroundWidth
`float`
@@ -2464,6 +2498,18 @@ the sytle of background.
the distance of label to axis line.
+### LabelStyle.fixedX
+
+`float` `0` `v3.15.0`
+
+the fixed x of label. When not 0, it will be fixed on the specified x value.
+
+### LabelStyle.fixedY
+
+`float` `0` `v3.15.0`
+
+the fixed y of label. When not 0, it will be fixed on the specified y value.
+
### LabelStyle.formatter
`string`
diff --git a/Documentation~/zh/api.md b/Documentation~/zh/api.md
index 5de80ded..d6d7854b 100644
--- a/Documentation~/zh/api.md
+++ b/Documentation~/zh/api.md
@@ -13,6 +13,7 @@ slug: /api
- [AnimationAddition](#animationaddition)
- [AnimationChange](#animationchange)
- [AnimationEasing](#animationeasing)
+- [AnimationExchange](#animationexchange)
- [AnimationFadeIn](#animationfadein)
- [AnimationFadeOut](#animationfadeout)
- [AnimationHiding](#animationhiding)
@@ -70,6 +71,7 @@ slug: /api
- [ColorUtil](#colorutil)
- [Comment](#comment)
- [CommentItem](#commentitem)
+- [CommentLayer](#commentlayer)
- [CommentMarkStyle](#commentmarkstyle)
- [ComponentHandlerAttribute](#componenthandlerattribute)
- [ComponentHelper](#componenthelper)
@@ -360,6 +362,14 @@ class in XCharts.Runtime
- `Linear`:
+## AnimationExchange
+
+class in XCharts.Runtime / 继承自: [AnimationInfo](#animationinfo)
+
+> 从 `v3.15.0` 开始支持
+
+数据交换动画。一般用于图表数据排序时顺序变化的动画。
+
## AnimationFadeIn
class in XCharts.Runtime / 继承自: [AnimationInfo](#animationinfo)
@@ -386,7 +396,7 @@ class in XCharts.Runtime / 继承自: [AnimationInfo](#animationinfo)
## AnimationInfo
-class in XCharts.Runtime / 子类: [AnimationFadeIn](#animationfadein),[AnimationFadeOut](#animationfadeout),[AnimationChange](#animationchange),[AnimationAddition](#animationaddition),[AnimationHiding](#animationhiding),[AnimationInteraction](#animationinteraction)
+class in XCharts.Runtime / 子类: [AnimationFadeIn](#animationfadein),[AnimationFadeOut](#animationfadeout),[AnimationChange](#animationchange),[AnimationAddition](#animationaddition),[AnimationHiding](#animationhiding),[AnimationInteraction](#animationinteraction),[AnimationExchange](#animationexchange)
> 从 `v3.8.0` 开始支持
@@ -531,7 +541,7 @@ public float GetWidth(float width)
class in XCharts.Runtime / 继承自: [ChildComponent](#childcomponent)
-动画组件,用于控制图表的动画播放。支持配置五种动画表现:FadeIn(渐入动画),FadeOut(渐出动画),Change(变更动画),Addition(新增动画),Interaction(交互动画)。 按作用的对象可以分为两类:SerieAnimation(系列动画)和DataAnimation(数据动画)。
+动画组件,用于控制图表的动画播放。支持配置五种动画表现:FadeIn(渐入动画),FadeOut(渐出动画),Change(变更动画),Addition(新增动画),Interaction(交互动画),Exchange(交换动画)。 按作用的对象可以分为两类:SerieAnimation(系列动画)和DataAnimation(数据动画)。
### AnimationStyle.addition
@@ -548,6 +558,11 @@ public AnimationChange change
public bool enable
是否开启动画效果。
+### AnimationStyle.exchange
+
+public AnimationExchange exchange
+交换动画配置。如在排序柱图中有效。
+
### AnimationStyle.fadeIn
public AnimationFadeIn fadeIn
@@ -639,6 +654,10 @@ public int GetCurrIndex()
public float GetCurrRate()
+### AnimationStyle.GetExchangeDuration
+
+public float GetExchangeDuration()
+
### AnimationStyle.GetInteractionDuration
public float GetInteractionDuration()
@@ -1097,7 +1116,7 @@ public static float GetAxisValueDistance(GridCoord grid, Axis axis, float scaleW
### AxisHelper.GetAxisValueLength
-public static float GetAxisValueLength(GridCoord grid, Axis axis, float scaleWidth, double value)
+public static float GetAxisValueLength(GridCoord grid, Axis axis, float scaleWidth, double value, float gap = 0)
获得数值value在坐标轴上对应的长度
### AxisHelper.GetAxisValuePosition
@@ -1674,6 +1693,10 @@ public Settings settings
public ThemeStyle theme
+### BaseChart.topPainter
+
+public Painter topPainter
+
### BaseChart.typeListForComponent
public Dictionary<Type, FieldInfo> typeListForComponent
@@ -3428,13 +3451,20 @@ public static Color32 GetColor(string hexColorStr)
class in XCharts.Runtime / 继承自: [MainComponent](#maincomponent),[IPropertyChanged](#ipropertychanged)
-图表注解组件。
+> 从 `v3.15.0` 开始支持
+
+图表注解组件。用于标注图表中的特殊信息。
### Comment.items
public List<CommentItem> items
注解项。每个注解组件可以设置多个注解项。
+### Comment.layer
+
+public CommentLayer layer
+注解的显示层级。
+
### Comment.show
public bool show
@@ -3443,10 +3473,12 @@ public bool show
### Comment.GetLabelStyle
public LabelStyle GetLabelStyle(int index)
+获取注解项的文本样式。
### Comment.GetMarkStyle
public CommentMarkStyle GetMarkStyle(int index)
+获取注解项的标记样式。
### Comment.OnChanged
@@ -3478,6 +3510,17 @@ public CommentMarkStyle markStyle
public bool show
是否显示当前注解项。
+## CommentLayer
+
+class in XCharts.Runtime
+
+注解的显示层级。
+
+可选:
+
+- `Lower`: 注解在系列下方。
+- `Upper`: 注解在系列上方。
+
## CommentMarkStyle
class in XCharts.Runtime / 继承自: [ChildComponent](#childcomponent)
@@ -7257,6 +7300,10 @@ class in XCharts.Runtime
public void Reset()
+### SerieDataContext.UpdateExchangePosition
+
+public void UpdateExchangePosition(ref float x, ref float y, float totalTime)
+
## SerieDataExtraFieldAttribute
class in XCharts.Runtime / 继承自: [Attribute](https://docs.unity3d.com/ScriptReference/30_search.html?q=attribute)
@@ -7685,6 +7732,10 @@ public override void RefreshLabelInternal()
public override void RefreshLabelNextFrame()
+### SerieHandler<T>.RefreshTitleLabelInternal
+
+public void RefreshTitleLabelInternal()
+
### SerieHandler<T>.RemoveComponent
public override void RemoveComponent()
diff --git a/Documentation~/zh/changelog.md b/Documentation~/zh/changelog.md
index 3f4658a4..ff3bd9a4 100644
--- a/Documentation~/zh/changelog.md
+++ b/Documentation~/zh/changelog.md
@@ -80,6 +80,7 @@ slug: /changelog
## master
+* (2025.03.26) 增加`Animation`的`Exchange`排序交换动画
* (2025.03.22) 增加`Comment`的`layer`设置层级
* (2025.03.21) 优化`Comment`的坐标刷新
* (2025.03.19) 增加`Serie`的`Label`的`formatter`支持`{index}`通配符
diff --git a/Documentation~/zh/configuration.md b/Documentation~/zh/configuration.md
index 6d096ac0..1a3f7d9e 100644
--- a/Documentation~/zh/configuration.md
+++ b/Documentation~/zh/configuration.md
@@ -176,6 +176,7 @@ slug: /configuration
- [AnimationAddition](#animationaddition)
- [AnimationChange](#animationchange)
+- [AnimationExchange](#animationexchange)
- [AnimationFadeIn](#animationfadein)
- [AnimationFadeOut](#animationfadeout)
- [AnimationHiding](#animationhiding)
@@ -234,6 +235,14 @@ class in XCharts.Runtime / 继承自: [AnimationInfo](#animationinfo)
数据变更动画。
+## AnimationExchange
+
+class in XCharts.Runtime / 继承自: [AnimationInfo](#animationinfo)
+
+> 从 `v3.15.0` 开始支持
+
+数据交换动画。一般用于图表数据排序时顺序变化的动画。
+
## AnimationFadeIn
class in XCharts.Runtime / 继承自: [AnimationInfo](#animationinfo)
@@ -260,7 +269,7 @@ class in XCharts.Runtime / 继承自: [AnimationInfo](#animationinfo)
## AnimationInfo
-class in XCharts.Runtime / 子类: [AnimationFadeIn](#animationfadein), [AnimationFadeOut](#animationfadeout), [AnimationChange](#animationchange), [AnimationAddition](#animationaddition), [AnimationHiding](#animationhiding), [AnimationInteraction](#animationinteraction)
+class in XCharts.Runtime / 子类: [AnimationFadeIn](#animationfadein), [AnimationFadeOut](#animationfadeout), [AnimationChange](#animationchange), [AnimationAddition](#animationaddition), [AnimationHiding](#animationhiding), [AnimationInteraction](#animationinteraction), [AnimationExchange](#animationexchange)
> 从 `v3.8.0` 开始支持
@@ -326,7 +335,7 @@ class in XCharts.Runtime / 继承自: [AnimationInfo](#animationinfo)
class in XCharts.Runtime / 继承自: [ChildComponent](#childcomponent)
-动画组件,用于控制图表的动画播放。支持配置五种动画表现:FadeIn(渐入动画),FadeOut(渐出动画),Change(变更动画),Addition(新增动画),Interaction(交互动画)。 按作用的对象可以分为两类:SerieAnimation(系列动画)和DataAnimation(数据动画)。
+动画组件,用于控制图表的动画播放。支持配置五种动画表现:FadeIn(渐入动画),FadeOut(渐出动画),Change(变更动画),Addition(新增动画),Interaction(交互动画),Exchange(交换动画)。 按作用的对象可以分为两类:SerieAnimation(系列动画)和DataAnimation(数据动画)。
### AnimationStyle.addition
@@ -356,6 +365,12 @@ class in XCharts.Runtime / 继承自: [ChildComponent](#childcomponent)
是否开启动画效果。
+### AnimationStyle.exchange
+
+[AnimationExchange](#animationexchange) `v3.15.0`
+
+交换动画配置。如在排序柱图中有效。
+
### AnimationStyle.fadeIn
[AnimationFadeIn](#animationfadein) `v3.8.0`
@@ -1247,7 +1262,9 @@ class in XCharts.Runtime / 子类: [AnimationStyle](#animationstyle), [AxisAnima
class in XCharts.Runtime / 继承自: [MainComponent](#maincomponent), [IPropertyChanged](#ipropertychanged)
-图表注解组件。
+> 从 `v3.15.0` 开始支持
+
+图表注解组件。用于标注图表中的特殊信息。
### Comment.items
@@ -1261,6 +1278,17 @@ class in XCharts.Runtime / 继承自: [MainComponent](#maincomponent), [IPropert
所有组件的文本样式。
+### Comment.layer
+
+[CommentLayer](#commentlayer) `v3.15.0`
+
+注解的显示层级。
+
+可选:
+
+- `Lower`: 注解在系列下方。
+- `Upper`: 注解在系列上方。
+
### Comment.markStyle
[CommentMarkStyle](#commentmarkstyle)
@@ -2238,6 +2266,12 @@ class in XCharts.Runtime / 继承自: [ChildComponent](#childcomponent), [ISerie
数据项背景颜色。
+### ItemStyle.backgroundGap
+
+`float` `v3.15.0`
+
+数据项背景间隙。
+
### ItemStyle.backgroundWidth
`float`
@@ -2464,6 +2498,18 @@ class in XCharts.Runtime / 继承自: [ChildComponent](#childcomponent), [ISerie
距离轴线的距离。
+### LabelStyle.fixedX
+
+`float` `0` `v3.15.0`
+
+固定的X值。不为0时,会固定在指定的X值上。
+
+### LabelStyle.fixedY
+
+`float` `0` `v3.15.0`
+
+固定的Y值。不为0时,会固定在指定的Y值上。
+
### LabelStyle.formatter
`string`
diff --git a/Editor/ChildComponents/AnimationDrawer.cs b/Editor/ChildComponents/AnimationDrawer.cs
index ac09c04d..6c014482 100644
--- a/Editor/ChildComponents/AnimationDrawer.cs
+++ b/Editor/ChildComponents/AnimationDrawer.cs
@@ -71,6 +71,21 @@ namespace XCharts.Editor
}
}
+ [CustomPropertyDrawer(typeof(XCharts.Runtime.AnimationExchange), true)]
+ public class AnimationExchangeDrawer : BasePropertyDrawer
+ {
+ public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
+ {
+ base.OnGUI(pos, prop, label);
+ if (MakeComponentFoldout(prop, "m_Enable", true))
+ {
+ ++EditorGUI.indentLevel;
+ PropertyField(prop, "m_Duration");
+ --EditorGUI.indentLevel;
+ }
+ }
+ }
+
[CustomPropertyDrawer(typeof(AnimationStyle), true)]
public class AnimationDrawer : BasePropertyDrawer
{
@@ -88,6 +103,7 @@ namespace XCharts.Editor
PropertyField(prop, "m_Change");
PropertyField(prop, "m_Addition");
PropertyField(prop, "m_Interaction");
+ PropertyField(prop, "m_Exchange");
--EditorGUI.indentLevel;
}
}
diff --git a/Runtime/Component/Animation/AnimationInfo.cs b/Runtime/Component/Animation/AnimationInfo.cs
index d87c7d0e..43587991 100644
--- a/Runtime/Component/Animation/AnimationInfo.cs
+++ b/Runtime/Component/Animation/AnimationInfo.cs
@@ -493,4 +493,14 @@ namespace XCharts.Runtime
return m_Offset.value;
}
}
+
+ ///
+ /// Data exchange animation. Generally used for animation of data sorting.
+ /// ||数据交换动画。一般用于图表数据排序时顺序变化的动画。
+ ///
+ [Since("v3.15.0")]
+ [System.Serializable]
+ public class AnimationExchange : AnimationInfo
+ {
+ }
}
\ No newline at end of file
diff --git a/Runtime/Component/Animation/AnimationStyle.cs b/Runtime/Component/Animation/AnimationStyle.cs
index a14980c9..08eee5d7 100644
--- a/Runtime/Component/Animation/AnimationStyle.cs
+++ b/Runtime/Component/Animation/AnimationStyle.cs
@@ -44,8 +44,8 @@ namespace XCharts.Runtime
}
///
- /// the animation of serie. support animation type: fadeIn, fadeOut, change, addition.
- /// ||动画组件,用于控制图表的动画播放。支持配置五种动画表现:FadeIn(渐入动画),FadeOut(渐出动画),Change(变更动画),Addition(新增动画),Interaction(交互动画)。
+ /// the animation of serie. support animation type: fadeIn, fadeOut, change, addition, exchange.
+ /// ||动画组件,用于控制图表的动画播放。支持配置五种动画表现:FadeIn(渐入动画),FadeOut(渐出动画),Change(变更动画),Addition(新增动画),Interaction(交互动画),Exchange(交换动画)。
/// 按作用的对象可以分为两类:SerieAnimation(系列动画)和DataAnimation(数据动画)。
///
[System.Serializable]
@@ -62,6 +62,7 @@ namespace XCharts.Runtime
[SerializeField][Since("v3.8.0")] private AnimationAddition m_Addition = new AnimationAddition() { duration = 500 };
[SerializeField][Since("v3.8.0")] private AnimationHiding m_Hiding = new AnimationHiding() { duration = 500 };
[SerializeField][Since("v3.8.0")] private AnimationInteraction m_Interaction = new AnimationInteraction() { duration = 250 };
+ [SerializeField][Since("v3.15.0")] private AnimationExchange m_Exchange = new AnimationExchange() { duration = 250 };
[Obsolete("Use animation.fadeIn.delayFunction instead.", true)]
public AnimationDelayFunction fadeInDelayFunction;
@@ -138,6 +139,11 @@ namespace XCharts.Runtime
/// ||交互动画配置。
///
public AnimationInteraction interaction { get { return m_Interaction; } }
+ ///
+ /// Exchange animation configuration. Valid in sort bar chart.
+ /// ||交换动画配置。如在排序柱图中有效。
+ ///
+ public AnimationExchange exchange { get { return m_Exchange; } }
private Vector3 m_LinePathLastPos;
private List m_Animations;
@@ -147,12 +153,15 @@ namespace XCharts.Runtime
{
if (m_Animations == null)
{
- m_Animations = new List();
- m_Animations.Add(m_FadeIn);
- m_Animations.Add(m_FadeOut);
- m_Animations.Add(m_Change);
- m_Animations.Add(m_Addition);
- m_Animations.Add(m_Hiding);
+ m_Animations = new List
+ {
+ m_FadeIn,
+ m_FadeOut,
+ m_Change,
+ m_Addition,
+ m_Hiding,
+ m_Exchange
+ };
}
return m_Animations;
}
@@ -565,6 +574,14 @@ namespace XCharts.Runtime
return 0;
}
+ public float GetExchangeDuration()
+ {
+ if (m_Enable && m_Exchange.enable)
+ return m_Exchange.context.currDuration > 0 ? m_Exchange.context.currDuration : m_Exchange.duration;
+ else
+ return 0;
+ }
+
public float GetAdditionDuration()
{
if (m_Enable && m_Addition.enable)
diff --git a/Runtime/Component/Axis/AxisHandler.cs b/Runtime/Component/Axis/AxisHandler.cs
index f77f51b9..793435ab 100644
--- a/Runtime/Component/Axis/AxisHandler.cs
+++ b/Runtime/Component/Axis/AxisHandler.cs
@@ -253,9 +253,9 @@ namespace XCharts
var serie = chart.GetSerie(0);
if (isCategory && serie != null && serie.useSortData)
{
+ var isY = axis is YAxis;
var showData = serie.GetDataList(dataZoom, true);
- var isChanged = CheckSortedDataChanged(axis, showData);
- if (isChanged)
+ if (CheckSortedDataChanged(axis, showData))
{
for (int i = 0; i < context.labelObjectList.Count; i++)
{
@@ -268,6 +268,25 @@ namespace XCharts
}
SaveSortedDataIndex(axis, showData);
}
+ if (CheckSortedDataAnimation(axis, showData))
+ {
+ float diff = axis.context.scaleWidth / 2;
+ for (int i = 0; i < context.labelObjectList.Count; i++)
+ {
+ var labelObject = context.labelObjectList[i];
+ if (labelObject != null)
+ {
+ if (i < showData.Count)
+ {
+ var serieData = showData[i];
+ var pos = serieData.context.exchangePosition;
+ if (ChartHelper.IsZeroVector(pos)) continue;
+ var sourPos = labelObject.GetPosition();
+ labelObject.SetPosition(isY ? new Vector3(sourPos.x, pos.y + diff) : new Vector3(pos.x + diff, sourPos.y));
+ }
+ }
+ }
+ }
}
else
{
@@ -282,7 +301,7 @@ namespace XCharts
}
}
- private bool CheckSortedDataChanged(Axis axis, List dataList)
+ private static bool CheckSortedDataChanged(Axis axis, List dataList)
{
if (dataList.Count != axis.context.sortedDataIndices.Count) return true;
for (int i = 0; i < dataList.Count; i++)
@@ -292,7 +311,17 @@ namespace XCharts
return false;
}
- private void SaveSortedDataIndex(Axis axis, List dataList)
+ private static bool CheckSortedDataAnimation(Axis axis, List dataList)
+ {
+ if (!axis.IsCategory()) return false;
+ foreach (var data in dataList)
+ {
+ if (!data.context.exchangeEnd) return true;
+ }
+ return false;
+ }
+
+ private static void SaveSortedDataIndex(Axis axis, List dataList)
{
axis.context.sortedDataIndices.Clear();
for (int i = 0; i < dataList.Count; i++)
@@ -484,7 +513,6 @@ namespace XCharts
SerieHelper.UpdateSerieRuntimeFilterData(sortSerie);
}
var showData = sortSerie != null ? sortSerie.GetDataList(dataZoom, true) : null;
-
for (int i = 0; i < splitNumber; i++)
{
var labelWidth = AxisHelper.GetScaleWidth(axis, axisLength, i + 1, dataZoom);
diff --git a/Runtime/Serie/Bar/BarHandler.cs b/Runtime/Serie/Bar/BarHandler.cs
index beec6ea7..9a203cb4 100644
--- a/Runtime/Serie/Bar/BarHandler.cs
+++ b/Runtime/Serie/Bar/BarHandler.cs
@@ -207,11 +207,13 @@ namespace XCharts.Runtime
var dataChangeDuration = serie.animation.GetChangeDuration();
var dataAddDuration = serie.animation.GetAdditionDuration();
var interactDuration = serie.animation.GetInteractionDuration();
+ var exchangeDuration = serie.animation.GetExchangeDuration();
var areaColor = ColorUtil.clearColor32;
var areaToColor = ColorUtil.clearColor32;
var interacting = false;
+ axis.context.scaleWidth = categoryWidth;
serie.context.isHorizontal = isY;
serie.containerIndex = m_SerieGrid.index;
serie.containterInstanceId = m_SerieGrid.instanceId;
@@ -249,7 +251,11 @@ namespace XCharts.Runtime
var pY = 0f;
UpdateXYPosition(m_SerieGrid, isY, axis, relativedAxis, i, categoryWidth, relativedCategoryWidth,
barWidth, isStack, value, backgroundGap, ref pX, ref pY);
- var barHig = 0f;
+ if (serie.useSortData)
+ {
+ serieData.context.UpdateExchangePosition(ref pX, ref pY, exchangeDuration);
+ }
+ float barHig;
if (isPercentStack)
{
var valueTotal = chart.GetSerieSameStackTotalValue(serie.stack, i, m_SerieGrid.index);
diff --git a/Runtime/Serie/SerieDataContext.cs b/Runtime/Serie/SerieDataContext.cs
index 0e99efa0..b43a9ad6 100644
--- a/Runtime/Serie/SerieDataContext.cs
+++ b/Runtime/Serie/SerieDataContext.cs
@@ -35,6 +35,19 @@ namespace XCharts.Runtime
public float offsetRadius;
public float outsideRadius;
public Vector3 position;
+ ///
+ /// is the exchange animation end.
+ /// ||交换动画是否结束。
+ ///
+ public bool exchangeEnd;
+ ///
+ /// the current position of the exchange animation.
+ /// ||交换动画的当前位置。
+ ///
+ public Vector3 exchangePosition;
+ private float exchangeStartTime;
+ private Vector3 exchangeStartPosition;
+ private Vector3 exchangeEndPosition;
public List dataPoints = new List();
public List dataLabels = new List();
public List children = new List();
@@ -77,9 +90,61 @@ namespace XCharts.Runtime
symbol = null;
rect = Rect.zero;
subRect = Rect.zero;
+ exchangeEnd = true;
+ exchangeStartPosition = Vector3.zero;
+ exchangePosition = Vector3.zero;
+ exchangeEndPosition = Vector3.zero;
children.Clear();
dataPoints.Clear();
dataLabels.Clear();
}
+
+ public void UpdateExchangePosition(ref float x, ref float y, float totalTime)
+ {
+ if (exchangeEndPosition.x != x || exchangeEndPosition.y != y)
+ {
+ if (exchangeStartPosition == Vector3.zero || Time.time - exchangeStartTime < 0.1f)
+ {
+ exchangeEnd = true;
+ exchangeStartTime = Time.time;
+ exchangeEndPosition.x = x;
+ exchangeEndPosition.y = y;
+ exchangeStartPosition = exchangeEndPosition;
+ exchangePosition = exchangeEndPosition;
+ return;
+ }
+ else
+ {
+ exchangeEnd = false;
+ exchangeStartTime = Time.time;
+ exchangeStartPosition = exchangePosition;
+ exchangeEndPosition.x = x;
+ exchangeEndPosition.y = y;
+ }
+ }
+ if (exchangeStartPosition == exchangeEndPosition)
+ {
+ exchangeEnd = true;
+ exchangePosition = exchangeEndPosition;
+ x = exchangePosition.x;
+ y = exchangePosition.y;
+ return;
+ }
+ var spendTime = Time.time - exchangeStartTime;
+ totalTime /= 1000;
+ if (spendTime >= totalTime)
+ {
+ exchangeEnd = true;
+ exchangeStartPosition = exchangeEndPosition;
+ exchangePosition = exchangeEndPosition;
+ x = exchangePosition.x;
+ y = exchangePosition.y;
+ return;
+ }
+ exchangePosition = Vector3.Lerp(exchangeStartPosition, exchangeEndPosition, spendTime / totalTime);
+ x = exchangePosition.x;
+ y = exchangePosition.y;
+ return;
+ }
}
}
\ No newline at end of file