diff --git a/Documentation~/zh/changelog.md b/Documentation~/zh/changelog.md index a742bd99..5e2d5fc9 100644 --- a/Documentation~/zh/changelog.md +++ b/Documentation~/zh/changelog.md @@ -69,6 +69,7 @@ slug: /changelog ## master +* (2023.11.15) 取消`Legend`的`formatter`,用`LabelStyle`的代替 * (2023.11.14) 完善`LabelStyle`的`formatter`的注释和文档(#291) * (2023.11.11) 修复`Documentation`部分注释生成文档不完整的问题 (#290) * (2023.11.11) 修复`Legend`的`formatter`在数据变更时没有自动刷新的问题 diff --git a/Editor/MainComponents/LegendEditor.cs b/Editor/MainComponents/LegendEditor.cs index 340b567b..64623f5a 100644 --- a/Editor/MainComponents/LegendEditor.cs +++ b/Editor/MainComponents/LegendEditor.cs @@ -17,7 +17,6 @@ namespace XCharts.Editor PropertyField("m_ItemOpacity"); PropertyField("m_SelectedMode"); PropertyField("m_Orient"); - PropertyField("m_Formatter"); PropertyField("m_Location"); PropertyField("m_LabelStyle"); PropertyField("m_Background"); diff --git a/Runtime/Component/Legend/Legend.cs b/Runtime/Component/Legend/Legend.cs index 088ca7bc..7549885a 100644 --- a/Runtime/Component/Legend/Legend.cs +++ b/Runtime/Component/Legend/Legend.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using UnityEngine; @@ -79,7 +80,6 @@ namespace XCharts.Runtime [SerializeField] private bool m_ItemAutoColor = true; [SerializeField] private float m_ItemOpacity = 1; [SerializeField] private string m_Formatter; - [SerializeField] protected string m_NumericFormatter = ""; [SerializeField] private LabelStyle m_LabelStyle = new LabelStyle(); [SerializeField] private List m_Data = new List(); [SerializeField] private List m_Icons = new List(); @@ -181,21 +181,10 @@ namespace XCharts.Runtime set { if (PropertyUtil.SetStruct(ref m_ItemOpacity, value)) SetComponentDirty(); } } /// - /// Standard numeric format strings. - /// ||标准数字格式字符串。用于将数值格式化显示为字符串。 - /// 使用Axx的形式:A是格式说明符的单字符,支持C货币、D十进制、E指数、F定点数、G常规、N数字、P百分比、R往返、X十六进制的。xx是精度说明,从0-99。 - /// 参考:https://docs.microsoft.com/zh-cn/dotnet/standard/base-types/standard-numeric-format-strings - /// - public string numericFormatter - { - get { return m_NumericFormatter; } - set { if (PropertyUtil.SetClass(ref m_NumericFormatter, value)) SetComponentDirty(); } - } - /// - /// Legend content string template formatter. Support for wrapping lines with \n. Template:{value}. - /// ||图例内容字符串模版格式器。支持用 \n 换行。 - /// 模板变量为图例名称 {value}。其他模板变量参考Toolip的itemFormatter。 + /// No longer used, the use of LabelStyle.formatter instead. + /// ||不再使用,使用LabelStyle.formatter代替。 /// + [Obsolete("Use LabelStyle.formatter instead.", false)] public string formatter { get { return m_Formatter; } diff --git a/Runtime/Component/Legend/LegendHandler.cs b/Runtime/Component/Legend/LegendHandler.cs index e2a0bd48..478689a5 100644 --- a/Runtime/Component/Legend/LegendHandler.cs +++ b/Runtime/Component/Legend/LegendHandler.cs @@ -42,8 +42,10 @@ namespace XCharts.Runtime public override void OnSerieDataUpdate(int serieIndex) { - if (FormatterHelper.NeedFormat(component.formatter)) +#pragma warning disable 0618 + if (FormatterHelper.NeedFormat(component.formatter) || FormatterHelper.NeedFormat(component.labelStyle.formatter)) component.refreshComponent(); +#pragma warning restore 0618 } private void InitLegend(Legend legend) @@ -150,16 +152,19 @@ namespace XCharts.Runtime private string GetFormatterContent(Legend legend, int dataIndex, string category) { - if (string.IsNullOrEmpty(legend.formatter)) +#pragma warning disable 0618 + if (string.IsNullOrEmpty(legend.formatter) || string.IsNullOrEmpty(legend.labelStyle.formatter)) return category; else { - var content = legend.formatter.Replace("{name}", category); + var formatter = string.IsNullOrEmpty(legend.labelStyle.formatter) ? legend.formatter : legend.labelStyle.formatter; + var content = formatter.Replace("{name}", category); content = content.Replace("{value}", category); var serie = chart.GetSerie(0); - FormatterHelper.ReplaceContent(ref content, dataIndex, legend.numericFormatter, serie, chart, category); + FormatterHelper.ReplaceContent(ref content, dataIndex, legend.labelStyle.numericFormatter, serie, chart, category); return content; } +#pragma warning restore 0618 } private void OnLegendButtonClick(Legend legend, int index, string legendName, bool show)