mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-25 10:20:10 +00:00
3.0
This commit is contained in:
@@ -69,6 +69,8 @@ namespace XCharts.Runtime
|
||||
/// </summary>
|
||||
public Vector3 chartPosition { get { return m_ChartPosition; } }
|
||||
public Rect chartRect { get { return m_ChartRect; } }
|
||||
public Action onInit { set { m_OnInit = value; } }
|
||||
public Action onUpdate { set { m_OnUpdate = value; } }
|
||||
/// <summary>
|
||||
/// 自定义绘制回调。在绘制Serie前调用。
|
||||
/// </summary>
|
||||
@@ -103,6 +105,19 @@ namespace XCharts.Runtime
|
||||
/// 坐标轴变更数据索引时回调。参数:axis, dataIndex/dataValue
|
||||
/// </summary>
|
||||
public Action<Axis, double> onAxisPointerValueChanged { set { m_OnAxisPointerValueChanged = value; } get { return m_OnAxisPointerValueChanged; } }
|
||||
|
||||
public void Init(bool defaultChart = true)
|
||||
{
|
||||
if (defaultChart)
|
||||
{
|
||||
OnInit();
|
||||
DefaultChart();
|
||||
}
|
||||
else
|
||||
{
|
||||
OnBeforeSerialize();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Redraw chart in next frame.
|
||||
/// 在下一帧刷新图表。
|
||||
@@ -138,6 +153,7 @@ namespace XCharts.Runtime
|
||||
foreach (var component in m_Components)
|
||||
component.ClearData();
|
||||
m_Series.Clear();
|
||||
m_SerieHandlers.Clear();
|
||||
m_CheckAnimation = false;
|
||||
RefreshChart();
|
||||
}
|
||||
|
||||
@@ -55,12 +55,16 @@ namespace XCharts.Runtime
|
||||
{
|
||||
if (!CanAddChartComponent(type))
|
||||
{
|
||||
throw new InvalidOperationException("CanAddChartComponent:" + type.Name);
|
||||
Debug.LogError("XCharts ERROR: CanAddChartComponent:" + type.Name);
|
||||
return null;
|
||||
}
|
||||
CheckAddRequireChartComponent(type);
|
||||
var component = Activator.CreateInstance(type) as MainComponent;
|
||||
if (component == null)
|
||||
throw new InvalidOperationException("CanAddChartComponent:" + type.Name);
|
||||
{
|
||||
Debug.LogError("XCharts ERROR: CanAddChartComponent:" + type.Name);
|
||||
return null;
|
||||
}
|
||||
component.SetDefaultValue();
|
||||
if (component is IUpdateRuntimeData)
|
||||
(component as IUpdateRuntimeData).UpdateRuntimeData(chartX, chartY, chartWidth, chartHeight);
|
||||
|
||||
@@ -79,6 +79,8 @@ namespace XCharts.Runtime
|
||||
protected Vector2 m_ChartSizeDelta;
|
||||
|
||||
protected Rect m_ChartRect = new Rect(0, 0, 0, 0);
|
||||
protected Action m_OnInit;
|
||||
protected Action m_OnUpdate;
|
||||
protected Action<VertexHelper> m_OnDrawBase;
|
||||
protected Action<VertexHelper> m_OnDrawTop;
|
||||
protected Action<VertexHelper, Serie> m_OnDrawSerieBefore;
|
||||
@@ -101,6 +103,10 @@ namespace XCharts.Runtime
|
||||
protected List<MainComponentHandler> m_ComponentHandlers = new List<MainComponentHandler>();
|
||||
protected List<SerieHandler> m_SerieHandlers = new List<SerieHandler>();
|
||||
|
||||
protected virtual void DefaultChart()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void InitComponent()
|
||||
{
|
||||
base.InitComponent();
|
||||
@@ -125,10 +131,8 @@ namespace XCharts.Runtime
|
||||
XChartsMgr.AddChart(this);
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
protected override void Reset()
|
||||
protected void OnInit()
|
||||
{
|
||||
base.Reset();
|
||||
RemoveAllChartComponent();
|
||||
OnBeforeSerialize();
|
||||
AddChartComponentWhenNoExist<Title>();
|
||||
@@ -148,6 +152,16 @@ namespace XCharts.Runtime
|
||||
rectTransform.sizeDelta = new Vector2(580, 300);
|
||||
}
|
||||
ChartHelper.HideAllObject(transform);
|
||||
if (m_OnInit != null)
|
||||
m_OnInit();
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
protected override void Reset()
|
||||
{
|
||||
base.Reset();
|
||||
OnInit();
|
||||
DefaultChart();
|
||||
Awake();
|
||||
}
|
||||
#endif
|
||||
@@ -167,6 +181,8 @@ namespace XCharts.Runtime
|
||||
foreach (var handler in m_SerieHandlers) handler.Update();
|
||||
foreach (var handler in m_ComponentHandlers) handler.Update();
|
||||
m_DebugInfo.Update();
|
||||
if (m_OnUpdate != null)
|
||||
m_OnUpdate();
|
||||
}
|
||||
|
||||
public Painter GetPainter(int index)
|
||||
@@ -537,7 +553,7 @@ namespace XCharts.Runtime
|
||||
serie.context.dataPoints.Clear();
|
||||
serie.context.dataIgnores.Clear();
|
||||
serie.animation.context.isAllItemAnimationEnd = true;
|
||||
|
||||
|
||||
if (m_OnDrawSerieBefore != null)
|
||||
{
|
||||
m_OnDrawSerieBefore.Invoke(vh, serie);
|
||||
|
||||
Reference in New Issue
Block a user