mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-30 21:38:49 +00:00
屏蔽Chart的Init()接口,动态创建图表不再需要调用
This commit is contained in:
@@ -42,7 +42,6 @@ namespace XCharts.Example
|
|||||||
{
|
{
|
||||||
var chartObject = CreateChartObject(chartName);
|
var chartObject = CreateChartObject(chartName);
|
||||||
var chart = chartObject.AddComponent<PieChart>();
|
var chart = chartObject.AddComponent<PieChart>();
|
||||||
chart.Init();
|
|
||||||
chart.SetSize(580, 300);
|
chart.SetSize(580, 300);
|
||||||
|
|
||||||
chart.EnsureChartComponent<Title>().show = true;
|
chart.EnsureChartComponent<Title>().show = true;
|
||||||
@@ -64,7 +63,6 @@ namespace XCharts.Example
|
|||||||
{
|
{
|
||||||
var chartObject = CreateChartObject(chartName);
|
var chartObject = CreateChartObject(chartName);
|
||||||
var chart = chartObject.AddComponent<PieChart>();
|
var chart = chartObject.AddComponent<PieChart>();
|
||||||
chart.Init();
|
|
||||||
chart.SetSize(580, 300);
|
chart.SetSize(580, 300);
|
||||||
|
|
||||||
chart.EnsureChartComponent<Title>().show = true;
|
chart.EnsureChartComponent<Title>().show = true;
|
||||||
|
|||||||
@@ -25,11 +25,10 @@ namespace XCharts.Example
|
|||||||
|
|
||||||
void AddData()
|
void AddData()
|
||||||
{
|
{
|
||||||
var chart = gameObject.GetComponent<SimplifiedLineChart>();
|
var chart = gameObject.GetComponent<LineChart>();
|
||||||
if (chart == null)
|
if (chart == null)
|
||||||
{
|
{
|
||||||
chart = gameObject.AddComponent<SimplifiedLineChart>();
|
chart = gameObject.AddComponent<LineChart>();
|
||||||
chart.Init();
|
|
||||||
chart.SetSize(580, 300);
|
chart.SetSize(580, 300);
|
||||||
}
|
}
|
||||||
chart.EnsureChartComponent<Title>().show = true;
|
chart.EnsureChartComponent<Title>().show = true;
|
||||||
@@ -49,9 +48,9 @@ namespace XCharts.Example
|
|||||||
xAxis.boundaryGap = true;
|
xAxis.boundaryGap = true;
|
||||||
|
|
||||||
chart.RemoveData();
|
chart.RemoveData();
|
||||||
chart.AddSerie<SimplifiedLine>();
|
chart.AddSerie<Line>();
|
||||||
chart.AddSerie<SimplifiedLine>();
|
chart.AddSerie<Line>();
|
||||||
for (int i = 0; i < 200; i++)
|
for (int i = 0; i < 20; i++)
|
||||||
{
|
{
|
||||||
chart.AddXAxisData("x" + i);
|
chart.AddXAxisData("x" + i);
|
||||||
chart.AddData(0, Random.Range(10, 20));
|
chart.AddData(0, Random.Range(10, 20));
|
||||||
|
|||||||
@@ -165,19 +165,10 @@ namespace XCharts.Runtime
|
|||||||
/// ||鼠标退出图例回调。参数:legendIndex, legendName
|
/// ||鼠标退出图例回调。参数:legendIndex, legendName
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Action<Legend, int, string> onLegendExit { set { m_OnLegendExit = value; } internal get { return m_OnLegendExit; } }
|
public Action<Legend, int, string> onLegendExit { set { m_OnLegendExit = value; } internal get { return m_OnLegendExit; } }
|
||||||
public void Init(bool defaultChart = true)
|
|
||||||
{
|
[Obsolete("No need to call Init() anymore.", true)]
|
||||||
if (defaultChart)
|
public void Init(bool defaultChart = true) { }
|
||||||
{
|
|
||||||
OnInit();
|
|
||||||
DefaultChart();
|
|
||||||
m_DefaultChartInited = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
OnBeforeSerialize();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Redraw chart in next frame.
|
/// Redraw chart in next frame.
|
||||||
/// ||在下一帧刷新整个图表。
|
/// ||在下一帧刷新整个图表。
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace XCharts.Runtime
|
|||||||
[SerializeField] protected ThemeStyle m_Theme = new ThemeStyle();
|
[SerializeField] protected ThemeStyle m_Theme = new ThemeStyle();
|
||||||
[SerializeField] protected Settings m_Settings;
|
[SerializeField] protected Settings m_Settings;
|
||||||
[SerializeField] protected DebugInfo m_DebugInfo = new DebugInfo();
|
[SerializeField] protected DebugInfo m_DebugInfo = new DebugInfo();
|
||||||
[SerializeField] protected bool m_DefaultChartInited = false;
|
[SerializeField] protected bool m_ChartInited = false;
|
||||||
|
|
||||||
#pragma warning disable 0414
|
#pragma warning disable 0414
|
||||||
[SerializeField][ListForComponent(typeof(AngleAxis))] private List<AngleAxis> m_AngleAxes = new List<AngleAxis>();
|
[SerializeField][ListForComponent(typeof(AngleAxis))] private List<AngleAxis> m_AngleAxes = new List<AngleAxis>();
|
||||||
@@ -136,6 +136,7 @@ namespace XCharts.Runtime
|
|||||||
m_Settings = Settings.DefaultSettings;
|
m_Settings = Settings.DefaultSettings;
|
||||||
CheckTheme(true);
|
CheckTheme(true);
|
||||||
base.Awake();
|
base.Awake();
|
||||||
|
CheckChartInit();
|
||||||
InitComponentHandlers();
|
InitComponentHandlers();
|
||||||
InitSerieHandlers();
|
InitSerieHandlers();
|
||||||
AnimationReset();
|
AnimationReset();
|
||||||
@@ -171,17 +172,26 @@ namespace XCharts.Runtime
|
|||||||
rectTransform.sizeDelta = new Vector2(m_ChartWidth, m_ChartHeight);
|
rectTransform.sizeDelta = new Vector2(m_ChartWidth, m_ChartHeight);
|
||||||
}
|
}
|
||||||
ChartHelper.HideAllObject(transform);
|
ChartHelper.HideAllObject(transform);
|
||||||
|
m_ChartInited = true;
|
||||||
if (m_OnInit != null)
|
if (m_OnInit != null)
|
||||||
m_OnInit();
|
m_OnInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void CheckChartInit()
|
||||||
|
{
|
||||||
|
if (!m_ChartInited)
|
||||||
|
{
|
||||||
|
OnInit();
|
||||||
|
DefaultChart();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
protected override void Reset()
|
protected override void Reset()
|
||||||
{
|
{
|
||||||
base.Reset();
|
base.Reset();
|
||||||
OnInit();
|
OnInit();
|
||||||
DefaultChart();
|
DefaultChart();
|
||||||
m_DefaultChartInited = true;
|
|
||||||
Awake();
|
Awake();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user