性能优化

This commit is contained in:
monitor1394
2020-08-18 09:29:23 +08:00
parent 12ce85de9c
commit c926b9efb2
4 changed files with 58 additions and 26 deletions

View File

@@ -48,7 +48,7 @@ namespace XCharts
float dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
float xMinValue = xAxis.GetCurrMinValue(dataChangeDuration);
float xMaxValue = xAxis.GetCurrMaxValue(dataChangeDuration);
var isAllBarEnd = true;
for (int i = serie.minShow; i < maxCount; i++)
{
if (i >= seriesHig.Count)
@@ -92,8 +92,9 @@ namespace XCharts
seriesHig[i] += barHig;
}
float currHig = CheckAnimation(serie, i, barHig);
var isBarEnd = false;
float currHig = CheckAnimation(serie, i, barHig, out isBarEnd);
if (!isBarEnd) isAllBarEnd = false;
Vector3 plt, prt, prb, plb, top;
if (value < 0)
{
@@ -135,6 +136,7 @@ namespace XCharts
}
}
}
if (isAllBarEnd) serie.animation.AllBarEnd();
if (!SeriesHelper.IsStack(m_Series, serie.stack, SerieType.Bar))
{
m_BarLastOffset += barGapWidth;
@@ -145,9 +147,9 @@ namespace XCharts
}
}
private float CheckAnimation(Serie serie, int dataIndex, float barHig)
private float CheckAnimation(Serie serie, int dataIndex, float barHig, out bool isBarEnd)
{
float currHig = serie.animation.CheckBarProgress(dataIndex, barHig, serie.dataCount);
float currHig = serie.animation.CheckBarProgress(dataIndex, barHig, serie.dataCount, out isBarEnd);
if (!serie.animation.IsFinish())
{
RefreshChart();
@@ -189,6 +191,7 @@ namespace XCharts
float dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
float yMinValue = yAxis.GetCurrMinValue(dataChangeDuration);
float yMaxValue = yAxis.GetCurrMaxValue(dataChangeDuration);
var isAllBarEnd = true;
for (int i = serie.minShow; i < maxCount; i++)
{
if (i >= seriesHig.Count)
@@ -230,7 +233,9 @@ namespace XCharts
/ valueTotal * m_CoordinateHeight;
seriesHig[i] += barHig;
}
float currHig = CheckAnimation(serie, i, barHig);
var isBarEnd = false;
float currHig = CheckAnimation(serie, i, barHig, out isBarEnd);
if (!isBarEnd) isAllBarEnd = false;
Vector3 plb, plt, prt, prb, top;
if (value < 0)
{
@@ -275,6 +280,10 @@ namespace XCharts
}
}
}
if (isAllBarEnd)
{
serie.animation.AllBarEnd();
}
if (dataChanging)
{
RefreshChart();

View File

@@ -1028,13 +1028,13 @@ namespace XCharts
private bool TryAddToList(bool isTurnBack, bool isYAxis, List<Vector3> list, Vector3 lastPos, Vector3 pos, bool ignoreClose = false)
{
if (pos == Vector3.zero) return false;
if (ChartHelper.IsZeroVector(pos)) return false;
if (isTurnBack)
{
list.Add(pos);
return true;
}
else if (lastPos != Vector3.zero && IsInRightOrUp(isYAxis, pos, lastPos))
else if (!ChartHelper.IsZeroVector(lastPos) && IsInRightOrUpNotCheckZero(isYAxis, pos, lastPos))
{
return false;
}
@@ -1046,7 +1046,7 @@ namespace XCharts
else
{
var end = list[list.Count - 1];
if (IsInRightOrUp(isYAxis, end, pos) && (!ignoreClose || !WasTooClose(isYAxis, end, pos, ignoreClose)))
if (IsInRightOrUpNotCheckZero(isYAxis, end, pos) && (!ignoreClose || !WasTooClose(isYAxis, end, pos, ignoreClose)))
{
list.Add(pos);
return true;
@@ -1065,7 +1065,12 @@ namespace XCharts
private bool IsInRightOrUp(bool isYAxis, Vector3 lp, Vector3 rp)
{
return lp == Vector3.zero || ((isYAxis && rp.y > lp.y) || (!isYAxis && rp.x > lp.x));
return ChartHelper.IsZeroVector(lp) || ((isYAxis && rp.y > lp.y) || (!isYAxis && rp.x > lp.x));
}
private bool IsInRightOrUpNotCheckZero(bool isYAxis, Vector3 lp, Vector3 rp)
{
return (isYAxis && rp.y > lp.y) || (!isYAxis && rp.x > lp.x);
}
private bool WasTooClose(bool isYAxis, Vector3 lp, Vector3 rp, bool ignore)

View File

@@ -455,6 +455,11 @@ namespace XCharts
return color.a == 0 && color.b == 0 && color.g == 0 && color.r == 0;
}
public static bool IsZeroVector(Vector3 pos)
{
return pos.x == 0 && pos.y == 0 && pos.z == 0;
}
public static bool CopyList<T>(List<T> toList, List<T> fromList)
{
if (toList == null || fromList == null) return false;