mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-21 16:00:24 +00:00
代码整理,接口优化
This commit is contained in:
@@ -123,14 +123,14 @@ namespace XCharts
|
||||
|
||||
public string GetData(int index, DataZoom dataZoom)
|
||||
{
|
||||
var showData = GetData(dataZoom);
|
||||
var showData = GetDataList(dataZoom);
|
||||
if (index >= 0 && index < showData.Count)
|
||||
return showData[index];
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
public List<string> GetData(DataZoom dataZoom)
|
||||
public List<string> GetDataList(DataZoom dataZoom)
|
||||
{
|
||||
if (dataZoom != null && dataZoom.show)
|
||||
{
|
||||
@@ -179,7 +179,7 @@ namespace XCharts
|
||||
public int GetSplitNumber(DataZoom dataZoom)
|
||||
{
|
||||
if (type == AxisType.Value) return m_SplitNumber;
|
||||
int dataCount = GetData(dataZoom).Count;
|
||||
int dataCount = GetDataList(dataZoom).Count;
|
||||
if (dataCount > 2 * m_SplitNumber || dataCount <= 0)
|
||||
return m_SplitNumber;
|
||||
else
|
||||
@@ -193,7 +193,7 @@ namespace XCharts
|
||||
|
||||
public int GetDataNumber(DataZoom dataZoom)
|
||||
{
|
||||
return GetData(dataZoom).Count;
|
||||
return GetDataList(dataZoom).Count;
|
||||
}
|
||||
|
||||
public float GetDataWidth(float coordinateWidth, DataZoom dataZoom)
|
||||
@@ -202,7 +202,7 @@ namespace XCharts
|
||||
return coordinateWidth / (m_BoundaryGap ? dataCount : dataCount - 1);
|
||||
}
|
||||
|
||||
public string GetScaleName(int index, float minValue, float maxValue, DataZoom dataZoom)
|
||||
public string GetLabelName(int index, float minValue, float maxValue, DataZoom dataZoom)
|
||||
{
|
||||
if (m_Type == AxisType.Value)
|
||||
{
|
||||
@@ -212,7 +212,7 @@ namespace XCharts
|
||||
else
|
||||
return (value).ToString("f1");
|
||||
}
|
||||
var showData = GetData(dataZoom);
|
||||
var showData = GetDataList(dataZoom);
|
||||
int dataCount = showData.Count;
|
||||
if (dataCount <= 0) return "";
|
||||
|
||||
@@ -239,7 +239,7 @@ namespace XCharts
|
||||
}
|
||||
else
|
||||
{
|
||||
var showData = GetData(dataZoom);
|
||||
var showData = GetDataList(dataZoom);
|
||||
int dataCount = showData.Count;
|
||||
if (dataCount > 2 * splitNumber || dataCount <= 0)
|
||||
return m_BoundaryGap ? m_SplitNumber + 1 : m_SplitNumber;
|
||||
@@ -259,7 +259,10 @@ namespace XCharts
|
||||
{
|
||||
for (int i = 0; i < axisLabelTextList.Count; i++)
|
||||
{
|
||||
axisLabelTextList[i].text = GetScaleName(i, minValue, maxValue, dataZoom);
|
||||
if (axisLabelTextList[i] != null)
|
||||
{
|
||||
axisLabelTextList[i].text = GetLabelName(i, minValue, maxValue, dataZoom);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -26,10 +26,10 @@ namespace XCharts
|
||||
{
|
||||
var coordinate = new Coordinate
|
||||
{
|
||||
m_Left = 40f,
|
||||
m_Right = 80f,
|
||||
m_Top = 50f,
|
||||
m_Bottom = 30f,
|
||||
m_Left = 50,
|
||||
m_Right = 30,
|
||||
m_Top = 60,
|
||||
m_Bottom = 30,
|
||||
m_Tickness = 0.6f,
|
||||
m_FontSize = 16,
|
||||
};
|
||||
|
||||
@@ -27,8 +27,8 @@ namespace XCharts
|
||||
private List<YAxis> m_CheckYAxises = new List<YAxis>();
|
||||
private Coordinate m_CheckCoordinate = Coordinate.defaultCoordinate;
|
||||
|
||||
public float zeroX { get { return coordinateX; } }
|
||||
public float zeroY { get { return coordinateY; } }
|
||||
// public float coordinateX { get { return coordinateX; } }
|
||||
// public float coordinateY { get { return coordinateY; } }
|
||||
public float coordinateX { get { return m_Coordinate.left; } }
|
||||
public float coordinateY { get { return m_Coordinate.bottom; } }
|
||||
public float coordinateWid { get { return chartWidth - m_Coordinate.left - m_Coordinate.right; } }
|
||||
@@ -36,6 +36,52 @@ namespace XCharts
|
||||
public List<XAxis> xAxises { get { return m_XAxises; } }
|
||||
public List<YAxis> yAxises { get { return m_YAxises; } }
|
||||
|
||||
/// <summary>
|
||||
/// Remove all data from series,legend and axis.
|
||||
/// It just emptying all of serie's data without emptying the list of series.
|
||||
/// </summary>
|
||||
public override void ClearData()
|
||||
{
|
||||
base.ClearData();
|
||||
ClearAxisData();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove all data from series,legend and axis.
|
||||
/// The series list is also cleared.
|
||||
/// </summary>
|
||||
public override void RemoveData()
|
||||
{
|
||||
base.RemoveData();
|
||||
ClearAxisData();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove all data of axises.
|
||||
/// </summary>
|
||||
public void ClearAxisData()
|
||||
{
|
||||
foreach (var item in m_XAxises) item.data.Clear();
|
||||
foreach (var item in m_YAxises) item.data.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="category"></param>
|
||||
/// <param name="xAxisIndex"></param>
|
||||
public void AddXAxisData(string category, int xAxisIndex = 0)
|
||||
{
|
||||
m_XAxises[xAxisIndex].AddData(category, m_MaxCacheDataNumber);
|
||||
OnXAxisChanged();
|
||||
}
|
||||
|
||||
public void AddYAxisData(string category, int yAxisIndex = 0)
|
||||
{
|
||||
m_YAxises[yAxisIndex].AddData(category, m_MaxCacheDataNumber);
|
||||
OnYAxisChanged();
|
||||
}
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
@@ -64,9 +110,7 @@ namespace XCharts
|
||||
m_Coordinate = Coordinate.defaultCoordinate;
|
||||
m_XAxises.Clear();
|
||||
m_YAxises.Clear();
|
||||
InitDefaultAxises();
|
||||
InitAxisX();
|
||||
InitAxisY();
|
||||
Awake();
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -270,39 +314,24 @@ namespace XCharts
|
||||
InitAxisY();
|
||||
}
|
||||
|
||||
public void ClearAxisData()
|
||||
{
|
||||
foreach (var item in m_XAxises) item.data.Clear();
|
||||
foreach (var item in m_YAxises) item.data.Clear();
|
||||
}
|
||||
public void AddXAxisData(string category, int xAxisIndex = 0)
|
||||
{
|
||||
m_XAxises[xAxisIndex].AddData(category, m_MaxCacheDataNumber);
|
||||
OnXAxisChanged();
|
||||
}
|
||||
|
||||
public void AddYAxisData(string category, int yAxisIndex = 0)
|
||||
{
|
||||
m_YAxises[yAxisIndex].AddData(category, m_MaxCacheDataNumber);
|
||||
OnYAxisChanged();
|
||||
}
|
||||
|
||||
private void InitDefaultAxises()
|
||||
{
|
||||
if (m_XAxises.Count <= 0)
|
||||
{
|
||||
var axis1 = new XAxis();
|
||||
axis1.Copy(axis1);
|
||||
var axis1 = XAxis.defaultXAxis;
|
||||
var axis2 = XAxis.defaultXAxis;
|
||||
axis1.show = true;
|
||||
axis2.show = false;
|
||||
m_XAxises.Add(axis1);
|
||||
m_XAxises.Add(axis2);
|
||||
}
|
||||
if (m_YAxises.Count <= 0)
|
||||
{
|
||||
var axis1 = new YAxis();
|
||||
axis1.Copy(axis1);
|
||||
var axis1 = YAxis.defaultYAxis;
|
||||
var axis2 = YAxis.defaultYAxis;
|
||||
axis1.show = true;
|
||||
axis1.splitNumber = 6;
|
||||
axis1.boundaryGap = false;
|
||||
axis2.show = false;
|
||||
m_YAxises.Add(axis1);
|
||||
m_YAxises.Add(axis2);
|
||||
@@ -353,7 +382,7 @@ namespace XCharts
|
||||
}
|
||||
|
||||
txt.transform.localPosition = GetLabelYPosition(labelWidth, i, yAxisIndex, yAxis);
|
||||
txt.text = yAxis.GetScaleName(i, yAxis.minValue, yAxis.maxValue, m_DataZoom);
|
||||
txt.text = yAxis.GetLabelName(i, yAxis.minValue, yAxis.maxValue, m_DataZoom);
|
||||
txt.gameObject.SetActive(yAxis.show &&
|
||||
(yAxis.axisLabel.interval == 0 || i % (yAxis.axisLabel.interval + 1) == 0));
|
||||
yAxis.axisLabelTextList.Add(txt);
|
||||
@@ -397,12 +426,15 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
//init tooltip label
|
||||
Vector2 privot = yAxisIndex > 0 ? new Vector2(0, 0.5f) : new Vector2(1, 0.5f);
|
||||
var labelParent = m_Tooltip.gameObject.transform;
|
||||
GameObject labelObj = ChartHelper.AddTooltipLabel(objName + "_label", labelParent, m_ThemeInfo.font, privot);
|
||||
yAxis.SetTooltipLabel(labelObj);
|
||||
yAxis.SetTooltipLabelColor(m_ThemeInfo.tooltipBackgroundColor, m_ThemeInfo.tooltipTextColor);
|
||||
yAxis.SetTooltipLabelActive(yAxis.show && m_Tooltip.show && m_Tooltip.crossLabel);
|
||||
if (m_Tooltip.gameObject)
|
||||
{
|
||||
Vector2 privot = yAxisIndex > 0 ? new Vector2(0, 0.5f) : new Vector2(1, 0.5f);
|
||||
var labelParent = m_Tooltip.gameObject.transform;
|
||||
GameObject labelObj = ChartHelper.AddTooltipLabel(objName + "_label", labelParent, m_ThemeInfo.font, privot);
|
||||
yAxis.SetTooltipLabel(labelObj);
|
||||
yAxis.SetTooltipLabelColor(m_ThemeInfo.tooltipBackgroundColor, m_ThemeInfo.tooltipTextColor);
|
||||
yAxis.SetTooltipLabelActive(yAxis.show && m_Tooltip.show && m_Tooltip.crossLabel);
|
||||
}
|
||||
}
|
||||
|
||||
private void InitAxisX()
|
||||
@@ -438,7 +470,7 @@ namespace XCharts
|
||||
xAxis.axisLabel.fontSize, xAxis.axisLabel.rotate, xAxis.axisLabel.fontStyle);
|
||||
|
||||
txt.transform.localPosition = GetLabelXPosition(labelWidth, i, xAxisIndex, xAxis);
|
||||
txt.text = xAxis.GetScaleName(i, xAxis.minValue, xAxis.maxValue, m_DataZoom);
|
||||
txt.text = xAxis.GetLabelName(i, xAxis.minValue, xAxis.maxValue, m_DataZoom);
|
||||
txt.gameObject.SetActive(xAxis.show &&
|
||||
(xAxis.axisLabel.interval == 0 || i % (xAxis.axisLabel.interval + 1) == 0));
|
||||
xAxis.axisLabelTextList.Add(txt);
|
||||
@@ -481,12 +513,15 @@ namespace XCharts
|
||||
break;
|
||||
}
|
||||
}
|
||||
Vector2 privot = xAxisIndex > 0 ? new Vector2(0.5f, 1) : new Vector2(0.5f, 1);
|
||||
var labelParent = m_Tooltip.gameObject.transform;
|
||||
GameObject labelObj = ChartHelper.AddTooltipLabel(objName + "_label", labelParent, m_ThemeInfo.font, privot);
|
||||
xAxis.SetTooltipLabel(labelObj);
|
||||
xAxis.SetTooltipLabelColor(m_ThemeInfo.tooltipBackgroundColor, m_ThemeInfo.tooltipTextColor);
|
||||
xAxis.SetTooltipLabelActive(xAxis.show && m_Tooltip.show && m_Tooltip.crossLabel);
|
||||
if (m_Tooltip.gameObject)
|
||||
{
|
||||
Vector2 privot = xAxisIndex > 0 ? new Vector2(0.5f, 1) : new Vector2(0.5f, 1);
|
||||
var labelParent = m_Tooltip.gameObject.transform;
|
||||
GameObject labelObj = ChartHelper.AddTooltipLabel(objName + "_label", labelParent, m_ThemeInfo.font, privot);
|
||||
xAxis.SetTooltipLabel(labelObj);
|
||||
xAxis.SetTooltipLabelColor(m_ThemeInfo.tooltipBackgroundColor, m_ThemeInfo.tooltipTextColor);
|
||||
xAxis.SetTooltipLabelActive(xAxis.show && m_Tooltip.show && m_Tooltip.crossLabel);
|
||||
}
|
||||
}
|
||||
|
||||
private void InitDataZoom()
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace XCharts
|
||||
{
|
||||
m_Show = true,
|
||||
m_Orient = Orient.Horizonal,
|
||||
m_Location = Location.defaultRight,
|
||||
m_Location = Location.defaultTop,
|
||||
m_ItemWidth = 60.0f,
|
||||
m_ItemHeight = 20.0f,
|
||||
m_ItemGap = 5,
|
||||
@@ -54,6 +54,7 @@ namespace XCharts
|
||||
"Legend"
|
||||
}
|
||||
};
|
||||
legend.location.top = 30;
|
||||
return legend;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,10 +92,16 @@ namespace XCharts
|
||||
m_LineColor = Color.grey,
|
||||
m_Indicator = true,
|
||||
m_BackgroundColorList = new List<Color> {
|
||||
new Color32(194, 53, 49, 255),
|
||||
new Color32(47, 69, 84, 255)
|
||||
new Color32(246, 246, 246, 255),
|
||||
new Color32(231, 231, 231, 255)
|
||||
},
|
||||
m_IndicatorList = new List<Indicator>(5)
|
||||
m_IndicatorList = new List<Indicator>(5){
|
||||
new Indicator(){name="radar1",max = 100},
|
||||
new Indicator(){name="radar2",max = 100},
|
||||
new Indicator(){name="radar3",max = 100},
|
||||
new Indicator(){name="radar4",max = 100},
|
||||
new Indicator(){name="radar5",max = 100},
|
||||
}
|
||||
};
|
||||
return radar;
|
||||
}
|
||||
|
||||
@@ -149,13 +149,24 @@ namespace XCharts
|
||||
while (m_XData.Count > maxDataNumber) m_XData.RemoveAt(0);
|
||||
while (m_YData.Count > maxDataNumber) m_YData.RemoveAt(0);
|
||||
}
|
||||
m_YData.Add(value);
|
||||
m_XData.Add(m_XData.Count);
|
||||
m_YData.Add(value);
|
||||
}
|
||||
|
||||
public void AddXYData(float xValue, float yValue, int maxDataNumber = 0)
|
||||
{
|
||||
if (maxDataNumber > 0)
|
||||
{
|
||||
while (m_XData.Count > maxDataNumber) m_XData.RemoveAt(0);
|
||||
while (m_YData.Count > maxDataNumber) m_YData.RemoveAt(0);
|
||||
}
|
||||
m_XData.Add(xValue);
|
||||
m_YData.Add(yValue);
|
||||
}
|
||||
|
||||
public float GetYData(int index, DataZoom dataZoom = null)
|
||||
{
|
||||
var showData = GetYData(dataZoom);
|
||||
var showData = GetYDataList(dataZoom);
|
||||
if (index >= 0 && index <= showData.Count - 1)
|
||||
{
|
||||
return showData[index];
|
||||
@@ -163,7 +174,17 @@ namespace XCharts
|
||||
return 0;
|
||||
}
|
||||
|
||||
public List<float> GetYData(DataZoom dataZoom)
|
||||
public void GetXYData(int index, DataZoom dataZoom, out float xValue, out float yVlaue)
|
||||
{
|
||||
xValue = 0;
|
||||
yVlaue = 0;
|
||||
var xShowData = GetXDataList(dataZoom);
|
||||
if (index >= 0 && index < xShowData.Count) xValue = xShowData[index];
|
||||
var yShowData = GetYDataList(dataZoom);
|
||||
if (index >= 0 && index < yShowData.Count) yVlaue = yShowData[index];
|
||||
}
|
||||
|
||||
public List<float> GetYDataList(DataZoom dataZoom)
|
||||
{
|
||||
if (dataZoom != null && dataZoom.show)
|
||||
{
|
||||
@@ -182,7 +203,7 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
public List<float> GetXData(DataZoom dataZoom)
|
||||
public List<float> GetXDataList(DataZoom dataZoom)
|
||||
{
|
||||
if (dataZoom != null && dataZoom.show)
|
||||
{
|
||||
@@ -246,6 +267,18 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateXYData(int index, float xValue, float yValue)
|
||||
{
|
||||
if (index >= 0 && index <= m_YData.Count - 1)
|
||||
{
|
||||
m_YData[index] = yValue;
|
||||
}
|
||||
if (index >= 0 && index <= m_XData.Count - 1)
|
||||
{
|
||||
m_XData[index] = xValue;
|
||||
}
|
||||
}
|
||||
|
||||
public override void ParseJsonData(string jsonData)
|
||||
{
|
||||
if (string.IsNullOrEmpty(jsonData) || !m_DataFromJson) return;
|
||||
|
||||
@@ -79,15 +79,47 @@ namespace XCharts
|
||||
return false;
|
||||
}
|
||||
|
||||
public void RemoveData(string name)
|
||||
/// <summary>
|
||||
/// Remove serie from series.
|
||||
/// </summary>
|
||||
/// <param name="serieName">the name of serie</param>
|
||||
public void Remove(string serieName)
|
||||
{
|
||||
var serie = GetSerie(name);
|
||||
var serie = GetSerie(serieName);
|
||||
if (serie != null)
|
||||
{
|
||||
m_Series.Remove(serie);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove all serie from series.
|
||||
/// </summary>
|
||||
public void RemoveAll()
|
||||
{
|
||||
m_Series.Clear();
|
||||
}
|
||||
|
||||
public Serie AddSerie(string serieName, SerieType type, bool show = true)
|
||||
{
|
||||
var serie = GetSerie(serieName);
|
||||
if (serie == null)
|
||||
{
|
||||
serie = new Serie();
|
||||
serie.type = type;
|
||||
serie.show = show;
|
||||
serie.name = serieName;
|
||||
serie.yData = new List<float>();
|
||||
m_Series.Add(serie);
|
||||
}
|
||||
else
|
||||
{
|
||||
serie.type = type;
|
||||
serie.show = show;
|
||||
}
|
||||
return serie;
|
||||
}
|
||||
|
||||
public Serie AddData(string name, float value, int maxDataNumber = 0)
|
||||
{
|
||||
if (m_Series == null)
|
||||
@@ -116,6 +148,16 @@ namespace XCharts
|
||||
return serie;
|
||||
}
|
||||
|
||||
public Serie AddXYData(int index, float xValue, float yValue, int maxDataNumber = 0)
|
||||
{
|
||||
var serie = GetSerie(index);
|
||||
if (serie != null)
|
||||
{
|
||||
serie.AddXYData(xValue, yValue, maxDataNumber);
|
||||
}
|
||||
return serie;
|
||||
}
|
||||
|
||||
public void UpdateData(string name, float value, int dataIndex = 0)
|
||||
{
|
||||
var serie = GetSerie(name);
|
||||
@@ -125,6 +167,15 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateXYData(string name, float xValue, float yValue, int dataIndex = 0)
|
||||
{
|
||||
var serie = GetSerie(name);
|
||||
if (serie != null)
|
||||
{
|
||||
serie.UpdateXYData(dataIndex, xValue, yValue);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateData(int index, float value, int dataIndex = 0)
|
||||
{
|
||||
var serie = GetSerie(index);
|
||||
@@ -134,6 +185,15 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateXYData(int index, float xValue, float yValue, int dataIndex = 0)
|
||||
{
|
||||
var serie = GetSerie(index);
|
||||
if (serie != null)
|
||||
{
|
||||
serie.UpdateXYData(dataIndex, xValue, yValue);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateFilterData(DataZoom dataZoom)
|
||||
{
|
||||
if (dataZoom != null && dataZoom.show)
|
||||
@@ -186,12 +246,12 @@ namespace XCharts
|
||||
|
||||
public void GetXMinMaxValue(DataZoom dataZoom, int axisIndex, out int minVaule, out int maxValue)
|
||||
{
|
||||
GetMinMaxValue(dataZoom,axisIndex,false,out minVaule,out maxValue);
|
||||
GetMinMaxValue(dataZoom, axisIndex, false, out minVaule, out maxValue);
|
||||
}
|
||||
|
||||
public void GetYMinMaxValue(DataZoom dataZoom, int axisIndex, out int minVaule, out int maxValue)
|
||||
{
|
||||
GetMinMaxValue(dataZoom,axisIndex,true,out minVaule,out maxValue);
|
||||
GetMinMaxValue(dataZoom, axisIndex, true, out minVaule, out maxValue);
|
||||
}
|
||||
|
||||
public void GetMinMaxValue(DataZoom dataZoom, int axisIndex, bool yValue, out int minVaule, out int maxValue)
|
||||
@@ -208,7 +268,7 @@ namespace XCharts
|
||||
{
|
||||
var serie = ss.Value[i];
|
||||
if (serie.axisIndex != axisIndex) continue;
|
||||
var showData = yValue ? serie.GetYData(dataZoom) : serie.GetXData(dataZoom);
|
||||
var showData = yValue ? serie.GetYDataList(dataZoom) : serie.GetXDataList(dataZoom);
|
||||
for (int j = 0; j < showData.Count; j++)
|
||||
{
|
||||
if (!seriesTotalValue.ContainsKey(j))
|
||||
@@ -234,7 +294,7 @@ namespace XCharts
|
||||
if (m_Series[i].axisIndex != axisIndex) continue;
|
||||
if (IsActive(i))
|
||||
{
|
||||
var showData = yValue ? m_Series[i].GetYData(dataZoom) : m_Series[i].GetXData(dataZoom);
|
||||
var showData = yValue ? m_Series[i].GetYDataList(dataZoom) : m_Series[i].GetXDataList(dataZoom);
|
||||
foreach (var data in showData)
|
||||
{
|
||||
if (data > max) max = data;
|
||||
@@ -246,7 +306,7 @@ namespace XCharts
|
||||
if (max == int.MinValue && min == int.MaxValue)
|
||||
{
|
||||
minVaule = 0;
|
||||
maxValue = 100;
|
||||
maxValue = 90;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user