diff --git a/Runtime/Component/Legend/LegendHandler.cs b/Runtime/Component/Legend/LegendHandler.cs index f923aca9..b2852b51 100644 --- a/Runtime/Component/Legend/LegendHandler.cs +++ b/Runtime/Component/Legend/LegendHandler.cs @@ -93,14 +93,14 @@ namespace XCharts.Runtime int clickedIndex = int.Parse(temp[0]); if (legend.selectedMode == Legend.SelectedMode.Multiple) { - chart.OnLegendButtonClick(clickedIndex, selectedName, !chart.IsActiveByLegend(selectedName)); + OnLegendButtonClick(legend, clickedIndex, selectedName, !chart.IsActiveByLegend(selectedName)); } else { var btnList = legend.context.buttonList.Values.ToArray(); if (btnList.Length == 1) { - chart.OnLegendButtonClick(0, selectedName, !chart.IsActiveByLegend(selectedName)); + OnLegendButtonClick(legend, 0, selectedName, !chart.IsActiveByLegend(selectedName)); } else { @@ -109,7 +109,7 @@ namespace XCharts.Runtime temp = btnList[n].name.Split('_'); selectedName = btnList[n].legendName; var index = btnList[n].index; - chart.OnLegendButtonClick(n, selectedName, index == clickedIndex ? true : false); + OnLegendButtonClick(legend, n, selectedName, index == clickedIndex ? true : false); } } } @@ -120,7 +120,7 @@ namespace XCharts.Runtime var temp = item.button.name.Split('_'); string selectedName = temp[1]; int index = int.Parse(temp[0]); - chart.OnLegendButtonEnter(index, selectedName); + OnLegendButtonEnter(legend, index, selectedName); }); ChartHelper.AddEventListener(item.button.gameObject, EventTriggerType.PointerExit, (data) => { @@ -128,7 +128,7 @@ namespace XCharts.Runtime var temp = item.button.name.Split('_'); string selectedName = temp[1]; int index = int.Parse(temp[0]); - chart.OnLegendButtonExit(index, selectedName); + OnLegendButtonExit(legend, index, selectedName); }); } LegendHelper.ResetItemPosition(legend, chart.chartPosition, chart.chartWidth, chart.chartHeight); @@ -136,6 +136,27 @@ namespace XCharts.Runtime legend.refreshComponent(); } + private void OnLegendButtonClick(Legend legend, int index, string legendName, bool show) + { + chart.OnLegendButtonClick(index, legendName, show); + if (chart.onLegendClick != null) + chart.onLegendClick(legend, index, legendName, show); + } + + private void OnLegendButtonEnter(Legend legend, int index, string legendName) + { + chart.OnLegendButtonEnter(index, legendName); + if (chart.onLegendEnter != null) + chart.onLegendEnter(legend, index, legendName); + } + + private void OnLegendButtonExit(Legend legend, int index, string legendName) + { + chart.OnLegendButtonExit(index, legendName); + if (chart.onLegendExit != null) + chart.onLegendExit(legend, index, legendName); + } + private void DrawLegend(VertexHelper vh) { if (chart.series.Count == 0) return; diff --git a/Runtime/Internal/BaseChart.API.cs b/Runtime/Internal/BaseChart.API.cs index 491577a3..782a2ca6 100644 --- a/Runtime/Internal/BaseChart.API.cs +++ b/Runtime/Internal/BaseChart.API.cs @@ -105,7 +105,21 @@ namespace XCharts.Runtime /// 坐标轴变更数据索引时回调。参数:axis, dataIndex/dataValue /// public Action onAxisPointerValueChanged { set { m_OnAxisPointerValueChanged = value; } get { return m_OnAxisPointerValueChanged; } } - + /// + /// the callback function of click legend. + /// |点击图例按钮回调。参数:legendIndex, legendName, show + /// + public Action onLegendClick { set { m_OnLegendClick = value; } internal get { return m_OnLegendClick; } } + /// + /// the callback function of enter legend. + /// |鼠标进入图例回调。参数:legendIndex, legendName + /// + public Action onLegendEnter { set { m_OnLegendEnter = value; } internal get { return m_OnLegendEnter; } } + /// + /// the callback function of exit legend. + /// |鼠标退出图例回调。参数:legendIndex, legendName + /// + public Action onLegendExit { set { m_OnLegendExit = value; } internal get { return m_OnLegendExit; } } public void Init(bool defaultChart = true) { if (defaultChart) diff --git a/Runtime/Internal/BaseChart.cs b/Runtime/Internal/BaseChart.cs index 50afe53e..5cfc96a3 100644 --- a/Runtime/Internal/BaseChart.cs +++ b/Runtime/Internal/BaseChart.cs @@ -88,6 +88,9 @@ namespace XCharts.Runtime protected Action m_OnPointerClickPie; protected Action m_OnPointerClickBar; protected Action m_OnAxisPointerValueChanged; + protected Action m_OnLegendClick; + protected Action m_OnLegendEnter; + protected Action m_OnLegendExit; protected CustomDrawGaugePointerFunction m_CustomDrawGaugePointerFunction;