mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-24 01:40:06 +00:00
增加Chart的onSerieClick,onSerieDown,onSerieEnter和onSerieExit回调
This commit is contained in:
@@ -104,21 +104,48 @@ namespace XCharts.Runtime
|
||||
/// </summary>
|
||||
public CustomDrawGaugePointerFunction customDrawGaugePointerFunction { set { m_CustomDrawGaugePointerFunction = value; } get { return m_CustomDrawGaugePointerFunction; } }
|
||||
/// <summary>
|
||||
/// the callback function of pointer click serie.
|
||||
/// |鼠标点击Serie回调。
|
||||
/// </summary>
|
||||
[Since("v3.6.0")]
|
||||
public Action<SerieEventData> onSerieClick { set { m_OnSerieClick = value; m_ForceOpenRaycastTarget = true; } get { return m_OnSerieClick; } }
|
||||
/// <summary>
|
||||
/// the callback function of pointer down serie.
|
||||
/// |鼠标按下Serie回调。
|
||||
/// </summary>
|
||||
[Since("v3.6.0")]
|
||||
public Action<SerieEventData> onSerieDown { set { m_OnSerieDown = value; m_ForceOpenRaycastTarget = true; } get { return m_OnSerieDown; } }
|
||||
/// <summary>
|
||||
/// the callback function of pointer enter serie.
|
||||
/// |鼠标进入Serie回调。
|
||||
/// </summary>
|
||||
[Since("v3.6.0")]
|
||||
public Action<SerieEventData> onSerieEnter { set { m_OnSerieEnter = value; m_ForceOpenRaycastTarget = true; } get { return m_OnSerieEnter; } }
|
||||
/// <summary>
|
||||
/// the callback function of pointer exit serie.
|
||||
/// |鼠标离开Serie回调。
|
||||
/// </summary>
|
||||
[Since("v3.6.0")]
|
||||
public Action<SerieEventData> onSerieExit { set { m_OnSerieExit = value; m_ForceOpenRaycastTarget = true; } get { return m_OnSerieExit; } }
|
||||
/// <summary>
|
||||
/// the callback function of pointer click pie area.
|
||||
/// |点击饼图区域回调。参数:PointerEventData,SerieIndex,SerieDataIndex
|
||||
/// </summary>
|
||||
public Action<PointerEventData, int, int> onPointerClickPie { set { m_OnPointerClickPie = value; m_ForceOpenRaycastTarget = true; } get { return m_OnPointerClickPie; } }
|
||||
[Obsolete("Use \"onSerieClick\" instead", true)]
|
||||
public Action<PointerEventData, int, int> onPointerClickPie { get; set; }
|
||||
/// <summary>
|
||||
/// the callback function of pointer enter pie area.
|
||||
/// |鼠标进入和离开饼图区域回调,SerieDataIndex为-1时表示离开。参数:PointerEventData,SerieIndex,SerieDataIndex
|
||||
/// </summary>
|
||||
[Since("v3.3.0")]
|
||||
[Obsolete("Use \"onSerieEnter\" instead", true)]
|
||||
public Action<int, int> onPointerEnterPie { set { m_OnPointerEnterPie = value; m_ForceOpenRaycastTarget = true; } get { return m_OnPointerEnterPie; } }
|
||||
/// <summary>
|
||||
/// the callback function of click bar.
|
||||
/// |点击柱形图柱条回调。参数:eventData, dataIndex
|
||||
/// </summary>
|
||||
public Action<PointerEventData, int> onPointerClickBar { set { m_OnPointerClickBar = value; m_ForceOpenRaycastTarget = true; } get { return m_OnPointerClickBar; } }
|
||||
[Obsolete("Use \"onSerieClick\" instead", true)]
|
||||
public Action<PointerEventData, int> onPointerClickBar { get; set; }
|
||||
/// <summary>
|
||||
/// 坐标轴变更数据索引时回调。参数:axis, dataIndex/dataValue
|
||||
/// </summary>
|
||||
|
||||
@@ -89,9 +89,11 @@ namespace XCharts.Runtime
|
||||
protected Action<VertexHelper> m_OnDrawTop;
|
||||
protected Action<VertexHelper, Serie> m_OnDrawSerieBefore;
|
||||
protected Action<VertexHelper, Serie> m_OnDrawSerieAfter;
|
||||
protected Action<PointerEventData, int, int> m_OnPointerClickPie;
|
||||
protected Action<SerieEventData> m_OnSerieClick;
|
||||
protected Action<SerieEventData> m_OnSerieDown;
|
||||
protected Action<SerieEventData> m_OnSerieEnter;
|
||||
protected Action<SerieEventData> m_OnSerieExit;
|
||||
protected Action<int, int> m_OnPointerEnterPie;
|
||||
protected Action<PointerEventData, int> m_OnPointerClickBar;
|
||||
protected Action<Axis, double> m_OnAxisPointerValueChanged;
|
||||
protected Action<Legend, int, string, bool> m_OnLegendClick;
|
||||
protected Action<Legend, int, string> m_OnLegendEnter;
|
||||
|
||||
@@ -228,7 +228,7 @@ namespace XCharts.Runtime
|
||||
|
||||
protected virtual void CheckRefreshChart()
|
||||
{
|
||||
if (m_RefreshChart)
|
||||
if (m_RefreshChart && m_Painter != null)
|
||||
{
|
||||
m_Painter.Refresh();
|
||||
m_RefreshChart = false;
|
||||
@@ -237,6 +237,7 @@ namespace XCharts.Runtime
|
||||
|
||||
protected virtual void CheckRefreshPainter()
|
||||
{
|
||||
if (m_Painter == null) return;
|
||||
m_Painter.CheckRefresh();
|
||||
}
|
||||
|
||||
|
||||
46
Runtime/Internal/Misc/SerieEventData.cs
Normal file
46
Runtime/Internal/Misc/SerieEventData.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
/// <summary>
|
||||
/// the data of serie event.
|
||||
/// |serie事件的数据。
|
||||
/// </summary>
|
||||
public class SerieEventData
|
||||
{
|
||||
/// <summary>
|
||||
/// the position of pointer in chart.
|
||||
/// |鼠标在chart中的位置。
|
||||
/// </summary>
|
||||
public Vector3 pointerPos { get; set; }
|
||||
/// <summary>
|
||||
/// the index of serie in chart.series.
|
||||
/// |在chart.series中的索引。
|
||||
/// </summary>
|
||||
public int serieIndex { get; set; }
|
||||
/// <summary>
|
||||
/// the index of data in serie.data.
|
||||
/// |在serie.data中的索引。
|
||||
/// </summary>
|
||||
public int dataIndex { get; set; }
|
||||
/// <summary>
|
||||
/// the dimension of data.
|
||||
/// |数据的维度。
|
||||
/// </summary>
|
||||
public int dimension { get; set; }
|
||||
/// <summary>
|
||||
/// the value of data.
|
||||
/// |数据的值。
|
||||
/// </summary>
|
||||
public double value { get; set; }
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
serieIndex = -1;
|
||||
dataIndex = -1;
|
||||
dimension = -1;
|
||||
value = 0;
|
||||
pointerPos = Vector3.zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Runtime/Internal/Misc/SerieEventData.cs.meta
Normal file
11
Runtime/Internal/Misc/SerieEventData.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fdfaa773d93294d78b2fb4b8f42708a3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
33
Runtime/Internal/Pools/SerieEventDataPool.cs
Normal file
33
Runtime/Internal/Pools/SerieEventDataPool.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
public static class SerieEventDataPool
|
||||
{
|
||||
private static readonly ObjectPool<SerieEventData> s_ListPool = new ObjectPool<SerieEventData>(null, OnClear);
|
||||
|
||||
static void OnGet(SerieEventData data)
|
||||
{
|
||||
}
|
||||
|
||||
static void OnClear(SerieEventData data)
|
||||
{
|
||||
data.Reset();
|
||||
}
|
||||
|
||||
public static SerieEventData Get(Vector3 pos, int serieIndex, int dataIndex, int dimension, double value)
|
||||
{
|
||||
var data = s_ListPool.Get();
|
||||
data.serieIndex = serieIndex;
|
||||
data.dataIndex = dataIndex;
|
||||
data.pointerPos = pos;
|
||||
data.dimension = dimension;
|
||||
return data;
|
||||
}
|
||||
|
||||
public static void Release(SerieEventData toRelease)
|
||||
{
|
||||
s_ListPool.Release(toRelease);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Runtime/Internal/Pools/SerieEventDataPool.cs.meta
Normal file
11
Runtime/Internal/Pools/SerieEventDataPool.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 30d123dd5c38446f18183f50336322bb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -161,11 +161,11 @@ namespace XCharts.Runtime
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (!Application.isPlaying)
|
||||
GameObject.DestroyImmediate(component as GameObject, true);
|
||||
GameObject.DestroyImmediate(component as UnityEngine.Object);
|
||||
else
|
||||
GameObject.Destroy(component as GameObject);
|
||||
GameObject.Destroy(component as UnityEngine.Object);
|
||||
#else
|
||||
GameObject.Destroy(component as GameObject);
|
||||
GameObject.Destroy(component as UnityEngine.Object);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -389,6 +389,7 @@ namespace XCharts.Runtime
|
||||
var alignment = textStyle.GetAlignment(autoAlignment);
|
||||
UpdateAnchorAndPivotByTextAlignment(alignment, out anchorMin, out anchorMax, out pivot);
|
||||
var labelObj = AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta);
|
||||
ChartHelper.RemoveComponent<Text>(labelObj);
|
||||
var label = EnsureComponent<ChartLabel>(labelObj);
|
||||
label.text = AddTextObject("Text", label.gameObject.transform, anchorMin, anchorMax, pivot,
|
||||
sizeDelta, textStyle, theme, autoColor, autoAlignment, label.text);
|
||||
|
||||
Reference in New Issue
Block a user