取消Legendformatter,用LabelStyle的代替

This commit is contained in:
monitor1394
2023-11-16 08:40:28 +08:00
parent f94f678661
commit ddf44a8c1d
4 changed files with 14 additions and 20 deletions

View File

@@ -69,6 +69,7 @@ slug: /changelog
## master ## master
* (2023.11.15) 取消`Legend``formatter`,用`LabelStyle`的代替
* (2023.11.14) 完善`LabelStyle``formatter`的注释和文档(#291) * (2023.11.14) 完善`LabelStyle``formatter`的注释和文档(#291)
* (2023.11.11) 修复`Documentation`部分注释生成文档不完整的问题 (#290) * (2023.11.11) 修复`Documentation`部分注释生成文档不完整的问题 (#290)
* (2023.11.11) 修复`Legend``formatter`在数据变更时没有自动刷新的问题 * (2023.11.11) 修复`Legend``formatter`在数据变更时没有自动刷新的问题

View File

@@ -17,7 +17,6 @@ namespace XCharts.Editor
PropertyField("m_ItemOpacity"); PropertyField("m_ItemOpacity");
PropertyField("m_SelectedMode"); PropertyField("m_SelectedMode");
PropertyField("m_Orient"); PropertyField("m_Orient");
PropertyField("m_Formatter");
PropertyField("m_Location"); PropertyField("m_Location");
PropertyField("m_LabelStyle"); PropertyField("m_LabelStyle");
PropertyField("m_Background"); PropertyField("m_Background");

View File

@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
@@ -79,7 +80,6 @@ namespace XCharts.Runtime
[SerializeField] private bool m_ItemAutoColor = true; [SerializeField] private bool m_ItemAutoColor = true;
[SerializeField] private float m_ItemOpacity = 1; [SerializeField] private float m_ItemOpacity = 1;
[SerializeField] private string m_Formatter; [SerializeField] private string m_Formatter;
[SerializeField] protected string m_NumericFormatter = "";
[SerializeField] private LabelStyle m_LabelStyle = new LabelStyle(); [SerializeField] private LabelStyle m_LabelStyle = new LabelStyle();
[SerializeField] private List<string> m_Data = new List<string>(); [SerializeField] private List<string> m_Data = new List<string>();
[SerializeField] private List<Sprite> m_Icons = new List<Sprite>(); [SerializeField] private List<Sprite> m_Icons = new List<Sprite>();
@@ -181,21 +181,10 @@ namespace XCharts.Runtime
set { if (PropertyUtil.SetStruct(ref m_ItemOpacity, value)) SetComponentDirty(); } set { if (PropertyUtil.SetStruct(ref m_ItemOpacity, value)) SetComponentDirty(); }
} }
/// <summary> /// <summary>
/// Standard numeric format strings. /// No longer used, the use of LabelStyle.formatter instead.
/// ||标准数字格式字符串。用于将数值格式化显示为字符串 /// ||不再使用使用LabelStyle.formatter代替
/// 使用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
/// </summary>
public string numericFormatter
{
get { return m_NumericFormatter; }
set { if (PropertyUtil.SetClass(ref m_NumericFormatter, value)) SetComponentDirty(); }
}
/// <summary>
/// Legend content string template formatter. Support for wrapping lines with \n. Template:{value}.
/// ||图例内容字符串模版格式器。支持用 \n 换行。
/// 模板变量为图例名称 {value}。其他模板变量参考Toolip的itemFormatter。
/// </summary> /// </summary>
[Obsolete("Use LabelStyle.formatter instead.", false)]
public string formatter public string formatter
{ {
get { return m_Formatter; } get { return m_Formatter; }

View File

@@ -42,8 +42,10 @@ namespace XCharts.Runtime
public override void OnSerieDataUpdate(int serieIndex) 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(); component.refreshComponent();
#pragma warning restore 0618
} }
private void InitLegend(Legend legend) private void InitLegend(Legend legend)
@@ -150,16 +152,19 @@ namespace XCharts.Runtime
private string GetFormatterContent(Legend legend, int dataIndex, string category) 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; return category;
else 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); content = content.Replace("{value}", category);
var serie = chart.GetSerie(0); 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; return content;
} }
#pragma warning restore 0618
} }
private void OnLegendButtonClick(Legend legend, int index, string legendName, bool show) private void OnLegendButtonClick(Legend legend, int index, string legendName, bool show)