重构minShowDataNumber、maxShowDataNumber、maxCacheDataNumber到Serie的minShow、maxShow、maxCache

This commit is contained in:
monitor1394
2019-09-29 07:37:53 +08:00
parent c54d62c8f8
commit 2a1ad8886e
14 changed files with 118 additions and 112 deletions

View File

@@ -96,6 +96,7 @@ namespace XCharts
[SerializeField] protected bool m_ShowSplitLine = false;
[SerializeField] protected SplitLineType m_SplitLineType = SplitLineType.Dashed;
[SerializeField] protected bool m_BoundaryGap = true;
[SerializeField] protected int m_MaxCache = 0;
[SerializeField] protected List<string> m_Data = new List<string>();
[SerializeField] protected AxisLine m_AxisLine = AxisLine.defaultAxisLine;
[SerializeField] protected AxisName m_AxisName = AxisName.defaultAxisName;
@@ -156,6 +157,12 @@ namespace XCharts
/// </summary>
public bool boundaryGap { get { return m_BoundaryGap; } set { m_BoundaryGap = value; } }
/// <summary>
/// The max number of axis data cache.
/// The first data will be remove when the size of axis data is larger then maxCache.
/// 可缓存的最大数据量。默认为0没有限制大于0时超过指定值会移除旧数据再插入新数据。
/// </summary>
public int maxCache { get { return m_MaxCache; } set { m_MaxCache = value < 0 ? 0 : value; } }
/// <summary>
/// Category data, available in type: 'Category' axis.
/// 类目数据在类目轴type: 'category')中有效。
/// </summary>
@@ -268,12 +275,11 @@ namespace XCharts
/// 添加一个类目到类目数据列表
/// </summary>
/// <param name="category"></param>
/// <param name="maxDataNumber"></param>
public void AddData(string category, int maxDataNumber)
public void AddData(string category)
{
if (maxDataNumber > 0)
if (maxCache > 0)
{
while (m_Data.Count > maxDataNumber) m_Data.RemoveAt(0);
while (m_Data.Count > maxCache) m_Data.RemoveAt(0);
}
m_Data.Add(category);
}

View File

