From 465af108aa253dc3e203da49d749a91a17ed1cb0 Mon Sep 17 00:00:00 2001
From: monitor1394
Date: Thu, 9 Mar 2023 21:31:26 +0800
Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0`Chart`=E7=9A=84`onSerieClick?=
=?UTF-8?q?`=EF=BC=8C`onSerieDown`=EF=BC=8C`onSerieEnter`=E5=92=8C`onSerie?=
=?UTF-8?q?Exit`=E5=9B=9E=E8=B0=83?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Documentation~/en/api.md | 20 ++++
Documentation~/zh/api.md | 20 ++++
Documentation~/zh/changelog.md | 2 +
Editor/Series/PieEditor.cs | 1 +
Examples/Example30_PieChart.cs | 2 +-
Examples/Example_Test.cs | 19 ++++
README.md | 14 +--
Runtime/Internal/BaseChart.API.cs | 31 ++++++-
Runtime/Internal/BaseChart.cs | 6 +-
Runtime/Internal/BaseGraph.cs | 3 +-
Runtime/Internal/Misc/SerieEventData.cs | 46 ++++++++++
Runtime/Internal/Misc/SerieEventData.cs.meta | 11 +++
Runtime/Internal/Pools/SerieEventDataPool.cs | 33 +++++++
.../Internal/Pools/SerieEventDataPool.cs.meta | 11 +++
Runtime/Internal/Utilities/ChartHelper.cs | 7 +-
Runtime/Serie/Bar/BarHandler.cs | 16 +---
Runtime/Serie/Bar/SimplifiedBarHandler.cs | 3 +-
Runtime/Serie/Heatmap/HeatmapHandler.cs | 16 ++--
Runtime/Serie/Line/LineHandler.cs | 25 ++++-
Runtime/Serie/Line/SimplifiedLineHandler.cs | 3 +-
Runtime/Serie/Parallel/ParallelHandler.cs | 3 -
Runtime/Serie/Pie/PieHandler.cs | 56 +++++------
Runtime/Serie/Radar/RadarHandler.cs | 39 +++++---
Runtime/Serie/Ring/RingHandler.cs | 3 +-
Runtime/Serie/Scatter/BaseScatterHandler.cs | 3 +-
Runtime/Serie/Serie.cs | 21 +++++
Runtime/Serie/SerieContext.cs | 4 +
Runtime/Serie/SerieHandler.cs | 92 +++++++++++++++++--
28 files changed, 408 insertions(+), 102 deletions(-)
create mode 100644 Runtime/Internal/Misc/SerieEventData.cs
create mode 100644 Runtime/Internal/Misc/SerieEventData.cs.meta
create mode 100644 Runtime/Internal/Pools/SerieEventDataPool.cs
create mode 100644 Runtime/Internal/Pools/SerieEventDataPool.cs.meta
diff --git a/Documentation~/en/api.md b/Documentation~/en/api.md
index c5aa7fd5..980de0cd 100644
--- a/Documentation~/en/api.md
+++ b/Documentation~/en/api.md
@@ -69,6 +69,8 @@ slug: /api
- [SerieDataComponentAttribute](#seriedatacomponentattribute)
- [SerieDataContext](#seriedatacontext)
- [SerieDataExtraFieldAttribute](#seriedataextrafieldattribute)
+- [SerieEventData](#serieeventdata)
+- [SerieEventDataPool](#serieeventdatapool)
- [SerieHandler](#seriehandler)
- [SerieHandler<T>](#seriehandlert)
- [SerieHandlerAttribute](#seriehandlerattribute)
@@ -870,6 +872,19 @@ Inherits or Implemented: [Attribute](#attribute)
| SerieDataExtraFieldAttribute() |public SerieDataExtraFieldAttribute(string field1, string field2, string field3, string field4, string field5, string field6)|
| SerieDataExtraFieldAttribute() |public SerieDataExtraFieldAttribute(string field1, string field2, string field3, string field4, string field5, string field6, string field7)|
+## SerieEventData
+
+|public method|description|
+|--|--|
+| Reset() |public void Reset()|
+
+## SerieEventDataPool
+
+|public method|description|
+|--|--|
+| Get() |public static SerieEventData Get(Vector3 pos, int serieIndex, int dataIndex, int dimension, double value)|
+| Release() |public static void Release(SerieEventData toRelease)|
+
## SerieHandler
|public method|description|
@@ -896,6 +911,7 @@ Inherits or Implemented: [Attribute](#attribute)
| RefreshLabelNextFrame() |public virtual void RefreshLabelNextFrame() { }|
| RemoveComponent() |public virtual void RemoveComponent() { }|
| Update() |public virtual void Update() { }|
+| UpdateSerieContext() |public virtual void UpdateSerieContext() { }|
## SerieHandler<T>
@@ -904,6 +920,8 @@ Inherits or Implemented: [SerieHandler where T](#seriehandler where t),[Serie](#
|public method|description|
|--|--|
| DrawLabelLineSymbol() |public void DrawLabelLineSymbol(VertexHelper vh, LabelLine labelLine, Vector3 startPos, Vector3 endPos, Color32 defaultColor)|
+| GetPointerItemDataDimension() |public override int GetPointerItemDataDimension()|
+| GetPointerItemDataIndex() |public override int GetPointerItemDataIndex()|
| GetSerieDataAutoColor() |public virtual Color GetSerieDataAutoColor(SerieData serieData)|
| GetSerieDataLabelOffset() |public virtual Vector3 GetSerieDataLabelOffset(SerieData serieData, LabelStyle label)|
| GetSerieDataLabelPosition() |public virtual Vector3 GetSerieDataLabelPosition(SerieData serieData, LabelStyle label)|
@@ -912,6 +930,8 @@ Inherits or Implemented: [SerieHandler where T](#seriehandler where t),[Serie](#
| OnLegendButtonClick() |public override void OnLegendButtonClick(int index, string legendName, bool show)|
| OnLegendButtonEnter() |public override void OnLegendButtonEnter(int index, string legendName)|
| OnLegendButtonExit() |public override void OnLegendButtonExit(int index, string legendName)|
+| OnPointerClick() |public override void OnPointerClick(PointerEventData eventData)|
+| OnPointerDown() |public override void OnPointerDown(PointerEventData eventData)|
| RefreshEndLabelInternal() |public virtual void RefreshEndLabelInternal()|
| RefreshLabelInternal() |public override void RefreshLabelInternal()|
| RefreshLabelNextFrame() |public override void RefreshLabelNextFrame()|
diff --git a/Documentation~/zh/api.md b/Documentation~/zh/api.md
index 5a9f3078..42d4dae3 100644
--- a/Documentation~/zh/api.md
+++ b/Documentation~/zh/api.md
@@ -69,6 +69,8 @@ slug: /api
- [SerieDataComponentAttribute](#seriedatacomponentattribute)
- [SerieDataContext](#seriedatacontext)
- [SerieDataExtraFieldAttribute](#seriedataextrafieldattribute)
+- [SerieEventData](#serieeventdata)
+- [SerieEventDataPool](#serieeventdatapool)
- [SerieHandler](#seriehandler)
- [SerieHandler<T>](#seriehandlert)
- [SerieHandlerAttribute](#seriehandlerattribute)
@@ -870,6 +872,19 @@ Inherits or Implemented: [Attribute](#attribute)
| SerieDataExtraFieldAttribute() |public SerieDataExtraFieldAttribute(string field1, string field2, string field3, string field4, string field5, string field6)|
| SerieDataExtraFieldAttribute() |public SerieDataExtraFieldAttribute(string field1, string field2, string field3, string field4, string field5, string field6, string field7)|
+## SerieEventData
+
+|public method|description|
+|--|--|
+| Reset() |public void Reset()|
+
+## SerieEventDataPool
+
+|public method|description|
+|--|--|
+| Get() |public static SerieEventData Get(Vector3 pos, int serieIndex, int dataIndex, int dimension, double value)|
+| Release() |public static void Release(SerieEventData toRelease)|
+
## SerieHandler
|public method|description|
@@ -896,6 +911,7 @@ Inherits or Implemented: [Attribute](#attribute)
| RefreshLabelNextFrame() |public virtual void RefreshLabelNextFrame() { }|
| RemoveComponent() |public virtual void RemoveComponent() { }|
| Update() |public virtual void Update() { }|
+| UpdateSerieContext() |public virtual void UpdateSerieContext() { }|
## SerieHandler<T>
@@ -904,6 +920,8 @@ Inherits or Implemented: [SerieHandler where T](#seriehandler where t),[Serie](#
|public method|description|
|--|--|
| DrawLabelLineSymbol() |public void DrawLabelLineSymbol(VertexHelper vh, LabelLine labelLine, Vector3 startPos, Vector3 endPos, Color32 defaultColor)|
+| GetPointerItemDataDimension() |public override int GetPointerItemDataDimension()|
+| GetPointerItemDataIndex() |public override int GetPointerItemDataIndex()|
| GetSerieDataAutoColor() |public virtual Color GetSerieDataAutoColor(SerieData serieData)|
| GetSerieDataLabelOffset() |public virtual Vector3 GetSerieDataLabelOffset(SerieData serieData, LabelStyle label)|
| GetSerieDataLabelPosition() |public virtual Vector3 GetSerieDataLabelPosition(SerieData serieData, LabelStyle label)|
@@ -912,6 +930,8 @@ Inherits or Implemented: [SerieHandler where T](#seriehandler where t),[Serie](#
| OnLegendButtonClick() |public override void OnLegendButtonClick(int index, string legendName, bool show)|
| OnLegendButtonEnter() |public override void OnLegendButtonEnter(int index, string legendName)|
| OnLegendButtonExit() |public override void OnLegendButtonExit(int index, string legendName)|
+| OnPointerClick() |public override void OnPointerClick(PointerEventData eventData)|
+| OnPointerDown() |public override void OnPointerDown(PointerEventData eventData)|
| RefreshEndLabelInternal() |public virtual void RefreshEndLabelInternal()|
| RefreshLabelInternal() |public override void RefreshLabelInternal()|
| RefreshLabelNextFrame() |public override void RefreshLabelNextFrame()|
diff --git a/Documentation~/zh/changelog.md b/Documentation~/zh/changelog.md
index 694e2d9d..872efefb 100644
--- a/Documentation~/zh/changelog.md
+++ b/Documentation~/zh/changelog.md
@@ -65,6 +65,8 @@ slug: /changelog
## master
+* (2023.03.09) 增加`Chart`的`onSerieClick`,`onSerieDown`,`onSerieEnter`和`onSerieExit`回调
+* (2023.03.09) 修复`Pie`的点击选中偏移不生效的问题
* (2023.03.04) 增加`Legend`的`Positions`可自定义图例的位置
* (2023.03.03) 修复`Animation`变更动画可能无效的问题
* (2023.02.28) 修复`Legend`点击时`Serie`的`Label`不刷新的问题
diff --git a/Editor/Series/PieEditor.cs b/Editor/Series/PieEditor.cs
index 7a66372f..f8e19be5 100644
--- a/Editor/Series/PieEditor.cs
+++ b/Editor/Series/PieEditor.cs
@@ -18,6 +18,7 @@ namespace XCharts.Editor
PropertyField("m_RoundCap");
PropertyField("m_Ignore");
PropertyField("m_IgnoreValue");
+ PropertyField("m_ClickOffset");
});
PropertyField("m_ItemStyle");
PropertyField("m_Animation");
diff --git a/Examples/Example30_PieChart.cs b/Examples/Example30_PieChart.cs
index e6e5f912..a92d19b7 100644
--- a/Examples/Example30_PieChart.cs
+++ b/Examples/Example30_PieChart.cs
@@ -64,7 +64,7 @@ namespace XCharts.Example
chart.AddData(0, 135, "视频广告");
chart.AddData(0, 1548, "搜索引擎");
- chart.onPointerClickPie = delegate (PointerEventData e, int serieIndex, int dataIndex)
+ chart.onSerieClick = delegate (SerieEventData data)
{
};
diff --git a/Examples/Example_Test.cs b/Examples/Example_Test.cs
index 33018a71..b70b7c5c 100644
--- a/Examples/Example_Test.cs
+++ b/Examples/Example_Test.cs
@@ -1,4 +1,5 @@
using UnityEngine;
+using UnityEngine.EventSystems;
using UnityEngine.UI;
using XCharts.Runtime;
#if INPUT_SYSTEM_ENABLED
@@ -14,6 +15,9 @@ namespace XCharts.Example
void Awake()
{
chart = gameObject.GetComponent();
+ chart.onSerieClick = OnPointerClickLine;
+ chart.onSerieEnter = OnPointerEnterLine;
+ chart.onSerieExit = OnPointerExitLine;
var btnTrans = transform.parent.Find("Button");
if (btnTrans)
{
@@ -21,6 +25,21 @@ namespace XCharts.Example
}
}
+ void OnPointerClickLine(SerieEventData data)
+ {
+ Debug.Log("OnPointerClick: " + data.serieIndex+ " " + data.dataIndex +" "+ data.dimension);
+ }
+
+ void OnPointerEnterLine(SerieEventData data)
+ {
+ Debug.Log("OnPointerEnter: " + data.serieIndex + " " + data.dataIndex + " " + data.dimension);
+ }
+
+ void OnPointerExitLine(SerieEventData data)
+ {
+ Debug.Log("OnPointerExit: " + data.serieIndex + " " + data.dataIndex + " " + data.dimension);
+ }
+
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
diff --git a/README.md b/README.md
index b1bf2f3c..4bf30cd0 100644
--- a/README.md
+++ b/README.md
@@ -18,27 +18,27 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
diff --git a/Runtime/Internal/BaseChart.API.cs b/Runtime/Internal/BaseChart.API.cs
index 76c8c953..fb8cf4d0 100644
--- a/Runtime/Internal/BaseChart.API.cs
+++ b/Runtime/Internal/BaseChart.API.cs
@@ -104,21 +104,48 @@ namespace XCharts.Runtime
///
public CustomDrawGaugePointerFunction customDrawGaugePointerFunction { set { m_CustomDrawGaugePointerFunction = value; } get { return m_CustomDrawGaugePointerFunction; } }
///
+ /// the callback function of pointer click serie.
+ /// |鼠标点击Serie回调。
+ ///
+ [Since("v3.6.0")]
+ public Action onSerieClick { set { m_OnSerieClick = value; m_ForceOpenRaycastTarget = true; } get { return m_OnSerieClick; } }
+ ///
+ /// the callback function of pointer down serie.
+ /// |鼠标按下Serie回调。
+ ///
+ [Since("v3.6.0")]
+ public Action onSerieDown { set { m_OnSerieDown = value; m_ForceOpenRaycastTarget = true; } get { return m_OnSerieDown; } }
+ ///
+ /// the callback function of pointer enter serie.
+ /// |鼠标进入Serie回调。
+ ///
+ [Since("v3.6.0")]
+ public Action onSerieEnter { set { m_OnSerieEnter = value; m_ForceOpenRaycastTarget = true; } get { return m_OnSerieEnter; } }
+ ///
+ /// the callback function of pointer exit serie.
+ /// |鼠标离开Serie回调。
+ ///
+ [Since("v3.6.0")]
+ public Action onSerieExit { set { m_OnSerieExit = value; m_ForceOpenRaycastTarget = true; } get { return m_OnSerieExit; } }
+ ///
/// the callback function of pointer click pie area.
/// |点击饼图区域回调。参数:PointerEventData,SerieIndex,SerieDataIndex
///
- public Action onPointerClickPie { set { m_OnPointerClickPie = value; m_ForceOpenRaycastTarget = true; } get { return m_OnPointerClickPie; } }
+ [Obsolete("Use \"onSerieClick\" instead", true)]
+ public Action onPointerClickPie { get; set; }
///
/// the callback function of pointer enter pie area.
/// |鼠标进入和离开饼图区域回调,SerieDataIndex为-1时表示离开。参数:PointerEventData,SerieIndex,SerieDataIndex
///
[Since("v3.3.0")]
+ [Obsolete("Use \"onSerieEnter\" instead", true)]
public Action onPointerEnterPie { set { m_OnPointerEnterPie = value; m_ForceOpenRaycastTarget = true; } get { return m_OnPointerEnterPie; } }
///
/// the callback function of click bar.
/// |点击柱形图柱条回调。参数:eventData, dataIndex
///
- public Action onPointerClickBar { set { m_OnPointerClickBar = value; m_ForceOpenRaycastTarget = true; } get { return m_OnPointerClickBar; } }
+ [Obsolete("Use \"onSerieClick\" instead", true)]
+ public Action onPointerClickBar { get; set; }
///
/// 坐标轴变更数据索引时回调。参数:axis, dataIndex/dataValue
///
diff --git a/Runtime/Internal/BaseChart.cs b/Runtime/Internal/BaseChart.cs
index 3d90a2d3..46b3d4f9 100644
--- a/Runtime/Internal/BaseChart.cs
+++ b/Runtime/Internal/BaseChart.cs
@@ -89,9 +89,11 @@ namespace XCharts.Runtime
protected Action m_OnDrawTop;
protected Action m_OnDrawSerieBefore;
protected Action m_OnDrawSerieAfter;
- protected Action m_OnPointerClickPie;
+ protected Action m_OnSerieClick;
+ protected Action m_OnSerieDown;
+ protected Action m_OnSerieEnter;
+ protected Action m_OnSerieExit;
protected Action m_OnPointerEnterPie;
- protected Action m_OnPointerClickBar;
protected Action m_OnAxisPointerValueChanged;
protected Action