From 03d18d50ed0f6d7fdef143aca15a7d0a63c4a2bc Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Tue, 3 May 2022 22:30:51 +0800 Subject: [PATCH] add delegate callback function for legend --- CHANGELOG-EN.md | 1 + CHANGELOG.md | 1 + Runtime/API/BaseChart_API.cs | 16 +++++++++++++++- Runtime/Internal/BaseChart.cs | 9 +++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/CHANGELOG-EN.md b/CHANGELOG-EN.md index 2e8f30e5..6eda4b33 100644 --- a/CHANGELOG-EN.md +++ b/CHANGELOG-EN.md @@ -44,6 +44,7 @@ ## branch-2.0 +* (2022.05.03) Added `onLegendClick`, `onLegendEnter` and `onLegendExit` delegate callbacks for `Legend` * (2022.04.21) Fixed bug #192 with `RingChart` `Tooltip` exception * (2022.04.21) Fixed error when setting `minShowNum` in `DataZoom` diff --git a/CHANGELOG.md b/CHANGELOG.md index 3bfa3233..08939b26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,7 @@ ## branch-2.0 +* (2022.05.03) 增加`Legend`的`onLegendClick`,`onLegendEnter`和`onLegendExit`委托回调 * (2022.04.21) 修复`RingChart`的`Tooltip`异常的问题 #192 * (2022.04.21) 修复`DataZoom`设置`minShowNum`时可能会报错的问题 diff --git a/Runtime/API/BaseChart_API.cs b/Runtime/API/BaseChart_API.cs index b65d42a9..de3456fa 100644 --- a/Runtime/API/BaseChart_API.cs +++ b/Runtime/API/BaseChart_API.cs @@ -132,7 +132,21 @@ namespace XCharts /// 点击饼图区域回调。参数:PointerEventData,SerieIndex,SerieDataIndex /// public Action onPointerClickPie { set { m_OnPointerClickPie = value; m_ForceOpenRaycastTarget = true; } get { return m_OnPointerClickPie; } } - + /// + /// the callback function of click legend. + /// 点击图例按钮回调。参数:legendIndex, legendName, show + /// + public Action onLegendClick { set { m_OnLegendClick = value; } } + /// + /// the callback function of enter legend. + /// 鼠标进入图例回调。参数:legendIndex, legendName + /// + public Action onLegendEnter { set { m_OnLegendEnter = value; } } + /// + /// the callback function of exit legend. + /// 鼠标退出图例回调。参数:legendIndex, legendName + /// + public Action onLegendExit { set { m_OnLegendExit = value; } } /// /// Redraw chart in next frame. /// 在下一帧刷新图表。 diff --git a/Runtime/Internal/BaseChart.cs b/Runtime/Internal/BaseChart.cs index c105e045..33f510b3 100644 --- a/Runtime/Internal/BaseChart.cs +++ b/Runtime/Internal/BaseChart.cs @@ -74,6 +74,9 @@ namespace XCharts protected Action m_OnCustomDrawSerieBeforeCallback; protected Action m_OnCustomDrawSerieAfterCallback; protected Action m_OnPointerClickPie; + protected Action m_OnLegendClick; + protected Action m_OnLegendEnter; + protected Action m_OnLegendExit; protected bool m_RefreshLabel = false; internal bool m_ReinitLabel = false; @@ -847,6 +850,8 @@ namespace XCharts } OnYMaxValueChanged(); } + if(m_OnLegendClick != null) + m_OnLegendClick(index, legendName, show); } protected virtual void OnLegendButtonEnter(int index, string legendName) @@ -862,6 +867,8 @@ namespace XCharts RefreshPainter(serie); } } + if(m_OnLegendEnter != null) + m_OnLegendEnter(index, legendName); } protected virtual void OnLegendButtonExit(int index, string legendName) @@ -877,6 +884,8 @@ namespace XCharts RefreshPainter(serie); } } + if(m_OnLegendExit != null) + m_OnLegendExit(index, legendName); } protected virtual void UpdateTooltip()