From 8c6e9a2f9121660311e5f6936974409142023a72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=A8=E8=90=BD=E9=9A=8F=E9=A3=8E?= Date: Sun, 9 Aug 2020 18:10:33 +0800 Subject: [PATCH 1/2] =?UTF-8?q?Tooltips=20=E6=94=AF=E6=8C=81=20ToString=20?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E6=A0=BC=E5=BC=8F=20=E2=80=9C0.##=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 本次更新用于改善ToString("f2") 出现 100.00%的情况,“#”代表后面不是0就被保留,反之去掉,也就不会出现100.00%的情况 --- Runtime/Component/Main/Tooltip.cs | 2 ++ Runtime/Helper/FormatterHelper.cs | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Runtime/Component/Main/Tooltip.cs b/Runtime/Component/Main/Tooltip.cs index 7aab7490..08c51750 100644 --- a/Runtime/Component/Main/Tooltip.cs +++ b/Runtime/Component/Main/Tooltip.cs @@ -109,6 +109,7 @@ namespace XCharts /// {c1:2} represents the third data from serie's current indication data item indexed to 1 (a data item has multiple data, index 2 represents the third data). /// {c1:2-2} represents the third data item from serie's third data item indexed to 1 (i.e., which data item must be specified to specify). /// {d1:2: F2} indicates that a formatted string with a value specified separately is F2 (numericFormatter is used when numericFormatter is not specified). + /// {d:0.##} indicates that a formatted string with a value specified separately is 0.## (used for percentages, reserved 2 valid digits while eliminating the redundant value 0, compared to f2 100.00% will not happen). /// Example: "{a}, {c}", "{a1}, {c1: f1}", "{a1}, {c1:0: f1}", "{a1} : {c1:1-1: f1}" /// 提示框总内容的字符串模版格式器。支持用 \n 换行。当formatter不为空时,优先使用formatter,否则使用itemFormatter。 /// 模板变量有{.}、{a}、{b}、{c}、{d}。 @@ -122,6 +123,7 @@ namespace XCharts /// {c1:2}表示索引为1的serie的当前指示数据项的第3个数据(一个数据项有多个数据,index为2表示第3个数据)。 /// {c1:2-2}表示索引为1的serie的第3个数据项的第3个数据(也就是要指定第几个数据项时必须要指定第几个数据)。 /// {d1:2:f2}表示单独指定了数值的格式化字符串为f2(不指定时用numericFormatter)。 + /// {d:0.##} 表示单独指定了数值的格式化字符串为 0.## (用于百分比,保留2位有效书同时又能剔除冗余的 0 ,相比于f2不会出现100.00%的情况 )。 /// 示例:"{a}:{c}"、"{a1}:{c1:f1}"、"{a1}:{c1:0:f1}"、"{a1}:{c1:1-1:f1}" /// public string formatter { get { return m_Formatter; } set { m_Formatter = value; } } diff --git a/Runtime/Helper/FormatterHelper.cs b/Runtime/Helper/FormatterHelper.cs index 665d53c3..aef41c84 100644 --- a/Runtime/Helper/FormatterHelper.cs +++ b/Runtime/Helper/FormatterHelper.cs @@ -15,11 +15,11 @@ namespace XCharts public static class FormatterHelper { public const string PH_NN = "\n"; - private static Regex s_Regex = new Regex(@"{([a-d|.]\d*)(:\d+(-\d+)?)?(:[c-g|x|p|r]\d*)?}", RegexOptions.IgnoreCase); - private static Regex s_RegexSub = new Regex(@"(\w?-?\d+)|(\w)|(\.)", RegexOptions.IgnoreCase); + private static Regex s_Regex = new Regex(@"{([a-d|.]\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); - private static Regex s_RegexFn = new Regex(@"[c-g|x|p|r]\d*", RegexOptions.IgnoreCase); + private static Regex s_RegexFn = new Regex(@"[c-g|x|p|r]\d*|0\.#*", RegexOptions.IgnoreCase); 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); From d94ea553152a372af2f353b59b9138ab06e588e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=A8=E8=90=BD=E9=9A=8F=E9=A3=8E?= Date: Sun, 9 Aug 2020 18:17:52 +0800 Subject: [PATCH 2/2] Update Tooltip.cs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 更新对 Tooltips.formatter 的描述 --- Runtime/Component/Main/Tooltip.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Runtime/Component/Main/Tooltip.cs b/Runtime/Component/Main/Tooltip.cs index 08c51750..ae48f286 100644 --- a/Runtime/Component/Main/Tooltip.cs +++ b/Runtime/Component/Main/Tooltip.cs @@ -109,7 +109,7 @@ namespace XCharts /// {c1:2} represents the third data from serie's current indication data item indexed to 1 (a data item has multiple data, index 2 represents the third data). /// {c1:2-2} represents the third data item from serie's third data item indexed to 1 (i.e., which data item must be specified to specify). /// {d1:2: F2} indicates that a formatted string with a value specified separately is F2 (numericFormatter is used when numericFormatter is not specified). - /// {d:0.##} indicates that a formatted string with a value specified separately is 0.## (used for percentages, reserved 2 valid digits while eliminating the redundant value 0, compared to f2 100.00% will not happen). + /// {d:0.##} indicates that a formatted string with a value specified separately is 0.## (used for percentage, reserved 2 valid digits while avoiding the situation similar to "100.00%" when using f2 ). /// Example: "{a}, {c}", "{a1}, {c1: f1}", "{a1}, {c1:0: f1}", "{a1} : {c1:1-1: f1}" /// 提示框总内容的字符串模版格式器。支持用 \n 换行。当formatter不为空时,优先使用formatter,否则使用itemFormatter。 /// 模板变量有{.}、{a}、{b}、{c}、{d}。 @@ -123,7 +123,7 @@ namespace XCharts /// {c1:2}表示索引为1的serie的当前指示数据项的第3个数据(一个数据项有多个数据,index为2表示第3个数据)。 /// {c1:2-2}表示索引为1的serie的第3个数据项的第3个数据(也就是要指定第几个数据项时必须要指定第几个数据)。 /// {d1:2:f2}表示单独指定了数值的格式化字符串为f2(不指定时用numericFormatter)。 - /// {d:0.##} 表示单独指定了数值的格式化字符串为 0.## (用于百分比,保留2位有效书同时又能剔除冗余的 0 ,相比于f2不会出现100.00%的情况 )。 + /// {d:0.##} 表示单独指定了数值的格式化字符串为 0.## (用于百分比,保留2位有效数同时又能避免使用 f2 而出现的类似于"100.00%"的情况 )。 /// 示例:"{a}:{c}"、"{a1}:{c1:f1}"、"{a1}:{c1:0:f1}"、"{a1}:{c1:1-1:f1}" /// public string formatter { get { return m_Formatter; } set { m_Formatter = value; } }