From 927644fb1022a0b9b140c0ab58e855535ec1adba Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Wed, 7 Dec 2022 13:19:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0`Formatter`=E7=9A=84=E6=96=87?= =?UTF-8?q?=E6=9C=AC=E9=80=9A=E9=85=8D=E7=AC=A6`{h}`=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E5=BD=93=E5=89=8D=E9=A2=9C=E8=89=B2=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Runtime/Component/Tooltip/Tooltip.cs | 2 ++ Runtime/Helper/FormatterHelper.cs | 23 +++++++++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/Runtime/Component/Tooltip/Tooltip.cs b/Runtime/Component/Tooltip/Tooltip.cs index 08a0b423..9a823d71 100644 --- a/Runtime/Component/Tooltip/Tooltip.cs +++ b/Runtime/Component/Tooltip/Tooltip.cs @@ -184,6 +184,7 @@ namespace XCharts.Runtime /// {c}为当前所指示或index为0的serie的y维(dimesion为1)的数值。
/// {d}为当前所指示或index为0的serie的y维(dimesion为1)百分比值,注意不带%号。
/// {e}为当前所指示或index为0的serie的数据项serieData的name。
+ /// {h}为当前所指示或index为0的serie的数据项serieData的十六进制颜色值。
/// {f}为数据总和。
/// {g}为数据总个数。
/// {.1}表示指定index为1的serie对应颜色的圆点。
@@ -224,6 +225,7 @@ namespace XCharts.Runtime /// {e}为当前所指示的serie或数据项的数据项serieData的name。
/// {f}为当前所指示的serie的默认维度的数据总和。
/// {g}为当前所指示的serie的数据总个数。
+ /// {h}为当前所指示的serie的十六进制颜色值。
/// {c0}表示当前数据项维度为0的数据。
/// {c1}表示当前数据项维度为1的数据。
/// {d3}表示维度3的数据的百分比。它的分母是默认维度(一般是1维度)数据。
diff --git a/Runtime/Helper/FormatterHelper.cs b/Runtime/Helper/FormatterHelper.cs index 02ddaea8..c91491a7 100644 --- a/Runtime/Helper/FormatterHelper.cs +++ b/Runtime/Helper/FormatterHelper.cs @@ -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|
|
|
", 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); }