优化性能,优化折线图和柱状图的大数据绘制,重构代码

This commit is contained in:
monitor1394
2020-05-13 09:54:40 +08:00
parent d56ed2e086
commit 34f3ef5182
44 changed files with 744 additions and 607 deletions

View File

@@ -149,6 +149,7 @@ namespace XCharts
m_Tooltip.ClearValue();
m_CheckAnimation = false;
m_ReinitLabel = true;
m_SerieLabelRoot = null;
RefreshChart();
}
@@ -161,6 +162,7 @@ namespace XCharts
{
m_Series.Remove(serieName);
m_Legend.RemoveData(serieName);
m_SerieLabelRoot = null;
RefreshChart();
}
@@ -191,8 +193,9 @@ namespace XCharts
var serieData = m_Series.AddData(serieName, data, dataName);
if (serieData != null)
{
var serie = m_Series.GetSerie(serieName);
AddSerieLabel(serie, serieData);
RefreshChart();
RefreshLabel();
}
return serieData;
}
@@ -210,8 +213,9 @@ namespace XCharts
var serieData = m_Series.AddData(serieIndex, data, dataName);
if (serieData != null)
{
var serie = m_Series.GetSerie(serieIndex);
AddSerieLabel(serie, serieData);
RefreshChart();
RefreshLabel();
}
return serieData;
}
@@ -229,8 +233,9 @@ namespace XCharts
var serieData = m_Series.AddData(serieName, multidimensionalData, dataName);
if (serieData != null)
{
var serie = m_Series.GetSerie(serieName);
AddSerieLabel(serie, serieData);
RefreshChart();
RefreshLabel();
}
return serieData;
}
@@ -248,8 +253,9 @@ namespace XCharts
var serieData = m_Series.AddData(serieIndex, multidimensionalData, dataName);
if (serieData != null)
{
var serie = m_Series.GetSerie(serieIndex);
AddSerieLabel(serie, serieData);
RefreshChart();
RefreshLabel();
}
return serieData;
}
@@ -268,8 +274,9 @@ namespace XCharts
var serieData = m_Series.AddXYData(serieName, xValue, yValue, dataName);
if (serieData != null)
{
var serie = m_Series.GetSerie(serieName);
AddSerieLabel(serie, serieData);
RefreshChart();
RefreshLabel();
}
return serieData;
}
@@ -288,8 +295,9 @@ namespace XCharts
var serieData = m_Series.AddXYData(serieIndex, xValue, yValue, dataName);
if (serieData != null)
{
var serie = m_Series.GetSerie(serieIndex);
AddSerieLabel(serie, serieData);
RefreshChart();
RefreshLabel();
}
return serieData;
}
@@ -529,6 +537,7 @@ namespace XCharts
public void RefreshLabel()
{
m_ReinitLabel = true;
m_SerieLabelRoot = null;
}
/// <summary>
@@ -643,25 +652,27 @@ namespace XCharts
/// <returns></returns>
public bool IsInChart(Vector2 local)
{
if (local.x < m_ChartX || local.x > m_ChartX + m_ChartWidth ||
local.y < m_ChartY || local.y > m_ChartY + m_ChartHeight)
return IsInChart(local.x, local.y);
}
public bool IsInChart(float x, float y)
{
if (x < m_ChartX || x > m_ChartX + m_ChartWidth ||
y < m_ChartY || y > m_ChartY + m_ChartHeight)
{
return false;
}
return true;
}
public Vector3 ClampInChart(Vector3 pos)
public void ClampInChart(ref Vector3 pos)
{
if (IsInChart(pos)) return pos;
else
if (!IsInChart(pos.x, pos.y))
{
var np = new Vector3(pos.x, pos.y);
if (np.x < m_ChartX) np.x = m_ChartX;
if (np.x > m_ChartX + chartWidth) np.x = m_ChartX + chartWidth;
if (np.y < m_ChartY) np.y = m_ChartY;
if (np.y > m_ChartY + chartHeight) np.y = m_ChartY + chartHeight;
return np;
if (pos.x < m_ChartX) pos.x = m_ChartX;
if (pos.x > m_ChartX + m_ChartWidth) pos.x = m_ChartX + m_ChartWidth;
if (pos.y < m_ChartY) pos.y = m_ChartY;
if (pos.y > m_ChartY + m_ChartHeight) pos.y = m_ChartY + m_ChartHeight;
}
}

