From bece2eb564917483ddacfbc497c0709c4f54a1d0 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Fri, 1 Dec 2023 08:39:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D`Tooltip`=E7=9A=84`titleForma?= =?UTF-8?q?tter`=E8=AE=BE=E7=BD=AE=E4=B8=BA`{b}`=E5=90=8E=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E4=B8=8D=E5=87=86=E7=A1=AE=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Documentation~/en/changelog.md | 10 +++++----- Documentation~/zh/changelog.md | 17 +++++++++-------- Examples/Example02_ChartEvent.cs | 2 +- Runtime/Component/Comment/CommentHander.cs | 2 +- Runtime/Component/Title/TitleHandler.cs | 4 ++-- Runtime/Component/Tooltip/TooltipHandler.cs | 4 +++- Runtime/Component/Tooltip/TooltipHelper.cs | 2 +- Runtime/Helper/FormatterHelper.cs | 8 ++++++-- Runtime/Internal/BaseChart.Component.cs | 20 +++----------------- Runtime/Serie/SerieHandler.cs | 5 ++--- 10 files changed, 33 insertions(+), 41 deletions(-) diff --git a/Documentation~/en/changelog.md b/Documentation~/en/changelog.md index db68dc6c..e3c0602e 100644 --- a/Documentation~/en/changelog.md +++ b/Documentation~/en/changelog.md @@ -132,7 +132,7 @@ Log details: * (2023.08.22) Fixed `Bar` display hidden drawing performance exception * (2023.08.22) Improved Zebra histogram rendering performance (#276) * (2023.08.16) Added Daemon daemon to resolve an error after TMP is enabled locally -* (2023.08.15) Fixed `Data` displaying axes incorrectly when data is between -1 and 1 (#273) (by __Ambitroc__) +* (2023.08.15) Fixed `Data` displaying axes incorrectly when data is between -1 and 1 (#273) (by **Ambitroc**) * (2023.08.14) Fixed `XCharts` updating error after` TextMeshPro `and` NewInputSystem `are enabled locally (#272) * (2023.08.12) Fixed `Chart` error when deleted at runtime (#269) * (2023.08.11) Fixed an issue where data could not be added when DataZoom was enabled @@ -173,7 +173,7 @@ Log details: * (2022.06.08) Release v3.7.0 * (2023.06.04) Added `HelpDoc` help document skip -* (2023.05.30) Fixed Serie name with `_` line causing `Legend` to not fire (#252) (by __svr2kos2__) +* (2023.05.30) Fixed Serie name with `_` line causing `Legend` to not fire (#252) (by **svr2kos2**) * (2023.05.10) Added `MinMaxAuto` range type for `Axis` * (2023.05.10) Added support for `Clip` for `Line` * (2023.05.04) Fixed `Axis` setting` CeilRate `not taking effect in range -1 to 1 @@ -192,9 +192,9 @@ Log details: * (2023.04.01) Release `v3.6.0` version * (2023.03.14) Fix for Tooltip's `titleFormater` setting `{b}` may not take effect -* (2023.03.14) Fix for `BarChart` not drawing bar background when data is 0 (#250) (by __Ambitroc__) +* (2023.03.14) Fix for `BarChart` not drawing bar background when data is 0 (#250) (by **Ambitroc**) * (2023.03.12) Added `LabelStyle` `autoRotate` to set automatic rotation of angled vertical text -* (2023.03.10) Added `VR` and other non-mouse input for Point location acquisition (#248) (by __Ambitroc__) +* (2023.03.10) Added `VR` and other non-mouse input for Point location acquisition (#248) (by **Ambitroc**) * (2023.03.09) Adds callbacks to Chart's `onSerieClick`, `onSerieDown`, `onSerieEnter` and `onSerieExit` * (2023.03.09) Fixed click-check offset for `Pie` not taking effect * (2023.03.04) Added Positions for Legend to customize legend positions @@ -208,7 +208,7 @@ Log details: * (2023.02.02) Fixed bug where datazoom xaxis label could be displayed off-chart when datazoom is turned on * (2023.02.02) Optimizes the `ignore` setting of `SerieData` to ignore data * (2023.02.01) Fix `XChartsMgr.ContainsChart()` interface exception -* (2023.01.31) Added support for `InputSystem` (#242) (by __Bian-Sh__) +* (2023.01.31) Added support for `InputSystem` (#242) (by **Bian-Sh**) * (2023.01.11) Fixed chart not refreshing after removing Component from Inspector (#241) * (2023.01.06) Fixed bug with `Pie` displaying abnormal Label when the last few values are 0 (#240) * (2023.01.03) deletes serie `MarkColor` and adds ItemStyle `MarkColor` diff --git a/Documentation~/zh/changelog.md b/Documentation~/zh/changelog.md index c78daece..c4aea062 100644 --- a/Documentation~/zh/changelog.md +++ b/Documentation~/zh/changelog.md @@ -83,6 +83,7 @@ slug: /changelog 日志详情: +* (2023.12.01) 修复`Tooltip`的`titleFormatter`设置为`{b}`后显示不准确的问题 * (2023.11.30) 增加`SerieData`可单独添加`Label`的支持 * (2023.11.28) 修复`Tooltip`在对数轴时指示不准确的问题 * (2023.11.24) 修复`Chart`的`UpdateData()`接口返回值不准确的问题 @@ -143,7 +144,7 @@ slug: /changelog * (2023.08.22) 修复`Bar`显示隐藏时绘制表现异常的问题 * (2023.08.22) 优化`Zebra`斑马柱图的绘制表现 (#276) * (2023.08.16) 增加`Daemon`守护程序,解决本地开启TMP后更新版本报错问题 -* (2023.08.15) 修复`Data`数据在-1到1之间时坐标轴显示错误的问题 (#273) (by __Ambitroc__) +* (2023.08.15) 修复`Data`数据在-1到1之间时坐标轴显示错误的问题 (#273) (by **Ambitroc**) * (2023.08.14) 修复`XCharts`本地开启`TextMeshPro`和 `NewInputSystem`后更新版本会报错的问题 (#272) * (2023.08.12) 修复`Chart`在运行时被删除时会异常报错的问题 (#269) * (2023.08.11) 修复`DataZoom`开启时可能会导致无法添加数据的问题 @@ -184,7 +185,7 @@ slug: /changelog * (2023.06.08) 发布`v3.7.0`版本 * (2023.06.04) 增加`HelpDoc`帮助文档跳转 -* (2023.05.30) 修复`Serie`的名字带`_`线导致`Legend`无法触发的问题 (#259) (by __svr2kos2__) +* (2023.05.30) 修复`Serie`的名字带`_`线导致`Legend`无法触发的问题 (#259) (by **svr2kos2**) * (2023.05.10) 增加`Axis`的`MinMaxAuto`范围类型 * (2023.05.10) 增加`Line`对`Clip`的支持 * (2023.05.04) 优化`Axis`在-1到1范围时设置`CeilRate`不生效的问题 @@ -203,9 +204,9 @@ slug: /changelog 版本要点: -* 增加`InputSystem`支持 (by __Bian-Sh__) -* 增加官网[在线示例](https://xcharts-team.github.io/examples/)多版本支持 (by __SHL-COOL__) -* 完善对`VR`的支持 (by __Ambitroc__) +* 增加`InputSystem`支持 (by **Bian-Sh**) +* 增加官网[在线示例](https://xcharts-team.github.io/examples/)多版本支持 (by **SHL-COOL**) +* 完善对`VR`的支持 (by **Ambitroc**) * 增加`UITable`,`UIStatistic`等[扩展UI组件](https://xcharts-team.github.io/docs/ui) * 增加`ItemStyle`的`MarkColor` * 增加通配符`{h}`的支持 @@ -221,9 +222,9 @@ slug: /changelog * (2023.04.01) 发布`v3.6.0`版本 * (2023.03.14) 修复`Tooltip`的`titleFormater`设置`{b}`可能不生效的问题 -* (2023.03.14) 修复`BarChart`在数据为0时不绘制柱条背景的问题 (#250) (by __Ambitroc__) +* (2023.03.14) 修复`BarChart`在数据为0时不绘制柱条背景的问题 (#250) (by **Ambitroc**) * (2023.03.12) 增加`LabelStyle`的`autoRotate`可设置有角度的竖版文本的自动旋转 -* (2023.03.10) 增加`VR`等其他非鼠标输入方式的Point位置获取 (#248) (by __Ambitroc__) +* (2023.03.10) 增加`VR`等其他非鼠标输入方式的Point位置获取 (#248) (by **Ambitroc**) * (2023.03.09) 增加`Chart`的`onSerieClick`,`onSerieDown`,`onSerieEnter`和`onSerieExit`回调 * (2023.03.09) 修复`Pie`的点击选中偏移不生效的问题 * (2023.03.04) 增加`Legend`的`Positions`可自定义图例的位置 @@ -237,7 +238,7 @@ slug: /changelog * (2023.02.02) 修复`DataZoom`开启时`X轴`的`Label`可能会显示在图表外的问题 * (2023.02.02) 优化`SerieData`的`ignore`设置时的忽略数据判断 * (2023.02.01) 修复`XChartsMgr.ContainsChart()`接口异常 -* (2023.01.31) 增加`InputSystem`的支持 (#242) (by __Bian-Sh__) +* (2023.01.31) 增加`InputSystem`的支持 (#242) (by **Bian-Sh**) * (2023.01.11) 修复`Inspector`上移除`Component`后图表没有及时刷新的问题 (#241) * (2023.01.06) 修复`Pie`在最后的几个数据都为0时`Label`显示不正常的问题 (#240) * (2023.01.03) 删除`Serie`的`MarkColor`,增加`ItemStyle`的`MarkColor` diff --git a/Examples/Example02_ChartEvent.cs b/Examples/Example02_ChartEvent.cs index 6c2ce5b8..51bbfaad 100644 --- a/Examples/Example02_ChartEvent.cs +++ b/Examples/Example02_ChartEvent.cs @@ -93,7 +93,7 @@ void OnDrawAfterSerie(VertexHelper vh, Serie serie) //Debug.Log("OnDrawAfterSerie: " + serie.index); if (serie.index != 0) return; var dataPoints = serie.context.dataPoints; - if (dataPoints.Count > 0) + if (dataPoints.Count > 4) { var pos = dataPoints[3]; var grid = chart.GetChartComponent(); diff --git a/Runtime/Component/Comment/CommentHander.cs b/Runtime/Component/Comment/CommentHander.cs index eef0f5d2..4e515f2e 100644 --- a/Runtime/Component/Comment/CommentHander.cs +++ b/Runtime/Component/Comment/CommentHander.cs @@ -47,7 +47,7 @@ private string GetContent(CommentItem item) if (item.content.IndexOf("{") >= 0) { var content = item.content; - FormatterHelper.ReplaceContent(ref content, 0, item.labelStyle.numericFormatter, null, chart); + FormatterHelper.ReplaceContent(ref content, -1, item.labelStyle.numericFormatter, null, chart); return content; } else diff --git a/Runtime/Component/Title/TitleHandler.cs b/Runtime/Component/Title/TitleHandler.cs index a0437acb..e059352c 100644 --- a/Runtime/Component/Title/TitleHandler.cs +++ b/Runtime/Component/Title/TitleHandler.cs @@ -62,7 +62,7 @@ private string GetTitleText(Title title) if (FormatterHelper.NeedFormat(title.text)) { var content = title.text; - FormatterHelper.ReplaceContent(ref content, 0, title.labelStyle.numericFormatter, null, chart); + FormatterHelper.ReplaceContent(ref content, -1, title.labelStyle.numericFormatter, null, chart); return content; } else @@ -76,7 +76,7 @@ private string GetSubTitleText(Title title) if (FormatterHelper.NeedFormat(title.subText)) { var content = title.subText; - FormatterHelper.ReplaceContent(ref content, 0, title.subLabelStyle.numericFormatter, null, chart); + FormatterHelper.ReplaceContent(ref content, -1, title.subLabelStyle.numericFormatter, null, chart); return content; } else diff --git a/Runtime/Component/Tooltip/TooltipHandler.cs b/Runtime/Component/Tooltip/TooltipHandler.cs index 884807b0..4fc3007c 100644 --- a/Runtime/Component/Tooltip/TooltipHandler.cs +++ b/Runtime/Component/Tooltip/TooltipHandler.cs @@ -306,8 +306,10 @@ private void UpdateAxisPointerDataIndex(Serie serie, XAxis xAxis, YAxis yAxis, G { if (isTriggerAxis) { + var index = serie.context.dataZoomStartIndex + (int)yAxis.context.pointerValue; serie.context.pointerEnter = true; - serie.context.pointerAxisDataIndexs.Add((int)yAxis.context.pointerValue); + serie.context.pointerAxisDataIndexs.Add(index); + serie.context.pointerItemDataIndex = index; yAxis.context.axisTooltipValue = yAxis.context.pointerValue; } } diff --git a/Runtime/Component/Tooltip/TooltipHelper.cs b/Runtime/Component/Tooltip/TooltipHelper.cs index eeae3318..50b5dbda 100644 --- a/Runtime/Component/Tooltip/TooltipHelper.cs +++ b/Runtime/Component/Tooltip/TooltipHelper.cs @@ -16,7 +16,7 @@ internal static void ResetTooltipParamsByItemFormatter(Tooltip tooltip, BaseChar else { tooltip.context.data.title = tooltip.titleFormatter; - FormatterHelper.ReplaceContent(ref tooltip.context.data.title, 0, + FormatterHelper.ReplaceContent(ref tooltip.context.data.title, -1, tooltip.numericFormatter, null, chart); } } diff --git a/Runtime/Helper/FormatterHelper.cs b/Runtime/Helper/FormatterHelper.cs index 893b8857..02fcc327 100644 --- a/Runtime/Helper/FormatterHelper.cs +++ b/Runtime/Helper/FormatterHelper.cs @@ -40,6 +40,10 @@ public static bool ReplaceContent(ref string content, int dataIndex, string nume { var foundDot = false; var mc = s_Regex.Matches(content); + if (dataIndex < 0) + { + dataIndex = serie != null ? serie.context.pointerItemDataIndex : 0; + } foreach (var m in mc) { var old = m.ToString(); @@ -99,10 +103,10 @@ public static bool ReplaceContent(ref string content, int dataIndex, string nume var args1Str = args[1].ToString(); if (s_RegexN.IsMatch(args1Str)) bIndex = int.Parse(args1Str); } - var needCategory = (p != 'e' && p != 'E') && serie.defaultColorBy != SerieColorBy.Data; + var needCategory = p != 'e' && p != 'E' && serie.defaultColorBy != SerieColorBy.Data; if (needCategory) { - var category = chart.GetTooltipCategory(dataIndex, serie); + var category = chart.GetTooltipCategory(serie); content = content.Replace(old, category); } else diff --git a/Runtime/Internal/BaseChart.Component.cs b/Runtime/Internal/BaseChart.Component.cs index 75e8faac..ac19ddc6 100644 --- a/Runtime/Internal/BaseChart.Component.cs +++ b/Runtime/Internal/BaseChart.Component.cs @@ -439,31 +439,17 @@ public bool IsInAnyGrid(Vector2 local) return false; } - internal string GetTooltipCategory(int dataIndex, DataZoom dataZoom = null) - { - var xAxis = GetChartComponent(); - var yAxis = GetChartComponent(); - if (yAxis.IsCategory()) - { - return yAxis.GetData((int)yAxis.context.pointerValue, dataZoom); - } - else if (xAxis.IsCategory()) - { - return xAxis.GetData((int)xAxis.context.pointerValue, dataZoom); - } - return null; - } - internal string GetTooltipCategory(int dataIndex, Serie serie, DataZoom dataZoom = null) + internal string GetTooltipCategory(Serie serie) { var xAxis = GetChartComponent(serie.xAxisIndex); var yAxis = GetChartComponent(serie.yAxisIndex); if (yAxis.IsCategory()) { - return yAxis.GetData((int)yAxis.context.pointerValue, dataZoom); + return yAxis.GetData(serie.context.pointerItemDataIndex); } else if (xAxis.IsCategory()) { - return xAxis.GetData((int)xAxis.context.pointerValue, dataZoom); + return xAxis.GetData(serie.context.pointerItemDataIndex); } return null; } diff --git a/Runtime/Serie/SerieHandler.cs b/Runtime/Serie/SerieHandler.cs index 7031162a..fb1e94f7 100644 --- a/Runtime/Serie/SerieHandler.cs +++ b/Runtime/Serie/SerieHandler.cs @@ -419,7 +419,7 @@ private void InitSerieTitle() else { content = titleStyle.formatter; - FormatterHelper.ReplaceContent(ref content, 0, titleStyle.numericFormatter, serie, chart); + FormatterHelper.ReplaceContent(ref content, -1, titleStyle.numericFormatter, serie, chart); } var label = ChartHelper.AddChartLabel("title_" + 0, serieTitleRoot.transform, titleStyle, chart.theme.common, content, color, TextAnchor.MiddleCenter); @@ -446,9 +446,8 @@ private void InitSerieTitle() else { content = titleStyle.formatter; - FormatterHelper.ReplaceContent(ref content, 0, titleStyle.numericFormatter, serie, chart); + FormatterHelper.ReplaceContent(ref content, i, titleStyle.numericFormatter, serie, chart); } - FormatterHelper.ReplaceContent(ref content, i, titleStyle.numericFormatter, serie, chart); var label = ChartHelper.AddChartLabel("title_" + i, serieTitleRoot.transform, titleStyle, chart.theme.common, content, color, TextAnchor.MiddleCenter); serieData.titleObject = label;