mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-17 05:50:09 +00:00
增加BarChart的Animation初始化动画配置支持
This commit is contained in:
@@ -71,11 +71,14 @@ namespace XCharts
|
||||
float barHig = (xAxis.minValue > 0 ? value - xAxis.minValue : value)
|
||||
/ (xAxis.maxValue - xAxis.minValue) * coordinateWid;
|
||||
seriesHig[i] += barHig;
|
||||
|
||||
float currHig = CheckAnimation(serie,i,barHig);
|
||||
|
||||
Vector3 p1 = new Vector3(pX, pY + space + barWidth);
|
||||
Vector3 p2 = new Vector3(pX + barHig, pY + space + barWidth);
|
||||
Vector3 p3 = new Vector3(pX + barHig, pY + space);
|
||||
Vector3 p2 = new Vector3(pX + currHig, pY + space + barWidth);
|
||||
Vector3 p3 = new Vector3(pX + currHig, pY + space);
|
||||
Vector3 p4 = new Vector3(pX, pY + space);
|
||||
serie.dataPoints.Add(new Vector3(pX + barHig, pY + space + barWidth / 2));
|
||||
serie.dataPoints.Add(new Vector3(pX + currHig, pY + space + barWidth / 2));
|
||||
var highlight = (m_Tooltip.show && m_Tooltip.IsSelected(i))
|
||||
|| serie.data[i].highlighted
|
||||
|| serie.highlighted;
|
||||
@@ -92,6 +95,28 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
private float CheckAnimation(Serie serie, int dataIndex, float barHig)
|
||||
{
|
||||
float currHig = barHig;
|
||||
if (!serie.animation.IsFinish())
|
||||
{
|
||||
if (serie.animation.IsInDelay()) currHig = 0;
|
||||
else
|
||||
{
|
||||
var speed = serie.animation.duration > 0 ? barHig / serie.animation.duration * 1000 : barHig;
|
||||
currHig = serie.animation.GetDataState(dataIndex) + speed * Time.deltaTime;
|
||||
serie.animation.SetDataState(dataIndex, currHig);
|
||||
if (Mathf.Abs(currHig) >= Mathf.Abs(barHig))
|
||||
{
|
||||
serie.animation.End();
|
||||
currHig = barHig;
|
||||
}
|
||||
}
|
||||
RefreshChart();
|
||||
}
|
||||
return currHig;
|
||||
}
|
||||
|
||||
private void DrawXBarSerie(VertexHelper vh, int serieIndex, int stackCount,
|
||||
Serie serie, int colorIndex, ref List<float> seriesHig)
|
||||
{
|
||||
@@ -133,11 +158,13 @@ namespace XCharts
|
||||
/ (yAxis.maxValue - yAxis.minValue) * coordinateHig;
|
||||
seriesHig[i] += barHig;
|
||||
|
||||
float currHig = CheckAnimation(serie,i,barHig);
|
||||
|
||||
Vector3 p1 = new Vector3(pX + space, pY);
|
||||
Vector3 p2 = new Vector3(pX + space, pY + barHig);
|
||||
Vector3 p3 = new Vector3(pX + space + barWidth, pY + barHig);
|
||||
Vector3 p2 = new Vector3(pX + space, pY + currHig);
|
||||
Vector3 p3 = new Vector3(pX + space + barWidth, pY + currHig);
|
||||
Vector3 p4 = new Vector3(pX + space + barWidth, pY);
|
||||
serie.dataPoints.Add(new Vector3(pX + space + barWidth / 2, pY + barHig));
|
||||
serie.dataPoints.Add(new Vector3(pX + space + barWidth / 2, pY + currHig));
|
||||
var highlight = (m_Tooltip.show && m_Tooltip.IsSelected(i))
|
||||
|| serie.data[i].highlighted
|
||||
|| serie.highlighted;
|
||||
|
||||
@@ -793,6 +793,15 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
public void AnimationStart()
|
||||
{
|
||||
foreach (var serie in m_Series)
|
||||
{
|
||||
if(serie.animation.enable)
|
||||
serie.animation.Start();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从json中解析数据
|
||||
/// </summary>
|
||||
|
||||
@@ -57,12 +57,11 @@ namespace XCharts
|
||||
/// <value></value>
|
||||
public int delay { get { return m_Delay; } set { m_Delay = value; if (m_Delay < 0) m_Delay = 0; } }
|
||||
|
||||
private List<bool> m_DataAnimationState = new List<bool>();
|
||||
private Dictionary<int,float> m_DataAnimationState = new Dictionary<int,float>();
|
||||
private bool m_IsEnd = true;
|
||||
private bool m_Inited = false;
|
||||
|
||||
private float startTime { get; set; }
|
||||
private List<bool> dataState { get { return m_DataAnimationState; } }
|
||||
private int m_CurrDataProgress { get; set; }
|
||||
private int m_DestDataProgress { get; set; }
|
||||
[SerializeField] private float m_CurrDetailProgress;
|
||||
@@ -79,8 +78,7 @@ namespace XCharts
|
||||
m_CurrDetailProgress = 0;
|
||||
m_DestDetailProgress = 1;
|
||||
m_CurrSymbolProgress = 0;
|
||||
dataState.Clear();
|
||||
dataState.Add(false);
|
||||
m_DataAnimationState.Clear();
|
||||
}
|
||||
|
||||
public void End()
|
||||
@@ -91,10 +89,7 @@ namespace XCharts
|
||||
m_IsEnd = true;
|
||||
}
|
||||
|
||||
public void InitDataState(float i)
|
||||
{
|
||||
if (i >= dataState.Count) dataState.Add(false);
|
||||
}
|
||||
|
||||
|
||||
public void InitProgress(int data, float curr, float dest)
|
||||
{
|
||||
@@ -109,13 +104,25 @@ namespace XCharts
|
||||
|
||||
public void SetDataFinish(int dataIndex)
|
||||
{
|
||||
if (!m_IsEnd && dataIndex < dataState.Count && !dataState[dataIndex])
|
||||
if (!m_IsEnd)
|
||||
{
|
||||
dataState[dataIndex] = true;
|
||||
m_CurrDataProgress = dataIndex + 1;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetDataState(int index,float state)
|
||||
{
|
||||
m_DataAnimationState[index] = state;
|
||||
}
|
||||
|
||||
public float GetDataState(int index){
|
||||
if(IsInDelay()) return 0;
|
||||
if(!m_DataAnimationState.ContainsKey(index)){
|
||||
m_DataAnimationState.Add(index,0);
|
||||
}
|
||||
return m_DataAnimationState[index];
|
||||
}
|
||||
|
||||
public bool IsFinish()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
|
||||
@@ -79,6 +79,7 @@ namespace XCharts
|
||||
InitSerieLabel();
|
||||
InitTooltip();
|
||||
TransferOldVersionData();
|
||||
m_Series.AnimationStart();
|
||||
}
|
||||
|
||||
protected override void Start()
|
||||
|
||||
@@ -11,14 +11,6 @@ namespace XCharts
|
||||
[DisallowMultipleComponent]
|
||||
public class LineChart : CoordinateChart
|
||||
{
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
foreach (var serie in m_Series.series)
|
||||
{
|
||||
serie.animation.Start();
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
protected override void Reset()
|
||||
@@ -162,7 +154,6 @@ namespace XCharts
|
||||
{
|
||||
np = serie.dataPoints[i];
|
||||
serie.ClearSmoothList(i);
|
||||
serie.animation.InitDataState(i);
|
||||
if (!serie.animation.NeedAnimation(i)) break;
|
||||
bool isFinish = true;
|
||||
switch (serie.lineType)
|
||||
@@ -302,7 +293,6 @@ namespace XCharts
|
||||
{
|
||||
np = serie.dataPoints[i];
|
||||
serie.ClearSmoothList(i);
|
||||
serie.animation.InitDataState(i);
|
||||
if (!serie.animation.NeedAnimation(i)) break;
|
||||
bool isFinish = true;
|
||||
switch (serie.lineType)
|
||||
|
||||
Reference in New Issue
Block a user