From c926b9efb2c82075f647b1c3d4d63d8a9070700e Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Tue, 18 Aug 2020 09:29:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=80=A7=E8=83=BD=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Runtime/Component/Sub/SerieAnimation.cs | 45 +++++++++++++------- Runtime/Internal/CoordinateChart_DrawBar.cs | 21 ++++++--- Runtime/Internal/CoordinateChart_DrawLine.cs | 13 ++++-- Runtime/Internal/Utility/ChartHelper.cs | 5 +++ 4 files changed, 58 insertions(+), 26 deletions(-) diff --git a/Runtime/Component/Sub/SerieAnimation.cs b/Runtime/Component/Sub/SerieAnimation.cs index 8099c4d0..09bde95a 100644 --- a/Runtime/Component/Sub/SerieAnimation.cs +++ b/Runtime/Component/Sub/SerieAnimation.cs @@ -259,23 +259,31 @@ namespace XCharts m_DataCurrProgress[index] = state; } - private float GetDataCurrProgress(int index, float initValue, float destValue) + private float GetDataCurrProgress(int index, float initValue, float destValue, out bool isBarEnd) { - if (IsInDelay()) return initValue; + if (IsInDelay()) + { + isBarEnd = false; + return initValue; + } if (!m_DataCurrProgress.ContainsKey(index)) { m_DataCurrProgress.Add(index, initValue); m_DataDestProgress.Add(index, destValue); + isBarEnd = false; + } + else + { + isBarEnd = m_DataCurrProgress[index] == m_DataDestProgress[index]; } return m_DataCurrProgress[index]; } - public bool IsFinish(int dataCount = -1) + public bool IsFinish() { #if UNITY_EDITOR if (!Application.isPlaying) return true; #endif - if (dataCount > 0 && (!IsAllOutDelay(dataCount) || !IsAllDataFinishProgress(dataCount))) return false; return !m_Enable || m_IsEnd || (m_CurrDataProgress > m_DestDataProgress && m_CurrDetailProgress > m_DestDetailProgress); } @@ -387,47 +395,52 @@ namespace XCharts else return m_FadeInDuration > 0 ? m_FadeInDuration / 1000 : 1f; } - internal float CheckBarProgress(int dataIndex, float barHig, int dataCount) + internal float CheckBarProgress(int dataIndex, float barHig, int dataCount, out bool isBarEnd) { + isBarEnd = false; var initHig = m_FadeOut ? barHig : 0; var destHig = m_FadeOut ? 0 : barHig; - if (IsFinish() || m_IsEnd) - { - return m_FadeOuted ? 0 : barHig; - } - else if (IsInDelay() || IsInDataDelay(dataIndex)) + if (IsInDelay() || IsInDataDelay(dataIndex)) { return m_FadeOut ? barHig : 0; } + var currHig = GetDataCurrProgress(dataIndex, initHig, destHig, out isBarEnd); + if (isBarEnd || m_IsEnd) + { + return m_FadeOuted ? 0 : barHig; + } else if (m_IsPause) { - return GetDataCurrProgress(dataIndex, initHig, destHig); + return currHig; } else { var duration = GetCurrAnimationDuration(dataIndex); var delta = barHig / duration * Time.deltaTime; - var currHig = GetDataCurrProgress(dataIndex, initHig, destHig) + (m_FadeOut ? -delta : delta); + currHig = currHig + (m_FadeOut ? -delta : delta); if (m_FadeOut) { if ((initHig > 0 && currHig <= 0) || (initHig < 0 && currHig >= 0)) { currHig = 0; + isBarEnd = true; } } else if (Mathf.Abs(currHig) >= Mathf.Abs(barHig)) { currHig = barHig; + isBarEnd = true; } SetDataCurrProgress(dataIndex, currHig); - if (IsAllOutDelay(dataCount) && IsAllDataFinishProgress(dataCount)) - { - End(); - } return currHig; } } + internal void AllBarEnd() + { + End(); + } + internal void CheckSymbol(float dest) { if (!enable || m_IsEnd || m_IsPause || !m_IsInit) return; diff --git a/Runtime/Internal/CoordinateChart_DrawBar.cs b/Runtime/Internal/CoordinateChart_DrawBar.cs index dfbfb175..c17284b9 100644 --- a/Runtime/Internal/CoordinateChart_DrawBar.cs +++ b/Runtime/Internal/CoordinateChart_DrawBar.cs @@ -48,7 +48,7 @@ namespace XCharts float dataChangeDuration = serie.animation.GetUpdateAnimationDuration(); float xMinValue = xAxis.GetCurrMinValue(dataChangeDuration); float xMaxValue = xAxis.GetCurrMaxValue(dataChangeDuration); - + var isAllBarEnd = true; for (int i = serie.minShow; i < maxCount; i++) { if (i >= seriesHig.Count) @@ -92,8 +92,9 @@ namespace XCharts seriesHig[i] += barHig; } - - float currHig = CheckAnimation(serie, i, barHig); + var isBarEnd = false; + float currHig = CheckAnimation(serie, i, barHig, out isBarEnd); + if (!isBarEnd) isAllBarEnd = false; Vector3 plt, prt, prb, plb, top; if (value < 0) { @@ -135,6 +136,7 @@ namespace XCharts } } } + if (isAllBarEnd) serie.animation.AllBarEnd(); if (!SeriesHelper.IsStack(m_Series, serie.stack, SerieType.Bar)) { m_BarLastOffset += barGapWidth; @@ -145,9 +147,9 @@ namespace XCharts } } - private float CheckAnimation(Serie serie, int dataIndex, float barHig) + private float CheckAnimation(Serie serie, int dataIndex, float barHig, out bool isBarEnd) { - float currHig = serie.animation.CheckBarProgress(dataIndex, barHig, serie.dataCount); + float currHig = serie.animation.CheckBarProgress(dataIndex, barHig, serie.dataCount, out isBarEnd); if (!serie.animation.IsFinish()) { RefreshChart(); @@ -189,6 +191,7 @@ namespace XCharts float dataChangeDuration = serie.animation.GetUpdateAnimationDuration(); float yMinValue = yAxis.GetCurrMinValue(dataChangeDuration); float yMaxValue = yAxis.GetCurrMaxValue(dataChangeDuration); + var isAllBarEnd = true; for (int i = serie.minShow; i < maxCount; i++) { if (i >= seriesHig.Count) @@ -230,7 +233,9 @@ namespace XCharts / valueTotal * m_CoordinateHeight; seriesHig[i] += barHig; } - float currHig = CheckAnimation(serie, i, barHig); + var isBarEnd = false; + float currHig = CheckAnimation(serie, i, barHig, out isBarEnd); + if (!isBarEnd) isAllBarEnd = false; Vector3 plb, plt, prt, prb, top; if (value < 0) { @@ -275,6 +280,10 @@ namespace XCharts } } } + if (isAllBarEnd) + { + serie.animation.AllBarEnd(); + } if (dataChanging) { RefreshChart(); diff --git a/Runtime/Internal/CoordinateChart_DrawLine.cs b/Runtime/Internal/CoordinateChart_DrawLine.cs index a5447af0..3706b93e 100644 --- a/Runtime/Internal/CoordinateChart_DrawLine.cs +++ b/Runtime/Internal/CoordinateChart_DrawLine.cs @@ -1028,13 +1028,13 @@ namespace XCharts private bool TryAddToList(bool isTurnBack, bool isYAxis, List list, Vector3 lastPos, Vector3 pos, bool ignoreClose = false) { - if (pos == Vector3.zero) return false; + if (ChartHelper.IsZeroVector(pos)) return false; if (isTurnBack) { list.Add(pos); return true; } - else if (lastPos != Vector3.zero && IsInRightOrUp(isYAxis, pos, lastPos)) + else if (!ChartHelper.IsZeroVector(lastPos) && IsInRightOrUpNotCheckZero(isYAxis, pos, lastPos)) { return false; } @@ -1046,7 +1046,7 @@ namespace XCharts else { var end = list[list.Count - 1]; - if (IsInRightOrUp(isYAxis, end, pos) && (!ignoreClose || !WasTooClose(isYAxis, end, pos, ignoreClose))) + if (IsInRightOrUpNotCheckZero(isYAxis, end, pos) && (!ignoreClose || !WasTooClose(isYAxis, end, pos, ignoreClose))) { list.Add(pos); return true; @@ -1065,7 +1065,12 @@ namespace XCharts private bool IsInRightOrUp(bool isYAxis, Vector3 lp, Vector3 rp) { - return lp == Vector3.zero || ((isYAxis && rp.y > lp.y) || (!isYAxis && rp.x > lp.x)); + return ChartHelper.IsZeroVector(lp) || ((isYAxis && rp.y > lp.y) || (!isYAxis && rp.x > lp.x)); + } + + private bool IsInRightOrUpNotCheckZero(bool isYAxis, Vector3 lp, Vector3 rp) + { + return (isYAxis && rp.y > lp.y) || (!isYAxis && rp.x > lp.x); } private bool WasTooClose(bool isYAxis, Vector3 lp, Vector3 rp, bool ignore) diff --git a/Runtime/Internal/Utility/ChartHelper.cs b/Runtime/Internal/Utility/ChartHelper.cs index 558e7a51..8eba20a1 100644 --- a/Runtime/Internal/Utility/ChartHelper.cs +++ b/Runtime/Internal/Utility/ChartHelper.cs @@ -455,6 +455,11 @@ namespace XCharts return color.a == 0 && color.b == 0 && color.g == 0 && color.r == 0; } + public static bool IsZeroVector(Vector3 pos) + { + return pos.x == 0 && pos.y == 0 && pos.z == 0; + } + public static bool CopyList(List toList, List fromList) { if (toList == null || fromList == null) return false;