增加AnimationAddition动画支持

This commit is contained in:
monitor1394
2023-07-11 13:32:50 +08:00
parent 0adc9e71e5
commit f678477c88
39 changed files with 704 additions and 432 deletions

View File

@@ -13,7 +13,6 @@ namespace XCharts.Editor
if (MakeComponentFoldout(prop, "m_Enable", true)) if (MakeComponentFoldout(prop, "m_Enable", true))
{ {
++EditorGUI.indentLevel; ++EditorGUI.indentLevel;
//PropertyField(prop, "m_Type");
PropertyField(prop, "m_Delay"); PropertyField(prop, "m_Delay");
PropertyField(prop, "m_Duration"); PropertyField(prop, "m_Duration");
--EditorGUI.indentLevel; --EditorGUI.indentLevel;
@@ -21,6 +20,36 @@ namespace XCharts.Editor
} }
} }
[CustomPropertyDrawer(typeof(XCharts.Runtime.AnimationChange), true)]
public class AnimationChangeDrawer : 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(XCharts.Runtime.AnimationAddition), true)]
public class AnimationAdditionDrawer : 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)] [CustomPropertyDrawer(typeof(AnimationStyle), true)]
public class AnimationDrawer : BasePropertyDrawer public class AnimationDrawer : BasePropertyDrawer
{ {
@@ -33,10 +62,10 @@ namespace XCharts.Editor
++EditorGUI.indentLevel; ++EditorGUI.indentLevel;
PropertyField(prop, "m_Type"); PropertyField(prop, "m_Type");
PropertyField(prop, "m_UnscaledTime"); PropertyField(prop, "m_UnscaledTime");
PropertyField(prop, "m_FadeIn"); PropertyField(prop, "m_Fadein");
PropertyField(prop, "m_FadeOut"); PropertyField(prop, "m_Fadeout");
PropertyField(prop, "m_Updated"); PropertyField(prop, "m_Change");
PropertyField(prop, "m_Added"); PropertyField(prop, "m_Addition");
--EditorGUI.indentLevel; --EditorGUI.indentLevel;
} }
} }

View File

@@ -19,9 +19,9 @@ namespace XCharts.Example
var serie = chart.GetSerie(0); var serie = chart.GetSerie(0);
serie.animation.enable = true; serie.animation.enable = true;
//自定义每个数据项的渐入延时 //自定义每个数据项的渐入延时
serie.animation.fadeIn.delayFunction = CustomFadeInDelay; serie.animation.fadein.delayFunction = CustomFadeInDelay;
//自定义每个数据项的渐入时长 //自定义每个数据项的渐入时长
serie.animation.fadeIn.durationFunction = CustomFadeInDuration; serie.animation.fadein.durationFunction = CustomFadeInDuration;
} }
float CustomFadeInDelay(int dataIndex) float CustomFadeInDelay(int dataIndex)

View File

