mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-26 10:50:08 +00:00
增加Animation在重新初始化数据时自启动功能
This commit is contained in:
@@ -5,7 +5,8 @@ using XCharts;
|
|||||||
[ExecuteInEditMode]
|
[ExecuteInEditMode]
|
||||||
public class Demo10_LineSimple : MonoBehaviour
|
public class Demo10_LineSimple : MonoBehaviour
|
||||||
{
|
{
|
||||||
void Awake()
|
//void Awake()
|
||||||
|
void Start()
|
||||||
{
|
{
|
||||||
var chart = gameObject.GetComponent<LineChart>();
|
var chart = gameObject.GetComponent<LineChart>();
|
||||||
if (chart == null) return;
|
if (chart == null) return;
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ namespace XCharts
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void ClearData()
|
public void ClearData()
|
||||||
{
|
{
|
||||||
|
AnimationStop();
|
||||||
foreach (var serie in m_Series)
|
foreach (var serie in m_Series)
|
||||||
{
|
{
|
||||||
serie.ClearData();
|
serie.ClearData();
|
||||||
@@ -200,6 +201,7 @@ namespace XCharts
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void RemoveAll()
|
public void RemoveAll()
|
||||||
{
|
{
|
||||||
|
AnimationStop();
|
||||||
m_Series.Clear();
|
m_Series.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -793,6 +795,9 @@ namespace XCharts
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 开始初始动画
|
||||||
|
/// </summary>
|
||||||
public void AnimationStart()
|
public void AnimationStart()
|
||||||
{
|
{
|
||||||
foreach (var serie in m_Series)
|
foreach (var serie in m_Series)
|
||||||
@@ -804,6 +809,17 @@ namespace XCharts
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 停止初始动画
|
||||||
|
/// </summary>
|
||||||
|
public void AnimationStop()
|
||||||
|
{
|
||||||
|
foreach (var serie in m_Series)
|
||||||
|
{
|
||||||
|
if (serie.animation.enable) serie.animation.Stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 从json中解析数据
|
/// 从json中解析数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -57,7 +57,8 @@ namespace XCharts
|
|||||||
/// <value></value>
|
/// <value></value>
|
||||||
public int delay { get { return m_Delay; } set { m_Delay = value; if (m_Delay < 0) m_Delay = 0; } }
|
public int delay { get { return m_Delay; } set { m_Delay = value; if (m_Delay < 0) m_Delay = 0; } }
|
||||||
|
|
||||||
private Dictionary<int,float> m_DataAnimationState = new Dictionary<int,float>();
|
private Dictionary<int, float> m_DataAnimationState = new Dictionary<int, float>();
|
||||||
|
private bool m_IsStart = false;
|
||||||
private bool m_IsEnd = true;
|
private bool m_IsEnd = true;
|
||||||
private bool m_Inited = false;
|
private bool m_Inited = false;
|
||||||
|
|
||||||
@@ -70,7 +71,9 @@ namespace XCharts
|
|||||||
|
|
||||||
public void Start()
|
public void Start()
|
||||||
{
|
{
|
||||||
|
if (m_IsStart) return;
|
||||||
startTime = Time.time;
|
startTime = Time.time;
|
||||||
|
m_IsStart = true;
|
||||||
m_IsEnd = false;
|
m_IsEnd = false;
|
||||||
m_Inited = false;
|
m_Inited = false;
|
||||||
m_CurrDataProgress = 1;
|
m_CurrDataProgress = 1;
|
||||||
@@ -81,6 +84,14 @@ namespace XCharts
|
|||||||
m_DataAnimationState.Clear();
|
m_DataAnimationState.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Stop()
|
||||||
|
{
|
||||||
|
m_IsStart = false;
|
||||||
|
m_IsEnd = true;
|
||||||
|
m_Inited = false;
|
||||||
|
m_DataAnimationState.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
public void End()
|
public void End()
|
||||||
{
|
{
|
||||||
if (m_IsEnd) return;
|
if (m_IsEnd) return;
|
||||||
@@ -89,8 +100,6 @@ namespace XCharts
|
|||||||
m_IsEnd = true;
|
m_IsEnd = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void InitProgress(int data, float curr, float dest)
|
public void InitProgress(int data, float curr, float dest)
|
||||||
{
|
{
|
||||||
if (!m_Inited)
|
if (!m_Inited)
|
||||||
@@ -110,15 +119,17 @@ namespace XCharts
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetDataState(int index,float state)
|
public void SetDataState(int index, float state)
|
||||||
{
|
{
|
||||||
m_DataAnimationState[index] = state;
|
m_DataAnimationState[index] = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float GetDataState(int index){
|
public float GetDataState(int index)
|
||||||
if(IsInDelay()) return 0;
|
{
|
||||||
if(!m_DataAnimationState.ContainsKey(index)){
|
if (IsInDelay()) return 0;
|
||||||
m_DataAnimationState.Add(index,0);
|
if (!m_DataAnimationState.ContainsKey(index))
|
||||||
|
{
|
||||||
|
m_DataAnimationState.Add(index, 0);
|
||||||
}
|
}
|
||||||
return m_DataAnimationState[index];
|
return m_DataAnimationState[index];
|
||||||
}
|
}
|
||||||
@@ -186,11 +197,13 @@ namespace XCharts
|
|||||||
return m_CurrSymbolProgress;
|
return m_CurrSymbolProgress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float GetCurrDetail(){
|
public float GetCurrDetail()
|
||||||
|
{
|
||||||
return m_CurrDetailProgress;
|
return m_CurrDetailProgress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float GetCurrData(){
|
public float GetCurrData()
|
||||||
|
{
|
||||||
return m_CurrDataProgress;
|
return m_CurrDataProgress;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ namespace XCharts
|
|||||||
[NonSerialized] private bool m_RefreshChart = false;
|
[NonSerialized] private bool m_RefreshChart = false;
|
||||||
[NonSerialized] private bool m_RefreshLabel = false;
|
[NonSerialized] private bool m_RefreshLabel = false;
|
||||||
[NonSerialized] private bool m_ReinitLabel = false;
|
[NonSerialized] private bool m_ReinitLabel = false;
|
||||||
|
[NonSerialized] private bool m_CheckAnimation = false;
|
||||||
|
|
||||||
protected Vector2 chartAnchorMax { get { return rectTransform.anchorMax; } }
|
protected Vector2 chartAnchorMax { get { return rectTransform.anchorMax; } }
|
||||||
protected Vector2 chartAnchorMin { get { return rectTransform.anchorMin; } }
|
protected Vector2 chartAnchorMin { get { return rectTransform.anchorMin; } }
|
||||||
@@ -79,6 +80,7 @@ namespace XCharts
|
|||||||
InitSerieLabel();
|
InitSerieLabel();
|
||||||
InitTooltip();
|
InitTooltip();
|
||||||
TransferOldVersionData();
|
TransferOldVersionData();
|
||||||
|
m_Series.AnimationStop();
|
||||||
m_Series.AnimationStart();
|
m_Series.AnimationStart();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,6 +98,7 @@ namespace XCharts
|
|||||||
CheckTooltip();
|
CheckTooltip();
|
||||||
CheckRefreshChart();
|
CheckRefreshChart();
|
||||||
CheckRefreshLabel();
|
CheckRefreshLabel();
|
||||||
|
CheckAnimation();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnEnable()
|
protected override void OnEnable()
|
||||||
@@ -315,7 +318,7 @@ namespace XCharts
|
|||||||
var backgroundColor = serie.label.backgroundColor;
|
var backgroundColor = serie.label.backgroundColor;
|
||||||
var labelObj = ChartHelper.AddSerieLabel(textName, labelObject.transform, m_ThemeInfo.font,
|
var labelObj = ChartHelper.AddSerieLabel(textName, labelObject.transform, m_ThemeInfo.font,
|
||||||
color, backgroundColor, serie.label.fontSize, serie.label.fontStyle, serie.label.rotate,
|
color, backgroundColor, serie.label.fontSize, serie.label.fontStyle, serie.label.rotate,
|
||||||
serie.label.backgroundWidth,serie.label.backgroundHeight);
|
serie.label.backgroundWidth, serie.label.backgroundHeight);
|
||||||
var isAutoSize = serie.label.backgroundWidth == 0 || serie.label.backgroundHeight == 0;
|
var isAutoSize = serie.label.backgroundWidth == 0 || serie.label.backgroundHeight == 0;
|
||||||
serieData.InitLabel(labelObj, isAutoSize, serie.label.paddingLeftRight, serie.label.paddingTopBottom);
|
serieData.InitLabel(labelObj, isAutoSize, serie.label.paddingLeftRight, serie.label.paddingTopBottom);
|
||||||
serieData.SetLabelActive(false);
|
serieData.SetLabelActive(false);
|
||||||
@@ -469,6 +472,15 @@ namespace XCharts
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void CheckAnimation()
|
||||||
|
{
|
||||||
|
if (!m_CheckAnimation)
|
||||||
|
{
|
||||||
|
m_CheckAnimation = true;
|
||||||
|
m_Series.AnimationStart();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected virtual void OnRefreshLabel()
|
protected virtual void OnRefreshLabel()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ namespace XCharts
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value></value>
|
/// <value></value>
|
||||||
public float lineSmoothStyle { get { return m_LineSmoothStyle; } set { m_LineSmoothStyle = value; } }
|
public float lineSmoothStyle { get { return m_LineSmoothStyle; } set { m_LineSmoothStyle = value; } }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Set the size of chart.
|
/// Set the size of chart.
|
||||||
/// 设置图表的大小。
|
/// 设置图表的大小。
|
||||||
@@ -106,6 +106,7 @@ namespace XCharts
|
|||||||
{
|
{
|
||||||
m_Series.ClearData();
|
m_Series.ClearData();
|
||||||
m_Legend.ClearData();
|
m_Legend.ClearData();
|
||||||
|
m_CheckAnimation = false;
|
||||||
RefreshChart();
|
RefreshChart();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,6 +119,7 @@ namespace XCharts
|
|||||||
{
|
{
|
||||||
m_Legend.ClearData();
|
m_Legend.ClearData();
|
||||||
m_Series.RemoveAll();
|
m_Series.RemoveAll();
|
||||||
|
m_CheckAnimation = false;
|
||||||
RefreshChart();
|
RefreshChart();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -422,5 +424,22 @@ namespace XCharts
|
|||||||
OnThemeChanged();
|
OnThemeChanged();
|
||||||
RefreshChart();
|
RefreshChart();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 开始初始动画
|
||||||
|
/// </summary>
|
||||||
|
public void AnimationStart()
|
||||||
|
{
|
||||||
|
m_Series.AnimationStart();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 停止初始化动画
|
||||||
|
/// </summary>
|
||||||
|
public void AnimationStop()
|
||||||
|
{
|
||||||
|
m_CheckAnimation = false;
|
||||||
|
m_Series.AnimationStop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,8 @@ QQ交流群:XCharts交流群(202030963)
|
|||||||
|
|
||||||
## 更新日志
|
## 更新日志
|
||||||
|
|
||||||
* (2019.09.05)增加`SerieLabel`的`Border`边框相关配置支持
|
* (2019.09.06)增加`Animation`在重新初始化数据时自启动功能
|
||||||
|
* (2019.09.06)增加`SerieLabel`的`Border`边框相关配置支持
|
||||||
* (2019.09.05)增加`PieChart`的`Animation`初始化动画配置支持
|
* (2019.09.05)增加`PieChart`的`Animation`初始化动画配置支持
|
||||||
* (2019.09.03)增加`BarChart`的`Animation`初始化动画配置支持
|
* (2019.09.03)增加`BarChart`的`Animation`初始化动画配置支持
|
||||||
* (2019.09.02)增加`LineChart`的`Animation`初始化动画配置支持
|
* (2019.09.02)增加`LineChart`的`Animation`初始化动画配置支持
|
||||||
|
|||||||
Reference in New Issue
Block a user