mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-30 13:28:47 +00:00
优化图表性能
This commit is contained in:
@@ -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<string, double[]> dataZoomMinMaxCache = new Dictionary<string, double[]>();
|
||||
|
||||
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;
|
||||
}
|
||||
/// <summary>
|
||||
/// 鼠标是否进入serie
|
||||
/// </summary>
|
||||
|
||||
@@ -69,6 +69,7 @@ namespace XCharts.Runtime
|
||||
protected bool m_ForceUpdateSerieContext = false;
|
||||
protected int m_LegendEnterIndex;
|
||||
protected ChartLabel m_EndLabel;
|
||||
private HashSet<int> m_DataIndexsSet = new HashSet<int>();
|
||||
|
||||
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) :
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user