增加运行时和非运行时参数变更自动刷新图表

This commit is contained in:
monitor1394
2020-03-05 20:25:19 +08:00
parent 11ee36de58
commit 7465bb760d
44 changed files with 1989 additions and 1209 deletions

View File

@@ -51,7 +51,6 @@ namespace XCharts
[SerializeField] protected Action<VertexHelper> m_CustomDrawCallback;
[NonSerialized] private Theme m_CheckTheme = 0;
[NonSerialized] private Title m_CheckTitle = Title.defaultTitle;
[NonSerialized] private Legend m_CheckLegend = Legend.defaultLegend;
[NonSerialized] private float m_CheckWidth = 0;
[NonSerialized] private float m_CheckHeight = 0;
@@ -59,7 +58,6 @@ namespace XCharts
[NonSerialized] private Vector2 m_CheckMaxAnchor;
[NonSerialized] private float m_CheckSerieCount = 0;
[NonSerialized] private List<string> m_CheckSerieName = new List<string>();
[NonSerialized] protected bool m_RefreshChart = false;
[NonSerialized] protected bool m_RefreshLabel = false;
[NonSerialized] protected bool m_ReinitLabel = false;
@@ -72,6 +70,15 @@ namespace XCharts
protected Vector2 chartAnchorMin { get { return rectTransform.anchorMin; } }
protected Vector2 chartPivot { get { return rectTransform.pivot; } }
protected virtual void InitComponent()
{
InitTitle();
InitLegend();
InitSerieLabel();
InitSerieTitle();
InitTooltip();
}
protected override void Awake()
{
if (m_ThemeInfo == null)
@@ -87,11 +94,7 @@ namespace XCharts
m_CheckWidth = m_ChartWidth;
m_CheckHeight = m_ChartHeight;
m_CheckTheme = m_ThemeInfo.theme;
InitTitle();
InitLegend();
InitSerieLabel();
InitSerieTitle();
InitTooltip();
InitComponent();
m_Series.AnimationReset();
m_Series.AnimationFadeIn();
}
@@ -104,9 +107,8 @@ namespace XCharts
protected virtual void Update()
{
CheckSize();
CheckTheme();
CheckTile();
CheckLegend();
CheckComponent();
CheckPointerPos();
CheckTooltip();
CheckRefreshChart();
@@ -114,6 +116,57 @@ namespace XCharts
CheckAnimation();
}
protected virtual void CheckComponent()
{
if (m_ThemeInfo.anyDirty)
{
if (m_CheckTheme != m_ThemeInfo.theme)
{
m_CheckTheme = m_ThemeInfo.theme;
m_ThemeInfo.Copy(m_CheckTheme);
OnThemeChanged();
}
if (m_ThemeInfo.componentDirty)
{
m_Title.SetAllDirty();
m_Legend.SetAllDirty();
m_Tooltip.SetAllDirty();
}
if (m_ThemeInfo.vertsDirty) RefreshChart();
m_ThemeInfo.ClearDirty();
}
if (m_Title.anyDirty)
{
if (m_Title.componentDirty) InitTitle();
if (m_Title.vertsDirty) RefreshChart();
m_Title.ClearDirty();
}
if (m_Legend.anyDirty)
{
if (m_Legend.componentDirty) InitLegend();
if (m_Legend.vertsDirty) RefreshChart();
m_Legend.ClearDirty();
}
if (m_Tooltip.anyDirty)
{
if (m_Tooltip.componentDirty) InitTooltip();
if (m_Tooltip.vertsDirty) RefreshChart();
m_Tooltip.ClearDirty();
}
if (m_Settings.vertsDirty)
{
RefreshChart();
m_Settings.ClearDirty();
}
if (m_Series.anyDirty)
{
if (m_Series.vertsDirty) RefreshChart();
if (m_Series.labelDirty) m_ReinitLabel = true;
if (m_Series.labelUpdate && !m_RefreshChart) m_RefreshLabel = true;
m_Series.ClearDirty();
}
}
protected override void OnEnable()
{
base.OnEnable();
@@ -145,7 +198,11 @@ namespace XCharts
protected override void OnValidate()
{
//TODO:
m_ThemeInfo.SetAllDirty();
m_Title.SetAllDirty();
m_Legend.SetAllDirty();
m_Tooltip.SetAllDirty();
m_ReinitLabel = true;
}
#endif
@@ -368,7 +425,6 @@ namespace XCharts
}
}
private void InitTooltip()
{
var tooltipObject = ChartHelper.AddObject("tooltip", transform, chartAnchorMin,
@@ -412,46 +468,17 @@ namespace XCharts
}
}
private void CheckTheme()
{
if (m_CheckTheme != m_ThemeInfo.theme)
{
m_CheckTheme = m_ThemeInfo.theme;
OnThemeChanged();
}
}
private void CheckTile()
{
if (!m_CheckTitle.Equals(m_Title))
{
m_CheckTitle.Copy(m_Title);
OnTitleChanged();
}
}
private void CheckLegend()
{
if (m_CheckLegend != m_Legend)
if (m_Legend.show)
{
m_CheckLegend.Copy(m_Legend);
OnLegendChanged();
}
else if (m_Legend.show)
{
if (m_CheckSerieCount != m_Series.Count)
foreach (var serie in series.list)
{
m_CheckSerieCount = m_Series.Count;
m_CheckSerieName.Clear();
var serieNames = m_Series.GetSerieNameList();
foreach (var name in serieNames) m_CheckSerieName.Add(name);
OnLegendChanged();
}
else if (!ChartHelper.IsValueEqualsList(m_CheckSerieName, m_Series.GetSerieNameList()))
{
var serieNames = m_Series.GetSerieNameList();
foreach (var name in serieNames) m_CheckSerieName.Add(name);
OnLegendChanged();
if (serie.nameDirty)
{
m_Legend.SetAllDirty();
serie.ClearNameDirty();
}
}
}
}
@@ -525,25 +552,17 @@ namespace XCharts
protected void CheckRefreshChart()
{
if (m_RefreshChart)
if (m_RefreshChart || m_Series.vertsDirty)
{
int tempWid = (int)chartWidth;
rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, tempWid - 1);
rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, tempWid);
//SetAllDirty();
SetVerticesDirty();
m_RefreshChart = false;
m_Series.ClearVerticesDirty();
}
}
protected void CheckRefreshLabel()
{
foreach (var serie in m_Series.list)
{
if (serie.label.show && serie.runtimeLastCheckDataCount != serie.dataCount)
{
m_ReinitLabel = true;
serie.runtimeLastCheckDataCount = serie.dataCount;
}
}
if (m_ReinitLabel)
{
m_ReinitLabel = false;
@@ -573,44 +592,18 @@ namespace XCharts
protected virtual void OnRefreshLabel()
{
}
protected virtual void OnSizeChanged()
{
InitTitle();
InitLegend();
InitTooltip();
InitSerieLabel();
m_Title.SetAllDirty();
m_Legend.SetAllDirty();
m_Tooltip.SetAllDirty();
m_Series.SetLabelDirty();
}
protected virtual void OnThemeChanged()
{
switch (m_ThemeInfo.theme)
{
case Theme.Dark:
m_ThemeInfo.Copy(ThemeInfo.Dark);
break;
case Theme.Default:
m_ThemeInfo.Copy(ThemeInfo.Default);
break;
case Theme.Light:
m_ThemeInfo.Copy(ThemeInfo.Light);
break;
}
InitTitle();
InitLegend();
InitTooltip();
}
protected virtual void OnTitleChanged()
{
InitTitle();
}
protected virtual void OnLegendChanged()
{
InitLegend();
}
protected virtual void OnYMaxValueChanged()

View File

@@ -31,13 +31,10 @@ namespace XCharts
private bool m_DataZoomEndDrag;
private float m_DataZoomLastStartIndex;
private float m_DataZoomLastEndIndex;
private bool m_XAxisChanged;
private bool m_YAxisChanged;
private bool m_CheckMinMaxValue;
private bool m_CheckDataZoomLabel;
private List<XAxis> m_CheckXAxises = new List<XAxis>();
private List<YAxis> m_CheckYAxises = new List<YAxis>();
private Grid m_CheckCoordinate = Grid.defaultGrid;
private bool m_XAxisesDirty;
private bool m_YAxisesDirty;
private Dictionary<int, List<Serie>> m_StackSeries = new Dictionary<int, List<Serie>>();
private List<float> m_SeriesCurrHig = new List<float>();
@@ -55,14 +52,61 @@ namespace XCharts
protected override void Update()
{
base.Update();
CheckYAxis();
CheckXAxis();
CheckMinMaxValue();
CheckCoordinate();
CheckRaycastTarget();
CheckDataZoom();
CheckVisualMap();
base.Update();
}
protected override void CheckComponent()
{
if (m_DataZoom.anyDirty)
{
if (m_DataZoom.componentDirty) InitDataZoom();
if (m_DataZoom.vertsDirty) RefreshChart();
m_DataZoom.ClearDirty();
}
if (m_VisualMap.anyDirty)
{
if (m_VisualMap.vertsDirty) RefreshChart();
m_VisualMap.ClearDirty();
}
if (m_Grid.anyDirty)
{
if (m_Grid.componentDirty)
{
m_XAxisesDirty = true;
m_YAxisesDirty = true;
OnCoordinateChanged();
}
if (m_Grid.vertsDirty) RefreshChart();
m_Grid.ClearDirty();
}
for (int i = 0; i < m_XAxises.Count; i++)
{
var axis = m_XAxises[i];
if (m_XAxisesDirty || axis.anyDirty)
{
if (axis.componentDirty || m_XAxisesDirty) InitXAxis(i, axis);
if (axis.vertsDirty || m_XAxisesDirty) RefreshChart();
axis.ClearDirty();
m_XAxisesDirty = false;
}
}
for (int i = 0; i < m_YAxises.Count; i++)
{
var axis = m_YAxises[i];
if (m_YAxisesDirty || axis.anyDirty)
{
if (axis.componentDirty || m_YAxisesDirty) InitYAxis(i, axis);
if (axis.vertsDirty || m_YAxisesDirty) RefreshChart();
axis.ClearDirty();
m_YAxisesDirty = false;
}
}
base.CheckComponent();
}
#if UNITY_EDITOR
@@ -74,6 +118,16 @@ namespace XCharts
m_YAxises.Clear();
Awake();
}
protected override void OnValidate()
{
base.OnValidate();
m_XAxisesDirty = true;
m_YAxisesDirty = true;
m_Grid.SetAllDirty();
m_DataZoom.SetAllDirty();
m_VisualMap.SetAllDirty();
}
#endif
protected override void DrawChart(VertexHelper vh)
@@ -465,9 +519,9 @@ namespace XCharts
protected override void OnThemeChanged()
{
base.OnThemeChanged();
InitDataZoom();
InitAxisX();
InitAxisY();
m_DataZoom.SetAllDirty();
m_XAxisesDirty = true;
m_YAxisesDirty = true;
}
private void InitDefaultAxises()
@@ -753,56 +807,9 @@ namespace XCharts
{
posY = startY - xAxis.axisLabel.margin - xAxis.axisLabel.fontSize / 2;
}
// if (xAxis.boundaryGap)
// {
// return new Vector3(coordinateX + (i + 1) * scaleWid, posY);
// }
// else
// {
// return new Vector3(coordinateX + (i + 1 - 0.5f) * scaleWid, posY);
// }
return new Vector3(coordinateX + scaleWid, posY);
}
private void CheckCoordinate()
{
if (m_CheckCoordinate != m_Grid)
{
m_CheckCoordinate.Copy(m_Grid);
OnCoordinateChanged();
}
}
private void CheckYAxis()
{
if (m_YAxisChanged || !ChartHelper.IsValueEqualsList<YAxis>(m_CheckYAxises, m_YAxises))
{
foreach (var axis in m_CheckYAxises)
{
YAxisPool.Release(axis);
}
m_CheckYAxises.Clear();
foreach (var axis in m_YAxises) m_CheckYAxises.Add(axis.Clone());
m_YAxisChanged = false;
OnYAxisChanged();
}
}
private void CheckXAxis()
{
if (m_XAxisChanged || !ChartHelper.IsValueEqualsList<XAxis>(m_CheckXAxises, m_XAxises))
{
foreach (var axis in m_CheckXAxises)
{
XAxisPool.Release(axis);
}
m_CheckXAxises.Clear();
foreach (var axis in m_XAxises) m_CheckXAxises.Add(axis.Clone());
m_XAxisChanged = false;
OnXAxisChanged();
}
}
private void CheckMinMaxValue()
{
if (m_XAxises == null || m_YAxises == null) return;
@@ -884,25 +891,15 @@ namespace XCharts
protected virtual void OnCoordinateChanged()
{
InitAxisX();
InitAxisY();
}
protected virtual void OnYAxisChanged()
{
InitAxisY();
}
protected virtual void OnXAxisChanged()
{
InitAxisX();
m_XAxisesDirty = true;
m_YAxisesDirty = true;
}
protected override void OnSizeChanged()
{
base.OnSizeChanged();
InitAxisX();
InitAxisY();
m_XAxisesDirty = true;
m_YAxisesDirty = true;
}
private void DrawCoordinate(VertexHelper vh)

View File

@@ -0,0 +1,52 @@
using System.Collections.Generic;
using UnityEngine;
namespace XCharts
{
internal static class PropertyUtility
{
public static bool SetColor(ref Color currentValue, Color newValue)
{
if (currentValue.r == newValue.r && currentValue.g == newValue.g && currentValue.b == newValue.b && currentValue.a == newValue.a)
return false;
currentValue = newValue;
return true;
}
public static bool SetColor(ref Color32 currentValue, Color32 newValue)
{
if (currentValue.r == newValue.r && currentValue.g == newValue.g && currentValue.b == newValue.b && currentValue.a == newValue.a)
return false;
currentValue = newValue;
return true;
}
public static bool SetStruct<T>(ref T currentValue, T newValue) where T : struct
{
if (EqualityComparer<T>.Default.Equals(currentValue, newValue))
return false;
currentValue = newValue;
return true;
}
public static bool SetClass<T>(ref T currentValue, T newValue, bool notNull = false) where T : class
{
if (notNull)
{
if (newValue == null)
{
Debug.LogError("can not be null.");
return false;
}
}
if ((currentValue == null && newValue == null) || (currentValue != null && currentValue.Equals(newValue)))
return false;
currentValue = newValue;
return true;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 820c154b7b7d848cdaf52e68c369dd86
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: