mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-31 13:58:48 +00:00
优化图表性能
This commit is contained in:
@@ -25,6 +25,13 @@ namespace XCharts.Runtime
|
|||||||
return !string.IsNullOrEmpty(content) && content.IndexOf('{') >= 0;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 替换字符串中的通配符,支持的通配符有{.}、{a}、{b}、{c}、{d}、{e}、{f}、{g}、{h}、{y}。
|
/// 替换字符串中的通配符,支持的通配符有{.}、{a}、{b}、{c}、{d}、{e}、{f}、{g}、{h}、{y}。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -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[] 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 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 bool[] cacheValid = new bool[3] { false, false, false };
|
||||||
[System.NonSerialized] internal Dictionary<string, double[]> dataZoomMinMaxCache = new Dictionary<string, double[]>();
|
|
||||||
|
|
||||||
internal void InvalidateMinMaxCache()
|
internal void InvalidateMinMaxCache()
|
||||||
{
|
{
|
||||||
@@ -40,7 +39,6 @@ namespace XCharts.Runtime
|
|||||||
cacheValid[i] = false;
|
cacheValid[i] = false;
|
||||||
cachedMin[0] = cachedMin[1] = cachedMin[2] = double.MaxValue;
|
cachedMin[0] = cachedMin[1] = cachedMin[2] = double.MaxValue;
|
||||||
cachedMax[0] = cachedMax[1] = cachedMax[2] = double.MinValue;
|
cachedMax[0] = cachedMax[1] = cachedMax[2] = double.MinValue;
|
||||||
dataZoomMinMaxCache.Clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal bool TryGetCachedMinMax(int dimension, out double minValue, out double maxValue)
|
internal bool TryGetCachedMinMax(int dimension, out double minValue, out double maxValue)
|
||||||
@@ -64,32 +62,7 @@ namespace XCharts.Runtime
|
|||||||
cacheValid[dimension] = true;
|
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>
|
/// <summary>
|
||||||
/// 鼠标是否进入serie
|
/// 鼠标是否进入serie
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ namespace XCharts.Runtime
|
|||||||
protected bool m_ForceUpdateSerieContext = false;
|
protected bool m_ForceUpdateSerieContext = false;
|
||||||
protected int m_LegendEnterIndex;
|
protected int m_LegendEnterIndex;
|
||||||
protected ChartLabel m_EndLabel;
|
protected ChartLabel m_EndLabel;
|
||||||
|
private HashSet<int> m_DataIndexsSet = new HashSet<int>();
|
||||||
|
|
||||||
private float[] m_LastRadius = new float[2] { 0, 0 };
|
private float[] m_LastRadius = new float[2] { 0, 0 };
|
||||||
private float[] m_LastCenter = 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 dataAddDuration = serie.animation.GetAdditionDuration();
|
||||||
var unscaledTime = serie.animation.unscaledTime;
|
var unscaledTime = serie.animation.unscaledTime;
|
||||||
var needCheck = serie.context.dataIndexs.Count > 0;
|
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 allLabelZeroPosition = true;
|
||||||
var anyLabelActive = false;
|
var anyLabelActive = false;
|
||||||
SerieData lastActiveLabelSerieData = null;
|
SerieData lastActiveLabelSerieData = null;
|
||||||
@@ -517,7 +524,7 @@ namespace XCharts.Runtime
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (needCheck && !serie.context.dataIndexs.Contains(serieData.index))
|
if (needCheck && !m_DataIndexsSet.Contains(serieData.index))
|
||||||
{
|
{
|
||||||
serieData.SetLabelActive(false);
|
serieData.SetLabelActive(false);
|
||||||
continue;
|
continue;
|
||||||
@@ -533,7 +540,7 @@ namespace XCharts.Runtime
|
|||||||
{
|
{
|
||||||
if (serie.multiDimensionLabel)
|
if (serie.multiDimensionLabel)
|
||||||
{
|
{
|
||||||
var total = serieData.GetTotalData();
|
var total = FormatterHelper.NeedTotalContent(currLabel.formatter) ? serieData.GetTotalData() : 0;
|
||||||
var color = chart.GetItemColor(serie, serieData);
|
var color = chart.GetItemColor(serie, serieData);
|
||||||
for (int i = 0; i < serieData.context.dataLabels.Count; i++)
|
for (int i = 0; i < serieData.context.dataLabels.Count; i++)
|
||||||
{
|
{
|
||||||
@@ -570,7 +577,7 @@ namespace XCharts.Runtime
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
var value = serieData.GetCurrData(defaultDimension, dataAddDuration, dataChangeDuration, unscaledTime);
|
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 color = chart.GetItemColor(serie, serieData);
|
||||||
var content = string.IsNullOrEmpty(currLabel.formatter) ?
|
var content = string.IsNullOrEmpty(currLabel.formatter) ?
|
||||||
ChartCached.NumberToStr(value, currLabel.numericFormatter) :
|
ChartCached.NumberToStr(value, currLabel.numericFormatter) :
|
||||||
|
|||||||
@@ -409,16 +409,6 @@ namespace XCharts.Runtime
|
|||||||
}
|
}
|
||||||
else
|
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);
|
var showData = serie.GetDataList(useDataZoomFilter ? dz : null);
|
||||||
if (dimension > 0 && (serie is Candlestick || serie is SimplifiedCandlestick))
|
if (dimension > 0 && (serie is Candlestick || serie is SimplifiedCandlestick))
|
||||||
{
|
{
|
||||||
@@ -451,17 +441,9 @@ namespace XCharts.Runtime
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
// cache per-serie result for future calls
|
// cache per-serie result for future calls
|
||||||
if (!needAnimation)
|
if (!needAnimation && !useDataZoomFilter)
|
||||||
{
|
{
|
||||||
if (useDataZoomFilter)
|
serie.context.SetCachedMinMax(dimension, smin == double.MaxValue ? 0 : smin, smax == double.MinValue ? 0 : smax);
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (smax > max) max = smax;
|
if (smax > max) max = smax;
|
||||||
|
|||||||
Reference in New Issue
Block a user