@@ -123,6 +123,9 @@ namespace XCharts
[SerializeField] private string m_Stack;
[SerializeField] [Range(0, 1)] private int m_AxisIndex = 0;
[SerializeField] private int m_RadarIndex = 0;
[SerializeField] protected int m_MinShow;
[SerializeField] protected int m_MaxShow;
[SerializeField] protected int m_MaxCache;
[SerializeField] private AreaStyle m_AreaStyle = AreaStyle.defaultAreaStyle;
[SerializeField] private SerieSymbol m_Symbol = new SerieSymbol();
[SerializeField] private LineType m_LineType = LineType.Normal;
@@ -187,6 +190,35 @@ namespace XCharts
/// </summary>
public int radarIndex { get { return m_RadarIndex; } set { m_RadarIndex = value; } }
/// <summary>
/// The min number of data to show in chart.
/// 系列所显示数据的最小索引
/// </summary>
public int minShow
{
get { return m_MinShow; }
set { m_MinShow = value; if (m_MinShow < 0) m_MinShow = 0; }
}
/// <summary>
/// The max number of data to show in chart.
/// 系列所显示数据的最大索引
/// </summary>
public int maxShow
{
get { return m_MaxShow; }
set { m_MaxShow = value; if (m_MaxShow < 0) m_MaxShow = 0; }
}
/// <summary>
/// The max number of serie data cache.
/// The first data will be remove when the size of serie data is larger then maxCache.
/// default:0,unlimited.
/// 系列中可缓存的最大数据量。默认为0没有限制大于0时超过指定值会移除旧数据再插入新数据。
/// </summary>
public int maxCache
{
get { return m_MaxCache; }
set { m_MaxCache = value; if (m_MaxCache < 0) m_MaxCache = 0; }
}
/// <summary>
/// The style of area.
/// 区域填充样式。
/// </summary>
@@ -484,12 +516,11 @@ namespace XCharts
/// </summary>
/// <param name="value"></param>
/// <param name="dataName"></param>
/// <param name="maxDataNumber"></param>
public void AddYData(float value, string dataName = null, int maxDataNumber = 0)
public void AddYData(float value, string dataName = null)
{
if (maxDataNumber > 0)
if (m_MaxCache > 0)
{
while (m_Data.Count > maxDataNumber) m_Data.RemoveAt(0);
while (m_Data.Count > m_MaxCache) m_Data.RemoveAt(0);
}
int xValue = m_Data.Count;
m_Data.Add(new SerieData() { data = new List<float>() { xValue, value }, name = dataName });
@@ -502,11 +533,11 @@ namespace XCharts
/// <param name="yValue"></param>
/// <param name="dataName"></param>
/// <param name="maxDataNumber"></param>
public void AddXYData(float xValue, float yValue, string dataName = null, int maxDataNumber = 0)
public void AddXYData(float xValue, float yValue, string dataName = null)
{
if (maxDataNumber > 0)
if (m_MaxCache > 0)
{
while (m_Data.Count > maxDataNumber) m_Data.RemoveAt(0);
while (m_Data.Count > m_MaxCache) m_Data.RemoveAt(0);
}
m_Data.Add(new SerieData() { data = new List<float>() { xValue, yValue }, name = dataName });
}
@@ -518,22 +549,22 @@ namespace XCharts
/// <param name="valueList"></param>
/// <param name="dataName"></param>
/// <param name="maxDataNumber"></param>
public void AddData(List<float> valueList, string dataName = null, int maxDataNumber = 0)
public void AddData(List<float> valueList, string dataName = null)
{
if (valueList == null || valueList.Count == 0) return;
if (valueList.Count == 1)
{
AddYData(valueList[0], dataName, maxDataNumber);
AddYData(valueList[0], dataName);
}
else if (valueList.Count == 2)
{
AddXYData(valueList[0], valueList[1], dataName, maxDataNumber);
AddXYData(valueList[0], valueList[1], dataName);
}
else
{
if (maxDataNumber > 0)
if (m_MaxCache > 0)
{
while (m_Data.Count > maxDataNumber) m_Data.RemoveAt(0);
while (m_Data.Count > m_MaxCache) m_Data.RemoveAt(0);
}
var serieData = new SerieData();
serieData.name = dataName;

View File

@@ -256,12 +256,12 @@ namespace XCharts
/// <param name="dataName"></param>
/// <param name="maxDataNumber"></param>
/// <returns></returns>
public bool AddData(string serieName, float value, string dataName = null, int maxDataNumber = 0)
public bool AddData(string serieName, float value, string dataName = null)
{
var serie = GetSerie(serieName);
if (serie != null)
{
serie.AddYData(value, dataName, maxDataNumber);
serie.AddYData(value, dataName);
return true;
}
return false;
@@ -275,12 +275,12 @@ namespace XCharts
/// <param name="dataName"></param>
/// <param name="maxDataNumber"></param>
/// <returns></returns>
public bool AddData(int index, float value, string dataName = null, int maxDataNumber = 0)
public bool AddData(int index, float value, string dataName = null)
{
var serie = GetSerie(index);
if (serie != null)
{
serie.AddYData(value, dataName, maxDataNumber);
serie.AddYData(value, dataName);
return true;
}
return false;
@@ -294,12 +294,12 @@ namespace XCharts
/// <param name="dataName"></param>
/// <param name="maxDataNumber"></param>
/// <returns></returns>
public bool AddData(string serieName, List<float> multidimensionalData, string dataName = null, int maxDataNumber = 0)
public bool AddData(string serieName, List<float> multidimensionalData, string dataName = null)
{
var serie = GetSerie(serieName);
if (serie != null)
{
serie.AddData(multidimensionalData, dataName, maxDataNumber);
serie.AddData(multidimensionalData, dataName);
return true;
}
return false;
@@ -313,12 +313,12 @@ namespace XCharts
/// <param name="dataName"></param>
/// <param name="maxDataNumber"></param>
/// <returns></returns>
public bool AddData(int serieIndex, List<float> multidimensionalData, string dataName = null, int maxDataNumber = 0)
public bool AddData(int serieIndex, List<float> multidimensionalData, string dataName = null)
{
var serie = GetSerie(serieIndex);
if (serie != null)
{
serie.AddData(multidimensionalData, dataName, maxDataNumber);
serie.AddData(multidimensionalData, dataName);
return true;
}
return false;
@@ -333,12 +333,12 @@ namespace XCharts
/// <param name="dataName"></param>
/// <param name="maxDataNumber"></param>
/// <returns></returns>
public bool AddXYData(string serieName, float xValue, float yValue, string dataName = null, int maxDataNumber = 0)
public bool AddXYData(string serieName, float xValue, float yValue, string dataName = null)
{
var serie = GetSerie(serieName);
if (serie != null)
{
serie.AddXYData(xValue, yValue, dataName, maxDataNumber);
serie.AddXYData(xValue, yValue, dataName);
return true;
}
return false;
@@ -353,12 +353,12 @@ namespace XCharts
/// <param name="dataName"></param>
/// <param name="maxDataNumber"></param>
/// <returns></returns>
public bool AddXYData(int index, float xValue, float yValue, string dataName = null, int maxDataNumber = 0)
public bool AddXYData(int index, float xValue, float yValue, string dataName = null)
{
var serie = GetSerie(index);
if (serie != null)
{
serie.AddXYData(xValue, yValue, dataName, maxDataNumber);
serie.AddXYData(xValue, yValue, dataName);
return true;
}
return false;