[add][legend] add the delegate callback for legend

This commit is contained in:
monitor1394
2022-05-04 09:19:45 +08:00
parent d1fd4dcf44
commit e92afac0de
3 changed files with 44 additions and 6 deletions

View File

@@ -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;

View File

@@ -105,7 +105,21 @@ namespace XCharts.Runtime
/// 坐标轴变更数据索引时回调。参数axis, dataIndex/dataValue
/// </summary>
public Action<Axis, double> onAxisPointerValueChanged { set { m_OnAxisPointerValueChanged = value; } get { return m_OnAxisPointerValueChanged; } }
/// <summary>
/// the callback function of click legend.
/// |点击图例按钮回调。参数legendIndex, legendName, show
/// </summary>
public Action<Legend, int, string, bool> onLegendClick { set { m_OnLegendClick = value; } internal get { return m_OnLegendClick; } }
/// <summary>
/// the callback function of enter legend.
/// |鼠标进入图例回调。参数legendIndex, legendName
/// </summary>
public Action<Legend, int, string> onLegendEnter { set { m_OnLegendEnter = value; } internal get { return m_OnLegendEnter; } }
/// <summary>
/// the callback function of exit legend.
/// |鼠标退出图例回调。参数legendIndex, legendName
/// </summary>
public Action<Legend, int, string> onLegendExit { set { m_OnLegendExit = value; } internal get { return m_OnLegendExit; } }
public void Init(bool defaultChart = true)
{
if (defaultChart)

View File

@@ -88,6 +88,9 @@ namespace XCharts.Runtime
protected Action<PointerEventData, int, int> m_OnPointerClickPie;
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;
protected Action<Legend, int, string> m_OnLegendExit;
protected CustomDrawGaugePointerFunction m_CustomDrawGaugePointerFunction;