mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-21 07:50:16 +00:00
增加运行时和非运行时参数变更自动刷新图表
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user