@@ -12,8 +12,16 @@ namespace XCharts.Example
//[ExecuteInEditMode] //[ExecuteInEditMode]
public class Example_RandomData : MonoBehaviour public class Example_RandomData : MonoBehaviour
{ {
public int initDataNum = 3; public bool loopAdd = false;
public float loopAddTime = 1f;
public bool loopUpdate = false;
public float loopUpadteTime = 1f;
public int maxCache = 0;
BaseChart chart; BaseChart chart;
float lastAddTime;
float lastUpdateTime;
int dataCount;
void Awake() void Awake()
{ {
@@ -22,9 +30,11 @@ namespace XCharts.Example
void Start() void Start()
{ {
//chart.ClearData(); if (maxCache > 0)
// for (int i = 0; i < initDataNum; i++) {
// AddData(); chart.SetMaxCache(maxCache);
}
dataCount = chart.GetSerie(0).dataCount;
} }
void Update() void Update()
@@ -37,6 +47,19 @@ namespace XCharts.Example
{ {
UpdateData(); UpdateData();
} }
lastAddTime += Time.deltaTime;
if (loopAdd && lastAddTime >= loopAddTime)
{
lastAddTime = 0;
AddData();
}
lastUpdateTime += Time.deltaTime;
if (loopUpdate && lastUpdateTime >= loopUpadteTime)
{
lastUpdateTime = 0;
UpdateData();
}
} }
void AddData() void AddData()
@@ -90,6 +113,9 @@ namespace XCharts.Example
} }
else else
{ {
if (serie is Line)
chart.AddData(serie.index, dataCount++, Random.Range(10, 90), "data" + serie.dataCount);
else
chart.AddData(serie.index, Random.Range(10, 90), Random.Range(10, 90), "data" + serie.dataCount); chart.AddData(serie.index, Random.Range(10, 90), Random.Range(10, 90), "data" + serie.dataCount);
} }
} }
@@ -123,7 +149,7 @@ namespace XCharts.Example
var index = Random.Range(0, serie.dataCount); var index = Random.Range(0, serie.dataCount);
if (serie is Ring) if (serie is Ring)
{ {
chart.UpdateData(serie.index, index, Random.Range(10, 90), 100); chart.UpdateData(serie.index, index, 0, Random.Range(10, 90));
} }
else if (serie is Radar) else if (serie is Radar)
{ {

View File

@@ -0,0 +1,305 @@
using System;
using UnityEngine;
namespace XCharts.Runtime
{
[Since("v3.8.0")]
[System.Serializable]
public class AnimationInfo
{
[SerializeField][Since("v3.8.0")] private bool m_Enable = true;
[SerializeField][Since("v3.8.0")] private bool m_Reverse = false;
[SerializeField][Since("v3.8.0")] private float m_Delay = 0;
[SerializeField][Since("v3.8.0")] private float m_Duration = 1000;
public AnimationInfoContext context = new AnimationInfoContext();
public bool enable { get { return m_Enable; } set { m_Enable = value; } }
public bool reverse { get { return m_Reverse; } set { m_Reverse = value; } }
public float delay { get { return m_Delay; } set { m_Delay = value; } }
public float duration { get { return m_Duration; } set { m_Duration = value; } }
public Action OnAnimationStart { get; set; }
public Action OnAnimationEnd { get; set; }
public AnimationDelayFunction delayFunction { get; set; }
public AnimationDurationFunction durationFunction { get; set; }
public void Reset()
{
if (!enable) return;
context.init = false;
context.start = false;
context.pause = false;
context.end = false;
context.startTime = 0;
context.itemCurrProgress.Clear();
}
public void Start(bool reset = true)
{
if (!enable) return;
if (context.start) return;
if (context.pause)
{
context.pause = false;
return;
}
context.init = false;
context.start = true;
context.end = false;
context.pause = false;
context.startTime = Time.time;
if (reset)
{
context.currProgress = 0;
context.destProgress = 1;
context.totalProgress = 0;
context.sizeProgress = 0;
context.itemCurrProgress.Clear();
context.itemDestProgress.Clear();
}
if (OnAnimationStart != null)
{
OnAnimationStart();
}
}
public void Pause()
{
if (!enable) return;
if (!context.start || context.end) return;
context.pause = true;
}
public void Resume()
{
if (!enable) return;
if (!context.pause) return;
context.pause = false;
}
public void End()
{
if (!enable) return;
if (!context.start || context.end) return;
context.start = false;
context.end = true;
context.currPointIndex = context.destPointIndex;
context.startTime = Time.time;
if (OnAnimationEnd != null)
{
OnAnimationEnd();
}
}
public bool Init(float curr, float dest, int totalPointIndex)
{
if (!enable || !context.start) return false;
if (context.init || context.end) return false;
context.init = true;
context.totalProgress = dest - curr;
context.destPointIndex = totalPointIndex;
if (reverse)
{
context.currProgress = dest;
context.destProgress = curr;
}
else
{
context.currProgress = curr;
context.destProgress = dest;
}
return true;
}
public bool IsFinish()
{
if (!context.start) return true;
if (context.end) return true;
if (context.pause) return false;
return context.currProgress == context.destProgress;
}
public bool IsInDelay()
{
if (!context.start)
return false;
else
return (m_Delay > 0 && Time.time - context.startTime < m_Delay / 1000);
}
public bool IsInIndexDelay(int dataIndex)
{
if (context.start)
return Time.time - context.startTime < GetIndexDelay(dataIndex) / 1000f;
else
return false;
}
public float GetIndexDelay(int dataIndex)
{
if (!context.start) return 0;
if (delayFunction != null)
return delayFunction(dataIndex);
return delay;
}
internal float GetCurrAnimationDuration(int dataIndex = -1)
{
if (dataIndex >= 0)
{
if (context.start && durationFunction != null)
return durationFunction(dataIndex) / 1000f;
}
return m_Duration > 0 ? m_Duration / 1000 : 1f;
}
internal void SetDataCurrProgress(int index, float state)
{
context.itemCurrProgress[index] = state;
}
internal float GetDataCurrProgress(int index, float initValue, float destValue, ref bool isBarEnd)
{
if (IsInDelay())
{
isBarEnd = false;
return initValue;
}
var c1 = !context.itemCurrProgress.ContainsKey(index);
var c2 = !context.itemDestProgress.ContainsKey(index);
if (c1 || c2)
{
if (c1)
context.itemCurrProgress.Add(index, initValue);
if (c2)
context.itemDestProgress.Add(index, destValue);
isBarEnd = false;
}
else
{
isBarEnd = context.itemCurrProgress[index] == context.itemDestProgress[index];
}
return context.itemCurrProgress[index];
}
internal void CheckProgress(double total, bool m_UnscaledTime)
{
if (!context.start || !context.init || context.pause) return;
if (IsInDelay()) return;
var duration = GetCurrAnimationDuration();
var delta = (float)(total / duration * (m_UnscaledTime ? Time.unscaledDeltaTime : Time.deltaTime));
if (reverse)
{
context.currProgress -= delta;
if (context.currProgress <= context.destProgress)
{
context.currProgress = context.destProgress;
End();
}
}
else
{
context.currProgress += delta;
if (context.currProgress >= context.destProgress)
{
context.currProgress = context.destProgress;
End();
}
}
}
internal float CheckItemProgress(int dataIndex, float destProgress, ref bool isEnd, float startProgress, bool m_UnscaledTime)
{
var currHig = GetDataCurrProgress(dataIndex, startProgress, destProgress, ref isEnd);
if (IsFinish())
{
return reverse ? startProgress : destProgress;
}
else if (IsInDelay() || IsInIndexDelay(dataIndex))
{
return reverse ? destProgress : startProgress;
}
else if (context.pause)
{
return currHig;
}
else
{
var duration = GetCurrAnimationDuration(dataIndex);
var delta = (destProgress - startProgress) / duration * (m_UnscaledTime ? Time.unscaledDeltaTime : Time.deltaTime);
currHig = currHig + (reverse ? -delta : delta);
if (reverse)
{
if ((destProgress > 0 && currHig <= 0) || (destProgress < 0 && currHig >= 0))
{
currHig = 0;
isEnd = true;
}
}
else
{
if ((destProgress - startProgress > 0 && currHig > destProgress) ||
(destProgress - startProgress < 0 && currHig < destProgress))
{
currHig = destProgress;
isEnd = true;
}
}
SetDataCurrProgress(dataIndex, currHig);
return currHig;
}
}
internal void CheckSymbol(float dest, bool m_UnscaledTime)
{
if (!context.start || !context.init || context.pause) return;
if (IsInDelay())
return;
var duration = GetCurrAnimationDuration();
var delta = dest / duration * (m_UnscaledTime ? Time.unscaledDeltaTime : Time.deltaTime);
if (reverse)
{
context.sizeProgress -= delta;
if (context.sizeProgress < 0)
context.sizeProgress = 0;
}
else
{
context.sizeProgress += delta;
if (context.sizeProgress > dest)
context.sizeProgress = dest;
}
}
}
[Since("v3.8.0")]
[System.Serializable]
public class AnimationFadeIn : AnimationInfo
{
}
[Since("v3.8.0")]
[System.Serializable]
public class AnimationFadeOut : AnimationInfo
{
}
[Since("v3.8.0")]
[System.Serializable]
public class AnimationChange : AnimationInfo
{
}
[Since("v3.8.0")]
[System.Serializable]
public class AnimationAddition : AnimationInfo
{
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ae54b92d6276445ac9524b598bfb6e84
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace XCharts.Runtime
{
public sealed class AnimationInfoContext
{
public bool init;
public bool start;
public bool pause;
public bool end;
public float startTime;
public float currProgress;
public float destProgress;
public float totalProgress;
public float sizeProgress;
public int currPointIndex;
public int destPointIndex;
public Dictionary<int, float> itemCurrProgress = new Dictionary<int, float>();
public Dictionary<int, float> itemDestProgress = new Dictionary<int, float>();
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 023c7390605c34a72b13f5db7a647f06
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -43,55 +43,9 @@ namespace XCharts.Runtime
Linear, Linear,
} }
[Since("v3.8.0")]
[System.Serializable]
public class AnimationInfo
{
[SerializeField][Since("v3.8.0")] private bool m_Enable = true;
[SerializeField][Since("v3.8.0")] private float m_Delay = 0;
[SerializeField][Since("v3.8.0")] private float m_Duration = 1000;
public bool enable { get { return m_Enable; } set { m_Enable = value; } }
public float delay { get { return m_Delay; } set { m_Delay = value; } }
public float duration { get { return m_Duration; } set { m_Duration = value; } }
public Action OnAnimationStart { get; set; }
public Action OnAnimationEnd { get; set; }
public AnimationDelayFunction delayFunction { get; set; }
public AnimationDurationFunction durationFunction { get; set; }
internal bool start { get; set; }
internal bool end { get; set; }
}
[Since("v3.8.0")]
[System.Serializable]
public class AnimationFadeIn : AnimationInfo
{
}
[Since("v3.8.0")]
[System.Serializable]
public class AnimationFadeOut : AnimationInfo
{
}
[Since("v3.8.0")]
[System.Serializable]
public class AnimationUpdated : AnimationInfo
{
}
[Since("v3.8.0")]
[System.Serializable]
public class AnimationAdded : AnimationInfo
{
}
/// <summary> /// <summary>
/// the animation of serie. /// the animation of serie. support animation type: fadeIn, fadeOut, change, addition.
/// |动画表现。 /// |动画表现。支持配置四种动画表现FadeIn渐入动画FadeOut渐出动画Change变更动画Addition新增动画
/// </summary> /// </summary>
[System.Serializable] [System.Serializable]
public class AnimationStyle : ChildComponent public class AnimationStyle : ChildComponent
@@ -101,10 +55,10 @@ namespace XCharts.Runtime
[SerializeField] private AnimationEasing m_Easting; [SerializeField] private AnimationEasing m_Easting;
[SerializeField] private int m_Threshold = 2000; [SerializeField] private int m_Threshold = 2000;
[SerializeField][Since("v3.4.0")] private bool m_UnscaledTime; [SerializeField][Since("v3.4.0")] private bool m_UnscaledTime;
[SerializeField][Since("v3.8.0")] private AnimationFadeIn m_FadeIn = new AnimationFadeIn(); [SerializeField][Since("v3.8.0")] private AnimationFadeIn m_Fadein = new AnimationFadeIn();
[SerializeField][Since("v3.8.0")] private AnimationFadeOut m_FadeOut = new AnimationFadeOut(); [SerializeField][Since("v3.8.0")] private AnimationFadeOut m_Fadeout = new AnimationFadeOut() { reverse = true };
[SerializeField][Since("v3.8.0")] private AnimationUpdated m_Updated = new AnimationUpdated() { duration = 500 }; [SerializeField][Since("v3.8.0")] private AnimationChange m_Change = new AnimationChange() { duration = 500 };
[SerializeField][Since("v3.8.0")] private AnimationAdded m_Added = new AnimationAdded() { duration = 500 }; [SerializeField][Since("v3.8.0")] private AnimationAddition m_Addition = new AnimationAddition() { duration = 500 };
[Obsolete("Use animation.fadeIn.delayFunction instead.", true)] [Obsolete("Use animation.fadeIn.delayFunction instead.", true)]
public AnimationDelayFunction fadeInDelayFunction; public AnimationDelayFunction fadeInDelayFunction;
@@ -144,168 +98,146 @@ namespace XCharts.Runtime
/// Fade in animation configuration. /// Fade in animation configuration.
/// |渐入动画配置。 /// |渐入动画配置。
/// </summary> /// </summary>
public AnimationFadeIn fadeIn { get { return m_FadeIn; } } public AnimationFadeIn fadein { get { return m_Fadein; } }
/// <summary> /// <summary>
/// Fade out animation configuration. /// Fade out animation configuration.
/// |渐出动画配置。 /// |渐出动画配置。
/// </summary> /// </summary>
public AnimationFadeOut fadeOut { get { return m_FadeOut; } } public AnimationFadeOut fadeout { get { return m_Fadeout; } }
/// <summary> /// <summary>
/// Update data animation configuration. /// Update data animation configuration.
/// |更新数据动画配置。 /// |数据变更动画配置。
/// </summary> /// </summary>
public AnimationUpdated updated { get { return m_Updated; } } public AnimationChange change { get { return m_Change; } }
/// <summary> /// <summary>
/// Add data animation configuration. /// Add data animation configuration.
/// |添加数据动画配置。 /// |数据新增动画配置。
/// </summary> /// </summary>
public AnimationAdded added { get { return m_Added; } } public AnimationAddition addition { get { return m_Addition; } }
private Dictionary<int, float> m_ItemCurrProgress = new Dictionary<int, float>();
private Dictionary<int, float> m_ItemDestProgress = new Dictionary<int, float>();
private bool m_IsEnd = true;
private bool m_IsPause = false;
private bool m_IsInit = false;
private float startTime { get; set; }
private float m_CurrDetailProgress;
private float m_DestDetailProgress;
private float m_TotalDetailProgress;
private float m_CurrSymbolProgress;
private Vector3 m_LinePathLastPos; private Vector3 m_LinePathLastPos;
private List<AnimationInfo> m_Animations;
public void FadeIn() private List<AnimationInfo> animations
{ {
if (m_FadeOut.start) get
return;
if (m_IsPause)
{ {
m_IsPause = false; if (m_Animations == null)
return; {
m_Animations = new List<AnimationInfo>();
m_Animations.Add(m_Fadein);
m_Animations.Add(m_Fadeout);
m_Animations.Add(m_Change);
m_Animations.Add(m_Addition);
}
return m_Animations;
}
} }
if (m_FadeIn.start) public AnimationInfo activedAnimation
return; {
get
{
foreach (var anim in animations)
{
if (anim.context.start) return anim;
}
return null;
}
}
startTime = Time.time; public void Fadein()
m_FadeIn.start = true; {
m_IsEnd = false; if (m_Fadeout.context.start) return;
m_IsInit = false; m_Fadein.Start();
m_IsPause = false;
m_FadeOut.end = false;
m_CurrDetailProgress = 0;
m_DestDetailProgress = 1;
m_CurrSymbolProgress = 0;
m_ItemCurrProgress.Clear();
m_ItemDestProgress.Clear();
} }
public void Restart() public void Restart()
{ {
var anim = activedAnimation;
Reset(); Reset();
FadeIn(); if (anim != null)
{
anim.Start();
}
} }
public void FadeOut() public void Fadeout()
{ {
if (m_IsPause) m_Fadeout.Start();
{
m_IsPause = false;
return;
} }
m_FadeOut.start = true; public void Addition()
startTime = Time.time; {
m_FadeIn.start = true; if (!enable) return;
m_IsEnd = false; if (!m_Fadein.context.start && !m_Fadeout.context.start)
m_IsInit = false; {
m_IsPause = false; m_Addition.Start(false);
m_CurrDetailProgress = 0; }
m_DestDetailProgress = 1;
m_CurrSymbolProgress = 0;
m_ItemCurrProgress.Clear();
m_ItemDestProgress.Clear();
} }
public void Pause() public void Pause()
{ {
if (!m_IsPause) foreach (var anim in animations)
{ {
m_IsPause = true; anim.Pause();
} }
} }
public void Resume() public void Resume()
{ {
if (m_IsPause) foreach (var anim in animations)
{ {
m_IsPause = false; anim.Resume();
}
}
private void End()
{
if (m_IsEnd)
return;
m_IsEnd = true;
m_IsInit = false;
if (m_FadeIn.start)
{
m_FadeIn.start = false;
if (m_FadeIn.OnAnimationEnd != null)
{
m_FadeIn.OnAnimationEnd();
}
}
if (m_FadeOut.start)
{
m_FadeOut.start = false;
m_FadeOut.end = true;
if (m_FadeOut.OnAnimationEnd != null)
{
m_FadeOut.OnAnimationEnd();
}
} }
} }
public void Reset() public void Reset()
{ {
m_FadeIn.start = false; m_Fadein.Reset();
m_IsEnd = true; m_Fadeout.Reset();
m_IsInit = false;
m_IsPause = false;
m_FadeOut.start = false;
m_FadeOut.end = false;
m_ItemCurrProgress.Clear();
} }
public void InitProgress(float curr, float dest) public void InitProgress(float curr, float dest)
{ {
if (m_IsInit || m_IsEnd) var anim = activedAnimation;
return; if (anim == null) return;
var isAddedAnim = anim is AnimationAddition;
m_IsInit = true; if (IsIndexAnimation())
m_TotalDetailProgress = dest - curr;
if (m_FadeOut.start)
{ {
m_CurrDetailProgress = dest; if (isAddedAnim)
m_DestDetailProgress = curr; {
anim.Init(anim.context.currPointIndex, dest, (int)dest - 1);
} }
else else
{ {
m_CurrDetailProgress = curr; m_Addition.context.currPointIndex = (int)dest - 1;
m_DestDetailProgress = dest; anim.Init(curr, dest, (int)dest - 1);
}
}
else
{
anim.Init(curr, dest, 0);
} }
} }
public void InitProgress(List<Vector3> paths, bool isY) public void InitProgress(List<Vector3> paths, bool isY)
{ {
if (paths.Count < 1) return; if (paths.Count < 1) return;
var sp = paths[0]; var anim = activedAnimation;
if (anim == null) return;
var isAddedAnim = anim is AnimationAddition;
var startIndex = 0;
if (isAddedAnim)
{
startIndex = anim.context.currPointIndex == paths.Count - 1 ?
paths.Count - 2 :
anim.context.currPointIndex;
}
else
{
m_Addition.context.currPointIndex = paths.Count - 1;
}
var sp = paths[startIndex];
var ep = paths[paths.Count - 1]; var ep = paths[paths.Count - 1];
var currDetailProgress = isY ? sp.y : sp.x; var currDetailProgress = isY ? sp.y : sp.x;
var totalDetailProgress = isY ? ep.y : ep.x; var totalDetailProgress = isY ? ep.y : ep.x;
@@ -319,43 +251,25 @@ namespace XCharts.Runtime
var np = paths[i]; var np = paths[i];
totalDetailProgress += Vector3.Distance(np, lp); totalDetailProgress += Vector3.Distance(np, lp);
lp = np; lp = np;
if (startIndex > 0 && i == startIndex)
currDetailProgress = totalDetailProgress;
} }
m_LinePathLastPos = sp; m_LinePathLastPos = sp;
context.currentPathDistance = 0; context.currentPathDistance = 0;
} }
InitProgress(currDetailProgress, totalDetailProgress); anim.Init(currDetailProgress, totalDetailProgress, paths.Count - 1);
} }
private void SetDataCurrProgress(int index, float state) public bool IsEnd()
{ {
m_ItemCurrProgress[index] = state; foreach (var animation in animations)
{
if (animation.context.start)
return animation.context.end;
}
return m_Fadein.context.end;
} }
private float GetDataCurrProgress(int index, float initValue, float destValue, ref bool isBarEnd)
{
if (IsInDelay())
{
isBarEnd = false;
return initValue;
}
var c1 = !m_ItemCurrProgress.ContainsKey(index);
var c2 = !m_ItemDestProgress.ContainsKey(index);
if (c1 || c2)
{
if (c1)
m_ItemCurrProgress.Add(index, initValue);
if (c2)
m_ItemDestProgress.Add(index, destValue);
isBarEnd = false;
}
else
{
isBarEnd = m_ItemCurrProgress[index] == m_ItemDestProgress[index];
}
return m_ItemCurrProgress[index];
}
public bool IsFinish() public bool IsFinish()
{ {
@@ -363,29 +277,34 @@ namespace XCharts.Runtime
if (!Application.isPlaying) if (!Application.isPlaying)
return true; return true;
#endif #endif
if (!m_Enable || m_IsEnd) if (!m_Enable)
return true; return true;
foreach (var animation in animations)
{
if (animation.context.start && animation.context.end)
{
return true;
}
}
if (IsIndexAnimation()) if (IsIndexAnimation())
{ {
if (m_FadeOut.start) return m_CurrDetailProgress <= m_DestDetailProgress; if (m_Fadeout.context.start) return m_Fadeout.context.currProgress <= m_Fadeout.context.destProgress;
else return m_CurrDetailProgress > m_DestDetailProgress; else if (m_Addition.context.start) return m_Addition.context.currProgress >= m_Addition.context.destProgress;
else return m_Fadein.context.currProgress >= m_Fadein.context.destProgress;
} }
if (IsItemAnimation()) else if (IsItemAnimation())
return false;
return true;
}
public bool IsInFadeOut()
{ {
return m_FadeOut.start; return false;
}
return true;
} }
public bool IsInDelay() public bool IsInDelay()
{ {
if (m_FadeOut.start) var anim = activedAnimation;
return (m_FadeOut.delay > 0 && Time.time - startTime < m_FadeOut.delay / 1000); if (anim != null)
else return anim.IsInDelay();
return (m_FadeIn.delay > 0 && Time.time - startTime < m_FadeIn.delay / 1000); return false;
} }
public bool IsItemAnimation() public bool IsItemAnimation()
@@ -396,41 +315,19 @@ namespace XCharts.Runtime
public bool IsIndexAnimation() public bool IsIndexAnimation()
{ {
return context.type == AnimationType.LeftToRight || return context.type == AnimationType.LeftToRight ||
context.type == AnimationType.Clockwise || context.type == AnimationType.AlongPath || context.type == AnimationType.Clockwise;
context.type == AnimationType.AlongPath;
}
public float GetIndexDelay(int dataIndex)
{
if (m_FadeOut.start && m_FadeOut.delayFunction != null)
return m_FadeOut.delayFunction(dataIndex);
else if (m_FadeIn.start && m_FadeIn.delayFunction != null)
return m_FadeIn.delayFunction(dataIndex);
else
return 0;
}
public bool IsInIndexDelay(int dataIndex)
{
return Time.time - startTime < GetIndexDelay(dataIndex) / 1000f;
}
public bool IsAllOutDelay(int dataCount)
{
var nowTime = Time.time - startTime;
for (int i = 0; i < dataCount; i++)
{
if (nowTime < GetIndexDelay(i) / 1000)
return false;
}
return true;
} }
public bool CheckDetailBreak(float detail) public bool CheckDetailBreak(float detail)
{ {
if (!IsIndexAnimation()) if (!IsIndexAnimation())
return false; return false;
return !IsFinish() && detail > m_CurrDetailProgress; foreach (var animation in animations)
{
if (animation.context.start)
return !IsFinish() && detail > animation.context.currProgress;
}
return false;
} }
public bool CheckDetailBreak(Vector3 pos, bool isYAxis) public bool CheckDetailBreak(Vector3 pos, bool isYAxis)
@@ -450,9 +347,9 @@ namespace XCharts.Runtime
else else
{ {
if (isYAxis) if (isYAxis)
return pos.y > m_CurrDetailProgress; return pos.y > GetCurrDetail();
else else
return pos.x > m_CurrDetailProgress; return pos.x > GetCurrDetail();
} }
} }
@@ -460,128 +357,40 @@ namespace XCharts.Runtime
{ {
if (IsItemAnimation() && context.isAllItemAnimationEnd) if (IsItemAnimation() && context.isAllItemAnimationEnd)
{ {
End(); foreach (var animation in animations)
{
animation.End();
}
return; return;
} }
CheckProgress(m_TotalDetailProgress); foreach (var animation in animations)
{
animation.CheckProgress(animation.context.totalProgress, m_UnscaledTime);
}
} }
public void CheckProgress(double total) public void CheckProgress(double total)
{ {
if (IsFinish()) if (IsFinish())
return; return;
foreach (var animation in animations)
if (!m_IsInit || m_IsPause || m_IsEnd)
return;
if (IsInDelay())
return;
var duration = GetCurrAnimationDuration();
var delta = (float)(total / duration * (m_UnscaledTime ? Time.unscaledDeltaTime : Time.deltaTime));
if (m_FadeOut.start)
{ {
m_CurrDetailProgress -= delta; animation.CheckProgress(total, m_UnscaledTime);
if (m_CurrDetailProgress <= m_DestDetailProgress)
{
m_CurrDetailProgress = m_DestDetailProgress;
End();
} }
} }
else
{
m_CurrDetailProgress += delta;
if (m_CurrDetailProgress >= m_DestDetailProgress)
{
m_CurrDetailProgress = m_DestDetailProgress;
End();
}
}
}
internal float GetCurrAnimationDuration(int dataIndex = -1)
{
if (dataIndex >= 0)
{
if (m_FadeOut.start && m_FadeOut.durationFunction != null)
return m_FadeOut.durationFunction(dataIndex) / 1000f;
if (m_FadeIn.start && m_FadeIn.durationFunction != null)
return m_FadeIn.durationFunction(dataIndex) / 1000f;
}
if (m_FadeOut.start)
return m_FadeOut.delay > 0 ? m_FadeOut.delay / 1000 : 1f;
else
return m_FadeIn.delay > 0 ? m_FadeIn.delay / 1000 : 1f;
}
internal float CheckItemProgress(int dataIndex, float destProgress, ref bool isEnd, float startProgress = 0) internal float CheckItemProgress(int dataIndex, float destProgress, ref bool isEnd, float startProgress = 0)
{ {
isEnd = false; isEnd = false;
var initHig = m_FadeOut.start ? destProgress : startProgress; var anim = activedAnimation;
var destHig = m_FadeOut.start ? startProgress : destProgress; if (anim == null) return destProgress;
var currHig = GetDataCurrProgress(dataIndex, initHig, destHig, ref isEnd); return anim.CheckItemProgress(dataIndex, destProgress, ref isEnd, startProgress, m_UnscaledTime);
if (isEnd || IsFinish())
{
return m_FadeOut.end ? startProgress : destProgress;
}
else if (IsInDelay() || IsInIndexDelay(dataIndex))
{
return m_FadeOut.start ? destProgress : startProgress;
}
else if (m_IsPause)
{
return currHig;
}
else
{
var duration = GetCurrAnimationDuration(dataIndex);
var delta = (destProgress - startProgress) / duration * (m_UnscaledTime ? Time.unscaledDeltaTime : Time.deltaTime);
currHig = currHig + (m_FadeOut.start ? -delta : delta);
if (m_FadeOut.start)
{
if ((initHig > 0 && currHig <= 0) || (initHig < 0 && currHig >= 0))
{
currHig = 0;
isEnd = true;
}
}
else
{
if ((destProgress - startProgress > 0 && currHig > destProgress) ||
(destProgress - startProgress < 0 && currHig < destProgress))
{
currHig = destProgress;
isEnd = true;
}
}
SetDataCurrProgress(dataIndex, currHig);
return currHig;
}
} }
public void CheckSymbol(float dest) public void CheckSymbol(float dest)
{ {
if (!enable || m_IsEnd || m_IsPause || !m_IsInit) m_Fadein.CheckSymbol(dest, m_UnscaledTime);
return; m_Fadeout.CheckSymbol(dest, m_UnscaledTime);
if (IsInDelay())
return;
var duration = GetCurrAnimationDuration();
var delta = dest / duration * (m_UnscaledTime ? Time.unscaledDeltaTime : Time.deltaTime);
if (m_FadeOut.start)
{
m_CurrSymbolProgress -= delta;
if (m_CurrSymbolProgress < 0)
m_CurrSymbolProgress = 0;
}
else
{
m_CurrSymbolProgress += delta;
if (m_CurrSymbolProgress > dest)
m_CurrSymbolProgress = dest;
}
} }
public float GetSysmbolSize(float dest) public float GetSysmbolSize(float dest)
@@ -593,19 +402,30 @@ namespace XCharts.Runtime
if (!enable) if (!enable)
return dest; return dest;
if (m_IsEnd) if (IsEnd())
return m_FadeOut.start ? 0 : dest; return m_Fadeout.context.start ? 0 : dest;
return m_CurrSymbolProgress; return m_Fadeout.context.start ? m_Fadeout.context.sizeProgress : m_Fadein.context.sizeProgress;
} }
public float GetCurrDetail() public float GetCurrDetail()
{ {
#if UNITY_EDITOR #if UNITY_EDITOR
if (!Application.isPlaying) if (!Application.isPlaying)
return m_DestDetailProgress; {
foreach (var animation in animations)
{
if (animation.context.start)
return animation.context.destProgress;
}
}
#endif #endif
return m_CurrDetailProgress; foreach (var animation in animations)
{
if (animation.context.start)
return animation.context.currProgress;
}
return m_Fadein.context.currProgress;
} }
public float GetCurrRate() public float GetCurrRate()
@@ -614,9 +434,9 @@ namespace XCharts.Runtime
if (!Application.isPlaying) if (!Application.isPlaying)
return 1; return 1;
#endif #endif
if (!enable || m_IsEnd) if (!enable || IsEnd())
return 1; return 1;
return m_CurrDetailProgress; return m_Fadeout.context.start ? m_Fadeout.context.currProgress : m_Fadein.context.currProgress;
} }
public int GetCurrIndex() public int GetCurrIndex()
@@ -625,30 +445,33 @@ namespace XCharts.Runtime
if (!Application.isPlaying) if (!Application.isPlaying)
return -1; return -1;
#endif #endif
if (!enable || m_IsEnd) if (!enable)
return -1; return -1;
return (int)m_CurrDetailProgress; var anim = activedAnimation;
if (anim == null)
return -1;
return (int)anim.context.currProgress;
} }
public float GetDataChangeDuration() public float GetChangeDuration()
{ {
if (m_Enable && m_Updated.enable) if (m_Enable && m_Change.enable)
return m_Updated.duration; return m_Change.duration;
else else
return 0; return 0;
} }
public float GetDataAddDuration() public float GetAdditionDuration()
{ {
if (m_Enable && m_Added.enable) if (m_Enable && m_Addition.enable)
return m_Added.duration; return m_Addition.duration;
else else
return 0; return 0;
} }
public bool HasFadeOut() public bool HasFadeout()
{ {
return enable && m_FadeOut.end && m_IsEnd; return enable && m_Fadeout.context.end;
} }
} }
} }

