重构代码,废弃Series.series接口,用Series.list代替

This commit is contained in:
monitor1394
2019-10-01 13:52:02 +08:00
parent 9e6e01c718
commit ce91d4045f
16 changed files with 29 additions and 33 deletions

View File

@@ -33,7 +33,7 @@ public class Demo11_AddSinCurve : MonoBehaviour
chart.xAxises[0].boundaryGap = false;
chart.xAxises[0].maxCache = 0;
chart.series.series[0].maxCache = 0;
chart.series.list[0].maxCache = 0;
chart.RemoveData();

View File

@@ -14,7 +14,7 @@ public class Demo12_CustomDrawing : MonoBehaviour
chart.customDrawCallback = delegate (VertexHelper vh)
{
var dataPoints = chart.series.series[0].dataPoints;
var dataPoints = chart.series.list[0].dataPoints;
if (dataPoints.Count > 0)
{
var pos = dataPoints[3];

View File

@@ -20,7 +20,7 @@ public class Demo_LargeData : MonoBehaviour
timeNow = System.DateTime.Now;
chart.ClearAxisData();
chart.series.ClearData();
chart.series.series[0].maxCache = maxCacheDataNumber;
chart.series.list[0].maxCache = maxCacheDataNumber;
chart.xAxises[0].maxCache = maxCacheDataNumber;
chart.title.text = maxCacheDataNumber + "数据";
}

View File

@@ -21,7 +21,6 @@ namespace XCharts
private bool m_IndicatorJsonAreaToggle = false;
private string m_IndicatorJsonAreaText;
private int m_IndicatorSize;
private bool m_BackgroundColorToggle = false;
private int m_BackgroundColorSize;
private void InitProperty(SerializedProperty prop)

View File

@@ -7,7 +7,6 @@ namespace XCharts
[CustomPropertyDrawer(typeof(Serie), true)]
public class SerieDrawer : PropertyDrawer
{
private Dictionary<string, bool> m_SerieModuleToggle = new Dictionary<string, bool>();
private List<bool> m_DataFoldout = new List<bool>();
private bool m_ShowJsonDataArea = false;
@@ -35,7 +34,6 @@ namespace XCharts
SerializedProperty m_SampleAverage = prop.FindPropertyRelative("m_SampleAverage");
SerializedProperty m_BarWidth = prop.FindPropertyRelative("m_BarWidth");
SerializedProperty m_BarGap = prop.FindPropertyRelative("m_BarGap");
SerializedProperty m_BarCategoryGap = prop.FindPropertyRelative("m_BarCategoryGap");
SerializedProperty m_AreaStyle = prop.FindPropertyRelative("m_AreaStyle");
SerializedProperty m_Symbol = prop.FindPropertyRelative("m_Symbol");
SerializedProperty m_RoseType = prop.FindPropertyRelative("m_RoseType");

View File

@@ -423,7 +423,6 @@ namespace XCharts
return coordinateWidth / segment;
}
private Dictionary<float, string> _cacheValue2str = new Dictionary<float, string>();
/// <summary>
/// 获得标签显示的名称
/// </summary>

View File

@@ -1,5 +1,6 @@
using UnityEngine;
using System.Collections.Generic;
using System;
namespace XCharts
{
@@ -10,6 +11,7 @@ namespace XCharts
[System.Serializable]
public class Series : JsonDataSupport
{
[SerializeField] protected List<Serie> m_Series;
/// <summary>
@@ -17,7 +19,15 @@ namespace XCharts
/// 系列列表。
/// </summary>
/// <value></value>
[Obsolete("Use series.list instead.", true)]
public List<Serie> series { get { return m_Series; } }
/// <summary>
/// the list of serie
/// 系列列表。
/// </summary>
/// <value></value>
public List<Serie> list { get { return m_Series; } }
/// <summary>
/// the size of serie list.
/// 系列个数。
@@ -532,7 +542,7 @@ namespace XCharts
/// <returns></returns>
public bool IsUsedAxisIndex(int axisIndex)
{
foreach (var serie in series)
foreach (var serie in list)
{
if (serie.axisIndex == axisIndex) return true;
}

View File

@@ -254,7 +254,6 @@ namespace XCharts
{
for (int n = 0; n < datas.Count; n++)
{
var legendName = m_Legend.GetFormatterContent(datas[n]);
OnLegendButtonClick(n, datas[n], n == 0 ? true : false);
}
}
@@ -268,7 +267,7 @@ namespace XCharts
int count = 0;
for (int i = 0; i < m_Series.Count; i++)
{
var serie = m_Series.series[i];
var serie = m_Series.list[i];
if (serie.type != SerieType.Pie && !serie.label.show) continue;
for (int j = 0; j < serie.data.Count; j++)
{
@@ -533,7 +532,7 @@ namespace XCharts
protected bool CheckDataShow(string legendName, bool show)
{
bool needShow = false;
foreach (var serie in m_Series.series)
foreach (var serie in m_Series.list)
{
if (legendName.Equals(serie.name))
{
@@ -560,7 +559,7 @@ namespace XCharts
protected bool CheckDataHighlighted(string legendName, bool heighlight)
{
bool show = false;
foreach (var serie in m_Series.series)
foreach (var serie in m_Series.list)
{
if (legendName.Equals(serie.name))
{

View File

@@ -346,7 +346,7 @@ namespace XCharts
/// <returns></returns>
public virtual bool IsActiveByLegend(string legendName)
{
foreach (var serie in m_Series.series)
foreach (var serie in m_Series.list)
{
if (serie.show && legendName.Equals(serie.name))
{

View File

@@ -914,7 +914,7 @@ namespace XCharts
ChartDrawer.DrawLine(vh, p4, p1, xAxis.axisLine.width, m_ThemeInfo.dataZoomLineColor);
if (m_DataZoom.showDataShadow && m_Series.Count > 0)
{
Serie serie = m_Series.series[0];
Serie serie = m_Series.list[0];
Axis axis = yAxises[0];
float scaleWid = coordinateWid / (serie.data.Count - 1);
Vector3 lp = Vector3.zero;
@@ -963,7 +963,6 @@ namespace XCharts
protected void DrawSplitLine(VertexHelper vh, Axis axis, Axis.SplitLineType type,
Vector3 startPos, Vector3 endPos, Color color)
{
bool isYAxis = axis is YAxis;
switch (type)
{
case Axis.SplitLineType.Dashed:
@@ -1165,8 +1164,6 @@ namespace XCharts
protected override void OnRefreshLabel()
{
var isYAxis = m_YAxises[0].type == Axis.AxisType.Category
|| m_YAxises[1].type == Axis.AxisType.Category;
for (int i = 0; i < m_Series.Count; i++)
{
var serie = m_Series.GetSerie(i);

View File

@@ -165,7 +165,7 @@ namespace XCharts
float gap = 0.3f;
for (int i = 0; i < m_Series.Count; i++)
{
var serie = m_Series.series[i];
var serie = m_Series.list[i];
if (serie.type == SerieType.Bar)
{
if (serie.barGap != 0)
@@ -186,7 +186,7 @@ namespace XCharts
barStackSet.Clear();
for (int i = 0; i < m_Series.Count; i++)
{
var serie = m_Series.series[i];
var serie = m_Series.list[i];
if (serie.type == SerieType.Bar && serie.show)
{
if (!string.IsNullOrEmpty(serie.stack))
@@ -217,7 +217,7 @@ namespace XCharts
float barWidth = 0;
for (int i = 0; i < m_Series.Count; i++)
{
var serie = m_Series.series[i];
var serie = m_Series.list[i];
if (serie.type == SerieType.Bar && serie.show && now.stack.Equals(serie.stack))
{
if (serie.barWidth > barWidth) barWidth = serie.barWidth;

View File

@@ -79,7 +79,6 @@ namespace XCharts
var yAxis = m_YAxises[serie.axisIndex];
var xAxis = m_XAxises[serie.axisIndex];
var zeroPos = new Vector3(coordinateX, coordinateY + yAxis.zeroYOffset);
var lastSerie = m_Series.GetSerie(serie.index - 1);
var isStack = m_Series.IsStack(serie.stack, SerieType.Line);
if (!xAxis.show) xAxis = m_XAxises[(serie.axisIndex + 1) % m_XAxises.Count];
float scaleWid = xAxis.GetDataWidth(coordinateWid, m_DataZoom);
@@ -357,7 +356,6 @@ namespace XCharts
var xAxis = m_XAxises[serie.axisIndex];
var yAxis = m_YAxises[serie.axisIndex];
var zeroPos = new Vector3(coordinateX + xAxis.zeroXOffset, coordinateY);
var lastSerie = m_Series.GetSerie(serieIndex - 1);
var isStack = m_Series.IsStack(serie.stack, SerieType.Line);
if (!yAxis.show) yAxis = m_YAxises[(serie.axisIndex + 1) % m_YAxises.Count];
float scaleWid = yAxis.GetDataWidth(coordinateHig, m_DataZoom);
@@ -373,8 +371,6 @@ namespace XCharts
seriesHig.Add(0);
}
}
var fine = isStack && m_Series.IsAnyGradientSerie(serie.stack);
int rate = 1;
var sampleDist = serie.sampleDist;
if (sampleDist > 0) rate = (int)((maxCount - serie.minShow) / (coordinateWid / sampleDist));
@@ -493,7 +489,6 @@ namespace XCharts
bool isDown;
var dir1 = (np - lp).normalized;
dir1v = Vector3.Cross(dir1, Vector3.forward).normalized * (isYAxis ? -1 : 1);
float cut = 0;
if (np != nnp)
{
var dir2 = (nnp - np).normalized;
@@ -502,7 +497,6 @@ namespace XCharts
isDown = isYAxis ? normal.z >= 0 : normal.z <= 0;
var angle = (180 - Vector3.Angle(dir1, dir2)) * Mathf.Deg2Rad / 2;
var diff = serie.lineStyle.width / Mathf.Sin(angle);
cut = serie.lineStyle.width / Mathf.Tan(angle);
var dirDp = Vector3.Cross(dir3, Vector3.forward).normalized * (isYAxis ? -1 : 1);
dir2v = Vector3.Cross(dir2, Vector3.forward).normalized * (isYAxis ? -1 : 1);
dnPos = np + (isDown ? dirDp : -dirDp) * diff;

View File

@@ -67,7 +67,7 @@ namespace XCharts
bool isDataHighlight = false;
for (int i = 0; i < m_Series.Count; i++)
{
var serie = m_Series.series[i];
var serie = m_Series.list[i];
serie.index = i;
var data = serie.data;
serie.animation.InitProgress(data.Count, 0, 360);
@@ -213,7 +213,7 @@ namespace XCharts
private void DrawLabelBackground(VertexHelper vh)
{
foreach (var serie in m_Series.series)
foreach (var serie in m_Series.list)
{
if (serie.type == SerieType.Pie && serie.label.show)
{
@@ -279,7 +279,7 @@ namespace XCharts
int serieNameCount = -1;
for (int i = 0; i < m_Series.Count; i++)
{
var serie = m_Series.series[i];
var serie = m_Series.list[i];
serie.index = i;
if (!serie.show)

View File

@@ -201,7 +201,7 @@ namespace XCharts
int serieNameCount = -1;
for (int i = 0; i < m_Series.Count; i++)
{
var serie = m_Series.series[i];
var serie = m_Series.list[i];
var radar = m_Radars[serie.radarIndex];
int indicatorNum = radar.indicatorList.Count;
var angle = 2 * Mathf.PI / indicatorNum;
@@ -296,7 +296,6 @@ namespace XCharts
if (serie.symbol.type != SerieSymbolType.None )
{
var symbolSize = (isHighlight ? serie.symbol.selectedSize : serie.symbol.size);
float symbolRadius = symbolSize - serie.lineStyle.width * 2;
var symbolColor = serie.symbol.color != Color.clear ? serie.symbol.color : lineColor;
symbolColor.a *= serie.symbol.opacity;
foreach (var point in pointList)

View File

@@ -37,7 +37,7 @@ namespace XCharts
{
base.Update();
bool hasEffectScatter = false;
foreach (var serie in m_Series.series)
foreach (var serie in m_Series.list)
{
if (serie.type == SerieType.EffectScatter)
{
@@ -66,7 +66,7 @@ namespace XCharts
int serieNameCount = -1;
for (int i = 0; i < m_Series.Count; i++)
{
var serie = m_Series.series[i];
var serie = m_Series.list[i];
serie.index = i;
var yAxis = m_YAxises[serie.axisIndex];
var xAxis = m_XAxises[serie.axisIndex];

View File

@@ -28,6 +28,7 @@ QQ交流群XCharts交流群202030963
## 更新日志
* 2019.10.01)重构代码,废弃`Series.series`接口,用`Series.list`代替
* 2019.10.01)增加`customDrawCallback`自定义绘制回调
* 2019.10.01)增加`SmoothDash`平滑虚线的支持
* 2019.09.30)增加`Serie`采样类型`sampleType`的相关配置