View File

@@ -22,29 +22,23 @@ namespace XCharts
/// The lower left position x of coordinate system.
/// 坐标系的左下角坐标X。
/// </summary>
public float coordinateX { get { return m_ChartX + m_Grid.left; } }
public float coordinateX { get { return m_CoordinateX; } }
/// <summary>
/// The lower left position y of coordinate system.
/// 坐标系的左下角坐标Y。
/// </summary>
public float coordinateY { get { return m_ChartY + m_Grid.bottom; } }
[Obsolete("Use CoordinateChart.coordinateWidth instead.", true)]
public float coordinateWid { get { return coordinateWidth; } }
[Obsolete("Use CoordinateChart.coordinateHeight instead.", true)]
public float coordinateHig { get { return coordinateHeight; } }
public float coordinateY { get { return m_CoordinateY; } }
/// <summary>
/// the width of coordinate system。
/// 坐标系的宽。
/// </summary>
public float coordinateWidth { get { return chartWidth - m_Grid.left - m_Grid.right; } }
public float coordinateWidth { get { return m_CoordinateWidth; } }
/// <summary>
/// the height of coordinate system。
/// 坐标系的高。
/// </summary>
public float coordinateHeight { get { return chartHeight - m_Grid.top - m_Grid.bottom; } }
public float coordinateHeight { get { return m_CoordinateHeight; } }
/// <summary>
/// grid component.
/// 网格组件。
@@ -175,8 +169,18 @@ namespace XCharts
public bool IsInCooridate(Vector2 local)
{
if (local.x < coordinateX - 1 || local.x > coordinateX + coordinateWidth + 1 ||
local.y < coordinateY - 1 || local.y > coordinateY + coordinateHeight + 1)
return IsInCooridate(local.x, local.y);
}
public bool IsInCooridate(Vector3 local)
{
return IsInCooridate(local.x, local.y);
}
public bool IsInCooridate(float x, float y)
{
if (x < m_CoordinateX - 1 || x > m_CoordinateX + m_CoordinateWidth + 1 ||
y < m_CoordinateY - 1 || y > m_CoordinateY + m_CoordinateHeight + 1)
{
return false;
}
@@ -204,12 +208,12 @@ namespace XCharts
if (IsInCooridate(pos)) return pos;
else
{
var np = new Vector3(pos.x, pos.y);
if (np.x < coordinateX) np.x = coordinateX;
if (np.x > coordinateX + coordinateWidth) np.x = coordinateX + coordinateWidth;
if (np.y < coordinateY) np.y = coordinateY;
if (np.y > coordinateY + coordinateHeight) np.y = coordinateY + coordinateHeight;
return np;
// var pos = new Vector3(pos.x, pos.y);
if (pos.x < m_CoordinateX) pos.x = m_CoordinateX;
if (pos.x > m_CoordinateX + m_CoordinateWidth) pos.x = m_CoordinateX + m_CoordinateWidth;
if (pos.y < m_CoordinateY) pos.y = m_CoordinateY;
if (pos.y > m_CoordinateY + m_CoordinateHeight) pos.y = m_CoordinateY + m_CoordinateHeight;
return pos;
}
}
@@ -236,6 +240,27 @@ namespace XCharts
yAxis.runtimeMaxValue = 0;
}
}
/// <summary>
/// 更新坐标系原点和宽高
/// </summary>
public void UpdateCoordinate()
{
m_CoordinateX = m_ChartX + m_Grid.left;
m_CoordinateY = m_ChartY + m_Grid.bottom;
m_CoordinateWidth = m_ChartWidth - m_Grid.left - m_Grid.right;
m_CoordinateHeight = m_ChartHeight - m_Grid.top - m_Grid.bottom;
}
/// <summary>
/// 设置可缓存的最大数据量。
/// </summary>
public void SetMaxCache(int maxCache)
{
foreach (var serie in m_Series.list) serie.maxCache = maxCache;
foreach (var axis in m_XAxises) axis.maxCache = maxCache;
foreach (var axis in m_YAxises) axis.maxCache = maxCache;
}
}
}