View File

@@ -7,6 +7,7 @@ namespace XCharts.Runtime
public struct AnimationStyleContext public struct AnimationStyleContext
{ {
public AnimationType type; public AnimationType type;
public bool enableSerieDataAddedAnimation;
public float currentPathDistance; public float currentPathDistance;
public bool isAllItemAnimationEnd; public bool isAllItemAnimationEnd;
} }

View File

@@ -30,18 +30,22 @@ namespace XCharts.Runtime
{ {
var serieType = serie.GetType(); var serieType = serie.GetType();
var animationType = AnimationType.LeftToRight; var animationType = AnimationType.LeftToRight;
var enableSerieDataAnimation = true;
if (serieType.IsDefined(typeof(DefaultAnimationAttribute), false)) if (serieType.IsDefined(typeof(DefaultAnimationAttribute), false))
{ {
animationType = serieType.GetAttribute<DefaultAnimationAttribute>().type; var attribute = serieType.GetAttribute<DefaultAnimationAttribute>();
animationType = attribute.type;
enableSerieDataAnimation = attribute.enableSerieDataAddedAnimation;
} }
UpdateAnimationType(serie.animation, animationType); UpdateAnimationType(serie.animation, animationType,enableSerieDataAnimation);
} }
public static void UpdateAnimationType(AnimationStyle animation, AnimationType defaultType) public static void UpdateAnimationType(AnimationStyle animation, AnimationType defaultType, bool enableSerieDataAnimation)
{ {
animation.context.type = animation.type == AnimationType.Default ? animation.context.type = animation.type == AnimationType.Default ?
defaultType : defaultType :
animation.type; animation.type;
animation.context.enableSerieDataAddedAnimation = enableSerieDataAnimation;
} }
public static bool GetAnimationPosition(AnimationStyle animation, bool isY, Vector3 lp, Vector3 cp, float progress, ref Vector3 ip) public static bool GetAnimationPosition(AnimationStyle animation, bool isY, Vector3 lp, Vector3 cp, float progress, ref Vector3 ip)

