修复TooltiptitleFormatter设置为{b}后显示不准确的问题

This commit is contained in:
monitor1394
2023-12-01 08:39:27 +08:00
parent 735e36d6e5
commit bece2eb564
10 changed files with 33 additions and 41 deletions

View File

@@ -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`

View File

@@ -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`

View File

@@ -93,7 +93,7 @@ namespace XCharts.Example
//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<GridCoord>();

View File

@@ -47,7 +47,7 @@ namespace XCharts.Runtime
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

View File

@@ -62,7 +62,7 @@ namespace XCharts.Runtime
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 @@ namespace XCharts.Runtime
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

View File

@@ -306,8 +306,10 @@ namespace XCharts.Runtime
{
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;
}
}

View File

@@ -16,7 +16,7 @@ namespace XCharts.Runtime
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);
}
}

View File

@@ -40,6 +40,10 @@ namespace XCharts.Runtime
{
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 @@ namespace XCharts.Runtime
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

View File

@@ -439,31 +439,17 @@ namespace XCharts.Runtime
return false;
}
internal string GetTooltipCategory(int dataIndex, DataZoom dataZoom = null)
{
var xAxis = GetChartComponent<XAxis>();
var yAxis = GetChartComponent<YAxis>();
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<XAxis>(serie.xAxisIndex);
var yAxis = GetChartComponent<YAxis>(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;
}

View File

@@ -419,7 +419,7 @@ namespace XCharts.Runtime
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 @@ namespace XCharts.Runtime
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;