mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-22 00:20:18 +00:00
3.0
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -63,7 +62,8 @@ namespace XCharts.Runtime
|
||||
/// 无法选择。
|
||||
/// </summary>
|
||||
None
|
||||
};
|
||||
}
|
||||
|
||||
[SerializeField] private bool m_Show = true;
|
||||
[SerializeField] private Type m_IconType = Type.Auto;
|
||||
[SerializeField] private SelectedMode m_SelectedMode = SelectedMode.Multiple;
|
||||
@@ -73,11 +73,13 @@ namespace XCharts.Runtime
|
||||
[SerializeField] private float m_ItemHeight = 12.0f;
|
||||
[SerializeField] private float m_ItemGap = 10f;
|
||||
[SerializeField] private bool m_ItemAutoColor = true;
|
||||
[SerializeField] private bool m_TextAutoColor = false;
|
||||
[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<string> m_Data = new List<string>();
|
||||
[SerializeField] private List<Sprite> m_Icons = new List<Sprite>();
|
||||
[SerializeField] private List<Color> m_Colors = new List<Color>();
|
||||
|
||||
public LegendContext context = new LegendContext();
|
||||
|
||||
@@ -171,19 +173,30 @@ namespace XCharts.Runtime
|
||||
set { if (PropertyUtil.SetStruct(ref m_ItemAutoColor, value)) SetComponentDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Whether the legend text matches the color automatically.
|
||||
/// |图例标记的文本是否自动匹配颜色。
|
||||
/// [default:false]
|
||||
/// the opacity of item color.
|
||||
/// |图例标记的图形的颜色透明度。
|
||||
/// </summary>
|
||||
public bool textAutoColor
|
||||
public float itemOpacity
|
||||
{
|
||||
get { return m_TextAutoColor; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_TextAutoColor, value)) SetComponentDirty(); }
|
||||
get { return m_ItemOpacity; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_ItemOpacity, value)) SetComponentDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Legend content string template formatter. Support for wrapping lines with \n. Template:{name}.
|
||||
/// 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
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
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 换行。
|
||||
/// 模板变量为图例名称 {name}。
|
||||
/// 模板变量为图例名称 {value}。
|
||||
/// [default:null]
|
||||
/// </summary>
|
||||
public string formatter
|
||||
@@ -220,6 +233,11 @@ namespace XCharts.Runtime
|
||||
get { return m_Icons; }
|
||||
set { if (value != null) { m_Icons = value; SetComponentDirty(); } }
|
||||
}
|
||||
public List<Color> colors
|
||||
{
|
||||
get { return m_Colors; }
|
||||
set { if (value != null) { m_Colors = value; SetAllDirty(); } }
|
||||
}
|
||||
/// <summary>
|
||||
/// 图表是否需要刷新(图例组件不需要刷新图表)
|
||||
/// </summary>
|
||||
@@ -384,6 +402,14 @@ namespace XCharts.Runtime
|
||||
}
|
||||
}
|
||||
|
||||
public Color GetColor(int index)
|
||||
{
|
||||
if (index >= 0 && index < m_Colors.Count)
|
||||
return m_Colors[index];
|
||||
else
|
||||
return Color.white;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Callback handling when parameters change.
|
||||
/// |参数变更时的回调处理。
|
||||
@@ -392,23 +418,5 @@ namespace XCharts.Runtime
|
||||
{
|
||||
m_Location.OnChanged();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得图例格式化后的显示内容。
|
||||
/// </summary>
|
||||
/// <param name="category"></param>
|
||||
/// <returns></returns>
|
||||
public string GetFormatterContent(string category)
|
||||
{
|
||||
if (string.IsNullOrEmpty(m_Formatter))
|
||||
return category;
|
||||
else
|
||||
{
|
||||
var content = m_Formatter.Replace("{name}", category);
|
||||
content = content.Replace("\\n", "\n");
|
||||
content = content.Replace("<br/>", "\n");
|
||||
return content;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
@@ -40,14 +39,20 @@ namespace XCharts.Runtime
|
||||
DrawLegend(vh);
|
||||
}
|
||||
|
||||
public override void OnSerieDataUpdate(int serieIndex)
|
||||
{
|
||||
if (FormatterHelper.NeedFormat(component.formatter))
|
||||
component.refreshComponent();
|
||||
}
|
||||
|
||||
private void InitLegend(Legend legend)
|
||||
{
|
||||
legend.painter = null;
|
||||
legend.refreshComponent = delegate ()
|
||||
legend.refreshComponent = delegate()
|
||||
{
|
||||
legend.OnChanged();
|
||||
var legendObject = ChartHelper.AddObject(s_LegendObjectName + legend.index, chart.transform, chart.chartMinAnchor,
|
||||
chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta);
|
||||
chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta);
|
||||
legend.gameObject = legendObject;
|
||||
legendObject.hideFlags = chart.chartHideFlags;
|
||||
SeriesHelper.UpdateSerieNameList(chart, ref chart.m_LegendRealShowName);
|
||||
@@ -77,10 +82,11 @@ namespace XCharts.Runtime
|
||||
for (int i = 0; i < datas.Count; i++)
|
||||
{
|
||||
if (!SeriesHelper.IsLegalLegendName(datas[i])) continue;
|
||||
string legendName = legend.GetFormatterContent(datas[i]);
|
||||
string legendName = GetFormatterContent(legend, i, datas[i]);
|
||||
var readIndex = chart.m_LegendRealShowName.IndexOf(datas[i]);
|
||||
var active = chart.IsActiveByLegend(datas[i]);
|
||||
var bgColor = LegendHelper.GetIconColor(chart, legend, readIndex, datas[i], active);
|
||||
bgColor.a = legend.itemOpacity;
|
||||
var item = LegendHelper.AddLegendItem(legend, i, datas[i], legendObject.transform, chart.theme,
|
||||
legendName, bgColor, active, readIndex);
|
||||
legend.SetButton(legendName, item, totalLegend);
|
||||
@@ -136,6 +142,20 @@ namespace XCharts.Runtime
|
||||
legend.refreshComponent();
|
||||
}
|
||||
|
||||
private string GetFormatterContent(Legend legend, int dataIndex, string category)
|
||||
{
|
||||
if (string.IsNullOrEmpty(legend.formatter))
|
||||
return category;
|
||||
else
|
||||
{
|
||||
var content = legend.formatter.Replace("{name}", category);
|
||||
content = content.Replace("{value}", category);
|
||||
var serie = chart.GetSerie(0);
|
||||
FormatterHelper.ReplaceContent(ref content, dataIndex, legend.numericFormatter, serie, chart);
|
||||
return content;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnLegendButtonClick(Legend legend, int index, string legendName, bool show)
|
||||
{
|
||||
chart.OnLegendButtonClick(index, legendName, show);
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace XCharts.Runtime
|
||||
var textStyle = legend.labelStyle.textStyle;
|
||||
if (active)
|
||||
{
|
||||
if (legend.textAutoColor) return theme.GetColor(legendIndex);
|
||||
if (legend.labelStyle.textStyle.autoColor) return theme.GetColor(legendIndex);
|
||||
else return !ChartHelper.IsClearColor(textStyle.color) ? textStyle.color : theme.legend.textColor;
|
||||
}
|
||||
else return theme.legend.unableColor;
|
||||
@@ -21,12 +21,12 @@ namespace XCharts.Runtime
|
||||
{
|
||||
if (active)
|
||||
{
|
||||
if (legend.itemAutoColor || legend.GetIcon(readIndex) == null)
|
||||
if (legend.itemAutoColor)
|
||||
{
|
||||
return SeriesHelper.GetNameColor(chart, readIndex, legendName);
|
||||
}
|
||||
else
|
||||
return Color.white;
|
||||
return legend.GetColor(readIndex);
|
||||
}
|
||||
else return chart.theme.legend.unableColor;
|
||||
}
|
||||
@@ -54,7 +54,7 @@ namespace XCharts.Runtime
|
||||
ChartHelper.GetOrAddComponent<Image>(iconObj);
|
||||
|
||||
var label = ChartHelper.AddChartLabel("content", btnObj.transform, legend.labelStyle, theme.legend,
|
||||
content, contentColor, TextAnchor.MiddleLeft);
|
||||
content, contentColor, TextAnchor.MiddleLeft);
|
||||
label.SetActive(true);
|
||||
|
||||
var item = new LegendItem();
|
||||
|
||||
Reference in New Issue
Block a user