From 4d6e896d3237d42d25ea2c4f7c6a1b4c36ad6bc0 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Sat, 27 Nov 2021 22:06:15 +0800 Subject: [PATCH] add tooltip delegate function: positionFunction --- CHANGELOG-EN.md | 1 + CHANGELOG.md | 1 + Runtime/Component/Main/Tooltip.cs | 14 +++++++++++++- Runtime/Internal/Interface/DelegateFunction.cs | 12 ++++++++++-- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/CHANGELOG-EN.md b/CHANGELOG-EN.md index 5aef1dc5..5d5627fb 100644 --- a/CHANGELOG-EN.md +++ b/CHANGELOG-EN.md @@ -40,6 +40,7 @@ ## master +* (2021.11.27) Added `Tooltip` delegate function `positionFunction` * (2021.10.29) Removed settings for `TextMeshPro` when package first imported * (2021.10.29) Added support for `{e}` in `Tooltip` #170 * (2021.09.08) Improved `RadarChart` diff --git a/CHANGELOG.md b/CHANGELOG.md index f6b9508f..b54cfc5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,7 @@ ## master +* (2021.11.27) 增加`Tooltip`的`positionFunction`的坐标设置委托函数 * (2021.10.29) 移除`XCharts`首次导入时`TextMeshPro`的相关设置 * (2021.10.29) 增加`Tooltip`对通配符`{e}`的支持 #170 * (2021.09.08) 完善`RadarChart` diff --git a/Runtime/Component/Main/Tooltip.cs b/Runtime/Component/Main/Tooltip.cs index 97f7bdae..a024e78a 100644 --- a/Runtime/Component/Main/Tooltip.cs +++ b/Runtime/Component/Main/Tooltip.cs @@ -65,6 +65,7 @@ namespace XCharts [SerializeField] private Sprite m_BackgroundImage; [SerializeField] private TextStyle m_TextStyle = new TextStyle(); [SerializeField] private LineStyle m_LineStyle = new LineStyle(LineStyle.Type.None); + private DelegateTooltipPosition m_PositionFunction; private GameObject m_GameObject; private GameObject m_Content; @@ -300,6 +301,12 @@ namespace XCharts public int runtimeGridIndex { get; internal set; } public int runtimePolarIndex { get; internal set; } + public DelegateTooltipPosition positionFunction + { + get { return m_PositionFunction; } + set { m_PositionFunction = value; } + } + public static Tooltip defaultTooltip { get @@ -449,7 +456,12 @@ namespace XCharts public void UpdateContentPos(Vector2 pos) { if (m_Content) - m_Content.transform.localPosition = pos; + { + if (m_PositionFunction != null) + m_Content.transform.localPosition = m_PositionFunction(pos); + else + m_Content.transform.localPosition = pos; + } } /// diff --git a/Runtime/Internal/Interface/DelegateFunction.cs b/Runtime/Internal/Interface/DelegateFunction.cs index 10249463..9cbf2749 100644 --- a/Runtime/Internal/Interface/DelegateFunction.cs +++ b/Runtime/Internal/Interface/DelegateFunction.cs @@ -6,11 +6,13 @@ /* */ /************************************************/ +using UnityEngine; + namespace XCharts { /// /// The delegate function for AxisLabel's formatter. | - /// AxisLabel的formatter自定义委托。 + /// AxisLabel的formatter自定义委托函数。 /// /// label索引 /// 当前label对应的数值数据,Value轴或Time轴有效 @@ -19,10 +21,16 @@ namespace XCharts public delegate string DelegateAxisLabelFormatter(int labelIndex, double value, string category); /// /// The delegate function for SerieLabel‘s formatter. - /// SerieLabel的formatter自定义委托。 + /// SerieLabel的formatter自定义委托函数。 /// /// 数据索引 /// 数值 /// 最终显示的文本内容 public delegate string DelegateSerieLabelFormatter(int dataIndex, double value); + /// + /// Tooltip的position自定义委托函数。 + /// + /// Tooltip的当前坐标 + /// Tooltip的最终坐标 + public delegate Vector3 DelegateTooltipPosition(Vector3 pos); } \ No newline at end of file