增加ItemStyletooltipFormatter参数可单独配置SerieTooltip显示

This commit is contained in:
monitor1394
2020-03-21 11:26:50 +08:00
parent a2d666e350
commit b5b5850bf3
11 changed files with 292 additions and 247 deletions

View File

@@ -450,130 +450,5 @@ namespace XCharts
{
return runtimeDataIndex[0] == index || runtimeDataIndex[1] == index;
}
public bool IsNoFormatter()
{
return string.IsNullOrEmpty(m_Formatter) && string.IsNullOrEmpty(m_ItemFormatter);
}
internal string GetFormatterContent(int dataIndex, Series series, string category, ThemeInfo themeInfo = null, DataZoom dataZoom = null)
{
if (string.IsNullOrEmpty(m_Formatter))
{
if (string.IsNullOrEmpty(m_ItemFormatter)) return "";
else
{
var sb = ChartHelper.sb;
var title = m_TitleFormatter;
var formatTitle = !string.IsNullOrEmpty(title);
var needCategory = false;
var first = true;
sb.Length = 0;
for (int i = 0; i < series.Count; i++)
{
var serie = series.GetSerie(i);
var serieData = serie.GetSerieData(dataIndex, dataZoom);
var percent = serieData.GetData(1) / serie.yTotal * 100;
needCategory = needCategory || (serie.type == SerieType.Line || serie.type == SerieType.Bar);
if (serie.show)
{
string content = m_ItemFormatter;
content = content.Replace("{a}", serie.name);
content = content.Replace("{b}", needCategory ? category : serieData.name);
content = content.Replace("{c}", ChartCached.FloatToStr(serieData.GetData(1), 0, m_ForceENotation));
content = content.Replace("{d}", ChartCached.FloatToStr(percent, 1));
if (!first) sb.Append("\n");
sb.Append("<color=#").Append(themeInfo.GetColorStr(i)).Append(">● </color>");
sb.Append(content);
first = false;
}
if (formatTitle)
{
if (i == 0)
{
title = title.Replace("{a}", serie.name);
title = title.Replace("{b}", needCategory ? category : serieData.name);
title = title.Replace("{c}", ChartCached.FloatToStr(serieData.GetData(1), 0, m_ForceENotation));
title = title.Replace("{d}", ChartCached.FloatToStr(percent, 1));
}
title = title.Replace("{a" + i + "}", serie.name);
title = title.Replace("{b" + i + "}", needCategory ? category : serieData.name);
title = title.Replace("{c" + i + "}", ChartCached.FloatToStr(serieData.GetData(1), 0, m_ForceENotation));
title = title.Replace("{d" + i + "}", ChartCached.FloatToStr(percent, 1));
}
}
if (string.IsNullOrEmpty(title))
{
if (needCategory) return category + "\n" + sb.ToString();
else return sb.ToString();
}
else
{
title = title.Replace("\\n", "\n");
title = title.Replace("<br/>", "\n");
return title + "\n" + sb.ToString();
}
}
}
else
{
string content = m_Formatter;
for (int i = 0; i < series.Count; i++)
{
var serie = series.GetSerie(i);
if (serie.show)
{
var needCategory = serie.type == SerieType.Line || serie.type == SerieType.Bar;
var serieData = serie.GetSerieData(dataIndex, dataZoom);
var percent = serieData.GetData(1) / serie.yTotal * 100;
if (i == 0)
{
content = content.Replace("{a}", serie.name);
content = content.Replace("{b}", needCategory ? category : serieData.name);
content = content.Replace("{c}", ChartCached.FloatToStr(serieData.GetData(1), 0, m_ForceENotation));
content = content.Replace("{d}", ChartCached.FloatToStr(percent, 1));
}
content = content.Replace("{a" + i + "}", serie.name);
content = content.Replace("{b" + i + "}", needCategory ? category : serieData.name);
content = content.Replace("{c" + i + "}", ChartCached.FloatToStr(serieData.GetData(1), 0, m_ForceENotation));
content = content.Replace("{d" + i + "}", ChartCached.FloatToStr(percent, 1));
}
}
content = content.Replace("\\n", "\n");
content = content.Replace("<br/>", "\n");
return content;
}
}
internal string GetFormatterContent(string serieName, string dataName, float dataValue)
{
if (string.IsNullOrEmpty(m_Formatter))
return ChartCached.FloatToStr(dataValue, 0, m_ForceENotation);
else
{
var content = m_Formatter.Replace("{a}", serieName);
content = content.Replace("{b}", dataName);
content = content.Replace("{c}", ChartCached.FloatToStr(dataValue, 0, m_ForceENotation));
content = content.Replace("\\n", "\n");
content = content.Replace("<br/>", "\n");
return content;
}
}
internal Color GetLineColor(ThemeInfo theme)
{
if (lineStyle.color != Color.clear)
{
var color = lineStyle.color;
color.a *= lineStyle.opacity;
return color;
}
else
{
var color = (Color)theme.tooltipLineColor;
color.a *= lineStyle.opacity;
return color;
}
}
}
}