View File

@@ -152,7 +152,6 @@ namespace XCharts
else else
dataZoom.SetYAxisIndexValueInfo(axisIndex, ref tempMinValue, ref tempMaxValue); dataZoom.SetYAxisIndexValueInfo(axisIndex, ref tempMinValue, ref tempMaxValue);
} }
if (tempMinValue != axis.context.minValue || if (tempMinValue != axis.context.minValue ||
tempMaxValue != axis.context.maxValue || tempMaxValue != axis.context.maxValue ||
m_LastInterval != axis.interval || m_LastInterval != axis.interval ||

View File

@@ -543,8 +543,8 @@ namespace XCharts.Runtime
var totalAverage = serie.sampleAverage > 0 ? serie.sampleAverage : var totalAverage = serie.sampleAverage > 0 ? serie.sampleAverage :
DataHelper.DataAverage(ref showData, serie.sampleType, serie.minShow, maxCount, rate); DataHelper.DataAverage(ref showData, serie.sampleType, serie.minShow, maxCount, rate);
var dataChanging = false; var dataChanging = false;
var animationDuration = serie.animation.GetDataChangeDuration(); var animationDuration = serie.animation.GetChangeDuration();
var dataAddDuration = serie.animation.GetDataAddDuration(); var dataAddDuration = serie.animation.GetAdditionDuration();
var unscaledTime = serie.animation.unscaledTime; var unscaledTime = serie.animation.unscaledTime;
for (int i = 0; i < maxCount; i += rate) for (int i = 0; i < maxCount; i += rate)
@@ -635,8 +635,8 @@ namespace XCharts.Runtime
var totalAverage = serie.sampleAverage > 0 ? serie.sampleAverage : var totalAverage = serie.sampleAverage > 0 ? serie.sampleAverage :
DataHelper.DataAverage(ref showData, serie.sampleType, serie.minShow, maxCount, rate); DataHelper.DataAverage(ref showData, serie.sampleType, serie.minShow, maxCount, rate);
var dataChanging = false; var dataChanging = false;
var animationDuration = serie.animation.GetDataChangeDuration(); var animationDuration = serie.animation.GetChangeDuration();
var dataAddDuration = serie.animation.GetDataAddDuration(); var dataAddDuration = serie.animation.GetAdditionDuration();
var unscaledTime = serie.animation.unscaledTime; var unscaledTime = serie.animation.unscaledTime;
for (int i = 0; i < maxCount; i += rate) for (int i = 0; i < maxCount; i += rate)

View File

@@ -6,10 +6,17 @@ namespace XCharts.Runtime
public sealed class DefaultAnimationAttribute : Attribute public sealed class DefaultAnimationAttribute : Attribute
{ {
public readonly AnimationType type; public readonly AnimationType type;
public readonly bool enableSerieDataAddedAnimation = true;
public DefaultAnimationAttribute(AnimationType handler) public DefaultAnimationAttribute(AnimationType handler)
{ {
this.type = handler; this.type = handler;
} }
public DefaultAnimationAttribute(AnimationType handler, bool enableSerieDataAddedAnimation)
{
this.type = handler;
this.enableSerieDataAddedAnimation = enableSerieDataAddedAnimation;
}
} }
} }

