完善数据操作接口

This commit is contained in:
monitor1394
2019-05-15 09:44:18 +08:00
parent 0b716adb5a
commit e72cfbdd3f
18 changed files with 1916 additions and 15087 deletions

View File

@@ -11,8 +11,8 @@ namespace XCharts
{
Value,
Category,
Time,
Log
//Time,
//Log
}
public enum SplitLineType

View File

@@ -2,6 +2,7 @@
using UnityEngine.UI;
using System.Collections.Generic;
using System;
using UnityEngine.EventSystems;
namespace XCharts
{
@@ -101,29 +102,65 @@ namespace XCharts
}
}
public void AddData(string legend, float value)
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 void AddData(int legend, float value)
public virtual void AddData(int legend, float value)
{
m_Series.AddData(legend, value, m_MaxCacheDataNumber);
}
public void UpdateData(string legend, float value, int dataIndex = 0)
public virtual void UpdateData(string legend, float value, int dataIndex = 0)
{
m_Series.UpdateData(legend, value, dataIndex);
RefreshChart();
}
public void UpdateData(int legendIndex, float value, int dataIndex = 0)
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;
@@ -189,14 +226,15 @@ namespace XCharts
m_Legend.SetButton(i, btn);
m_Legend.UpdateButtonColor(i, m_ThemeInfo.GetColor(i), m_ThemeInfo.unableColor);
btn.GetComponentInChildren<Text>().text = m_Legend.data[i];
btn.onClick.AddListener(delegate ()
ChartHelper.AddEventListener(btn.gameObject, EventTriggerType.PointerDown, (data) =>
{
int index = int.Parse(btn.name.Split('_')[1]);
m_Legend.SetShowData(index, !m_Legend.IsShowSeries(index));
m_Legend.UpdateButtonColor(index, m_ThemeInfo.GetColor(index), m_ThemeInfo.unableColor);
OnYMaxValueChanged();
OnLegendButtonClicked();
RefreshChart();
int count = (data as PointerEventData).clickCount;
int index = int.Parse(data.selectedObject.name.Split('_')[1]);
SetActive(index, !m_Legend.IsActive(index));
m_Legend.UpdateButtonColor(index, m_ThemeInfo.GetColor(index), m_ThemeInfo.unableColor);
OnYMaxValueChanged();
OnLegendButtonClicked();
RefreshChart();
});
}
}
@@ -260,7 +298,7 @@ namespace XCharts
private void CheckTooltip()
{
if (!m_Tooltip.show) return;
if (!m_Tooltip.show || !m_Tooltip.isInited) return;
m_Tooltip.dataIndex = 0;
Vector2 local;

View File

@@ -23,7 +23,7 @@ namespace XCharts
[SerializeField] private int m_ItemFontSize = 18;
[SerializeField] private List<string> m_Data = new List<string>();
[NonSerialized] private List<bool> m_DataShowList = new List<bool>();
[NonSerialized] private List<bool> m_DataActiveList = new List<bool>();
[NonSerialized] private List<Button> m_DataBtnList = new List<Button>();
public bool show { get { return m_Show; } set { m_Show = value; } }
@@ -109,33 +109,67 @@ namespace XCharts
return base.GetHashCode();
}
public bool IsShowSeries(string name)
public bool IsActive(string name)
{
if (string.IsNullOrEmpty(name)) return true;
for(int i = 0; i < data.Count; i++)
{
if (name.Equals(data[i])) return m_DataShowList[i];
if (data[i].Equals(name)) return m_DataActiveList[i];
}
return true;
return false;
}
public bool IsShowSeries(int seriesIndex)
public bool IsActive(int seriesIndex)
{
if (seriesIndex < 0 || seriesIndex > data.Count - 1) seriesIndex = 0;
if (seriesIndex >= data.Count) return false;
if (seriesIndex < 0 || seriesIndex > m_DataShowList.Count - 1)
{
if (seriesIndex >= data.Count) return true;
if (seriesIndex < 0 || seriesIndex > m_DataActiveList.Count - 1)
return true;
}
else
return m_DataActiveList[seriesIndex];
}
public void ClearData()
{
m_Data.Clear();
}
public bool ContainsData(string name)
{
return m_Data.Contains(name);
}
public void RemoveData(string name)
{
if (m_Data.Contains(name))
{
return m_DataShowList[seriesIndex];
m_Data.Remove(name);
}
}
public void SetShowData(int index, bool flag)
public void AddData(string name)
{
m_DataShowList[index] = flag;
if (!m_Data.Contains(name))
{
m_Data.Add(name);
}
}
public void SetActive(int index, bool flag)
{
m_DataActiveList[index] = flag;
}
public void SetActive(string name, bool flag)
{
for (int i = 0; i < data.Count; i++)
{
if (data[i].Equals(name))
{
m_DataActiveList[i] = flag;
break;
}
}
}
public void SetButton(int index, Button btn)
@@ -144,7 +178,7 @@ namespace XCharts
if (index < 0 || index > m_DataBtnList.Count - 1)
{
m_DataBtnList.Add(btn);
m_DataShowList.Add(true);
m_DataActiveList.Add(true);
}
else
{
@@ -156,7 +190,7 @@ namespace XCharts
public void UpdateButtonColor(int index,Color ableColor,Color unableColor)
{
if (IsShowSeries(index))
if (IsActive(index))
{
m_DataBtnList[index].GetComponent<Image>().color = ableColor;
}
@@ -166,18 +200,6 @@ namespace XCharts
}
}
public void SetShowData(string name, bool flag)
{
for (int i = 0; i < data.Count; i++)
{
if (data[i].Equals(name))
{
m_DataShowList[i] = flag;
break;
}
}
}
public void OnChanged()
{
m_Location.OnChanged();

View File

@@ -12,8 +12,8 @@ namespace XCharts
[System.Serializable]
public class Indicator: IEquatable<Indicator>
{
public string m_Name;
public float m_Max;
[SerializeField] private string m_Name;
[SerializeField] private float m_Max;
public string name { get { return m_Name; }set { m_Name = value; } }
public float max { get { return m_Max; }set { m_Max = value; } }

View File

@@ -24,7 +24,7 @@ namespace XCharts
public SerieType type { get { return m_Type; } set { m_Type = value; } }
public string name { get { return m_Name; } set { m_Name = value; } }
public string stack { get { return m_Stack; } set { m_Stack = value; } }
public List<float> data { get { return m_Data; } }
public List<float> data { get { return m_Data; }set { m_Data = value; } }
public float Max
{
@@ -81,7 +81,7 @@ namespace XCharts
m_Data.RemoveAt(index);
}
public void AddData(float value, int maxDataNumber)
public void AddData(float value, int maxDataNumber = 0)
{
if (maxDataNumber > 0)
{

View File

@@ -46,47 +46,121 @@ namespace XCharts
}
}
public void AddData(string legend, float value, int maxDataNumber = 0)
public Serie GetSerie(string name)
{
for (int i = 0; i < m_Series.Count; i++)
{
if (m_Series[i].name.Equals(legend))
if (name.Equals(m_Series[i].name))
{
m_Series[i].AddData(value, maxDataNumber);
break;
return m_Series[i];
}
}
return null;
}
public void AddData(int legend, float value, int maxDataNumber = 0)
public Serie GetSerie(int index)
{
if (legend >= 0 && legend < Count)
if (index >= 0 && index < m_Series.Count)
{
m_Series[legend].AddData(value, maxDataNumber);
return m_Series[index];
}
return null;
}
public void UpdateData(string legend, float value, int dataIndex = 0)
public bool Contains(string name)
{
for (int i = 0; i < m_Series.Count; i++)
{
if (m_Series[i].name.Equals(legend))
if (name.Equals(m_Series[i].name))
{
m_Series[i].UpdateData(dataIndex, value);
break;
return true;
}
}
return false;
}
public void RemoveData(string name)
{
var serie = GetSerie(name);
if (serie != null)
{
m_Series.Remove(serie);
}
}
public void UpdateData(int legendIndex, float value, int dataIndex = 0)
public Serie AddData(string name, float value, int maxDataNumber = 0)
{
for (int i = 0; i < m_Series.Count; i++)
if (m_Series == null)
{
if (i == legendIndex)
{
m_Series[i].UpdateData(dataIndex, value);
break;
}
m_Series = new List<Serie>();
}
var serie = GetSerie(name);
if (serie == null)
{
serie = new Serie();
serie.name = name;
serie.data = new List<float>();
m_Series.Add(serie);
}
serie.AddData(value, maxDataNumber);
return serie;
}
public Serie AddData(int index, float value, int maxDataNumber = 0)
{
var serie = GetSerie(index);
if (serie != null)
{
serie.AddData(value, maxDataNumber);
}
return serie;
}
public void UpdateData(string name, float value, int dataIndex = 0)
{
var serie = GetSerie(name);
if (serie != null)
{
serie.UpdateData(dataIndex, value);
}
}
public void UpdateData(int index, float value, int dataIndex = 0)
{
var serie = GetSerie(index);
if (serie != null)
{
serie.UpdateData(dataIndex, value);
}
}
public bool IsActive(string name)
{
var serie = GetSerie(name);
return serie == null ? false : serie.show;
}
public bool IsActive(int index)
{
var serie = GetSerie(index);
return serie == null ? false : serie.show;
}
public void SetActive(string name, bool active)
{
var serie = GetSerie(name);
if (serie != null)
{
serie.show = active;
}
}
public void SetActive(int index, bool active)
{
var serie = GetSerie(index);
if (serie != null)
{
serie.show = active;
}
}
@@ -125,7 +199,7 @@ namespace XCharts
{
for (int i = 0; i < m_Series.Count; i++)
{
if (legend.IsShowSeries(i))
if (legend.IsActive(i))
{
if (m_Series[i].Max > max) max = m_Series[i].Max;
if (m_Series[i].Min < min) min = m_Series[i].Min;

View File

@@ -18,6 +18,7 @@ namespace XCharts
public int lastDataIndex { get; set; }
public float width { get { return m_BackgroudRect.sizeDelta.x; } }
public float height { get { return m_BackgroudRect.sizeDelta.y; } }
public bool isInited { get { return m_GameObject != null; } }
public static Tooltip defaultTooltip
{
@@ -45,13 +46,19 @@ namespace XCharts
public void SetTextColor(Color color)
{
m_Text.color = color;
if (m_Text)
{
m_Text.color = color;
}
}
public void UpdateTooltipText(string txt)
{
m_Text.text = txt;
m_BackgroudRect.sizeDelta = new Vector2(m_Text.preferredWidth + 8, m_Text.preferredHeight + 8);
if (m_Text)
{
m_Text.text = txt;
m_BackgroudRect.sizeDelta = new Vector2(m_Text.preferredWidth + 8, m_Text.preferredHeight + 8);
}
}
public void SetActive(bool flag)
@@ -68,7 +75,10 @@ namespace XCharts
public Vector3 GetPos()
{
return m_GameObject.transform.localPosition;
if (m_GameObject)
return m_GameObject.transform.localPosition;
else
return Vector3.zero;
}
}
}