mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-23 09:20:08 +00:00
增加Formatter的文本通配符{h}支持设置当前颜色值
This commit is contained in:
@@ -184,6 +184,7 @@ namespace XCharts.Runtime
|
||||
/// {c}为当前所指示或index为0的serie的y维(dimesion为1)的数值。<br/>
|
||||
/// {d}为当前所指示或index为0的serie的y维(dimesion为1)百分比值,注意不带%号。<br/>
|
||||
/// {e}为当前所指示或index为0的serie的数据项serieData的name。<br/>
|
||||
/// {h}为当前所指示或index为0的serie的数据项serieData的十六进制颜色值。<br/>
|
||||
/// {f}为数据总和。<br/>
|
||||
/// {g}为数据总个数。<br/>
|
||||
/// {.1}表示指定index为1的serie对应颜色的圆点。<br/>
|
||||
@@ -224,6 +225,7 @@ namespace XCharts.Runtime
|
||||
/// {e}为当前所指示的serie或数据项的数据项serieData的name。<br/>
|
||||
/// {f}为当前所指示的serie的默认维度的数据总和。<br/>
|
||||
/// {g}为当前所指示的serie的数据总个数。<br/>
|
||||
/// {h}为当前所指示的serie的十六进制颜色值。<br/>
|
||||
/// {c0}表示当前数据项维度为0的数据。<br/>
|
||||
/// {c1}表示当前数据项维度为1的数据。<br/>
|
||||
/// {d3}表示维度3的数据的百分比。它的分母是默认维度(一般是1维度)数据。<br/>
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace XCharts.Runtime
|
||||
public static class FormatterHelper
|
||||
{
|
||||
public const string PH_NN = "\n";
|
||||
private static Regex s_Regex = new Regex(@"{([a-g|.]\d*)(:\d+(-\d+)?)?(:[c-g|x|p|r]\d*|:0\.#*)?}", RegexOptions.IgnoreCase);
|
||||
private static Regex s_Regex = new Regex(@"{([a-h|.]\d*)(:\d+(-\d+)?)?(:[c-g|x|p|r]\d*|:0\.#*)?}", RegexOptions.IgnoreCase);
|
||||
private static Regex s_RegexSub = new Regex(@"(0\.#*)|(\d+-\d+)|(\w+)|(\.)", RegexOptions.IgnoreCase);
|
||||
private static Regex s_RegexN = new Regex(@"^\d+", RegexOptions.IgnoreCase);
|
||||
private static Regex s_RegexN_N = new Regex(@"\d+-\d+", RegexOptions.IgnoreCase);
|
||||
@@ -16,8 +16,8 @@ namespace XCharts.Runtime
|
||||
private static Regex s_RegexNewLine = new Regex(@"[\\|/]+n|</br>|<br>|<br/>", RegexOptions.IgnoreCase);
|
||||
private static Regex s_RegexForAxisLabel = new Regex(@"{value(:[c-g|x|p|r]\d*)?}", RegexOptions.IgnoreCase);
|
||||
private static Regex s_RegexSubForAxisLabel = new Regex(@"(value)|([c-g|x|p|r]\d*)", RegexOptions.IgnoreCase);
|
||||
private static Regex s_RegexForSerieLabel = new Regex(@"{[a-g|\.]\d*(:[c-g|x|p|r]\d*)?}", RegexOptions.IgnoreCase);
|
||||
private static Regex s_RegexSubForSerieLabel = new Regex(@"(\.)|([a-g]\d*)|([c-g|x|p|r]\d*)", RegexOptions.IgnoreCase);
|
||||
private static Regex s_RegexForSerieLabel = new Regex(@"{[a-h|\.]\d*(:[c-g|x|p|r]\d*)?}", RegexOptions.IgnoreCase);
|
||||
private static Regex s_RegexSubForSerieLabel = new Regex(@"(\.)|([a-h]\d*)|([c-g|x|p|r]\d*)", RegexOptions.IgnoreCase);
|
||||
|
||||
public static bool NeedFormat(string content)
|
||||
{
|
||||
@@ -64,7 +64,7 @@ namespace XCharts.Runtime
|
||||
targetIndex = 0;
|
||||
}
|
||||
if (serie == null) continue;
|
||||
if (p == '.')
|
||||
if (p == '.' || p == 'h' || p == 'H')
|
||||
{
|
||||
var bIndex = targetIndex;
|
||||
if (argsCount >= 2)
|
||||
@@ -72,8 +72,15 @@ namespace XCharts.Runtime
|
||||
var args1Str = args[1].ToString();
|
||||
if (s_RegexN.IsMatch(args1Str)) bIndex = int.Parse(args1Str);
|
||||
}
|
||||
content = content.Replace(old, ChartCached.ColorToDotStr(chart.theme.GetColor(bIndex)));
|
||||
foundDot = true;
|
||||
if (p == '.')
|
||||
{
|
||||
content = content.Replace(old, ChartCached.ColorToDotStr(chart.theme.GetColor(bIndex)));
|
||||
foundDot = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
content = content.Replace(old, "#" + ChartCached.ColorToStr(chart.theme.GetColor(bIndex)));
|
||||
}
|
||||
}
|
||||
else if (p == 'a' || p == 'A')
|
||||
{
|
||||
@@ -225,6 +232,10 @@ namespace XCharts.Runtime
|
||||
{
|
||||
content = content.Replace(old, ChartCached.NumberToStr(dataCount, numericFormatter));
|
||||
}
|
||||
else if (p == 'h' || p == 'H')
|
||||
{
|
||||
content = content.Replace(old, "#" + ChartCached.ColorToStr(color));
|
||||
}
|
||||
}
|
||||
content = TrimAndReplaceLine(content);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user