View File

@@ -395,20 +395,30 @@ namespace XCharts.Runtime
/// fadeIn animation. /// fadeIn animation.
/// |开始渐入动画。 /// |开始渐入动画。
/// </summary> /// </summary>
public void AnimationFadeIn(bool reset = true) public void AnimationFadein(bool reset = true)
{ {
if (reset) if (reset)
AnimationReset(); AnimationReset();
foreach (var serie in m_Series) serie.AnimationFadeIn(); foreach (var serie in m_Series) serie.AnimationFadein();
}
[Obsolete("Use AnimationFadein() instead.", true)]
public void AnimationFadeIn(bool reset = true)
{
} }
/// <summary> /// <summary>
/// fadeIn animation. /// fadeIn animation.
/// |开始渐出动画。 /// |开始渐出动画。
/// </summary> /// </summary>
public void AnimationFadeout()
{
foreach (var serie in m_Series) serie.AnimationFadeout();
}
[Obsolete("Use AnimationFadeout() instead.", true)]
public void AnimationFadeOut() public void AnimationFadeOut()
{ {
foreach (var serie in m_Series) serie.AnimationFadeOut();
} }
/// <summary> /// <summary>

View File

@@ -649,7 +649,7 @@ namespace XCharts.Runtime
serie.show = active; serie.show = active;
serie.RefreshLabel(); serie.RefreshLabel();
serie.AnimationReset(); serie.AnimationReset();
if (active) serie.AnimationFadeIn(); if (active) serie.AnimationFadein();
UpdateLegendColor(serie.serieName, active); UpdateLegendColor(serie.serieName, active);
} }

View File

