diff --git a/Assets/XCharts/Editor/ChildComponents/AnimationDrawer.cs b/Assets/XCharts/Editor/ChildComponents/AnimationDrawer.cs index d131a2b7..c10372ba 100644 --- a/Assets/XCharts/Editor/ChildComponents/AnimationDrawer.cs +++ b/Assets/XCharts/Editor/ChildComponents/AnimationDrawer.cs @@ -20,6 +20,7 @@ namespace XCharts if (MakeComponentFoldout(prop, "m_Enable")) { ++EditorGUI.indentLevel; + PropertyField(prop, "m_Type"); PropertyField(prop, "m_FadeInDuration"); PropertyField(prop, "m_FadeInDelay"); PropertyField(prop, "m_FadeOutDuration"); diff --git a/Assets/XCharts/Runtime/Component/Animation.meta b/Assets/XCharts/Runtime/Component/Animation.meta new file mode 100644 index 00000000..4c94e654 --- /dev/null +++ b/Assets/XCharts/Runtime/Component/Animation.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 9f827513754e8436bbc63e64c5b5e6c3 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/XCharts/Runtime/Component/Child/AnimationStyle.cs b/Assets/XCharts/Runtime/Component/Animation/AnimationStyle.cs similarity index 80% rename from Assets/XCharts/Runtime/Component/Child/AnimationStyle.cs rename to Assets/XCharts/Runtime/Component/Animation/AnimationStyle.cs index e253d147..02eb1f66 100644 --- a/Assets/XCharts/Runtime/Component/Child/AnimationStyle.cs +++ b/Assets/XCharts/Runtime/Component/Animation/AnimationStyle.cs @@ -14,16 +14,45 @@ namespace XCharts public delegate float CustomAnimationDelay(int dataIndex); public delegate float CustomAnimationDuration(int dataIndex); - public enum AnimationType { + /// + /// he default. An animation playback mode will be selected according to the actual situation. + /// 默认。内部会根据实际情况选择一种动画播放方式。 + /// Default, + /// + /// Play the animation from left to right. + /// 从左往右播放动画。 + /// LeftToRight, + /// + /// Play the animation from bottom to top. + /// 从下往上播放动画。 + /// BottomToTop, + /// + /// Play animations from the inside out. + /// 由内到外播放动画。 + /// InsideOut, + /// + /// Play the animation along the path. + /// 沿着路径播放动画。 + /// + AlongPath, + /// + /// Play the animation clockwise. + /// 顺时针播放动画。 + /// Clockwise, - } + + public enum AnimationEasing + { + Linear, + } + /// /// the animation of serie. /// 动画表现。 @@ -31,12 +60,9 @@ namespace XCharts [System.Serializable] public class AnimationStyle : ChildComponent { - public enum Easing - { - Linear, - } [SerializeField] private bool m_Enable = true; - [SerializeField] private Easing m_Easting; + [SerializeField] private AnimationType m_Type; + [SerializeField] private AnimationEasing m_Easting; [SerializeField] private int m_Threshold = 2000; [SerializeField] private float m_FadeInDuration = 1000; [SerializeField] private float m_FadeInDelay = 0; @@ -62,6 +88,7 @@ namespace XCharts /// 自定义渐出动画时长函数。返回ms值。 /// public CustomAnimationDuration customFadeOutDuration; + public AnimationStyleContext context = new AnimationStyleContext(); /// /// Whether to enable animation. @@ -69,6 +96,11 @@ namespace XCharts /// public bool enable { get { return m_Enable; } set { m_Enable = value; } } /// + /// The type of animation. + /// 动画类型。 + /// + public AnimationType type { get { return m_Type; } set { m_Type = value; } } + /// /// Easing method used for the first animation. /// 动画的缓动效果。 /// @@ -112,10 +144,6 @@ namespace XCharts /// public float dataChangeDuration { get { return m_DataChangeDuration; } set { m_DataChangeDuration = value < 0 ? 0 : value; } } /// - /// 是否沿着线的轨迹进行匀速动画。 - /// - public bool alongWithLinePath { get { return m_AlongWithLinePath; } set { m_AlongWithLinePath = value; } } - /// /// 渐入动画完成回调 /// public Action fadeInFinishCallback { get; set; } @@ -123,8 +151,8 @@ namespace XCharts /// 渐出动画完成回调 /// public Action fadeOutFinishCallback { get; set; } - private Dictionary m_DataCurrProgress = new Dictionary(); - private Dictionary m_DataDestProgress = new Dictionary(); + private Dictionary m_ItemCurrProgress = new Dictionary(); + private Dictionary m_ItemDestProgress = new Dictionary(); private bool m_FadeIn = false; private bool m_IsEnd = true; private bool m_IsPause = false; @@ -133,14 +161,11 @@ namespace XCharts private bool m_IsInit = false; private float startTime { get; set; } - private int m_CurrDataProgress { get; set; } - private int m_DestDataProgress { get; set; } - [SerializeField] private float m_CurrDetailProgress; - [SerializeField] private float m_DestDetailProgress; - [SerializeField] private float m_TotalDetailProgress; + private float m_CurrDetailProgress; + private float m_DestDetailProgress; + private float m_TotalDetailProgress; private float m_CurrSymbolProgress; private Vector3 m_LinePathLastPos; - private float m_LinePathCurrTotalDist = 0f; public void FadeIn() { @@ -162,13 +187,11 @@ namespace XCharts m_IsInit = false; m_IsPause = false; m_FadeOuted = false; - m_CurrDataProgress = 1; - m_DestDataProgress = 1; m_CurrDetailProgress = 0; m_DestDetailProgress = 1; m_CurrSymbolProgress = 0; - m_DataCurrProgress.Clear(); - m_DataDestProgress.Clear(); + m_ItemCurrProgress.Clear(); + m_ItemDestProgress.Clear(); } public void Restart() @@ -191,13 +214,11 @@ namespace XCharts m_IsEnd = false; m_IsInit = false; m_IsPause = false; - m_CurrDataProgress = 0; - m_DestDataProgress = 0; m_CurrDetailProgress = 0; m_DestDetailProgress = 1; m_CurrSymbolProgress = 0; - m_DataCurrProgress.Clear(); - m_DataDestProgress.Clear(); + m_ItemCurrProgress.Clear(); + m_ItemDestProgress.Clear(); } public void Pause() @@ -222,7 +243,6 @@ namespace XCharts return; m_ActualDuration = (int)((Time.time - startTime) * 1000) - (m_FadeOut ? fadeOutDelay : fadeInDelay); - m_CurrDataProgress = m_DestDataProgress + (m_FadeOut ? -1 : 1); m_IsEnd = true; m_IsInit = false; @@ -253,10 +273,10 @@ namespace XCharts m_IsPause = false; m_FadeOut = false; m_FadeOuted = false; - m_DataCurrProgress.Clear(); + m_ItemCurrProgress.Clear(); } - public void InitProgress(int data, float curr, float dest) + public void InitProgress(float curr, float dest) { if (m_IsInit || m_IsEnd) return; @@ -264,7 +284,6 @@ namespace XCharts return; m_IsInit = true; - m_DestDataProgress = data; m_TotalDetailProgress = dest - curr; if (m_FadeOut) @@ -286,7 +305,7 @@ namespace XCharts var ep = paths[paths.Count - 1]; var currDetailProgress = isY ? sp.y : sp.x; var totalDetailProgress = isY ? ep.y : ep.x; - if (m_AlongWithLinePath) + if (context.type == AnimationType.AlongPath) { currDetailProgress = 0; totalDetailProgress = 0; @@ -297,51 +316,41 @@ namespace XCharts totalDetailProgress += Vector3.Distance(np, lp); lp = np; } - SetLinePathStartPos(sp); + m_LinePathLastPos = sp; + context.currentPathDistance = 0; } - else - { - - InitProgress(paths.Count, currDetailProgress, totalDetailProgress); - } - } - - public void SetDataFinish(int dataIndex) - { - if (m_IsEnd) - return; - m_CurrDataProgress = dataIndex + (m_FadeOut ? -1 : 1); + InitProgress(currDetailProgress, totalDetailProgress); } private void SetDataCurrProgress(int index, float state) { - m_DataCurrProgress[index] = state; + m_ItemCurrProgress[index] = state; } - private float GetDataCurrProgress(int index, float initValue, float destValue, out bool isBarEnd) + private float GetDataCurrProgress(int index, float initValue, float destValue, ref bool isBarEnd) { if (IsInDelay()) { isBarEnd = false; return initValue; } - var c1 = !m_DataCurrProgress.ContainsKey(index); - var c2 = !m_DataDestProgress.ContainsKey(index); + var c1 = !m_ItemCurrProgress.ContainsKey(index); + var c2 = !m_ItemDestProgress.ContainsKey(index); if (c1 || c2) { if (c1) - m_DataCurrProgress.Add(index, initValue); + m_ItemCurrProgress.Add(index, initValue); if (c2) - m_DataDestProgress.Add(index, destValue); + m_ItemDestProgress.Add(index, destValue); isBarEnd = false; } else { - isBarEnd = m_DataCurrProgress[index] == m_DataDestProgress[index]; + isBarEnd = m_ItemCurrProgress[index] == m_ItemDestProgress[index]; } - return m_DataCurrProgress[index]; + return m_ItemCurrProgress[index]; } public bool IsFinish() @@ -350,7 +359,14 @@ namespace XCharts if (!Application.isPlaying) return true; #endif - return !m_Enable || m_IsEnd || (m_CurrDataProgress > m_DestDataProgress && m_CurrDetailProgress > m_DestDetailProgress); + if (!m_Enable || m_IsEnd) + return true; + + if (IsIndexAnimation()) + return m_CurrDetailProgress > m_DestDetailProgress; + if (IsItemAnimation()) + return false; + return true; } public bool IsInFadeOut() @@ -366,7 +382,19 @@ namespace XCharts return (fadeInDelay > 0 && Time.time - startTime < fadeInDelay / 1000); } - public float GetDataDelay(int dataIndex) + public bool IsItemAnimation() + { + return context.type == AnimationType.BottomToTop || context.type == AnimationType.InsideOut; + } + + public bool IsIndexAnimation() + { + return context.type == AnimationType.LeftToRight + || context.type == AnimationType.Clockwise + || context.type == AnimationType.AlongPath; + } + + public float GetIndexDelay(int dataIndex) { if (m_FadeOut && customFadeOutDelay != null) return customFadeOutDelay(dataIndex); @@ -376,9 +404,9 @@ namespace XCharts return 0; } - public bool IsInDataDelay(int dataIndex) + public bool IsInIndexDelay(int dataIndex) { - return Time.time - startTime < GetDataDelay(dataIndex) / 1000f; + return Time.time - startTime < GetIndexDelay(dataIndex) / 1000f; } public bool IsAllOutDelay(int dataCount) @@ -386,53 +414,32 @@ namespace XCharts var nowTime = Time.time - startTime; for (int i = 0; i < dataCount; i++) { - if (nowTime < GetDataDelay(i) / 1000) + if (nowTime < GetIndexDelay(i) / 1000) return false; } return true; } - public bool IsAllDataFinishProgress(int dataCount) - { - for (int i = 0; i < dataCount; i++) - { - if (m_DataDestProgress.ContainsKey(i) && m_DataCurrProgress.ContainsKey(i)) - { - if (m_DataCurrProgress[i] != m_DataDestProgress[i]) - return false; - } - else - { - return false; - } - } - return true; - } - public bool CheckDetailBreak(float detail) { + if (!IsIndexAnimation()) + return false; return !IsFinish() && detail > m_CurrDetailProgress; } - public void SetLinePathStartPos(Vector3 pos) - { - if (m_AlongWithLinePath) - { - m_LinePathLastPos = pos; - m_LinePathCurrTotalDist = 0; - } - } - public bool CheckDetailBreak(Vector3 pos, bool isYAxis) { + if (!IsIndexAnimation()) + return false; + if (IsFinish()) return false; - if (m_AlongWithLinePath) + if (context.type == AnimationType.AlongPath) { - m_LinePathCurrTotalDist += Vector3.Distance(pos, m_LinePathLastPos); + context.currentPathDistance += Vector3.Distance(pos, m_LinePathLastPos); m_LinePathLastPos = pos; - return CheckDetailBreak(m_LinePathCurrTotalDist); + return CheckDetailBreak(context.currentPathDistance); } else { @@ -443,26 +450,17 @@ namespace XCharts } } - public bool NeedAnimation(int dataIndex) - { - if (!m_Enable || m_IsEnd) - return true; - - if (IsInDelay()) - return false; - - if (m_FadeOut) - return dataIndex > 0; - else - return dataIndex <= m_CurrDataProgress; - } - - internal void CheckProgress() + public void CheckProgress() { + if (IsItemAnimation() && context.isAllItemAnimationEnd) + { + End(); + return; + } CheckProgress(m_TotalDetailProgress); } - internal void CheckProgress(double total) + public void CheckProgress(double total) { if (IsFinish()) return; @@ -512,17 +510,17 @@ namespace XCharts return m_FadeInDuration > 0 ? m_FadeInDuration / 1000 : 1f; } - internal float CheckBarProgress(int dataIndex, float barHig, int dataCount, out bool isBarEnd) + internal float CheckItemProgress(int dataIndex, float barHig, ref bool isEnd) { - isBarEnd = false; + isEnd = false; var initHig = m_FadeOut ? barHig : 0; var destHig = m_FadeOut ? 0 : barHig; - var currHig = GetDataCurrProgress(dataIndex, initHig, destHig, out isBarEnd); - if (isBarEnd || IsFinish()) + var currHig = GetDataCurrProgress(dataIndex, initHig, destHig, ref isEnd); + if (isEnd || IsFinish()) { return m_FadeOuted ? 0 : barHig; } - else if (IsInDelay() || IsInDataDelay(dataIndex)) + else if (IsInDelay() || IsInIndexDelay(dataIndex)) { return m_FadeOut ? barHig : 0; } @@ -540,24 +538,19 @@ namespace XCharts if ((initHig > 0 && currHig <= 0) || (initHig < 0 && currHig >= 0)) { currHig = 0; - isBarEnd = true; + isEnd = true; } } else if (Mathf.Abs(currHig) >= Mathf.Abs(barHig)) { currHig = barHig; - isBarEnd = true; + isEnd = true; } SetDataCurrProgress(dataIndex, currHig); return currHig; } } - public void AllBarEnd() - { - End(); - } - internal void CheckSymbol(float dest) { if (!enable || m_IsEnd || m_IsPause || !m_IsInit) @@ -628,11 +621,6 @@ namespace XCharts return (int)m_CurrDetailProgress; } - public float GetCurrData() - { - return m_CurrDataProgress; - } - public float GetUpdateAnimationDuration() { if (m_Enable && m_DataChangeEnable && IsFinish()) diff --git a/Assets/XCharts/Runtime/Component/Child/AnimationStyle.cs.meta b/Assets/XCharts/Runtime/Component/Animation/AnimationStyle.cs.meta similarity index 83% rename from Assets/XCharts/Runtime/Component/Child/AnimationStyle.cs.meta rename to Assets/XCharts/Runtime/Component/Animation/AnimationStyle.cs.meta index 8bf3ddad..87c8cd8d 100644 --- a/Assets/XCharts/Runtime/Component/Child/AnimationStyle.cs.meta +++ b/Assets/XCharts/Runtime/Component/Animation/AnimationStyle.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: d51f91843500c4092909a6779592b654 +guid: e31c30f2ef61c48718a626f93307ce92 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/XCharts/Runtime/Component/Animation/AnimationStyleContext.cs b/Assets/XCharts/Runtime/Component/Animation/AnimationStyleContext.cs new file mode 100644 index 00000000..f61cd413 --- /dev/null +++ b/Assets/XCharts/Runtime/Component/Animation/AnimationStyleContext.cs @@ -0,0 +1,20 @@ +/******************************************/ +/* */ +/* Copyright (c) 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/******************************************/ + +using System; +using System.Collections.Generic; +using UnityEngine; + +namespace XCharts +{ + public struct AnimationStyleContext + { + public AnimationType type; + internal float currentPathDistance; + internal bool isAllItemAnimationEnd; + } +} \ No newline at end of file diff --git a/Assets/XCharts/Runtime/Component/Animation/AnimationStyleContext.cs.meta b/Assets/XCharts/Runtime/Component/Animation/AnimationStyleContext.cs.meta new file mode 100644 index 00000000..572eb5b0 --- /dev/null +++ b/Assets/XCharts/Runtime/Component/Animation/AnimationStyleContext.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b3dc504960589413fa6a76267067775c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/XCharts/Runtime/Component/Animation/AnimationStyleHelper.cs b/Assets/XCharts/Runtime/Component/Animation/AnimationStyleHelper.cs new file mode 100644 index 00000000..aa7c6d87 --- /dev/null +++ b/Assets/XCharts/Runtime/Component/Animation/AnimationStyleHelper.cs @@ -0,0 +1,72 @@ +/******************************************/ +/* */ +/* Copyright (c) 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/******************************************/ +using UnityEngine; +using XUGL; + +namespace XCharts +{ + public static class AnimationStyleHelper + { + public static float CheckDataAnimation(BaseChart chart, Serie serie, int dataIndex, float destProgress) + { + if (!serie.animation.IsItemAnimation()) + { + serie.animation.context.isAllItemAnimationEnd = false; + return destProgress; + } + if (serie.animation.IsFinish()) + { + serie.animation.context.isAllItemAnimationEnd = false; + return destProgress; + } + var isDataAnimationEnd = true; + float currHig = serie.animation.CheckItemProgress(dataIndex, destProgress, ref isDataAnimationEnd); + if (!isDataAnimationEnd) + { + serie.animation.context.isAllItemAnimationEnd = false; + } + return currHig; + } + + public static void UpdateSerieAnimation(Serie serie) + { + var serieType = serie.GetType(); + var animationType = AnimationType.LeftToRight; + if (serieType.IsDefined(typeof(DefaultAnimationAttribute), false)) + { + animationType = serieType.GetAttribute().type; + } + UpdateAnimationType(serie.animation, animationType); + serie.animation.context.isAllItemAnimationEnd = true; + } + + public static void UpdateAnimationType(AnimationStyle animation, AnimationType defaultType) + { + animation.context.type = animation.type == AnimationType.Default + ? defaultType + : animation.type; + } + + public static bool GetAnimationPosition(AnimationStyle animation, bool isY, Vector3 lp, Vector3 cp, float progress, ref Vector3 ip) + { + if (animation.context.type == AnimationType.AlongPath) + { + var dist = Vector3.Distance(lp, cp); + var rate = (dist - animation.context.currentPathDistance + animation.GetCurrDetail()) / dist; + ip = Vector3.Lerp(lp, cp, rate); + return true; + } + else + { + var startPos = isY ? new Vector3(-10000, progress) : new Vector3(progress, -10000); + var endPos = isY ? new Vector3(10000, progress) : new Vector3(progress, 10000); + + return UGLHelper.GetIntersection(lp, cp, startPos, endPos, ref ip); + } + } + } +} \ No newline at end of file diff --git a/Assets/XCharts/Runtime/Component/Animation/AnimationStyleHelper.cs.meta b/Assets/XCharts/Runtime/Component/Animation/AnimationStyleHelper.cs.meta new file mode 100644 index 00000000..eed1235d --- /dev/null +++ b/Assets/XCharts/Runtime/Component/Animation/AnimationStyleHelper.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 54cadaee0856b4f7085787fd450eec37 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/XCharts/Runtime/Component/Axis/AngleAxis/AngleAxisHandler.cs b/Assets/XCharts/Runtime/Component/Axis/AngleAxis/AngleAxisHandler.cs index b81f25c9..50c5b57f 100644 --- a/Assets/XCharts/Runtime/Component/Axis/AngleAxis/AngleAxisHandler.cs +++ b/Assets/XCharts/Runtime/Component/Axis/AngleAxis/AngleAxisHandler.cs @@ -41,7 +41,6 @@ namespace XCharts AxisHelper.AdjustMinMaxValue(axis, ref tempMinValue, ref tempMaxValue, true); if (tempMinValue != axis.context.minValue || tempMaxValue != axis.context.maxValue) { - chart.m_IsPlayingAnimation = true; axis.UpdateMinMaxValue(tempMinValue, tempMaxValue); axis.context.offset = 0; axis.context.lastCheckInverse = axis.inverse; @@ -51,11 +50,6 @@ namespace XCharts chart.RefreshChart(); } } - if (!chart.m_IsPlayingAnimation) - { - UpdateAxisLabelText(axis); - chart.RefreshChart(); - } } internal void UpdateAxisLabelText(AngleAxis axis) diff --git a/Assets/XCharts/Runtime/Component/Axis/AxisHandler.cs b/Assets/XCharts/Runtime/Component/Axis/AxisHandler.cs index b200ef4a..77af3b7a 100644 --- a/Assets/XCharts/Runtime/Component/Axis/AxisHandler.cs +++ b/Assets/XCharts/Runtime/Component/Axis/AxisHandler.cs @@ -132,7 +132,6 @@ namespace XCharts { m_LastSplitNumber = axis.splitNumber; m_LastInterval = axis.interval; - chart.m_IsPlayingAnimation = true; axis.UpdateMinMaxValue(tempMinValue, tempMaxValue); axis.context.offset = 0; @@ -178,12 +177,6 @@ namespace XCharts chart.RefreshChart(); } } - - if ( !chart.m_IsPlayingAnimation) - { - UpdateAxisLabelText(axis); - chart.RefreshChart(); - } } internal virtual void UpdateAxisLabelText(Axis axis) diff --git a/Assets/XCharts/Runtime/Component/Axis/RadiusAxis/RadiusAxisHandler.cs b/Assets/XCharts/Runtime/Component/Axis/RadiusAxis/RadiusAxisHandler.cs index c04d3cd7..d4f84695 100644 --- a/Assets/XCharts/Runtime/Component/Axis/RadiusAxis/RadiusAxisHandler.cs +++ b/Assets/XCharts/Runtime/Component/Axis/RadiusAxis/RadiusAxisHandler.cs @@ -40,7 +40,6 @@ namespace XCharts AxisHelper.AdjustMinMaxValue(axis, ref tempMinValue, ref tempMaxValue, true); if (tempMinValue != axis.context.minValue || tempMaxValue != axis.context.maxValue) { - chart.m_IsPlayingAnimation = true; axis.UpdateMinMaxValue(tempMinValue, tempMaxValue); axis.context.offset = 0; axis.context.lastCheckInverse = axis.inverse; @@ -51,11 +50,6 @@ namespace XCharts chart.RefreshChart(); } } - if (!chart.m_IsPlayingAnimation) - { - UpdateAxisLabelText(axis); - chart.RefreshChart(); - } } internal void UpdateAxisLabelText(RadiusAxis axis) diff --git a/Assets/XCharts/Runtime/Component/Mark/MarkLineHandler.cs b/Assets/XCharts/Runtime/Component/Mark/MarkLineHandler.cs index 12ac5c41..88bd6831 100644 --- a/Assets/XCharts/Runtime/Component/Mark/MarkLineHandler.cs +++ b/Assets/XCharts/Runtime/Component/Mark/MarkLineHandler.cs @@ -111,7 +111,7 @@ namespace XCharts var ep = Vector3.zero; var colorIndex = chart.GetLegendRealShowNameIndex(serie.serieName); var serieColor = SerieHelper.GetLineColor(serie, chart.theme, colorIndex, false); - animation.InitProgress(1, 0, 1f); + animation.InitProgress(0, 1f); ResetTempMarkLineGroupData(markLine); if (m_TempGroupData.Count > 0) { diff --git a/Assets/XCharts/Runtime/Coord/Parallel/ParallelCoordHandler.cs b/Assets/XCharts/Runtime/Coord/Parallel/ParallelCoordHandler.cs index f2789a18..1fe19a6e 100644 --- a/Assets/XCharts/Runtime/Coord/Parallel/ParallelCoordHandler.cs +++ b/Assets/XCharts/Runtime/Coord/Parallel/ParallelCoordHandler.cs @@ -167,7 +167,6 @@ namespace XCharts { m_LastSplitNumber = axis.splitNumber; m_LastInterval = axis.interval; - chart.m_IsPlayingAnimation = true; axis.UpdateMinMaxValue(tempMinValue, tempMaxValue); axis.context.offset = 0; diff --git a/Assets/XCharts/Runtime/Internal/Attributes/DefaultAnimationAttribute.cs b/Assets/XCharts/Runtime/Internal/Attributes/DefaultAnimationAttribute.cs new file mode 100644 index 00000000..878988c5 --- /dev/null +++ b/Assets/XCharts/Runtime/Internal/Attributes/DefaultAnimationAttribute.cs @@ -0,0 +1,21 @@ +/******************************************/ +/* */ +/* Copyright (c) 2021 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/******************************************/ +using System; + +namespace XCharts +{ + [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] + public sealed class DefaultAnimationAttribute : Attribute + { + public readonly AnimationType type; + + public DefaultAnimationAttribute(AnimationType handler) + { + this.type = handler; + } + } +} \ No newline at end of file diff --git a/Assets/XCharts/Runtime/Internal/Attributes/DefaultAnimationAttribute.cs.meta b/Assets/XCharts/Runtime/Internal/Attributes/DefaultAnimationAttribute.cs.meta new file mode 100644 index 00000000..8b15da5a --- /dev/null +++ b/Assets/XCharts/Runtime/Internal/Attributes/DefaultAnimationAttribute.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b25b7b1d8388945d4bf78e54f094470f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/XCharts/Runtime/Internal/BaseChart.Serie.cs b/Assets/XCharts/Runtime/Internal/BaseChart.Serie.cs index 30ae5b9c..b53e1ef0 100644 --- a/Assets/XCharts/Runtime/Internal/BaseChart.Serie.cs +++ b/Assets/XCharts/Runtime/Internal/BaseChart.Serie.cs @@ -773,17 +773,6 @@ namespace XCharts return 0; } - public float CheckSerieBarAnimation(Serie serie, int dataIndex, float barHig, out bool isBarEnd) - { - float currHig = serie.animation.CheckBarProgress(dataIndex, barHig, serie.dataCount, out isBarEnd); - if (!serie.animation.IsFinish()) - { - RefreshPainter(serie); - m_IsPlayingAnimation = true; - } - return currHig; - } - internal void InitSerieHandlers() { m_SerieHandlers.Clear(); diff --git a/Assets/XCharts/Runtime/Internal/BaseChart.cs b/Assets/XCharts/Runtime/Internal/BaseChart.cs index c6c3f4a6..f27400c5 100644 --- a/Assets/XCharts/Runtime/Internal/BaseChart.cs +++ b/Assets/XCharts/Runtime/Internal/BaseChart.cs @@ -93,7 +93,6 @@ namespace XCharts protected Action m_OnPointerClickBar; internal bool m_CheckAnimation = false; - internal bool m_IsPlayingAnimation = false; internal protected List m_LegendRealShowName = new List(); protected List m_PainterList = new List(); internal Painter m_PainterTop; @@ -576,6 +575,7 @@ namespace XCharts serie.context.colorIndex = GetLegendRealShowNameIndex(serie.legendName); serie.context.dataPoints.Clear(); serie.context.dataIgnore.Clear(); + AnimationStyleHelper.UpdateSerieAnimation(serie); if (m_OnCustomDrawSerieBeforeCallback != null) { m_OnCustomDrawSerieBeforeCallback.Invoke(vh, serie); diff --git a/Assets/XCharts/Runtime/Internal/Misc/DelegateFunction.cs b/Assets/XCharts/Runtime/Internal/Misc/DelegateFunction.cs index 10249463..b01092e1 100644 --- a/Assets/XCharts/Runtime/Internal/Misc/DelegateFunction.cs +++ b/Assets/XCharts/Runtime/Internal/Misc/DelegateFunction.cs @@ -9,7 +9,7 @@ namespace XCharts { /// - /// The delegate function for AxisLabel's formatter. | + /// The delegate function for AxisLabel's formatter. /// AxisLabel的formatter自定义委托。 /// /// label索引 diff --git a/Assets/XCharts/Runtime/Serie/Bar/Bar.cs b/Assets/XCharts/Runtime/Serie/Bar/Bar.cs index fdc17fdf..f5eafa90 100644 --- a/Assets/XCharts/Runtime/Serie/Bar/Bar.cs +++ b/Assets/XCharts/Runtime/Serie/Bar/Bar.cs @@ -15,6 +15,7 @@ namespace XCharts [SerieHandler(typeof(BarHandler), true)] [SerieConvert(typeof(Line),typeof(Pie))] [RequireChartComponent(typeof(GridCoord))] + [DefaultAnimation(AnimationType.BottomToTop)] public class Bar : Serie, INeedSerieContainer { public int containerIndex { get; internal set; } diff --git a/Assets/XCharts/Runtime/Serie/Bar/BarHandler.cs b/Assets/XCharts/Runtime/Serie/Bar/BarHandler.cs index 4194c381..769b1bd6 100644 --- a/Assets/XCharts/Runtime/Serie/Bar/BarHandler.cs +++ b/Assets/XCharts/Runtime/Serie/Bar/BarHandler.cs @@ -67,7 +67,7 @@ namespace XCharts public override void DrawSerie(VertexHelper vh) { - DrawXBarSerie(vh, serie, serie.context.colorIndex); + DrawBarSerie(vh, serie, serie.context.colorIndex); } private void UpdateSerieContext() @@ -91,152 +91,7 @@ namespace XCharts } } - private void DrawYBarSerie(VertexHelper vh, Bar serie, int colorIndex) - { - if (!serie.show) return; - if (serie.animation.HasFadeOut()) return; - XAxis xAxis; - YAxis yAxis; - GridCoord grid; - if (!chart.TryGetChartComponent(out xAxis, serie.xAxisIndex)) return; - if (!chart.TryGetChartComponent(out yAxis, serie.yAxisIndex)) return; - if (!chart.TryGetChartComponent(out grid, xAxis.gridIndex)) return; - var dataZoom = chart.GetDataZoomOfAxis(yAxis); - var showData = serie.GetDataList(dataZoom); - float categoryWidth = AxisHelper.GetDataWidth(yAxis, grid.context.height, showData.Count, dataZoom); - float barGap = chart.GetSerieBarGap(); - float totalBarWidth = chart.GetSerieTotalWidth(categoryWidth, barGap); - float barWidth = serie.GetBarWidth(categoryWidth); - float offset = (categoryWidth - totalBarWidth) / 2; - float barGapWidth = barWidth + barWidth * barGap; - float space = serie.barGap == -1 ? offset : offset + chart.GetSerieIndexIfStack(serie) * barGapWidth; - var isStack = SeriesHelper.IsStack(chart.series, serie.stack); - m_StackSerieData.Clear(); - if (isStack) SeriesHelper.UpdateStackDataList(chart.series, serie, dataZoom, m_StackSerieData); - - int maxCount = serie.maxShow > 0 ? - (serie.maxShow > showData.Count ? showData.Count : serie.maxShow) - : showData.Count; - var isPercentStack = SeriesHelper.IsPercentStack(chart.series, serie.stack); - bool dataChanging = false; - float dataChangeDuration = serie.animation.GetUpdateAnimationDuration(); - double xMinValue = xAxis.context.minValue; - double xMaxValue = xAxis.context.maxValue; - var isAllBarEnd = true; - serie.containerIndex = grid.index; - serie.containterInstanceId = grid.instanceId; - for (int i = serie.minShow; i < maxCount; i++) - { - var serieData = showData[i]; - if (!serieData.show || serie.IsIgnoreValue(serieData)) - { - serie.context.dataPoints.Add(Vector3.zero); - continue; - } - var highlight = serie.data[i].context.highlight - || serie.highlight; - var itemStyle = SerieHelper.GetItemStyle(serie, serieData, highlight); - - serieData.context.canShowLabel = true; - double value = showData[i].GetCurrData(1, dataChangeDuration, xAxis.inverse, xMinValue, xMaxValue); - float borderWidth = value == 0 ? 0 : itemStyle.runtimeBorderWidth; - if (showData[i].IsDataChanged()) dataChanging = true; - float axisLineWidth = value == 0 ? 0 - : ((value < 0 ? -1 : 1) * yAxis.axisLine.GetWidth(chart.theme.axis.lineWidth)); - - float pY = grid.context.y + i * categoryWidth; - if (!yAxis.boundaryGap) pY -= categoryWidth / 2; - float pX = grid.context.x + xAxis.context.offset + axisLineWidth; - if (isStack) - { - for (int n = 0; n < m_StackSerieData.Count - 1; n++) - { - pX += m_StackSerieData[n][i].context.stackHeight; - } - } - - var barHig = 0f; - double valueTotal = 0f; - if (isPercentStack) - { - valueTotal = chart.GetSerieSameStackTotalValue(serie.stack, i); - barHig = valueTotal != 0 ? (float)((value / valueTotal * grid.context.width)) : 0; - } - else - { - if (yAxis.IsLog()) - { - int minIndex = xAxis.GetLogMinIndex(); - float nowIndex = xAxis.GetLogValue(value); - barHig = (nowIndex - minIndex) / xAxis.splitNumber * grid.context.width; - } - else - { - valueTotal = xMaxValue - xMinValue; - if (valueTotal != 0) - barHig = (float)((xMinValue > 0 ? value - xMinValue : value) - / valueTotal * grid.context.width); - } - } - serieData.context.stackHeight = barHig; - var isBarEnd = false; - float currHig = chart.CheckSerieBarAnimation(serie, i, barHig, out isBarEnd); - if (!isBarEnd) isAllBarEnd = false; - Vector3 plt, prt, prb, plb, top; - if (value < 0) - { - plt = new Vector3(pX - borderWidth, pY + space + barWidth - borderWidth); - prt = new Vector3(pX + currHig + borderWidth, pY + space + barWidth - borderWidth); - prb = new Vector3(pX + currHig + borderWidth, pY + space + borderWidth); - plb = new Vector3(pX - borderWidth, pY + space + borderWidth); - } - else - { - plt = new Vector3(pX + borderWidth, pY + space + barWidth - borderWidth); - prt = new Vector3(pX + currHig - borderWidth, pY + space + barWidth - borderWidth); - prb = new Vector3(pX + currHig - borderWidth, pY + space + borderWidth); - plb = new Vector3(pX + borderWidth, pY + space + borderWidth); - } - top = new Vector3(pX + currHig - borderWidth, pY + space + barWidth / 2); - if (serie.clip) - { - plt = chart.ClampInGrid(grid, plt); - prt = chart.ClampInGrid(grid, prt); - prb = chart.ClampInGrid(grid, prb); - plb = chart.ClampInGrid(grid, plb); - top = chart.ClampInGrid(grid, top); - } - serieData.context.rect = Rect.MinMaxRect(plb.x, plb.y, prb.x, prt.y); - serie.context.dataPoints.Add(top); - if (serie.show) - { - switch (serie.barType) - { - case BarType.Normal: - DrawNormalBar(vh, serie, serieData, itemStyle, colorIndex, highlight, space, barWidth, - pX, pY, plb, plt, prt, prb, true, grid); - break; - case BarType.Zebra: - DrawZebraBar(vh, serie, serieData, itemStyle, colorIndex, highlight, space, barWidth, - pX, pY, plb, plt, prt, prb, true, grid); - break; - case BarType.Capsule: - DrawCapsuleBar(vh, serie, serieData, itemStyle, colorIndex, highlight, space, barWidth, - pX, pY, plb, plt, prt, prb, true, grid); - break; - } - } - } - if (isAllBarEnd) serie.animation.AllBarEnd(); - if (dataChanging) - { - chart.RefreshPainter(serie); - } - } - - - - private void DrawXBarSerie(VertexHelper vh, Bar serie, int colorIndex) + private void DrawBarSerie(VertexHelper vh, Bar serie, int colorIndex) { if (!serie.show || serie.animation.HasFadeOut()) return; @@ -273,6 +128,7 @@ namespace XCharts return; var axisLength = isY ? grid.context.height : grid.context.width; + var axisXY = isY ? grid.context.y : grid.context.x; var isStack = SeriesHelper.IsStack(chart.series, serie.stack); if (isStack) @@ -294,9 +150,9 @@ namespace XCharts float dataChangeDuration = serie.animation.GetUpdateAnimationDuration(); double yMinValue = relativedAxis.context.minValue; double yMaxValue = relativedAxis.context.maxValue; - var isAllBarEnd = true; serie.containerIndex = grid.index; serie.containterInstanceId = grid.instanceId; + serie.animation.InitProgress(axisXY, axisXY + axisLength); for (int i = serie.minShow; i < maxCount; i++) { var serieData = showData[i]; @@ -305,6 +161,7 @@ namespace XCharts serie.context.dataPoints.Add(Vector3.zero); continue; } + if (serieData.IsDataChanged()) dataChanging = true; @@ -329,10 +186,7 @@ namespace XCharts barHig = AxisHelper.GetAxisValueLength(grid, relativedAxis, categoryWidth, relativedValue); } - var isBarEnd = false; - float currHig = chart.CheckSerieBarAnimation(serie, i, barHig, out isBarEnd); - if (!isBarEnd) - isAllBarEnd = false; + float currHig = AnimationStyleHelper.CheckDataAnimation(chart, serie, i, barHig); Vector3 plb, plt, prt, prb, top; UpdateRectPosition(grid, isY, relativedValue, pX, pY, space, borderWidth, barWidth, currHig, @@ -359,10 +213,16 @@ namespace XCharts break; } } + + if (serie.animation.CheckDetailBreak(top, isY)) + { + break; + } } - if (isAllBarEnd) + if (!serie.animation.IsFinish()) { - serie.animation.AllBarEnd(); + serie.animation.CheckProgress(); + chart.RefreshPainter(serie); } if (dataChanging) { diff --git a/Assets/XCharts/Runtime/Serie/Candlestick/Candlestick.cs b/Assets/XCharts/Runtime/Serie/Candlestick/Candlestick.cs index 13675e1d..de04e8bb 100644 --- a/Assets/XCharts/Runtime/Serie/Candlestick/Candlestick.cs +++ b/Assets/XCharts/Runtime/Serie/Candlestick/Candlestick.cs @@ -11,6 +11,7 @@ namespace XCharts { [System.Serializable] [SerieHandler(typeof(CandlestickHandler), true)] + [DefaultAnimation(AnimationType.LeftToRight)] public class Candlestick : Serie, INeedSerieContainer { public int containerIndex { get; internal set; } diff --git a/Assets/XCharts/Runtime/Serie/Candlestick/CandlestickHandler.cs b/Assets/XCharts/Runtime/Serie/Candlestick/CandlestickHandler.cs index c6e3a243..0e9996b9 100644 --- a/Assets/XCharts/Runtime/Serie/Candlestick/CandlestickHandler.cs +++ b/Assets/XCharts/Runtime/Serie/Candlestick/CandlestickHandler.cs @@ -44,7 +44,6 @@ namespace XCharts float dataChangeDuration = serie.animation.GetUpdateAnimationDuration(); double yMinValue = yAxis.context.minValue; double yMaxValue = yAxis.context.maxValue; - var isAllBarEnd = true; var isYAxis = false; serie.containerIndex = grid.index; serie.containterInstanceId = grid.instanceId; @@ -80,9 +79,7 @@ namespace XCharts pY += (float)((open - minCut) / valueTotal * grid.context.height); } serieData.context.stackHeight = barHig; - var isBarEnd = false; - float currHig = chart.CheckSerieBarAnimation(serie, i, barHig, out isBarEnd); - if (!isBarEnd) isAllBarEnd = false; + float currHig = AnimationStyleHelper.CheckDataAnimation(chart, serie, i, barHig); Vector3 plb, plt, prt, prb, top; plb = new Vector3(pX + space + borderWidth, pY + borderWidth); @@ -145,9 +142,9 @@ namespace XCharts UGL.DrawLine(vh, openCenterPos, heighPos, borderWidth, borderColor); } } - if (isAllBarEnd) + if (!serie.animation.IsFinish()) { - serie.animation.AllBarEnd(); + serie.animation.CheckProgress(); } if (dataChanging) { diff --git a/Assets/XCharts/Runtime/Serie/Gauge/GaugeHandler.cs b/Assets/XCharts/Runtime/Serie/Gauge/GaugeHandler.cs index 7d703958..bbc69bb4 100644 --- a/Assets/XCharts/Runtime/Serie/Gauge/GaugeHandler.cs +++ b/Assets/XCharts/Runtime/Serie/Gauge/GaugeHandler.cs @@ -158,7 +158,7 @@ namespace XCharts { SerieHelper.UpdateCenter(serie, chart.chartPosition, chart.chartWidth, chart.chartHeight); var destAngle = GetCurrAngle(serie, true); - serie.animation.InitProgress(0, serie.startAngle, destAngle); + serie.animation.InitProgress(serie.startAngle, destAngle); var currAngle = serie.animation.IsFinish() ? GetCurrAngle(serie, false) : serie.animation.GetCurrDetail(); DrawProgressBar(vh, serie, (float)currAngle); DrawStageColor(vh, serie); diff --git a/Assets/XCharts/Runtime/Serie/Heatmap/Heatmap.cs b/Assets/XCharts/Runtime/Serie/Heatmap/Heatmap.cs index 579ca4f3..bb61327b 100644 --- a/Assets/XCharts/Runtime/Serie/Heatmap/Heatmap.cs +++ b/Assets/XCharts/Runtime/Serie/Heatmap/Heatmap.cs @@ -11,6 +11,7 @@ namespace XCharts { [System.Serializable] [SerieHandler(typeof(HeatmapHandler), true)] + [DefaultAnimation(AnimationType.LeftToRight)] public class Heatmap : Serie, INeedSerieContainer { public int containerIndex { get; internal set; } diff --git a/Assets/XCharts/Runtime/Serie/Heatmap/HeatmapHandler.cs b/Assets/XCharts/Runtime/Serie/Heatmap/HeatmapHandler.cs index a29e521f..fe2882a0 100644 --- a/Assets/XCharts/Runtime/Serie/Heatmap/HeatmapHandler.cs +++ b/Assets/XCharts/Runtime/Serie/Heatmap/HeatmapHandler.cs @@ -85,7 +85,7 @@ namespace XCharts var borderToColor = serie.itemStyle.opacity > 0 ? serie.itemStyle.borderToColor : ChartConst.clearColor32; borderToColor.a = (byte)(borderToColor.a * serie.itemStyle.opacity); serie.context.dataPoints.Clear(); - serie.animation.InitProgress(1, 0, xCount); + serie.animation.InitProgress(0, xCount); var animationIndex = serie.animation.GetCurrIndex(); var dataChangeDuration = serie.animation.GetUpdateAnimationDuration(); var dataChanging = false; @@ -146,7 +146,6 @@ namespace XCharts if (!serie.animation.IsFinish()) { serie.animation.CheckProgress(xCount); - chart.m_IsPlayingAnimation = true; chart.RefreshPainter(serie); } if (dataChanging) diff --git a/Assets/XCharts/Runtime/Serie/Line/Line.cs b/Assets/XCharts/Runtime/Serie/Line/Line.cs index 045eefb8..7f7d50b0 100644 --- a/Assets/XCharts/Runtime/Serie/Line/Line.cs +++ b/Assets/XCharts/Runtime/Serie/Line/Line.cs @@ -14,6 +14,7 @@ namespace XCharts [SerieHandler(typeof(LineHandler), true)] [SerieConvert(typeof(Bar), typeof(Pie))] [CoordOptions(typeof(GridCoord), typeof(PolarCoord))] + [DefaultAnimation(AnimationType.LeftToRight)] public class Line : Serie, INeedSerieContainer { public int containerIndex { get; internal set; } diff --git a/Assets/XCharts/Runtime/Serie/Line/LineHandler.GridCoord.cs b/Assets/XCharts/Runtime/Serie/Line/LineHandler.GridCoord.cs index 88824f23..913028c7 100644 --- a/Assets/XCharts/Runtime/Serie/Line/LineHandler.GridCoord.cs +++ b/Assets/XCharts/Runtime/Serie/Line/LineHandler.GridCoord.cs @@ -352,7 +352,6 @@ namespace XCharts return; serie.animation.InitProgress(serie.context.dataPoints, isY); - serie.animation.SetDataFinish(0); VisualMapHelper.AutoSetLineMinMax(visualMap, serie, isY, axis, relativedAxis); LineHelper.UpdateSerieDrawPoints(serie, chart.settings, chart.theme, isY); @@ -365,7 +364,6 @@ namespace XCharts { serie.animation.CheckProgress(); serie.animation.CheckSymbol(serie.symbol.GetSize(null, chart.theme.serie.lineSymbolSize)); - chart.m_IsPlayingAnimation = true; chart.RefreshPainter(serie); } } @@ -374,27 +372,37 @@ namespace XCharts double yValue, int i, float scaleWid, bool isStack, ref Vector3 np) { float xPos, yPos; + var gridXY = isY ? grid.context.x : grid.context.y; if (isY) { - xPos = AxisHelper.GetAxisPosition(grid, relativedAxis, scaleWid, yValue); + var valueHig = AxisHelper.GetAxisValueLength(grid, relativedAxis, scaleWid, yValue); + valueHig = AnimationStyleHelper.CheckDataAnimation(chart, serie, i, valueHig); + + xPos = gridXY + valueHig; yPos = AxisHelper.GetAxisPosition(grid, axis, scaleWid, xValue); - if (isStack) - { - for (int n = 0; n < m_StackSerieData.Count - 1; n++) - yPos += m_StackSerieData[n][i].context.stackHeight; - } - } - else - { - xPos = AxisHelper.GetAxisPosition(grid, axis, scaleWid, xValue); - yPos = AxisHelper.GetAxisPosition(grid, relativedAxis, scaleWid, yValue); + if (isStack) { for (int n = 0; n < m_StackSerieData.Count - 1; n++) xPos += m_StackSerieData[n][i].context.stackHeight; } } + else + { + + var valueHig = AxisHelper.GetAxisValueLength(grid, relativedAxis, scaleWid, yValue); + valueHig = AnimationStyleHelper.CheckDataAnimation(chart, serie, i, valueHig); + + yPos = gridXY + valueHig; + xPos = AxisHelper.GetAxisPosition(grid, axis, scaleWid, xValue); + + if (isStack) + { + for (int n = 0; n < m_StackSerieData.Count - 1; n++) + yPos += m_StackSerieData[n][i].context.stackHeight; + } + } np = new Vector3(xPos, yPos); return yPos; } diff --git a/Assets/XCharts/Runtime/Serie/Line/LineHandler.PolarCoord.cs b/Assets/XCharts/Runtime/Serie/Line/LineHandler.PolarCoord.cs index 2ded4308..7a7d2f2f 100644 --- a/Assets/XCharts/Runtime/Serie/Line/LineHandler.PolarCoord.cs +++ b/Assets/XCharts/Runtime/Serie/Line/LineHandler.PolarCoord.cs @@ -44,8 +44,7 @@ namespace XCharts var currDetailProgress = 0f; var totalDetailProgress = datas.Count; - serie.animation.InitProgress(serie.context.dataPoints.Count, currDetailProgress, totalDetailProgress); - serie.animation.SetDataFinish(0); + serie.animation.InitProgress(currDetailProgress, totalDetailProgress); for (int i = 1; i < datas.Count; i++) { @@ -62,7 +61,6 @@ namespace XCharts { serie.animation.CheckProgress(totalDetailProgress); serie.animation.CheckSymbol(serie.symbol.GetSize(null, chart.theme.serie.lineSymbolSize)); - chart.m_IsPlayingAnimation = true; chart.RefreshChart(); } } diff --git a/Assets/XCharts/Runtime/Serie/Line/LineHelper.cs b/Assets/XCharts/Runtime/Serie/Line/LineHelper.cs index 179ec833..e504b364 100644 --- a/Assets/XCharts/Runtime/Serie/Line/LineHelper.cs +++ b/Assets/XCharts/Runtime/Serie/Line/LineHelper.cs @@ -259,9 +259,6 @@ namespace XCharts var lastDataIsIgnore = datas[0].isIgnoreBreak; for (int i = 1; i < dataCount; i++) { - if (!serie.animation.NeedAnimation(i)) - break; - var cdata = datas[i]; var isIgnore = cdata.isIgnoreBreak; @@ -272,16 +269,10 @@ namespace XCharts if (serie.animation.CheckDetailBreak(cp, isY)) { isBreak = true; - - var progress = serie.animation.GetCurrDetail(); var ip = Vector3.zero; - - var axisStartPos = isY ? new Vector3(-10000, progress) : new Vector3(progress, -10000); - var axisEndPos = isY ? new Vector3(10000, progress) : new Vector3(progress, 10000); - - if (UGLHelper.GetIntersection(lp, cp, axisStartPos, axisEndPos, ref ip)) + var progress = serie.animation.GetCurrDetail(); + if (AnimationStyleHelper.GetAnimationPosition(serie.animation, isY, lp, cp, progress, ref ip)) cp = np = ip; - } bool bitp = true, bibp = true; UGLHelper.GetLinePoints(lp, cp, np, lineWidth, @@ -320,9 +311,7 @@ namespace XCharts } } lastDataIsIgnore = isIgnore; - if (!isBreak) - serie.animation.SetDataFinish(i); - else + if (isBreak) break; } } diff --git a/Assets/XCharts/Runtime/Serie/Liquid/LiquidHandler.cs b/Assets/XCharts/Runtime/Serie/Liquid/LiquidHandler.cs index b2b8704a..6929c3b7 100644 --- a/Assets/XCharts/Runtime/Serie/Liquid/LiquidHandler.cs +++ b/Assets/XCharts/Runtime/Serie/Liquid/LiquidHandler.cs @@ -169,7 +169,7 @@ namespace XCharts var colorIndex = chart.m_LegendRealShowName.IndexOf(serie.serieName); var realHig = (float)((value - serie.min) / (serie.max - serie.min) * radius * 2); - serie.animation.InitProgress(1, 0, realHig); + serie.animation.InitProgress(0, realHig); var hig = serie.animation.IsFinish() ? realHig : serie.animation.GetCurrDetail(); var a = Mathf.Abs(radius - hig + (hig > radius ? serie.waveHeight : -serie.waveHeight)); @@ -256,7 +256,6 @@ namespace XCharts if (!serie.animation.IsFinish()) { serie.animation.CheckProgress(realHig); - chart.m_IsPlayingAnimation = true; chart.RefreshPainter(serie); } } @@ -282,7 +281,7 @@ namespace XCharts var colorIndex = chart.m_LegendRealShowName.IndexOf(serie.serieName); var realHig = (value - serie.min) / (serie.max - serie.min) * vessel.context.height; - serie.animation.InitProgress(1, 0, (float)realHig); + serie.animation.InitProgress(0, (float)realHig); var hig = serie.animation.IsFinish() ? realHig : serie.animation.GetCurrDetail(); var color = SerieHelper.GetItemColor(serie, serieData, chart.theme, colorIndex, false); var toColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, colorIndex, false); @@ -371,7 +370,6 @@ namespace XCharts if (!serie.animation.IsFinish()) { serie.animation.CheckProgress(realHig); - chart.m_IsPlayingAnimation = true; chart.RefreshPainter(serie); } } diff --git a/Assets/XCharts/Runtime/Serie/Parallel/ParallelHandler.cs b/Assets/XCharts/Runtime/Serie/Parallel/ParallelHandler.cs index 50a9d33e..f424469b 100644 --- a/Assets/XCharts/Runtime/Serie/Parallel/ParallelHandler.cs +++ b/Assets/XCharts/Runtime/Serie/Parallel/ParallelHandler.cs @@ -59,8 +59,7 @@ namespace XCharts ? parallel.context.x + parallel.context.width : parallel.context.y + parallel.context.height; - serie.animation.InitProgress(serie.showDataDimension, currDetailProgress, totalDetailProgress); - serie.animation.SetDataFinish(0); + serie.animation.InitProgress(currDetailProgress, totalDetailProgress); serie.context.dataPoints.Clear(); serie.containerIndex = parallel.index; @@ -86,7 +85,6 @@ namespace XCharts else if (pos.x <= currProgress) { m_Points.Add(pos); - serie.animation.SetDataFinish(i); } else { @@ -110,7 +108,6 @@ namespace XCharts else if (pos.y <= currProgress) { m_Points.Add(pos); - serie.animation.SetDataFinish(i); } else { @@ -135,7 +132,6 @@ namespace XCharts if (!serie.animation.IsFinish()) { serie.animation.CheckProgress(totalDetailProgress - currDetailProgress); - chart.m_IsPlayingAnimation = true; chart.RefreshPainter(serie); } } diff --git a/Assets/XCharts/Runtime/Serie/Pie/Pie.cs b/Assets/XCharts/Runtime/Serie/Pie/Pie.cs index 0f6c4135..536e0ccb 100644 --- a/Assets/XCharts/Runtime/Serie/Pie/Pie.cs +++ b/Assets/XCharts/Runtime/Serie/Pie/Pie.cs @@ -10,6 +10,7 @@ namespace XCharts [System.Serializable] [SerieConvert(typeof(Line), typeof(Bar))] [SerieHandler(typeof(PieHandler), true)] + [DefaultAnimation(AnimationType.Clockwise)] public class Pie : Serie { public override bool useDataNameForColor { get { return true; } } diff --git a/Assets/XCharts/Runtime/Serie/Pie/PieHandler.cs b/Assets/XCharts/Runtime/Serie/Pie/PieHandler.cs index 1101bd85..e9cfcc81 100644 --- a/Assets/XCharts/Runtime/Serie/Pie/PieHandler.cs +++ b/Assets/XCharts/Runtime/Serie/Pie/PieHandler.cs @@ -188,7 +188,6 @@ namespace XCharts { dataTotalFilterMinAngle = GetTotalAngle(serie, runtimePieDataTotal, ref totalDegree); } - serie.animation.InitProgress(data.Count, 0, 360); for (int n = 0; n < data.Count; n++) { var serieData = data[n]; @@ -297,13 +296,13 @@ namespace XCharts private void DrawPie(VertexHelper vh, Serie serie) { - var data = serie.data; - serie.animation.InitProgress(data.Count, 0, 360); if (!serie.show || serie.animation.HasFadeOut()) { return; } - bool dataChanging = false; + var dataChanging = false; + var data = serie.data; + serie.animation.InitProgress(0, 360); for (int n = 0; n < data.Count; n++) { var serieData = data[n]; @@ -311,41 +310,51 @@ namespace XCharts { continue; } + if (serieData.IsDataChanged()) + dataChanging = true; + var itemStyle = SerieHelper.GetItemStyle(serie, serieData, serieData.context.highlight); - if (serieData.IsDataChanged()) dataChanging = true; var serieNameCount = chart.m_LegendRealShowName.IndexOf(serieData.legendName); + var color = SerieHelper.GetItemColor(serie, serieData, chart.theme, serieNameCount, serieData.context.highlight); + var toColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, serieNameCount, serieData.context.highlight); + var borderWidth = itemStyle.borderWidth; var borderColor = itemStyle.borderColor; + var progress = AnimationStyleHelper.CheckDataAnimation(chart, serie, n, 1); + var insideRadius = serieData.context.insideRadius * progress; + var outsideRadius = serieData.context.outsideRadius * progress; + if (serie.pieClickOffset && serieData.selected) { var drawEndDegree = serieData.context.currentAngle; - var needRoundCap = serie.roundCap && serieData.context.insideRadius > 0; - UGL.DrawDoughnut(vh, serieData.context.offsetCenter, serieData.context.insideRadius, - serieData.context.outsideRadius, color, toColor, Color.clear, serieData.context.startAngle, + var needRoundCap = serie.roundCap && insideRadius > 0; + UGL.DrawDoughnut(vh, serieData.context.offsetCenter, insideRadius, + outsideRadius, color, toColor, Color.clear, serieData.context.startAngle, drawEndDegree, borderWidth, borderColor, serie.pieSpace / 2, chart.settings.cicleSmoothness, needRoundCap, true); } else { var drawEndDegree = serieData.context.currentAngle; - var needRoundCap = serie.roundCap && serieData.context.insideRadius > 0; - UGL.DrawDoughnut(vh, serie.context.center, serieData.context.insideRadius, - serieData.context.outsideRadius, color, toColor, Color.clear, serieData.context.startAngle, + var needRoundCap = serie.roundCap && insideRadius > 0; + UGL.DrawDoughnut(vh, serie.context.center, insideRadius, + outsideRadius, color, toColor, Color.clear, serieData.context.startAngle, drawEndDegree, borderWidth, borderColor, serie.pieSpace / 2, chart.settings.cicleSmoothness, needRoundCap, true); - DrawPieCenter(vh, serie, itemStyle, serieData.context.insideRadius); + DrawPieCenter(vh, serie, itemStyle, insideRadius); } - if (!serie.animation.CheckDetailBreak(serieData.context.toAngle)) serie.animation.SetDataFinish(n); - else break; + + if (serie.animation.CheckDetailBreak(serieData.context.toAngle)) + break; } if (!serie.animation.IsFinish()) { - serie.animation.CheckProgress(360); + serie.animation.CheckProgress(); serie.animation.CheckSymbol(serie.symbol.GetSize(null, chart.theme.serie.lineSymbolSize)); chart.RefreshPainter(serie); } diff --git a/Assets/XCharts/Runtime/Serie/Radar/RadarHandler.cs b/Assets/XCharts/Runtime/Serie/Radar/RadarHandler.cs index 4b230e9e..c12cd09d 100644 --- a/Assets/XCharts/Runtime/Serie/Radar/RadarHandler.cs +++ b/Assets/XCharts/Runtime/Serie/Radar/RadarHandler.cs @@ -122,7 +122,7 @@ namespace XCharts var angle = 2 * Mathf.PI / indicatorNum; var centerPos = radar.context.center; var serieNameCount = -1; - serie.animation.InitProgress(1, 0, 1); + serie.animation.InitProgress(0, 1); if (!serie.show || serie.animation.HasFadeOut()) { return; @@ -288,7 +288,7 @@ namespace XCharts var angle = 2 * Mathf.PI / indicatorNum; var centerPos = radar.context.center; var serieNameCount = -1; - serie.animation.InitProgress(1, 0, 1); + serie.animation.InitProgress(0, 1); if (!serie.show || serie.animation.HasFadeOut()) { return; diff --git a/Assets/XCharts/Runtime/Serie/Ring/RingHandler.cs b/Assets/XCharts/Runtime/Serie/Ring/RingHandler.cs index 093ce8b6..83666e5e 100644 --- a/Assets/XCharts/Runtime/Serie/Ring/RingHandler.cs +++ b/Assets/XCharts/Runtime/Serie/Ring/RingHandler.cs @@ -69,7 +69,7 @@ namespace XCharts { if (!serie.show || serie.animation.HasFadeOut()) return; var data = serie.data; - serie.animation.InitProgress(data.Count, serie.startAngle, serie.startAngle + 360); + serie.animation.InitProgress(serie.startAngle, serie.startAngle + 360); SerieHelper.UpdateCenter(serie, chart.chartPosition, chart.chartWidth, chart.chartHeight); var dataChangeDuration = serie.animation.GetUpdateAnimationDuration(); var ringWidth = serie.context.outsideRadius - serie.context.insideRadius; diff --git a/Assets/XCharts/Runtime/Serie/Scatter/BaseScatterHandler.cs b/Assets/XCharts/Runtime/Serie/Scatter/BaseScatterHandler.cs index c73837ee..c03e5dbf 100644 --- a/Assets/XCharts/Runtime/Serie/Scatter/BaseScatterHandler.cs +++ b/Assets/XCharts/Runtime/Serie/Scatter/BaseScatterHandler.cs @@ -149,7 +149,7 @@ namespace XCharts int maxCount = serie.maxShow > 0 ? (serie.maxShow > serie.dataCount ? serie.dataCount : serie.maxShow) : serie.dataCount; - serie.animation.InitProgress(1, 0, 1); + serie.animation.InitProgress(0, 1); var rate = serie.animation.GetCurrRate(); var dataChangeDuration = serie.animation.GetUpdateAnimationDuration(); var dataChanging = false; @@ -221,7 +221,6 @@ namespace XCharts if (!serie.animation.IsFinish()) { serie.animation.CheckProgress(1); - chart.m_IsPlayingAnimation = true; chart.RefreshPainter(serie); } if (dataChanging) @@ -250,7 +249,7 @@ namespace XCharts int maxCount = serie.maxShow > 0 ? (serie.maxShow > serie.dataCount ? serie.dataCount : serie.maxShow) : serie.dataCount; - serie.animation.InitProgress(1, 0, 1); + serie.animation.InitProgress(0, 1); var rate = serie.animation.GetCurrRate(); var dataChangeDuration = serie.animation.GetUpdateAnimationDuration(); @@ -324,7 +323,6 @@ namespace XCharts if (!serie.animation.IsFinish()) { serie.animation.CheckProgress(1); - chart.m_IsPlayingAnimation = true; chart.RefreshPainter(serie); } if (dataChanging) diff --git a/Assets/XCharts/Runtime/Utilities/RuntimeUtil.cs b/Assets/XCharts/Runtime/Utilities/RuntimeUtil.cs index e9c292ce..d200a1c8 100644 --- a/Assets/XCharts/Runtime/Utilities/RuntimeUtil.cs +++ b/Assets/XCharts/Runtime/Utilities/RuntimeUtil.cs @@ -71,31 +71,6 @@ namespace XCharts return (T)type.GetCustomAttributes(typeof(T), false)[0]; } - public static D Mapper(S s) - { - D d = Activator.CreateInstance(); - try - { - var Types = s.GetType();//获得类型 - var Typed = typeof(D); - foreach (PropertyInfo sp in Types.GetProperties())//获得类型的属性字段 - { - foreach (PropertyInfo dp in Typed.GetProperties()) - { - if (dp.Name == sp.Name)//判断属性名是否相同 - { - dp.SetValue(d, sp.GetValue(s, null), null);//获得s对象属性的值复制给d对象的属性 - } - } - } - } - catch (Exception ex) - { - throw ex; - } - return d; - } - public static bool CopyFolder(string sourPath, string destPath) { try