mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-22 17:00:08 +00:00
修复Tooltip的titleFormatter设置为{b}后显示不准确的问题
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user