mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-17 22:10:11 +00:00
增加onPointerClickPie和onPointerClickBar回调
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
|
||||
# 更新日志
|
||||
|
||||
* (2020.08.29) Added the `onPointerClickPie` of `PieChart`, a callback function of click pie area.
|
||||
* (2020.08.29) Added the `onPointerClickBar` of `BarChart`, a callback function of click bar.
|
||||
* (2020.08.24) Release `V1.6.0` version
|
||||
* (2020.08.23) Refactor code, replace `Color` with `Color32` for reduce implicit conversion (Can cause custom colors to lose, reference [Q&A 29](https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Assets/XCharts/Documentation/xcharts-questions-and-answers-EN.md) to upgrade)
|
||||
* (2020.08.15) Optimize `PieChart` drawing performance effect #85
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
|
||||
# 更新日志
|
||||
|
||||
* (2020.08.29) 增加`PieChart`的`onPointerClickPie`点击扇形图扇区回调
|
||||
* (2020.08.29) 增加`BarChart`的`onPointerClickBar`点击柱形图柱条回调
|
||||
* (2020.08.24) 发布`v1.6.0`版本
|
||||
* (2020.08.23) 重构代码,将与绘制相关的`Color`改为`Color32`,减少隐式转换(更新后会导致自定义的颜色丢失,可参考[问答29](https://github.com/monitor1394/unity-ugui-XCharts/blob/master/Assets/XCharts/Documentation/XCharts问答.md)进行升级)
|
||||
* (2020.08.15) 优化`PieChart`绘制表现效果#85
|
||||
|
||||
@@ -103,10 +103,14 @@
|
||||
* 继承自 `BaseChart`。
|
||||
* 继承自 `CoordinateChart`。
|
||||
|
||||
* `BarChart.onPointerClickBar`:点击柱条回调。参数:`eventData`, `dataIndex`
|
||||
|
||||
## `PieChart`
|
||||
|
||||
* 继承自 `BaseChart`。
|
||||
|
||||
* `PieChart.onPointerClickPie`:点击柱条回调。参数:`eventData`, `serieIndex`, `dataIndex`
|
||||
|
||||
## `RadarChart`
|
||||
|
||||
* 继承自 `BaseChart`。
|
||||
|
||||
@@ -103,10 +103,14 @@
|
||||
* 继承自 `BaseChart`。
|
||||
* 继承自 `CoordinateChart`。
|
||||
|
||||
* `BarChart.onPointerClickBar`:点击柱条回调。参数:`eventData`, `dataIndex`
|
||||
|
||||
## `PieChart`
|
||||
|
||||
* 继承自 `BaseChart`。
|
||||
|
||||
* `PieChart.onPointerClickPie`:点击柱条回调。参数:`eventData`, `serieIndex`, `dataIndex`
|
||||
|
||||
## `RadarChart`
|
||||
|
||||
* 继承自 `BaseChart`。
|
||||
|
||||
@@ -31,32 +31,32 @@ namespace XCharts.Examples
|
||||
chart.onScroll = OnScroll;
|
||||
}
|
||||
|
||||
void OnPointerEnter(BaseGraph chart, PointerEventData eventData)
|
||||
void OnPointerEnter(PointerEventData eventData, BaseGraph chart)
|
||||
{
|
||||
//Debug.LogError("enter:" + chart);
|
||||
}
|
||||
|
||||
void OnPointerExit(BaseGraph chart, PointerEventData eventData)
|
||||
void OnPointerExit(PointerEventData eventData, BaseGraph chart)
|
||||
{
|
||||
//Debug.LogError("exit:" + chart);
|
||||
}
|
||||
|
||||
void OnPointerDown(BaseGraph chart, PointerEventData eventData)
|
||||
void OnPointerDown(PointerEventData eventData, BaseGraph chart)
|
||||
{
|
||||
//Debug.LogError("down:" + chart);
|
||||
}
|
||||
|
||||
void OnPointerUp(BaseGraph chart, PointerEventData eventData)
|
||||
void OnPointerUp(PointerEventData eventData, BaseGraph chart)
|
||||
{
|
||||
//Debug.LogError("up:" + chart);
|
||||
}
|
||||
|
||||
void OnPointerClick(BaseGraph chart, PointerEventData eventData)
|
||||
void OnPointerClick(PointerEventData eventData, BaseGraph chart)
|
||||
{
|
||||
//Debug.LogError("click:" + chart);
|
||||
}
|
||||
|
||||
void OnScroll(BaseGraph chart, PointerEventData eventData)
|
||||
void OnScroll(PointerEventData eventData, BaseGraph chart)
|
||||
{
|
||||
//Debug.LogError("scroll:" + chart);
|
||||
}
|
||||
|
||||
22
Runtime/API/BarChart_API.cs
Normal file
22
Runtime/API/BarChart_API.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
public partial class BarChart
|
||||
{
|
||||
/// <summary>
|
||||
/// the callback function of click bar.
|
||||
/// 点击柱形图柱条回调。参数:eventData, dataIndex
|
||||
/// </summary>
|
||||
public Action<PointerEventData, int> onPointerClickBar { set { m_OnPointerClickBar = value; m_ForceOpenRaycastTarget = true; } }
|
||||
}
|
||||
}
|
||||
11
Runtime/API/BarChart_API.cs.meta
Normal file
11
Runtime/API/BarChart_API.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 73ae9e0b481fc4587828be9149026b0f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -65,39 +65,39 @@ namespace XCharts
|
||||
/// <summary>
|
||||
/// 鼠标点击回调。
|
||||
/// </summary>
|
||||
public Action<BaseGraph, PointerEventData> onPointerClick { set { m_OnPointerClick = value; m_ForceOpenRaycastTarget = true; } }
|
||||
public Action<PointerEventData, BaseGraph> onPointerClick { set { m_OnPointerClick = value; m_ForceOpenRaycastTarget = true; } }
|
||||
/// <summary>
|
||||
/// 鼠标按下回调。
|
||||
/// </summary>
|
||||
public Action<BaseGraph, PointerEventData> onPointerDown { set { m_OnPointerDown = value; m_ForceOpenRaycastTarget = true; } }
|
||||
public Action<PointerEventData, BaseGraph> onPointerDown { set { m_OnPointerDown = value; m_ForceOpenRaycastTarget = true; } }
|
||||
/// <summary>
|
||||
/// 鼠标弹起回调。
|
||||
/// </summary>
|
||||
public Action<BaseGraph, PointerEventData> onPointerUp { set { m_OnPointerUp = value; m_ForceOpenRaycastTarget = true; } }
|
||||
public Action<PointerEventData, BaseGraph> onPointerUp { set { m_OnPointerUp = value; m_ForceOpenRaycastTarget = true; } }
|
||||
/// <summary>
|
||||
/// 鼠标进入回调。
|
||||
/// </summary>
|
||||
public Action<BaseGraph, PointerEventData> onPointerEnter { set { m_OnPointerEnter = value; m_ForceOpenRaycastTarget = true; } }
|
||||
public Action<PointerEventData, BaseGraph> onPointerEnter { set { m_OnPointerEnter = value; m_ForceOpenRaycastTarget = true; } }
|
||||
/// <summary>
|
||||
/// 鼠标退出回调。
|
||||
/// </summary>
|
||||
public Action<BaseGraph, PointerEventData> onPointerExit { set { m_OnPointerExit = value; m_ForceOpenRaycastTarget = true; } }
|
||||
public Action<PointerEventData, BaseGraph> onPointerExit { set { m_OnPointerExit = value; m_ForceOpenRaycastTarget = true; } }
|
||||
/// <summary>
|
||||
/// 鼠标开始拖拽回调。
|
||||
/// </summary>
|
||||
public Action<BaseGraph, PointerEventData> onBeginDrag { set { m_OnBeginDrag = value; m_ForceOpenRaycastTarget = true; } }
|
||||
public Action<PointerEventData, BaseGraph> onBeginDrag { set { m_OnBeginDrag = value; m_ForceOpenRaycastTarget = true; } }
|
||||
/// <summary>
|
||||
/// 鼠标拖拽回调。
|
||||
/// </summary>
|
||||
public Action<BaseGraph, PointerEventData> onDrag { set { m_OnDrag = value; m_ForceOpenRaycastTarget = true; } }
|
||||
public Action<PointerEventData, BaseGraph> onDrag { set { m_OnDrag = value; m_ForceOpenRaycastTarget = true; } }
|
||||
/// <summary>
|
||||
/// 鼠标结束拖拽回调。
|
||||
/// </summary>
|
||||
public Action<BaseGraph, PointerEventData> onEndDrag { set { m_OnEndDrag = value; m_ForceOpenRaycastTarget = true; } }
|
||||
public Action<PointerEventData, BaseGraph> onEndDrag { set { m_OnEndDrag = value; m_ForceOpenRaycastTarget = true; } }
|
||||
/// <summary>
|
||||
/// 鼠标滚动回调。
|
||||
/// </summary>
|
||||
public Action<BaseGraph, PointerEventData> onScroll { set { m_OnScroll = value; m_ForceOpenRaycastTarget = true; } }
|
||||
public Action<PointerEventData, BaseGraph> onScroll { set { m_OnScroll = value; m_ForceOpenRaycastTarget = true; } }
|
||||
|
||||
/// <summary>
|
||||
/// 设置图形的宽高(在非stretch pivot下才有效,其他情况需要自己调整RectTransform)
|
||||
|
||||
22
Runtime/API/PieChart_API.cs
Normal file
22
Runtime/API/PieChart_API.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
public partial class PieChart
|
||||
{
|
||||
/// <summary>
|
||||
/// the callback function of click pie area.
|
||||
/// 点击饼图区域回调。参数:PointerEventData,SerieIndex,SerieDataIndex
|
||||
/// </summary>
|
||||
public Action<PointerEventData, int, int> onPointerClickPie { set { m_OnPointerClickPie = value; m_ForceOpenRaycastTarget = true; } }
|
||||
}
|
||||
}
|
||||
11
Runtime/API/PieChart_API.cs.meta
Normal file
11
Runtime/API/PieChart_API.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 85c7f8858dca444f88830d61b9af3700
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -5,7 +5,9 @@
|
||||
/* */
|
||||
/******************************************/
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
@@ -13,9 +15,15 @@ namespace XCharts
|
||||
[ExecuteInEditMode]
|
||||
[RequireComponent(typeof(RectTransform))]
|
||||
[DisallowMultipleComponent]
|
||||
public class BarChart : CoordinateChart
|
||||
public partial class BarChart : CoordinateChart
|
||||
{
|
||||
protected Action<PointerEventData, int> m_OnPointerClickBar;
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
raycastTarget = false;
|
||||
}
|
||||
#if UNITY_EDITOR
|
||||
protected override void Reset()
|
||||
{
|
||||
@@ -27,9 +35,22 @@ namespace XCharts
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
AddXAxisData("x" + (i + 1));
|
||||
AddData(0, Random.Range(10, 90));
|
||||
AddData(0, UnityEngine.Random.Range(10, 90));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
public override void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
base.OnPointerDown(eventData);
|
||||
if (m_OnPointerClickBar == null) return;
|
||||
if (pointerPos == Vector2.zero) return;
|
||||
UpdateTooltipValue(pointerPos);
|
||||
var dataIndex = m_Tooltip.runtimeDataIndex[0];
|
||||
if (dataIndex >= 0)
|
||||
{
|
||||
m_OnPointerClickBar(eventData, dataIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,15 +33,15 @@ namespace XCharts
|
||||
protected bool m_IsControlledByLayout = false;
|
||||
protected Vector3 m_LastLocalPosition;
|
||||
|
||||
protected Action<BaseGraph, PointerEventData> m_OnPointerClick;
|
||||
protected Action<BaseGraph, PointerEventData> m_OnPointerDown;
|
||||
protected Action<BaseGraph, PointerEventData> m_OnPointerUp;
|
||||
protected Action<BaseGraph, PointerEventData> m_OnPointerEnter;
|
||||
protected Action<BaseGraph, PointerEventData> m_OnPointerExit;
|
||||
protected Action<BaseGraph, PointerEventData> m_OnBeginDrag;
|
||||
protected Action<BaseGraph, PointerEventData> m_OnDrag;
|
||||
protected Action<BaseGraph, PointerEventData> m_OnEndDrag;
|
||||
protected Action<BaseGraph, PointerEventData> m_OnScroll;
|
||||
protected Action<PointerEventData, BaseGraph> m_OnPointerClick;
|
||||
protected Action<PointerEventData, BaseGraph> m_OnPointerDown;
|
||||
protected Action<PointerEventData, BaseGraph> m_OnPointerUp;
|
||||
protected Action<PointerEventData, BaseGraph> m_OnPointerEnter;
|
||||
protected Action<PointerEventData, BaseGraph> m_OnPointerExit;
|
||||
protected Action<PointerEventData, BaseGraph> m_OnBeginDrag;
|
||||
protected Action<PointerEventData, BaseGraph> m_OnDrag;
|
||||
protected Action<PointerEventData, BaseGraph> m_OnEndDrag;
|
||||
protected Action<PointerEventData, BaseGraph> m_OnScroll;
|
||||
|
||||
protected Vector2 chartAnchorMax { get { return m_GraphMinAnchor; } }
|
||||
protected Vector2 chartAnchorMin { get { return m_GraphMaxAnchor; } }
|
||||
@@ -228,53 +228,53 @@ namespace XCharts
|
||||
|
||||
public virtual void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
if (m_OnPointerClick != null) m_OnPointerClick(this, eventData);
|
||||
if (m_OnPointerClick != null) m_OnPointerClick(eventData, this);
|
||||
}
|
||||
|
||||
public virtual void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
if (m_OnPointerDown != null) m_OnPointerDown(this, eventData);
|
||||
if (m_OnPointerDown != null) m_OnPointerDown(eventData, this);
|
||||
}
|
||||
|
||||
public virtual void OnPointerUp(PointerEventData eventData)
|
||||
{
|
||||
if (m_OnPointerUp != null) m_OnPointerUp(this, eventData);
|
||||
if (m_OnPointerUp != null) m_OnPointerUp(eventData, this);
|
||||
}
|
||||
|
||||
public virtual void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
isPointerInChart = true;
|
||||
if (m_OnPointerEnter != null) m_OnPointerEnter(this, eventData);
|
||||
if (m_OnPointerEnter != null) m_OnPointerEnter(eventData, this);
|
||||
}
|
||||
|
||||
public virtual void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
isPointerInChart = false;
|
||||
if (m_OnPointerExit != null) m_OnPointerExit(this, eventData);
|
||||
if (m_OnPointerExit != null) m_OnPointerExit(eventData, this);
|
||||
}
|
||||
|
||||
public virtual void OnBeginDrag(PointerEventData eventData)
|
||||
{
|
||||
if (m_ScrollRect != null) m_ScrollRect.OnBeginDrag(eventData);
|
||||
if (m_OnBeginDrag != null) m_OnBeginDrag(this, eventData);
|
||||
if (m_OnBeginDrag != null) m_OnBeginDrag(eventData, this);
|
||||
}
|
||||
|
||||
public virtual void OnEndDrag(PointerEventData eventData)
|
||||
{
|
||||
if (m_ScrollRect != null) m_ScrollRect.OnEndDrag(eventData);
|
||||
if (m_OnEndDrag != null) m_OnEndDrag(this, eventData);
|
||||
if (m_OnEndDrag != null) m_OnEndDrag(eventData, this);
|
||||
}
|
||||
|
||||
public virtual void OnDrag(PointerEventData eventData)
|
||||
{
|
||||
if (m_ScrollRect != null) m_ScrollRect.OnDrag(eventData);
|
||||
if (m_OnDrag != null) m_OnDrag(this, eventData);
|
||||
if (m_OnDrag != null) m_OnDrag(eventData, this);
|
||||
}
|
||||
|
||||
public virtual void OnScroll(PointerEventData eventData)
|
||||
{
|
||||
if (m_ScrollRect != null) m_ScrollRect.OnScroll(eventData);
|
||||
if (m_OnScroll != null) m_OnScroll(this, eventData);
|
||||
if (m_OnScroll != null) m_OnScroll(eventData, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -250,111 +250,7 @@ namespace XCharts
|
||||
}
|
||||
else
|
||||
{
|
||||
var isCartesian = IsValue();
|
||||
int dataCount = m_Series.list.Count > 0 ? m_Series.list[0].GetDataList(dataZoom).Count : 0;
|
||||
for (int i = 0; i < m_XAxises.Count; i++)
|
||||
{
|
||||
var xAxis = m_XAxises[i];
|
||||
var yAxis = m_YAxises[i];
|
||||
if (!xAxis.show && !yAxis.show) continue;
|
||||
if (isCartesian && xAxis.show && yAxis.show)
|
||||
{
|
||||
var yRate = (yAxis.runtimeMaxValue - yAxis.runtimeMinValue) / m_CoordinateHeight;
|
||||
var xRate = (xAxis.runtimeMaxValue - xAxis.runtimeMinValue) / m_CoordinateWidth;
|
||||
var yValue = yRate * (local.y - m_CoordinateY - yAxis.runtimeZeroYOffset);
|
||||
if (yAxis.runtimeMinValue > 0) yValue += yAxis.runtimeMinValue;
|
||||
m_Tooltip.runtimeYValues[i] = yValue;
|
||||
var xValue = xRate * (local.x - m_CoordinateX - xAxis.runtimeZeroXOffset);
|
||||
if (xAxis.runtimeMinValue > 0) xValue += xAxis.runtimeMinValue;
|
||||
m_Tooltip.runtimeXValues[i] = xValue;
|
||||
|
||||
for (int j = 0; j < m_Series.Count; j++)
|
||||
{
|
||||
var serie = m_Series.GetSerie(j);
|
||||
for (int n = 0; n < serie.data.Count; n++)
|
||||
{
|
||||
var serieData = serie.data[n];
|
||||
var xdata = serieData.GetData(0, xAxis.inverse);
|
||||
var ydata = serieData.GetData(1, yAxis.inverse);
|
||||
var symbol = SerieHelper.GetSerieSymbol(serie, serieData);
|
||||
var symbolSize = symbol.GetSize(serieData == null ? null : serieData.data);
|
||||
if (Mathf.Abs(xValue - xdata) / xRate < symbolSize
|
||||
&& Mathf.Abs(yValue - ydata) / yRate < symbolSize)
|
||||
{
|
||||
m_Tooltip.runtimeDataIndex[i] = n;
|
||||
serieData.highlighted = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
serieData.highlighted = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (IsCategory())
|
||||
{
|
||||
|
||||
for (int j = 0; j < xAxis.GetDataNumber(m_DataZoom); j++)
|
||||
{
|
||||
float splitWid = AxisHelper.GetDataWidth(xAxis, m_CoordinateWidth, dataCount, m_DataZoom);
|
||||
float pX = m_CoordinateX + j * splitWid;
|
||||
if ((xAxis.boundaryGap && (local.x > pX && local.x <= pX + splitWid)) ||
|
||||
(!xAxis.boundaryGap && (local.x > pX - splitWid / 2 && local.x <= pX + splitWid / 2)))
|
||||
{
|
||||
m_Tooltip.runtimeXValues[i] = j;
|
||||
m_Tooltip.runtimeDataIndex[i] = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (int j = 0; j < yAxis.GetDataNumber(m_DataZoom); j++)
|
||||
{
|
||||
float splitWid = AxisHelper.GetDataWidth(yAxis, m_CoordinateHeight, dataCount, m_DataZoom);
|
||||
float pY = m_CoordinateY + j * splitWid;
|
||||
if ((yAxis.boundaryGap && (local.y > pY && local.y <= pY + splitWid)) ||
|
||||
(!yAxis.boundaryGap && (local.y > pY - splitWid / 2 && local.y <= pY + splitWid / 2)))
|
||||
{
|
||||
m_Tooltip.runtimeYValues[i] = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (xAxis.IsCategory())
|
||||
{
|
||||
var value = (yAxis.runtimeMaxValue - yAxis.runtimeMinValue) * (local.y - m_CoordinateY - yAxis.runtimeZeroYOffset) / m_CoordinateHeight;
|
||||
if (yAxis.runtimeMinValue > 0) value += yAxis.runtimeMinValue;
|
||||
m_Tooltip.runtimeYValues[i] = value;
|
||||
for (int j = 0; j < xAxis.GetDataNumber(m_DataZoom); j++)
|
||||
{
|
||||
float splitWid = AxisHelper.GetDataWidth(xAxis, m_CoordinateWidth, dataCount, m_DataZoom);
|
||||
float pX = m_CoordinateX + j * splitWid;
|
||||
if ((xAxis.boundaryGap && (local.x > pX && local.x <= pX + splitWid)) ||
|
||||
(!xAxis.boundaryGap && (local.x > pX - splitWid / 2 && local.x <= pX + splitWid / 2)))
|
||||
{
|
||||
m_Tooltip.runtimeXValues[i] = j;
|
||||
m_Tooltip.runtimeDataIndex[i] = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (yAxis.IsCategory())
|
||||
{
|
||||
var value = (xAxis.runtimeMaxValue - xAxis.runtimeMinValue) * (local.x - m_CoordinateX - xAxis.runtimeZeroXOffset) / m_CoordinateWidth;
|
||||
if (xAxis.runtimeMinValue > 0) value += xAxis.runtimeMinValue;
|
||||
m_Tooltip.runtimeXValues[i] = value;
|
||||
for (int j = 0; j < yAxis.GetDataNumber(m_DataZoom); j++)
|
||||
{
|
||||
float splitWid = AxisHelper.GetDataWidth(yAxis, m_CoordinateHeight, dataCount, m_DataZoom);
|
||||
float pY = m_CoordinateY + j * splitWid;
|
||||
if ((yAxis.boundaryGap && (local.y > pY && local.y <= pY + splitWid)) ||
|
||||
(!yAxis.boundaryGap && (local.y > pY - splitWid / 2 && local.y <= pY + splitWid / 2)))
|
||||
{
|
||||
m_Tooltip.runtimeYValues[i] = j;
|
||||
m_Tooltip.runtimeDataIndex[i] = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
UpdateTooltipValue(local);
|
||||
}
|
||||
if (m_Tooltip.IsSelected())
|
||||
{
|
||||
@@ -373,6 +269,115 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
protected void UpdateTooltipValue(Vector2 local)
|
||||
{
|
||||
var isCartesian = IsValue();
|
||||
int dataCount = m_Series.list.Count > 0 ? m_Series.list[0].GetDataList(dataZoom).Count : 0;
|
||||
for (int i = 0; i < m_XAxises.Count; i++)
|
||||
{
|
||||
var xAxis = m_XAxises[i];
|
||||
var yAxis = m_YAxises[i];
|
||||
if (!xAxis.show && !yAxis.show) continue;
|
||||
if (isCartesian && xAxis.show && yAxis.show)
|
||||
{
|
||||
var yRate = (yAxis.runtimeMaxValue - yAxis.runtimeMinValue) / m_CoordinateHeight;
|
||||
var xRate = (xAxis.runtimeMaxValue - xAxis.runtimeMinValue) / m_CoordinateWidth;
|
||||
var yValue = yRate * (local.y - m_CoordinateY - yAxis.runtimeZeroYOffset);
|
||||
if (yAxis.runtimeMinValue > 0) yValue += yAxis.runtimeMinValue;
|
||||
m_Tooltip.runtimeYValues[i] = yValue;
|
||||
var xValue = xRate * (local.x - m_CoordinateX - xAxis.runtimeZeroXOffset);
|
||||
if (xAxis.runtimeMinValue > 0) xValue += xAxis.runtimeMinValue;
|
||||
m_Tooltip.runtimeXValues[i] = xValue;
|
||||
|
||||
for (int j = 0; j < m_Series.Count; j++)
|
||||
{
|
||||
var serie = m_Series.GetSerie(j);
|
||||
for (int n = 0; n < serie.data.Count; n++)
|
||||
{
|
||||
var serieData = serie.data[n];
|
||||
var xdata = serieData.GetData(0, xAxis.inverse);
|
||||
var ydata = serieData.GetData(1, yAxis.inverse);
|
||||
var symbol = SerieHelper.GetSerieSymbol(serie, serieData);
|
||||
var symbolSize = symbol.GetSize(serieData == null ? null : serieData.data);
|
||||
if (Mathf.Abs(xValue - xdata) / xRate < symbolSize
|
||||
&& Mathf.Abs(yValue - ydata) / yRate < symbolSize)
|
||||
{
|
||||
m_Tooltip.runtimeDataIndex[i] = n;
|
||||
serieData.highlighted = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
serieData.highlighted = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (IsCategory())
|
||||
{
|
||||
|
||||
for (int j = 0; j < xAxis.GetDataNumber(m_DataZoom); j++)
|
||||
{
|
||||
float splitWid = AxisHelper.GetDataWidth(xAxis, m_CoordinateWidth, dataCount, m_DataZoom);
|
||||
float pX = m_CoordinateX + j * splitWid;
|
||||
if ((xAxis.boundaryGap && (local.x > pX && local.x <= pX + splitWid)) ||
|
||||
(!xAxis.boundaryGap && (local.x > pX - splitWid / 2 && local.x <= pX + splitWid / 2)))
|
||||
{
|
||||
m_Tooltip.runtimeXValues[i] = j;
|
||||
m_Tooltip.runtimeDataIndex[i] = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (int j = 0; j < yAxis.GetDataNumber(m_DataZoom); j++)
|
||||
{
|
||||
float splitWid = AxisHelper.GetDataWidth(yAxis, m_CoordinateHeight, dataCount, m_DataZoom);
|
||||
float pY = m_CoordinateY + j * splitWid;
|
||||
if ((yAxis.boundaryGap && (local.y > pY && local.y <= pY + splitWid)) ||
|
||||
(!yAxis.boundaryGap && (local.y > pY - splitWid / 2 && local.y <= pY + splitWid / 2)))
|
||||
{
|
||||
m_Tooltip.runtimeYValues[i] = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (xAxis.IsCategory())
|
||||
{
|
||||
var value = (yAxis.runtimeMaxValue - yAxis.runtimeMinValue) * (local.y - m_CoordinateY - yAxis.runtimeZeroYOffset) / m_CoordinateHeight;
|
||||
if (yAxis.runtimeMinValue > 0) value += yAxis.runtimeMinValue;
|
||||
m_Tooltip.runtimeYValues[i] = value;
|
||||
for (int j = 0; j < xAxis.GetDataNumber(m_DataZoom); j++)
|
||||
{
|
||||
float splitWid = AxisHelper.GetDataWidth(xAxis, m_CoordinateWidth, dataCount, m_DataZoom);
|
||||
float pX = m_CoordinateX + j * splitWid;
|
||||
if ((xAxis.boundaryGap && (local.x > pX && local.x <= pX + splitWid)) ||
|
||||
(!xAxis.boundaryGap && (local.x > pX - splitWid / 2 && local.x <= pX + splitWid / 2)))
|
||||
{
|
||||
m_Tooltip.runtimeXValues[i] = j;
|
||||
m_Tooltip.runtimeDataIndex[i] = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (yAxis.IsCategory())
|
||||
{
|
||||
var value = (xAxis.runtimeMaxValue - xAxis.runtimeMinValue) * (local.x - m_CoordinateX - xAxis.runtimeZeroXOffset) / m_CoordinateWidth;
|
||||
if (xAxis.runtimeMinValue > 0) value += xAxis.runtimeMinValue;
|
||||
m_Tooltip.runtimeXValues[i] = value;
|
||||
for (int j = 0; j < yAxis.GetDataNumber(m_DataZoom); j++)
|
||||
{
|
||||
float splitWid = AxisHelper.GetDataWidth(yAxis, m_CoordinateHeight, dataCount, m_DataZoom);
|
||||
float pY = m_CoordinateY + j * splitWid;
|
||||
if ((yAxis.boundaryGap && (local.y > pY && local.y <= pY + splitWid)) ||
|
||||
(!yAxis.boundaryGap && (local.y > pY - splitWid / 2 && local.y <= pY + splitWid / 2)))
|
||||
{
|
||||
m_Tooltip.runtimeYValues[i] = j;
|
||||
m_Tooltip.runtimeDataIndex[i] = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected StringBuilder sb = new StringBuilder(100);
|
||||
protected override void UpdateTooltip()
|
||||
{
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
/* */
|
||||
/******************************************/
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
@@ -15,11 +16,13 @@ namespace XCharts
|
||||
[ExecuteInEditMode]
|
||||
[RequireComponent(typeof(RectTransform))]
|
||||
[DisallowMultipleComponent]
|
||||
public class PieChart : BaseChart
|
||||
public partial class PieChart : BaseChart
|
||||
{
|
||||
private bool isDrawPie;
|
||||
private bool m_IsEnterLegendButtom;
|
||||
|
||||
protected Action<PointerEventData, int, int> m_OnPointerClickPie;
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
@@ -529,28 +532,28 @@ namespace XCharts
|
||||
public override void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
base.OnPointerDown(eventData);
|
||||
|
||||
Vector2 local;
|
||||
if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform,
|
||||
eventData.position, canvas.worldCamera, out local))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (pointerPos == Vector2.zero) return;
|
||||
var refresh = false;
|
||||
for (int i = 0; i < m_Series.Count; i++)
|
||||
{
|
||||
var serie = m_Series.GetSerie(i);
|
||||
if (serie.type != SerieType.Pie) continue;
|
||||
var index = GetPosPieIndex(serie, local);
|
||||
var index = GetPosPieIndex(serie, pointerPos);
|
||||
if (index >= 0)
|
||||
{
|
||||
refresh = true;
|
||||
for (int j = 0; j < serie.data.Count; j++)
|
||||
{
|
||||
if (j == index) serie.data[j].selected = !serie.data[j].selected;
|
||||
else serie.data[j].selected = false;
|
||||
}
|
||||
if (m_OnPointerClickPie != null)
|
||||
{
|
||||
m_OnPointerClickPie(eventData, i, index);
|
||||
}
|
||||
}
|
||||
}
|
||||
RefreshChart();
|
||||
if (refresh) RefreshChart();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user