diff --git a/CHANGELOG.md b/CHANGELOG.md
index ff1b7aa6..f46e2b1f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,7 @@
# 更新日志
+* (2020.03.11) 优化清空并重新添加数据后的自动刷新问题
* (2020.03.10) 增加`LineChart`的普通折线图可通过`ignore`参数设置忽略数据的支持
* (2020.03.09) 增加`BarChart`可通过`ItemStyle`配置边框的支持
* (2020.03.08) 增加`RingChart`环形图
diff --git a/Runtime/API/BaseChart_API.cs b/Runtime/API/BaseChart_API.cs
index 6633af7c..364ea749 100644
--- a/Runtime/API/BaseChart_API.cs
+++ b/Runtime/API/BaseChart_API.cs
@@ -92,7 +92,9 @@ namespace XCharts
{
m_Series.ClearData();
m_Legend.ClearData();
+ m_Tooltip.ClearValue();
m_CheckAnimation = false;
+ m_ReinitLabel = true;
RefreshChart();
}
@@ -105,7 +107,9 @@ namespace XCharts
{
m_Legend.ClearData();
m_Series.RemoveAll();
+ m_Tooltip.ClearValue();
m_CheckAnimation = false;
+ m_ReinitLabel = true;
RefreshChart();
}
diff --git a/Runtime/Component/Main/Axis.cs b/Runtime/Component/Main/Axis.cs
index e13db2b3..2ab1393f 100644
--- a/Runtime/Component/Main/Axis.cs
+++ b/Runtime/Component/Main/Axis.cs
@@ -830,6 +830,7 @@ namespace XCharts
if (m_RuntimeMinValue == 0 && m_RuntimeMaxValue == 0) return 0;
if (!m_RuntimeMinValueChanged) return m_RuntimeMinValue;
var time = Time.time - m_RuntimeMinValueUpdateTime;
+ if (time == 0) return m_RuntimeMinValue;
var total = duration / 1000;
if (duration > 0 && time <= total)
{
@@ -849,8 +850,9 @@ namespace XCharts
if (m_RuntimeMinValue == 0 && m_RuntimeMaxValue == 0) return 0;
if (!m_RuntimeMaxValueChanged) return m_RuntimeMaxValue;
var time = Time.time - m_RuntimeMaxValueUpdateTime;
+ if (time == 0) return m_RuntimeMaxValue;
var total = duration / 1000;
- if (duration > 0 && time <= total)
+ if (duration > 0 && time < total)
{
var curr = Mathf.Lerp(m_RuntimeLastMaxValue, m_RuntimeMaxValue, time / total);
return curr;
diff --git a/Runtime/Component/Main/Serie.cs b/Runtime/Component/Main/Serie.cs
index 7846c0cc..3356bcec 100644
--- a/Runtime/Component/Main/Serie.cs
+++ b/Runtime/Component/Main/Serie.cs
@@ -1561,6 +1561,15 @@ namespace XCharts
return m_Ignore && Mathf.Approximately(value, m_IgnoreValue);
}
+ public bool IsIngorePoint(int index)
+ {
+ if (index >= 0 && index < dataPoints.Count)
+ {
+ return ChartHelper.IsIngore(dataPoints[index]);
+ }
+ return false;
+ }
+
///
/// 更新运行时中心点和半径
///
diff --git a/Runtime/Component/Main/Series.cs b/Runtime/Component/Main/Series.cs
index 1cb96dbb..c3ba17bf 100644
--- a/Runtime/Component/Main/Series.cs
+++ b/Runtime/Component/Main/Series.cs
@@ -125,7 +125,7 @@ namespace XCharts
///
public void ClearData()
{
- AnimationPause();
+ AnimationFadeIn();
foreach (var serie in m_Series)
{
serie.ClearData();
@@ -326,7 +326,7 @@ namespace XCharts
///
public void RemoveAll()
{
- AnimationPause();
+ AnimationFadeIn();
m_Series.Clear();
}
diff --git a/Runtime/Internal/CoordinateChart.cs b/Runtime/Internal/CoordinateChart.cs
index aab7525d..5cbb5f57 100644
--- a/Runtime/Internal/CoordinateChart.cs
+++ b/Runtime/Internal/CoordinateChart.cs
@@ -421,7 +421,7 @@ namespace XCharts
string key = serie.name;
float xValue, yValue;
serie.GetXYData(index, m_DataZoom, out xValue, out yValue);
- var isIngore = ChartHelper.IsIngore(serie.dataPoints[index]);
+ var isIngore = serie.IsIngorePoint(index);
if (isCartesian)
{
var serieData = serie.GetSerieData(index, m_DataZoom);
@@ -1521,7 +1521,7 @@ namespace XCharts
{
content = serie.label.GetFormatterContent(serie.name, serieData.name, value, total);
}
- serieData.SetLabelActive(value != 0);
+ serieData.SetLabelActive(value != 0 && serieData.labelPosition != Vector3.zero);
serieData.SetLabelPosition(serie.label.offset);
if (serieData.SetLabelText(content)) RefreshChart();
}
diff --git a/Runtime/Internal/SerieLabelPool.cs b/Runtime/Internal/SerieLabelPool.cs
index 155a4702..1ae07f00 100644
--- a/Runtime/Internal/SerieLabelPool.cs
+++ b/Runtime/Internal/SerieLabelPool.cs
@@ -14,6 +14,7 @@ namespace XCharts
internal static class SerieLabelPool
{
private static readonly Stack m_Stack = new Stack(200);
+ private static Dictionary m_ReleaseDic = new Dictionary(1000);
public static GameObject Get(string name, Transform parent, SerieLabel label, Font font, Color color,
float iconWidth, float iconHeight)
@@ -29,6 +30,7 @@ namespace XCharts
else
{
element = m_Stack.Pop();
+ m_ReleaseDic.Remove(element.GetInstanceID());
element.name = name;
element.transform.SetParent(parent);
element.transform.localEulerAngles = new Vector3(0, 0, label.rotate);
@@ -45,10 +47,12 @@ namespace XCharts
public static void Release(GameObject element)
{
ChartHelper.SetActive(element, false);
- //if (m_Stack.Count > 0 && ReferenceEquals(m_Stack.Peek(), element))
- // Debug.LogError("Internal error. Trying to destroy object that is already released to pool." + element.name);
- if (Application.isPlaying)
+ if (!Application.isPlaying) return;
+ if (!m_ReleaseDic.ContainsKey(element.GetInstanceID()))
+ {
m_Stack.Push(element);
+ m_ReleaseDic.Add(element.GetInstanceID(), true);
+ }
}
public static void ReleaseAll(Transform parent)
@@ -63,6 +67,7 @@ namespace XCharts
public static void ClearAll()
{
m_Stack.Clear();
+ m_ReleaseDic.Clear();
}
}
}