mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-28 03:58:49 +00:00
[add][legend] add the delegate callback for legend
This commit is contained in:
@@ -93,14 +93,14 @@ namespace XCharts.Runtime
|
|||||||
int clickedIndex = int.Parse(temp[0]);
|
int clickedIndex = int.Parse(temp[0]);
|
||||||
if (legend.selectedMode == Legend.SelectedMode.Multiple)
|
if (legend.selectedMode == Legend.SelectedMode.Multiple)
|
||||||
{
|
{
|
||||||
chart.OnLegendButtonClick(clickedIndex, selectedName, !chart.IsActiveByLegend(selectedName));
|
OnLegendButtonClick(legend, clickedIndex, selectedName, !chart.IsActiveByLegend(selectedName));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var btnList = legend.context.buttonList.Values.ToArray();
|
var btnList = legend.context.buttonList.Values.ToArray();
|
||||||
if (btnList.Length == 1)
|
if (btnList.Length == 1)
|
||||||
{
|
{
|
||||||
chart.OnLegendButtonClick(0, selectedName, !chart.IsActiveByLegend(selectedName));
|
OnLegendButtonClick(legend, 0, selectedName, !chart.IsActiveByLegend(selectedName));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -109,7 +109,7 @@ namespace XCharts.Runtime
|
|||||||
temp = btnList[n].name.Split('_');
|
temp = btnList[n].name.Split('_');
|
||||||
selectedName = btnList[n].legendName;
|
selectedName = btnList[n].legendName;
|
||||||
var index = btnList[n].index;
|
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('_');
|
var temp = item.button.name.Split('_');
|
||||||
string selectedName = temp[1];
|
string selectedName = temp[1];
|
||||||
int index = int.Parse(temp[0]);
|
int index = int.Parse(temp[0]);
|
||||||
chart.OnLegendButtonEnter(index, selectedName);
|
OnLegendButtonEnter(legend, index, selectedName);
|
||||||
});
|
});
|
||||||
ChartHelper.AddEventListener(item.button.gameObject, EventTriggerType.PointerExit, (data) =>
|
ChartHelper.AddEventListener(item.button.gameObject, EventTriggerType.PointerExit, (data) =>
|
||||||
{
|
{
|
||||||
@@ -128,7 +128,7 @@ namespace XCharts.Runtime
|
|||||||
var temp = item.button.name.Split('_');
|
var temp = item.button.name.Split('_');
|
||||||
string selectedName = temp[1];
|
string selectedName = temp[1];
|
||||||
int index = int.Parse(temp[0]);
|
int index = int.Parse(temp[0]);
|
||||||
chart.OnLegendButtonExit(index, selectedName);
|
OnLegendButtonExit(legend, index, selectedName);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
LegendHelper.ResetItemPosition(legend, chart.chartPosition, chart.chartWidth, chart.chartHeight);
|
LegendHelper.ResetItemPosition(legend, chart.chartPosition, chart.chartWidth, chart.chartHeight);
|
||||||
@@ -136,6 +136,27 @@ namespace XCharts.Runtime
|
|||||||
legend.refreshComponent();
|
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)
|
private void DrawLegend(VertexHelper vh)
|
||||||
{
|
{
|
||||||
if (chart.series.Count == 0) return;
|
if (chart.series.Count == 0) return;
|
||||||
|
|||||||
@@ -105,7 +105,21 @@ namespace XCharts.Runtime
|
|||||||
/// 坐标轴变更数据索引时回调。参数:axis, dataIndex/dataValue
|
/// 坐标轴变更数据索引时回调。参数:axis, dataIndex/dataValue
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Action<Axis, double> onAxisPointerValueChanged { set { m_OnAxisPointerValueChanged = value; } get { return m_OnAxisPointerValueChanged; } }
|
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)
|
public void Init(bool defaultChart = true)
|
||||||
{
|
{
|
||||||
if (defaultChart)
|
if (defaultChart)
|
||||||
|
|||||||
@@ -88,6 +88,9 @@ namespace XCharts.Runtime
|
|||||||
protected Action<PointerEventData, int, int> m_OnPointerClickPie;
|
protected Action<PointerEventData, int, int> m_OnPointerClickPie;
|
||||||
protected Action<PointerEventData, int> m_OnPointerClickBar;
|
protected Action<PointerEventData, int> m_OnPointerClickBar;
|
||||||
protected Action<Axis, double> m_OnAxisPointerValueChanged;
|
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;
|
protected CustomDrawGaugePointerFunction m_CustomDrawGaugePointerFunction;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user