@@ -136,7 +136,7 @@ namespace XCharts.Runtime
InitComponentHandlers(); InitComponentHandlers();
InitSerieHandlers(); InitSerieHandlers();
AnimationReset(); AnimationReset();
AnimationFadeIn(); AnimationFadein();
XChartsMgr.AddChart(this); XChartsMgr.AddChart(this);
} }
@@ -416,7 +416,7 @@ namespace XCharts.Runtime
if (!m_CheckAnimation) if (!m_CheckAnimation)
{ {
m_CheckAnimation = true; m_CheckAnimation = true;
AnimationFadeIn(); AnimationFadein();
} }
} }
@@ -590,7 +590,7 @@ namespace XCharts.Runtime
serie.context.dataIndexs.Clear(); serie.context.dataIndexs.Clear();
serie.context.dataIgnores.Clear(); serie.context.dataIgnores.Clear();
serie.animation.context.isAllItemAnimationEnd = true; serie.animation.context.isAllItemAnimationEnd = true;
if (serie.show && !serie.animation.HasFadeOut()) if (serie.show && !serie.animation.HasFadeout())
{ {
if (!serie.context.pointerEnter) if (!serie.context.pointerEnter)
serie.ResetInteract(); serie.ResetInteract();

View File

@@ -142,7 +142,7 @@ namespace XCharts.Runtime
private void DrawBarSerie(VertexHelper vh, Bar serie) private void DrawBarSerie(VertexHelper vh, Bar serie)
{ {
if (!serie.show || serie.animation.HasFadeOut()) if (!serie.show || serie.animation.HasFadeout())
return; return;
Axis axis; Axis axis;
@@ -184,8 +184,8 @@ namespace XCharts.Runtime
showData.Count; showData.Count;
var isPercentStack = SeriesHelper.IsPercentStack<Bar>(chart.series, serie.stack); var isPercentStack = SeriesHelper.IsPercentStack<Bar>(chart.series, serie.stack);
bool dataChanging = false; bool dataChanging = false;
float dataChangeDuration = serie.animation.GetDataChangeDuration(); float dataChangeDuration = serie.animation.GetChangeDuration();
var dataAddDuration = serie.animation.GetDataAddDuration(); var dataAddDuration = serie.animation.GetAdditionDuration();
double yMinValue = relativedAxis.context.minValue; double yMinValue = relativedAxis.context.minValue;
double yMaxValue = relativedAxis.context.maxValue; double yMaxValue = relativedAxis.context.maxValue;

View File

@@ -7,7 +7,7 @@ namespace XCharts.Runtime
[SerieHandler(typeof(SimplifiedBarHandler), true)] [SerieHandler(typeof(SimplifiedBarHandler), true)]
[SerieConvert(typeof(SimplifiedLine), typeof(Bar))] [SerieConvert(typeof(SimplifiedLine), typeof(Bar))]
[CoordOptions(typeof(GridCoord))] [CoordOptions(typeof(GridCoord))]
[DefaultAnimation(AnimationType.LeftToRight)] [DefaultAnimation(AnimationType.LeftToRight, false)]
[SerieComponent()] [SerieComponent()]
[SerieDataComponent()] [SerieDataComponent()]
[SerieDataExtraField()] [SerieDataExtraField()]

View File

@@ -97,7 +97,7 @@ namespace XCharts.Runtime
private void DrawBarSerie(VertexHelper vh, SimplifiedBar serie, int colorIndex) private void DrawBarSerie(VertexHelper vh, SimplifiedBar serie, int colorIndex)
{ {
if (!serie.show || serie.animation.HasFadeOut()) if (!serie.show || serie.animation.HasFadeout())
return; return;
Axis axis; Axis axis;
@@ -134,8 +134,8 @@ namespace XCharts.Runtime
showData.Count; showData.Count;
bool dataChanging = false; bool dataChanging = false;
float dataChangeDuration = serie.animation.GetDataChangeDuration(); float dataChangeDuration = serie.animation.GetChangeDuration();
var dataAddDuration = serie.animation.GetDataAddDuration(); var dataAddDuration = serie.animation.GetAdditionDuration();
double yMinValue = relativedAxis.context.minValue; double yMinValue = relativedAxis.context.minValue;
double yMaxValue = relativedAxis.context.maxValue; double yMaxValue = relativedAxis.context.maxValue;

View File

@@ -4,7 +4,7 @@ namespace XCharts.Runtime
{ {
[System.Serializable] [System.Serializable]
[SerieHandler(typeof(CandlestickHandler), true)] [SerieHandler(typeof(CandlestickHandler), true)]
[DefaultAnimation(AnimationType.LeftToRight)] [DefaultAnimation(AnimationType.LeftToRight, false)]
[SerieComponent()] [SerieComponent()]
[SerieDataComponent(typeof(ItemStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] [SerieDataComponent(typeof(ItemStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))]
[SerieDataExtraField()] [SerieDataExtraField()]

View File

@@ -81,7 +81,7 @@ namespace XCharts.Runtime
private void DrawCandlestickSerie(VertexHelper vh, Candlestick serie) private void DrawCandlestickSerie(VertexHelper vh, Candlestick serie)
{ {
if (!serie.show) return; if (!serie.show) return;
if (serie.animation.HasFadeOut()) return; if (serie.animation.HasFadeout()) return;
XAxis xAxis; XAxis xAxis;
YAxis yAxis; YAxis yAxis;
GridCoord grid; GridCoord grid;
@@ -99,8 +99,8 @@ namespace XCharts.Runtime
showData.Count; showData.Count;
bool dataChanging = false; bool dataChanging = false;
float dataChangeDuration = serie.animation.GetDataChangeDuration(); float dataChangeDuration = serie.animation.GetChangeDuration();
var dataAddDuration = serie.animation.GetDataAddDuration(); var dataAddDuration = serie.animation.GetAdditionDuration();
var unscaledTime = serie.animation.unscaledTime; var unscaledTime = serie.animation.unscaledTime;
double yMinValue = yAxis.context.minValue; double yMinValue = yAxis.context.minValue;
double yMaxValue = yAxis.context.maxValue; double yMaxValue = yAxis.context.maxValue;

View File

@@ -4,7 +4,7 @@ namespace XCharts.Runtime
{ {
[System.Serializable] [System.Serializable]
[SerieHandler(typeof(SimplifiedCandlestickHandler), true)] [SerieHandler(typeof(SimplifiedCandlestickHandler), true)]
[DefaultAnimation(AnimationType.LeftToRight)] [DefaultAnimation(AnimationType.LeftToRight, false)]
[SerieComponent()] [SerieComponent()]
[SerieDataComponent()] [SerieDataComponent()]
[SerieDataExtraField()] [SerieDataExtraField()]

View File

@@ -81,7 +81,7 @@ namespace XCharts.Runtime
private void DrawCandlestickSerie(VertexHelper vh, SimplifiedCandlestick serie) private void DrawCandlestickSerie(VertexHelper vh, SimplifiedCandlestick serie)
{ {
if (!serie.show) return; if (!serie.show) return;
if (serie.animation.HasFadeOut()) return; if (serie.animation.HasFadeout()) return;
XAxis xAxis; XAxis xAxis;
YAxis yAxis; YAxis yAxis;
GridCoord grid; GridCoord grid;
@@ -99,8 +99,8 @@ namespace XCharts.Runtime
showData.Count; showData.Count;
bool dataChanging = false; bool dataChanging = false;
float dataChangeDuration = serie.animation.GetDataChangeDuration(); float dataChangeDuration = serie.animation.GetChangeDuration();
var dataAddDuration = serie.animation.GetDataAddDuration(); var dataAddDuration = serie.animation.GetAdditionDuration();
var unscaledTime = serie.animation.unscaledTime; var unscaledTime = serie.animation.unscaledTime;
double yMinValue = yAxis.context.minValue; double yMinValue = yAxis.context.minValue;
double yMaxValue = yAxis.context.maxValue; double yMaxValue = yAxis.context.maxValue;

View File

@@ -22,7 +22,7 @@ namespace XCharts.Runtime
[System.Serializable] [System.Serializable]
[SerieHandler(typeof(HeatmapHandler), true)] [SerieHandler(typeof(HeatmapHandler), true)]
[DefaultAnimation(AnimationType.LeftToRight)] [DefaultAnimation(AnimationType.LeftToRight, false)]
[RequireChartComponent(typeof(VisualMap))] [RequireChartComponent(typeof(VisualMap))]
[CoordOptions(typeof(GridCoord), typeof(PolarCoord))] [CoordOptions(typeof(GridCoord), typeof(PolarCoord))]
[SerieComponent(typeof(LabelStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))] [SerieComponent(typeof(LabelStyle), typeof(EmphasisStyle), typeof(BlurStyle), typeof(SelectStyle))]

View File

@@ -185,7 +185,7 @@ namespace XCharts.Runtime
private void DrawDataHeatmapSerie(VertexHelper vh, Heatmap serie) private void DrawDataHeatmapSerie(VertexHelper vh, Heatmap serie)
{ {
if (!serie.show || serie.animation.HasFadeOut()) return; if (!serie.show || serie.animation.HasFadeout()) return;
XAxis xAxis; XAxis xAxis;
YAxis yAxis; YAxis yAxis;
if (!chart.TryGetChartComponent<XAxis>(out xAxis, serie.xAxisIndex)) return; if (!chart.TryGetChartComponent<XAxis>(out xAxis, serie.xAxisIndex)) return;
@@ -209,8 +209,8 @@ namespace XCharts.Runtime
serie.animation.InitProgress(0, xCount); serie.animation.InitProgress(0, xCount);
var animationIndex = serie.animation.GetCurrIndex(); var animationIndex = serie.animation.GetCurrIndex();
var dataChangeDuration = serie.animation.GetDataChangeDuration(); var dataChangeDuration = serie.animation.GetChangeDuration();
var dataAddDuration = serie.animation.GetDataAddDuration(); var dataAddDuration = serie.animation.GetAdditionDuration();
var unscaledTime = serie.animation.unscaledTime; var unscaledTime = serie.animation.unscaledTime;
var dataChanging = false; var dataChanging = false;
serie.containerIndex = m_SerieGrid.index; serie.containerIndex = m_SerieGrid.index;
@@ -332,7 +332,7 @@ namespace XCharts.Runtime
private void DrawCountHeatmapSerie(VertexHelper vh, Heatmap serie) private void DrawCountHeatmapSerie(VertexHelper vh, Heatmap serie)
{ {
if (!serie.show || serie.animation.HasFadeOut()) return; if (!serie.show || serie.animation.HasFadeout()) return;
XAxis xAxis; XAxis xAxis;
YAxis yAxis; YAxis yAxis;
if (!chart.TryGetChartComponent<XAxis>(out xAxis, serie.xAxisIndex)) return; if (!chart.TryGetChartComponent<XAxis>(out xAxis, serie.xAxisIndex)) return;

View File

@@ -6,7 +6,7 @@ namespace XCharts.Runtime
[SerieHandler(typeof(LineHandler), true)] [SerieHandler(typeof(LineHandler), true)]
[SerieConvert(typeof(Bar), typeof(Pie))] [SerieConvert(typeof(Bar), typeof(Pie))]
[CoordOptions(typeof(GridCoord), typeof(PolarCoord))] [CoordOptions(typeof(GridCoord), typeof(PolarCoord))]
[DefaultAnimation(AnimationType.LeftToRight)] [DefaultAnimation(AnimationType.LeftToRight, false)]
[SerieComponent( [SerieComponent(
typeof(LabelStyle), typeof(LabelStyle),
typeof(EndLabelStyle), typeof(EndLabelStyle),

View File

@@ -248,7 +248,7 @@ namespace XCharts.Runtime
private void DrawLineSerie(VertexHelper vh, Line serie) private void DrawLineSerie(VertexHelper vh, Line serie)
{ {
if (serie.animation.HasFadeOut()) if (serie.animation.HasFadeout())
return; return;
Axis axis; Axis axis;
@@ -288,8 +288,7 @@ namespace XCharts.Runtime
serie.sampleAverage : serie.sampleAverage :
DataHelper.DataAverage(ref showData, serie.sampleType, serie.minShow, maxCount, rate); DataHelper.DataAverage(ref showData, serie.sampleType, serie.minShow, maxCount, rate);
var dataChanging = false; var dataChanging = false;
var dataChangeDuration = serie.animation.GetDataChangeDuration(); var dataChangeDuration = serie.animation.GetChangeDuration();
var dataAddDuration = serie.animation.GetDataAddDuration();
var unscaledTime = serie.animation.unscaledTime; var unscaledTime = serie.animation.unscaledTime;
var interacting = false; var interacting = false;

View File

@@ -7,7 +7,7 @@ namespace XCharts.Runtime
[SerieHandler(typeof(SimplifiedLineHandler), true)] [SerieHandler(typeof(SimplifiedLineHandler), true)]
[SerieConvert(typeof(SimplifiedBar), typeof(Line))] [SerieConvert(typeof(SimplifiedBar), typeof(Line))]
[CoordOptions(typeof(GridCoord))] [CoordOptions(typeof(GridCoord))]
[DefaultAnimation(AnimationType.LeftToRight)] [DefaultAnimation(AnimationType.LeftToRight, false)]
[SerieComponent(typeof(AreaStyle))] [SerieComponent(typeof(AreaStyle))]
[SerieDataComponent()] [SerieDataComponent()]
[SerieDataExtraField()] [SerieDataExtraField()]

View File

@@ -139,7 +139,7 @@ namespace XCharts.Runtime
{ {
if (!serie.show) if (!serie.show)
return; return;
if (serie.animation.HasFadeOut()) if (serie.animation.HasFadeout())
return; return;
Axis axis; Axis axis;
@@ -172,8 +172,8 @@ namespace XCharts.Runtime
serie.sampleAverage : serie.sampleAverage :
DataHelper.DataAverage(ref showData, serie.sampleType, serie.minShow, maxCount, rate); DataHelper.DataAverage(ref showData, serie.sampleType, serie.minShow, maxCount, rate);
var dataChanging = false; var dataChanging = false;
var dataChangeDuration = serie.animation.GetDataChangeDuration(); var dataChangeDuration = serie.animation.GetChangeDuration();
var dataAddDuration = serie.animation.GetDataAddDuration(); var dataAddDuration = serie.animation.GetAdditionDuration();
var unscaledTime = serie.animation.unscaledTime; var unscaledTime = serie.animation.unscaledTime;
var interacting = false; var interacting = false;

View File

@@ -21,7 +21,7 @@ namespace XCharts.Runtime
private void DrawParallelSerie(VertexHelper vh, Parallel serie) private void DrawParallelSerie(VertexHelper vh, Parallel serie)
{ {
if (!serie.show) return; if (!serie.show) return;
if (serie.animation.HasFadeOut()) return; if (serie.animation.HasFadeout()) return;
var parallel = chart.GetChartComponent<ParallelCoord>(serie.parallelIndex); var parallel = chart.GetChartComponent<ParallelCoord>(serie.parallelIndex);
if (parallel == null) if (parallel == null)

View File

@@ -300,7 +300,7 @@ namespace XCharts.Runtime
private void DrawPie(VertexHelper vh, Serie serie) private void DrawPie(VertexHelper vh, Serie serie)
{ {
if (!serie.show || serie.animation.HasFadeOut()) if (!serie.show || serie.animation.HasFadeout())
{ {
return; return;
} }

View File

@@ -230,7 +230,7 @@ namespace XCharts.Runtime
var angle = 2 * Mathf.PI / indicatorNum; var angle = 2 * Mathf.PI / indicatorNum;
var centerPos = m_RadarCoord.context.center; var centerPos = m_RadarCoord.context.center;
serie.animation.InitProgress(0, 1); serie.animation.InitProgress(0, 1);
if (!serie.show || serie.animation.HasFadeOut()) if (!serie.show || serie.animation.HasFadeout())
{ {
return; return;
} }
@@ -365,7 +365,7 @@ namespace XCharts.Runtime
var angle = 2 * Mathf.PI / indicatorNum; var angle = 2 * Mathf.PI / indicatorNum;
var centerPos = m_RadarCoord.context.center; var centerPos = m_RadarCoord.context.center;
serie.animation.InitProgress(0, 1); serie.animation.InitProgress(0, 1);
if (!serie.show || serie.animation.HasFadeOut()) if (!serie.show || serie.animation.HasFadeout())
{ {
return; return;
} }

View File

@@ -176,7 +176,7 @@ namespace XCharts.Runtime
public override void DrawSerie(VertexHelper vh) public override void DrawSerie(VertexHelper vh)
{ {
if (!serie.show || serie.animation.HasFadeOut()) return; if (!serie.show || serie.animation.HasFadeout()) return;
var data = serie.data; var data = serie.data;
serie.animation.InitProgress(serie.startAngle, serie.startAngle + 360); serie.animation.InitProgress(serie.startAngle, serie.startAngle + 360);
SerieHelper.UpdateCenter(serie, chart.chartPosition, chart.chartWidth, chart.chartHeight); SerieHelper.UpdateCenter(serie, chart.chartPosition, chart.chartWidth, chart.chartHeight);

View File

@@ -106,7 +106,7 @@ namespace XCharts.Runtime
protected virtual void DrawScatterSerie(VertexHelper vh, BaseScatter serie) protected virtual void DrawScatterSerie(VertexHelper vh, BaseScatter serie)
{ {
if (serie.animation.HasFadeOut()) if (serie.animation.HasFadeout())
return; return;
if (!serie.show) if (!serie.show)
@@ -133,7 +133,7 @@ namespace XCharts.Runtime
serie.dataCount; serie.dataCount;
serie.animation.InitProgress(0, 1); serie.animation.InitProgress(0, 1);
var rate = serie.animation.GetCurrRate(); var rate = serie.animation.GetCurrRate();
var dataChangeDuration = serie.animation.GetDataChangeDuration(); var dataChangeDuration = serie.animation.GetChangeDuration();
var unscaledTime = serie.animation.unscaledTime; var unscaledTime = serie.animation.unscaledTime;
var dataChanging = false; var dataChanging = false;
var interacting = false; var interacting = false;
@@ -216,7 +216,7 @@ namespace XCharts.Runtime
protected virtual void DrawSingAxisScatterSerie(VertexHelper vh, BaseScatter serie) protected virtual void DrawSingAxisScatterSerie(VertexHelper vh, BaseScatter serie)
{ {
if (serie.animation.HasFadeOut()) if (serie.animation.HasFadeout())
return; return;
if (!serie.show) if (!serie.show)
@@ -237,7 +237,7 @@ namespace XCharts.Runtime
serie.animation.InitProgress(0, 1); serie.animation.InitProgress(0, 1);
var rate = serie.animation.GetCurrRate(); var rate = serie.animation.GetCurrRate();
var dataChangeDuration = serie.animation.GetDataChangeDuration(); var dataChangeDuration = serie.animation.GetChangeDuration();
var unscaledTime = serie.animation.unscaledTime; var unscaledTime = serie.animation.unscaledTime;
var dataChanging = false; var dataChanging = false;
var dataList = serie.GetDataList(xDataZoom); var dataList = serie.GetDataList(xDataZoom);

View File

@@ -1176,8 +1176,8 @@ namespace XCharts.Runtime
} }
else else
{ {
var duration = animation.GetDataChangeDuration(); var duration = animation.GetChangeDuration();
var dataAddDuration = animation.GetDataAddDuration(); var dataAddDuration = animation.GetAdditionDuration();
var unscaledTime = animation.unscaledTime; var unscaledTime = animation.unscaledTime;
foreach (var sdata in data) foreach (var sdata in data)
{ {
@@ -1537,7 +1537,7 @@ namespace XCharts.Runtime
var serieData = GetDataList(dataZoom); var serieData = GetDataList(dataZoom);
if (index < serieData.Count) if (index < serieData.Count)
{ {
var value = serieData[index].GetCurrData(1, 0, animation.GetDataChangeDuration(), animation.unscaledTime); var value = serieData[index].GetCurrData(1, 0, animation.GetChangeDuration(), animation.unscaledTime);
if (showAsPositiveNumber) if (showAsPositiveNumber)
value = Math.Abs(value); value = Math.Abs(value);
return value; return value;
@@ -1699,7 +1699,7 @@ namespace XCharts.Runtime
if (index >= 0 && index < m_Data.Count) if (index >= 0 && index < m_Data.Count)
{ {
var animationOpen = animation.enable; var animationOpen = animation.enable;
var animationDuration = animation.GetDataChangeDuration(); var animationDuration = animation.GetChangeDuration();
var unscaledTime = animation.unscaledTime; var unscaledTime = animation.unscaledTime;
var flag = m_Data[index].UpdateData(dimension, value, animationOpen, unscaledTime, animationDuration); var flag = m_Data[index].UpdateData(dimension, value, animationOpen, unscaledTime, animationDuration);
if (flag) if (flag)
@@ -1726,7 +1726,7 @@ namespace XCharts.Runtime
{ {
var serieData = m_Data[index]; var serieData = m_Data[index];
var animationOpen = animation.enable; var animationOpen = animation.enable;
var animationDuration = animation.GetDataChangeDuration(); var animationDuration = animation.GetChangeDuration();
var unscaledTime = animation.unscaledTime; var unscaledTime = animation.unscaledTime;
for (int i = 0; i < values.Count; i++) for (int i = 0; i < values.Count; i++)
serieData.UpdateData(i, values[i], animationOpen, unscaledTime, animationDuration); serieData.UpdateData(i, values[i], animationOpen, unscaledTime, animationDuration);
@@ -1907,18 +1907,32 @@ namespace XCharts.Runtime
/// <summary> /// <summary>
/// 渐入动画 /// 渐入动画
/// </summary> /// </summary>
public void AnimationFadein()
{
if (animation.enable) animation.Fadein();
SetVerticesDirty();
}
[Obsolete("Use Serie.AnimationFadein() instead.", true)]
public void AnimationFadeIn() public void AnimationFadeIn()
{ {
if (animation.enable) animation.FadeIn(); if (animation.enable) animation.Fadein();
SetVerticesDirty(); SetVerticesDirty();
} }
/// <summary> /// <summary>
/// 渐出动画 /// 渐出动画
/// </summary> /// </summary>
public void AnimationFadeout()
{
if (animation.enable) animation.Fadeout();
SetVerticesDirty();
}
[Obsolete("Use Serie.AnimationFadeout() instead.", true)]
public void AnimationFadeOut() public void AnimationFadeOut()
{ {
if (animation.enable) animation.FadeOut(); if (animation.enable) animation.Fadeout();
SetVerticesDirty(); SetVerticesDirty();
} }

View File

@@ -240,13 +240,19 @@ namespace XCharts.Runtime
public void OnAdd(AnimationStyle animation, double startValue = 0) public void OnAdd(AnimationStyle animation, double startValue = 0)
{ {
if (!animation.enable) return;
if (!animation.context.enableSerieDataAddedAnimation)
{
animation.Addition();
return;
}
#if UNITY_EDITOR #if UNITY_EDITOR
if (!Application.isPlaying) if (!Application.isPlaying)
return; return;
#endif #endif
m_DataAddTime.Clear(); m_DataAddTime.Clear();
m_DataAddFlag.Clear(); m_DataAddFlag.Clear();
if (animation.GetDataAddDuration() > 0) if (animation.GetAdditionDuration() > 0)
{ {
for (int i = 0; i < m_Data.Count; i++) for (int i = 0; i < m_Data.Count; i++)
{ {
@@ -506,7 +512,7 @@ namespace XCharts.Runtime
if (animation == null || !animation.enable) if (animation == null || !animation.enable)
return GetData(index, inverse); return GetData(index, inverse);
else else
return GetCurrData(index, animation.GetDataAddDuration(), animation.GetDataChangeDuration(), return GetCurrData(index, animation.GetAdditionDuration(), animation.GetChangeDuration(),
inverse, 0, 0, animation.unscaledTime, loop); inverse, 0, 0, animation.unscaledTime, loop);
} }
@@ -515,7 +521,7 @@ namespace XCharts.Runtime
if (animation == null || !animation.enable) if (animation == null || !animation.enable)
return GetData(index, inverse); return GetData(index, inverse);
else else
return GetCurrData(index, animation.GetDataAddDuration(), animation.GetDataChangeDuration(), return GetCurrData(index, animation.GetAdditionDuration(), animation.GetChangeDuration(),
inverse, min, max, animation.unscaledTime, loop); inverse, min, max, animation.unscaledTime, loop);
} }

View File

@@ -401,8 +401,8 @@ namespace XCharts.Runtime
if (!m_InitedLabel) if (!m_InitedLabel)
return; return;
var dataChangeDuration = serie.animation.GetDataChangeDuration(); var dataChangeDuration = serie.animation.GetChangeDuration();
var dataAddDuration = serie.animation.GetDataAddDuration(); var dataAddDuration = serie.animation.GetAdditionDuration();
var unscaledTime = serie.animation.unscaledTime; var unscaledTime = serie.animation.unscaledTime;
var needCheck = serie.context.dataIndexs.Count > 0; var needCheck = serie.context.dataIndexs.Count > 0;
foreach (var serieData in serie.data) foreach (var serieData in serie.data)

View File

@@ -698,7 +698,7 @@ namespace XCharts.Runtime
var symbol = stateStyle.symbol; var symbol = stateStyle.symbol;
size = symbol.GetSize(serieData == null ? null : serieData.data, defaultSize); size = symbol.GetSize(serieData == null ? null : serieData.data, defaultSize);
} }
size = (float)serieData.GetAddAnimationData(0, size, serie.animation.GetDataAddDuration()); size = (float)serieData.GetAddAnimationData(0, size, serie.animation.GetAdditionDuration());
return size; return size;
} }

View File

@@ -346,8 +346,8 @@ namespace XCharts.Runtime
if ((isPolar && serie.polarIndex != axisIndex) || if ((isPolar && serie.polarIndex != axisIndex) ||
(!isPolar && serie.yAxisIndex != axisIndex) || (!isPolar && serie.yAxisIndex != axisIndex) ||
!serie.show) continue; !serie.show) continue;
var updateDuration = serie.animation.GetDataChangeDuration(); var updateDuration = serie.animation.GetChangeDuration();
var dataAddDuration = serie.animation.GetDataAddDuration(); var dataAddDuration = serie.animation.GetAdditionDuration();
var unscaledTime = serie.animation.unscaledTime; var unscaledTime = serie.animation.unscaledTime;
if (isPercentStack && SeriesHelper.IsPercentStack<Bar>(series, serie.serieName)) if (isPercentStack && SeriesHelper.IsPercentStack<Bar>(series, serie.serieName))
{ {
@@ -406,6 +406,9 @@ namespace XCharts.Runtime
} }
else else
{ {
var updateDuration = serie.animation.GetChangeDuration();
var dataAddDuration = serie.animation.GetAdditionDuration();
var unscaledTime = serie.animation.unscaledTime;
for (int j = 0; j < showData.Count; j++) for (int j = 0; j < showData.Count; j++)
{ {
if (!_serieTotalValueForMinMax.ContainsKey(j)) if (!_serieTotalValueForMinMax.ContainsKey(j))
@@ -417,9 +420,10 @@ namespace XCharts.Runtime
} }
else else
{ {
currData = yValue ? showData[j].GetData(1) : showData[j].GetData(0); //currData = yValue ? showData[j].GetData(1) : showData[j].GetData(0);
currData = showData[j].GetCurrData(yValue ? 1 : 0, dataAddDuration, updateDuration, unscaledTime, inverse);
} }
if (inverse) currData = -currData; //if (inverse) currData = -currData;
if (!serie.IsIgnoreValue(showData[j], currData)) if (!serie.IsIgnoreValue(showData[j], currData))
_serieTotalValueForMinMax[j] = _serieTotalValueForMinMax[j] + currData; _serieTotalValueForMinMax[j] = _serieTotalValueForMinMax[j] + currData;
} }