diff --git a/Runtime/Helper/FormatterHelper.cs b/Runtime/Helper/FormatterHelper.cs
index ca005435..41221ec5 100644
--- a/Runtime/Helper/FormatterHelper.cs
+++ b/Runtime/Helper/FormatterHelper.cs
@@ -25,6 +25,13 @@ namespace XCharts.Runtime
return !string.IsNullOrEmpty(content) && content.IndexOf('{') >= 0;
}
+ public static bool NeedTotalContent(string content)
+ {
+ if (string.IsNullOrEmpty(content)) return false;
+ return content.IndexOf("{d", System.StringComparison.OrdinalIgnoreCase) >= 0 ||
+ content.IndexOf("{f", System.StringComparison.OrdinalIgnoreCase) >= 0;
+ }
+
///
/// 替换字符串中的通配符,支持的通配符有{.}、{a}、{b}、{c}、{d}、{e}、{f}、{g}、{h}、{y}。
///
diff --git a/Runtime/Serie/SerieContext.cs b/Runtime/Serie/SerieContext.cs
index 865efa7f..769d4434 100644
--- a/Runtime/Serie/SerieContext.cs
+++ b/Runtime/Serie/SerieContext.cs
@@ -32,7 +32,6 @@ namespace XCharts.Runtime
[System.NonSerialized] internal double[] cachedMin = new double[3] { double.MaxValue, double.MaxValue, double.MaxValue };
[System.NonSerialized] internal double[] cachedMax = new double[3] { double.MinValue, double.MinValue, double.MinValue };
[System.NonSerialized] internal bool[] cacheValid = new bool[3] { false, false, false };
- [System.NonSerialized] internal Dictionary dataZoomMinMaxCache = new Dictionary();
internal void InvalidateMinMaxCache()
{
@@ -40,7 +39,6 @@ namespace XCharts.Runtime
cacheValid[i] = false;
cachedMin[0] = cachedMin[1] = cachedMin[2] = double.MaxValue;
cachedMax[0] = cachedMax[1] = cachedMax[2] = double.MinValue;
- dataZoomMinMaxCache.Clear();
}
internal bool TryGetCachedMinMax(int dimension, out double minValue, out double maxValue)
@@ -64,32 +62,7 @@ namespace XCharts.Runtime
cacheValid[dimension] = true;
}
- internal bool TryGetDataZoomCachedMinMax(string key, int dimension, out double minValue, out double maxValue)
- {
- minValue = 0; maxValue = 0;
- if (string.IsNullOrEmpty(key)) return false;
- double[] arr;
- if (!dataZoomMinMaxCache.TryGetValue(key, out arr) || arr == null || arr.Length < 6) return false;
- int mi = dimension * 2;
- minValue = arr[mi];
- maxValue = arr[mi + 1];
- return true;
- }
- internal void SetDataZoomCachedMinMax(string key, int dimension, double minValue, double maxValue)
- {
- if (string.IsNullOrEmpty(key)) return;
- double[] arr;
- if (!dataZoomMinMaxCache.TryGetValue(key, out arr) || arr == null || arr.Length < 6)
- {
- arr = new double[6];
- for (int i = 0; i < 6; i++) arr[i] = 0;
- dataZoomMinMaxCache[key] = arr;
- }
- int mi = dimension * 2;
- arr[mi] = minValue;
- arr[mi + 1] = maxValue;
- }
///
/// 鼠标是否进入serie
///
diff --git a/Runtime/Serie/SerieHandler.cs b/Runtime/Serie/SerieHandler.cs
index 308b4e2b..2446e675 100644
--- a/Runtime/Serie/SerieHandler.cs
+++ b/Runtime/Serie/SerieHandler.cs
@@ -69,6 +69,7 @@ namespace XCharts.Runtime
protected bool m_ForceUpdateSerieContext = false;
protected int m_LegendEnterIndex;
protected ChartLabel m_EndLabel;
+ private HashSet m_DataIndexsSet = new HashSet();
private float[] m_LastRadius = new float[2] { 0, 0 };
private float[] m_LastCenter = new float[2] { 0, 0 };
@@ -506,6 +507,12 @@ namespace XCharts.Runtime
var dataAddDuration = serie.animation.GetAdditionDuration();
var unscaledTime = serie.animation.unscaledTime;
var needCheck = serie.context.dataIndexs.Count > 0;
+ if (needCheck)
+ {
+ m_DataIndexsSet.Clear();
+ foreach (var idx in serie.context.dataIndexs)
+ m_DataIndexsSet.Add(idx);
+ }
var allLabelZeroPosition = true;
var anyLabelActive = false;
SerieData lastActiveLabelSerieData = null;
@@ -517,7 +524,7 @@ namespace XCharts.Runtime
{
continue;
}
- if (needCheck && !serie.context.dataIndexs.Contains(serieData.index))
+ if (needCheck && !m_DataIndexsSet.Contains(serieData.index))
{
serieData.SetLabelActive(false);
continue;
@@ -533,7 +540,7 @@ namespace XCharts.Runtime
{
if (serie.multiDimensionLabel)
{
- var total = serieData.GetTotalData();
+ var total = FormatterHelper.NeedTotalContent(currLabel.formatter) ? serieData.GetTotalData() : 0;
var color = chart.GetItemColor(serie, serieData);
for (int i = 0; i < serieData.context.dataLabels.Count; i++)
{
@@ -570,7 +577,7 @@ namespace XCharts.Runtime
else
{
var value = serieData.GetCurrData(defaultDimension, dataAddDuration, dataChangeDuration, unscaledTime);
- var total = serie.GetDataTotal(defaultDimension, serieData);
+ var total = FormatterHelper.NeedTotalContent(currLabel.formatter) ? serie.GetDataTotal(defaultDimension, serieData) : 0;
var color = chart.GetItemColor(serie, serieData);
var content = string.IsNullOrEmpty(currLabel.formatter) ?
ChartCached.NumberToStr(value, currLabel.numericFormatter) :
diff --git a/Runtime/Serie/SeriesHelper.cs b/Runtime/Serie/SeriesHelper.cs
index 9c80e535..22567d5c 100644
--- a/Runtime/Serie/SeriesHelper.cs
+++ b/Runtime/Serie/SeriesHelper.cs
@@ -409,16 +409,6 @@ namespace XCharts.Runtime
}
else
{
- if (useDataZoomFilter)
- {
- var key = string.Format("dz:{0:F3}:{1:F3}:{2}", dz.start, dz.end, dz.filterMode);
- double cmin, cmax;
- if (serie.context.TryGetDataZoomCachedMinMax(key, dimension, out cmin, out cmax))
- {
- smin = cmin;
- smax = cmax;
- }
- }
var showData = serie.GetDataList(useDataZoomFilter ? dz : null);
if (dimension > 0 && (serie is Candlestick || serie is SimplifiedCandlestick))
{
@@ -451,17 +441,9 @@ namespace XCharts.Runtime
continue;
// cache per-serie result for future calls
- if (!needAnimation)
+ if (!needAnimation && !useDataZoomFilter)
{
- if (useDataZoomFilter)
- {
- var key = string.Format("dz:{0:F3}:{1:F3}:{2}", dz.start, dz.end, dz.filterMode);
- serie.context.SetDataZoomCachedMinMax(key, dimension, smin == double.MaxValue ? 0 : smin, smax == double.MinValue ? 0 : smax);
- }
- else
- {
- serie.context.SetCachedMinMax(dimension, smin == double.MaxValue ? 0 : smin, smax == double.MinValue ? 0 : smax);
- }
+ serie.context.SetCachedMinMax(dimension, smin == double.MaxValue ? 0 : smin, smax == double.MinValue ? 0 : smax);
}
if (smax > max) max = smax;