mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-19 15:00:08 +00:00
增加Symbol配置Serie标志图形的显示
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using UnityEngine;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
@@ -147,52 +146,62 @@ namespace XCharts
|
||||
|
||||
/// <summary>
|
||||
/// Add a data to serie.
|
||||
/// If serie doesn't exist,will be add to series.
|
||||
/// When serie doesn't exist, the data is ignored.
|
||||
/// 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)
|
||||
/// <returns>Returns True on success</returns>
|
||||
public virtual bool AddData(string serieName, float value)
|
||||
{
|
||||
m_Legend.AddData(serieName);
|
||||
m_Series.AddData(serieName, value, m_MaxCacheDataNumber);
|
||||
RefreshChart();
|
||||
var success = m_Series.AddData(serieName, value, m_MaxCacheDataNumber);
|
||||
if (success) RefreshChart();
|
||||
return success;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a data to serie.
|
||||
/// If serie doesn't exist, the data is ignored.
|
||||
/// When 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)
|
||||
/// <returns>Returns True on success</returns>
|
||||
public virtual bool AddData(int serieIndex, float value)
|
||||
{
|
||||
m_Series.AddData(serieIndex, value, m_MaxCacheDataNumber);
|
||||
RefreshChart();
|
||||
var success = m_Series.AddData(serieIndex, value, m_MaxCacheDataNumber);
|
||||
if (success) RefreshChart();
|
||||
return success;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a (x,y) data to serie
|
||||
/// Add a (x,y) data to serie.
|
||||
/// When serie doesn't exist, the data is ignored.
|
||||
/// </summary>
|
||||
/// <param name="serieName">the name of serie</param>
|
||||
/// <param name="xValue">x data</param>
|
||||
/// <param name="yValue">y data</param>
|
||||
public virtual void AddXYData(string serieName, float xValue, float yValue)
|
||||
/// <returns>Returns True on success</returns>
|
||||
public virtual bool AddXYData(string serieName, float xValue, float yValue)
|
||||
{
|
||||
m_Series.AddXYData(serieName, xValue, yValue, m_MaxCacheDataNumber);
|
||||
RefreshChart();
|
||||
var success = m_Series.AddXYData(serieName, xValue, yValue, m_MaxCacheDataNumber);
|
||||
if (success) RefreshChart();
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a (x,y) data to serie
|
||||
/// Add a (x,y) data to serie.
|
||||
/// When serie doesn't exist, the data is ignored.
|
||||
/// </summary>
|
||||
/// <param name="serieIndex">the index of serie</param>
|
||||
/// <param name="xValue">x data</param>
|
||||
/// <param name="yValue">y data</param>
|
||||
public virtual void AddXYData(int serieIndex, float xValue, float yValue)
|
||||
/// <returns>Returns True on success</returns>
|
||||
public virtual bool AddXYData(int serieIndex, float xValue, float yValue)
|
||||
{
|
||||
m_Series.AddXYData(serieIndex, xValue, yValue, m_MaxCacheDataNumber);
|
||||
RefreshChart();
|
||||
var success = m_Series.AddXYData(serieIndex, xValue, yValue, m_MaxCacheDataNumber);
|
||||
if (success) RefreshChart();
|
||||
return success;
|
||||
}
|
||||
/// <summary>
|
||||
/// Update serie data by serie name.
|
||||
@@ -652,6 +661,40 @@ namespace XCharts
|
||||
ChartHelper.DrawPolygon(vh, p1, p2, p3, p4, m_ThemeInfo.backgroundColor);
|
||||
}
|
||||
|
||||
protected void DrawSymbol(VertexHelper vh, SerieSymbolType type, float symbolSize, float tickness, Vector3 pos, Color color)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case SerieSymbolType.None:
|
||||
break;
|
||||
case SerieSymbolType.Circle:
|
||||
ChartHelper.DrawCricle(vh, pos, symbolSize, color);
|
||||
break;
|
||||
case SerieSymbolType.EmptyCircle:
|
||||
ChartHelper.DrawCricle(vh, pos, symbolSize, m_ThemeInfo.backgroundColor);
|
||||
ChartHelper.DrawDoughnut(vh, pos, symbolSize - tickness, symbolSize, 0, 360, color);
|
||||
break;
|
||||
case SerieSymbolType.Rect:
|
||||
ChartHelper.DrawPolygon(vh, pos, symbolSize, color);
|
||||
break;
|
||||
case SerieSymbolType.Triangle:
|
||||
var x = symbolSize * Mathf.Cos(30 * Mathf.PI / 180);
|
||||
var y = symbolSize * Mathf.Sin(30 * Mathf.PI / 180);
|
||||
var p1 = new Vector2(pos.x - x, pos.y - y);
|
||||
var p2 = new Vector2(pos.x, pos.y + symbolSize);
|
||||
var p3 = new Vector2(pos.x + x, pos.y - y);
|
||||
ChartHelper.DrawTriangle(vh, p1, p2, p3, color);
|
||||
break;
|
||||
case SerieSymbolType.Diamond:
|
||||
p1 = new Vector2(pos.x - symbolSize, pos.y);
|
||||
p2 = new Vector2(pos.x, pos.y + symbolSize);
|
||||
p3 = new Vector2(pos.x + symbolSize, pos.y);
|
||||
var p4 = new Vector2(pos.x, pos.y - symbolSize);
|
||||
ChartHelper.DrawPolygon(vh, p1, p2, p3, p4, color);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -12,9 +12,6 @@ namespace XCharts
|
||||
End
|
||||
}
|
||||
[SerializeField] private float m_Tickness;
|
||||
[SerializeField] private bool m_Point;
|
||||
[SerializeField] private float m_PointWidth;
|
||||
[SerializeField] private float m_PointSelectedWidth;
|
||||
[SerializeField] private bool m_Smooth;
|
||||
[SerializeField] [Range(1f, 10f)] private float m_SmoothStyle;
|
||||
[SerializeField] private bool m_Area;
|
||||
@@ -22,9 +19,6 @@ namespace XCharts
|
||||
[SerializeField] private StepType m_StepType;
|
||||
|
||||
public float tickness { get { return m_Tickness; } set { m_Tickness = value; } }
|
||||
public bool point { get { return m_Point; } set { m_Point = value; } }
|
||||
public float pointWidth { get { return m_PointWidth; } set { m_PointWidth = value; } }
|
||||
public float pointSelectedWidth { get { return m_PointSelectedWidth; } set { m_PointSelectedWidth = value; } }
|
||||
public float smoothStyle { get { return m_SmoothStyle; } set { m_SmoothStyle = value; } }
|
||||
public bool smooth { get { return m_Smooth; } set { m_Smooth = value; } }
|
||||
public bool area { get { return m_Area; } set { m_Area = value; } }
|
||||
@@ -38,9 +32,6 @@ namespace XCharts
|
||||
var line = new Line
|
||||
{
|
||||
m_Tickness = 0.8f,
|
||||
m_Point = true,
|
||||
m_PointWidth = 2.5f,
|
||||
m_PointSelectedWidth = 5.5f,
|
||||
m_Smooth = false,
|
||||
m_SmoothStyle = 2f,
|
||||
m_Area = false,
|
||||
|
||||
@@ -7,34 +7,52 @@ namespace XCharts
|
||||
{
|
||||
public enum SerieType
|
||||
{
|
||||
None,
|
||||
Line,
|
||||
Bar,
|
||||
Pie,
|
||||
Radar
|
||||
Radar,
|
||||
Scatter,
|
||||
EffectScatter
|
||||
}
|
||||
|
||||
public enum SerieSymbolType
|
||||
{
|
||||
EmptyCircle,
|
||||
Circle,
|
||||
Rect,
|
||||
Triangle,
|
||||
Diamond,
|
||||
None,
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class Serie : JsonDataSupport
|
||||
{
|
||||
[SerializeField] [DefaultValue("true")] private bool m_Show;
|
||||
[SerializeField] [DefaultValue("true")] private bool m_Show = true;
|
||||
[SerializeField] private SerieType m_Type;
|
||||
[SerializeField] private bool m_Selected;
|
||||
[SerializeField] private string m_Name;
|
||||
[SerializeField] private string m_Stack;
|
||||
[SerializeField] private int m_AxisIndex;
|
||||
[SerializeField] private SerieSymbolType m_Symbol = SerieSymbolType.Circle;
|
||||
[SerializeField] private float m_SymbolSize = 2.5f;
|
||||
[SerializeField] private float m_SymbolSelectedSize = 5f;
|
||||
[SerializeField] private bool m_TwoDimensionData;
|
||||
[FormerlySerializedAs("m_Data")]
|
||||
[SerializeField] private List<float> m_YData = new List<float>();
|
||||
[SerializeField] private List<float> m_XData = new List<float>();
|
||||
|
||||
public int index { get; set; }
|
||||
public int dataCount { get { return m_YData.Count; } }
|
||||
public bool selected { get { return m_Selected; } set { m_Selected = value; } }
|
||||
public bool show { get { return m_Show; } set { m_Show = value; } }
|
||||
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 int axisIndex { get { return m_AxisIndex; } set { m_AxisIndex = value; } }
|
||||
public SerieSymbolType symbol { get { return m_Symbol; } set { m_Symbol = value; } }
|
||||
public float symbolSize { get { return m_SymbolSize; } set { m_SymbolSize = value; } }
|
||||
public float symbolSelectedSize { get { return m_SymbolSelectedSize; } set { m_SymbolSelectedSize = value; } }
|
||||
public List<float> yData { get { return m_YData; } set { m_YData = value; } }
|
||||
public List<float> xData { get { return m_XData; } set { m_XData = value; } }
|
||||
|
||||
|
||||
@@ -125,6 +125,23 @@ namespace XCharts
|
||||
serie.name = serieName;
|
||||
serie.index = m_Series.Count;
|
||||
serie.yData = new List<float>();
|
||||
|
||||
if (type == SerieType.Scatter)
|
||||
{
|
||||
serie.symbol = SerieSymbolType.Circle;
|
||||
serie.symbolSize = 20f;
|
||||
serie.symbolSelectedSize = 30f;
|
||||
}
|
||||
else if (type == SerieType.Line)
|
||||
{
|
||||
serie.symbol = SerieSymbolType.EmptyCircle;
|
||||
serie.symbolSize = 2.5f;
|
||||
serie.symbolSelectedSize = 5f;
|
||||
}
|
||||
else
|
||||
{
|
||||
serie.symbol = SerieSymbolType.None;
|
||||
}
|
||||
m_Series.Add(serie);
|
||||
}
|
||||
else
|
||||
@@ -134,41 +151,48 @@ namespace XCharts
|
||||
return serie;
|
||||
}
|
||||
|
||||
public Serie AddData(string name, float value, int maxDataNumber = 0)
|
||||
public bool AddData(string serieName, float value, int maxDataNumber = 0)
|
||||
{
|
||||
var serie = AddSerie(name, SerieType.None);
|
||||
serie.AddYData(value, maxDataNumber);
|
||||
return serie;
|
||||
var serie = GetSerie(serieName);
|
||||
if (serie != null)
|
||||
{
|
||||
serie.AddYData(value, maxDataNumber);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Serie AddData(int index, float value, int maxDataNumber = 0)
|
||||
public bool AddData(int index, float value, int maxDataNumber = 0)
|
||||
{
|
||||
var serie = GetSerie(index);
|
||||
if (serie != null)
|
||||
{
|
||||
serie.AddYData(value, maxDataNumber);
|
||||
return true;
|
||||
}
|
||||
return serie;
|
||||
return false;
|
||||
}
|
||||
|
||||
public Serie AddXYData(string serieName, float xValue, float yValue, int maxDataNumber = 0)
|
||||
public bool AddXYData(string serieName, float xValue, float yValue, int maxDataNumber = 0)
|
||||
{
|
||||
var serie = GetSerie(serieName);
|
||||
if (serie != null)
|
||||
{
|
||||
serie.AddXYData(xValue, yValue, maxDataNumber);
|
||||
return true;
|
||||
}
|
||||
return serie;
|
||||
return false;
|
||||
}
|
||||
|
||||
public Serie AddXYData(int index, float xValue, float yValue, int maxDataNumber = 0)
|
||||
public bool AddXYData(int index, float xValue, float yValue, int maxDataNumber = 0)
|
||||
{
|
||||
var serie = GetSerie(index);
|
||||
if (serie != null)
|
||||
{
|
||||
serie.AddXYData(xValue, yValue, maxDataNumber);
|
||||
return true;
|
||||
}
|
||||
return serie;
|
||||
return false;
|
||||
}
|
||||
|
||||
public void UpdateData(string name, float value, int dataIndex = 0)
|
||||
|
||||
Reference in New Issue
Block a user