mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-18 22:40:10 +00:00
代码整理,接口优化
This commit is contained in:
@@ -50,23 +50,192 @@ namespace XCharts
|
||||
public Tooltip tooltip { get { return m_Tooltip; } }
|
||||
public Series series { get { return m_Series; } }
|
||||
|
||||
public bool large { get { return m_Large; } set { m_Large = value; } }
|
||||
/// <summary>
|
||||
/// The min number of data to show in chart.
|
||||
/// </summary>
|
||||
public int minShowDataNumber
|
||||
{
|
||||
get { return m_MinShowDataNumber; }
|
||||
set { m_MinShowDataNumber = value; if (m_MinShowDataNumber < 0) m_MinShowDataNumber = 0; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The max number of data to show in chart.
|
||||
/// </summary>
|
||||
public int maxShowDataNumber
|
||||
{
|
||||
get { return m_MaxShowDataNumber; }
|
||||
set { m_MaxShowDataNumber = value; if (m_MaxShowDataNumber < 0) m_MaxShowDataNumber = 0; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The max number of serie and axis data cache.
|
||||
/// The first data will be remove when the size of serie and axis data is larger then maxCacheDataNumber.
|
||||
/// default:0,unlimited.
|
||||
/// </summary>
|
||||
public int maxCacheDataNumber
|
||||
{
|
||||
get { return m_MaxCacheDataNumber; }
|
||||
set { m_MaxCacheDataNumber = value; if (m_MaxCacheDataNumber < 0) m_MaxCacheDataNumber = 0; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove all series and legend data.
|
||||
/// It just emptying all of serie's data without emptying the list of series.
|
||||
/// </summary>
|
||||
public virtual void ClearData()
|
||||
{
|
||||
m_Series.ClearData();
|
||||
m_Legend.ClearData();
|
||||
RefreshChart();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove legend and serie by name.
|
||||
/// </summary>
|
||||
/// <param name="serieName">the name of serie</param>
|
||||
public virtual void RemoveData(string serieName)
|
||||
{
|
||||
m_Series.Remove(serieName);
|
||||
m_Legend.RemoveData(serieName);
|
||||
RefreshChart();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove all data from series and legend.
|
||||
/// The series list is also cleared.
|
||||
/// </summary>
|
||||
public virtual void RemoveData()
|
||||
{
|
||||
m_Legend.ClearData();
|
||||
m_Series.RemoveAll();
|
||||
RefreshChart();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a serie to serie list.
|
||||
/// </summary>
|
||||
/// <param name="serieName">the name of serie</param>
|
||||
/// <param name="type">the type of serie</param>
|
||||
/// <param name="show">whether to show this serie</param>
|
||||
/// <returns>the added serie</returns>
|
||||
public virtual Serie AddSerie(string serieName, SerieType type, bool show = true)
|
||||
{
|
||||
m_Legend.AddData(serieName);
|
||||
return m_Series.AddSerie(serieName, type);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a data to serie.
|
||||
/// If serie doesn't exist,will be add to series.
|
||||
/// If serieName doesn't exist in legend,will be add to legend.
|
||||
/// </summary>
|
||||
/// <param name="serieName">the name of serie</param>
|
||||
/// <param name="value">the data to add</param>
|
||||
public virtual void AddData(string serieName, float value)
|
||||
{
|
||||
m_Legend.AddData(serieName);
|
||||
m_Series.AddData(serieName, value, m_MaxCacheDataNumber);
|
||||
RefreshChart();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a data to serie.
|
||||
/// If serie doesn't exist, the data is ignored.
|
||||
/// </summary>
|
||||
/// <param name="serieIndex">the index of serie</param>
|
||||
/// <param name="value">the data to add</param>
|
||||
public virtual void AddData(int serieIndex, float value)
|
||||
{
|
||||
m_Series.AddData(serieIndex, value, m_MaxCacheDataNumber);
|
||||
RefreshChart();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update serie data by serie name.
|
||||
/// </summary>
|
||||
/// <param name="serieName">the name of serie</param>
|
||||
/// <param name="value">the data will be update</param>
|
||||
/// <param name="dataIndex">the index of data</param>
|
||||
public virtual void UpdateData(string serieName, float value, int dataIndex = 0)
|
||||
{
|
||||
m_Series.UpdateData(serieName, value, dataIndex);
|
||||
RefreshChart();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update serie data by serie index.
|
||||
/// </summary>
|
||||
/// <param name="serieIndex">the index of serie</param>
|
||||
/// <param name="value">the data will be update</param>
|
||||
/// <param name="dataIndex">the index of data</param>
|
||||
public virtual void UpdateData(int serieIndex, float value, int dataIndex = 0)
|
||||
{
|
||||
m_Series.UpdateData(serieIndex, value, dataIndex);
|
||||
RefreshChart();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether to show serie and legend.
|
||||
/// </summary>
|
||||
/// <param name="serieName">the name of serie</param>
|
||||
/// <param name="active">Active or not</param>
|
||||
public virtual void SetActive(string serieName, bool active)
|
||||
{
|
||||
m_Legend.SetActive(serieName, active);
|
||||
m_Series.SetActive(serieName, active);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether to show serie and legend.
|
||||
/// </summary>
|
||||
/// <param name="serieIndex">the index of serie</param>
|
||||
/// <param name="active">Active or not</param>
|
||||
public virtual void SetActive(int serieIndex, bool active)
|
||||
{
|
||||
m_Legend.SetActive(serieIndex, active);
|
||||
m_Series.SetActive(serieIndex, active);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether serie is activated.
|
||||
/// </summary>
|
||||
/// <param name="serieName">the name of serie</param>
|
||||
/// <returns>True when activated</returns>
|
||||
public virtual bool IsActive(string serieName)
|
||||
{
|
||||
return m_Legend.IsActive(serieName) || m_Series.IsActive(serieName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether serie is activated.
|
||||
/// </summary>
|
||||
/// <param name="serieIndex">the index of serie</param>
|
||||
/// <returns>True when activated</returns>
|
||||
public virtual bool IsActive(int serieIndex)
|
||||
{
|
||||
return m_Legend.IsActive(serieIndex) || m_Series.IsActive(serieIndex);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Redraw chart next frame.
|
||||
/// </summary>
|
||||
public void RefreshChart()
|
||||
{
|
||||
m_RefreshChart = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update chart theme
|
||||
/// </summary>
|
||||
/// <param name="theme">theme</param>
|
||||
public void UpdateTheme(Theme theme)
|
||||
{
|
||||
this.m_Theme = theme;
|
||||
OnThemeChanged();
|
||||
RefreshChart();
|
||||
}
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
if (m_ThemeInfo == null)
|
||||
@@ -116,72 +285,6 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearData()
|
||||
{
|
||||
m_Series.ClearData();
|
||||
m_Legend.ClearData();
|
||||
}
|
||||
|
||||
public virtual void AddData(string legend, float value)
|
||||
{
|
||||
m_Legend.AddData(legend);
|
||||
m_Series.AddData(legend, value, m_MaxCacheDataNumber);
|
||||
RefreshChart();
|
||||
}
|
||||
|
||||
public virtual void AddData(int legend, float value)
|
||||
{
|
||||
m_Series.AddData(legend, value, m_MaxCacheDataNumber);
|
||||
}
|
||||
|
||||
public virtual void UpdateData(string legend, float value, int dataIndex = 0)
|
||||
{
|
||||
m_Series.UpdateData(legend, value, dataIndex);
|
||||
RefreshChart();
|
||||
}
|
||||
|
||||
public virtual void UpdateData(int legendIndex, float value, int dataIndex = 0)
|
||||
{
|
||||
m_Series.UpdateData(legendIndex, value, dataIndex);
|
||||
RefreshChart();
|
||||
}
|
||||
|
||||
public virtual void SetActive(string legend, bool active)
|
||||
{
|
||||
m_Legend.SetActive(legend, active);
|
||||
m_Series.SetActive(legend, active);
|
||||
}
|
||||
|
||||
public virtual void SetActive(int index, bool active)
|
||||
{
|
||||
m_Legend.SetActive(index, active);
|
||||
m_Series.SetActive(index, active);
|
||||
}
|
||||
|
||||
public virtual bool IsActive(string name)
|
||||
{
|
||||
return m_Legend.IsActive(name) || m_Series.IsActive(name);
|
||||
}
|
||||
|
||||
public virtual bool IsActive(int index)
|
||||
{
|
||||
return m_Legend.IsActive(index) || m_Series.IsActive(index);
|
||||
}
|
||||
|
||||
public virtual void RemoveData(string legend)
|
||||
{
|
||||
m_Legend.RemoveData(legend);
|
||||
m_Series.RemoveData(legend);
|
||||
RefreshChart();
|
||||
}
|
||||
|
||||
public void UpdateTheme(Theme theme)
|
||||
{
|
||||
this.m_Theme = theme;
|
||||
OnThemeChanged();
|
||||
SetAllDirty();
|
||||
}
|
||||
|
||||
private void InitTitle()
|
||||
{
|
||||
m_Title.OnChanged();
|
||||
@@ -411,11 +514,6 @@ namespace XCharts
|
||||
{
|
||||
}
|
||||
|
||||
public void RefreshChart()
|
||||
{
|
||||
m_RefreshChart = true;
|
||||
}
|
||||
|
||||
protected virtual void RefreshTooltip()
|
||||
{
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user