UI update 02

This commit is contained in:
2026-06-30 21:21:30 +08:00
parent b2a1e307a4
commit f62f643cfc
1666 changed files with 211081 additions and 22799 deletions
@@ -0,0 +1,115 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace XCharts.Runtime
{
/// <summary>
/// The layer of comment.
/// ||注解的显示层级。
/// </summary>
[Since("v3.15.0")]
public enum CommentLayer
{
/// <summary>
/// The comment is display under the serie.
/// ||注解在系列下方。
/// </summary>
Lower,
/// <summary>
/// The comment is display above the serie.
/// ||注解在系列上方。
/// </summary>
Upper
}
/// <summary>
/// comment of chart. Used to annotate special information in the chart.
/// ||图表注解组件。用于标注图表中的特殊信息。
/// </summary>
[Serializable]
[ComponentHandler(typeof(CommentHander), true)]
public class Comment : MainComponent, IPropertyChanged
{
[SerializeField] private bool m_Show = true;
[SerializeField][Since("v3.15.0")] private CommentLayer m_Layer = CommentLayer.Lower;
[SerializeField] private LabelStyle m_LabelStyle = new LabelStyle();
[SerializeField] private CommentMarkStyle m_MarkStyle;
[SerializeField] private List<CommentItem> m_Items = new List<CommentItem>() { new CommentItem() };
/// <summary>
/// Set this to false to prevent the comment from showing.
/// ||是否显示注解组件。
/// </summary>
public bool show { get { return m_Show; } set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); } }
/// <summary>
/// The layer of comment.
/// ||注解的显示层级。
/// </summary>
public CommentLayer layer { get { return m_Layer; } set { if (PropertyUtil.SetStruct(ref m_Layer, value)) SetComponentDirty(); } }
/// <summary>
/// The items of comment.
/// ||注解项。每个注解组件可以设置多个注解项。
/// </summary>
public List<CommentItem> items { get { return m_Items; } set { m_Items = value; SetComponentDirty(); } }
/// <summary>
/// The text style of all comments.
/// ||所有组件的文本样式。
/// </summary>
public LabelStyle labelStyle
{
get { return m_LabelStyle; }
set { if (PropertyUtil.SetClass(ref m_LabelStyle, value)) SetComponentDirty(); }
}
/// <summary>
/// The text style of all comments.
/// ||所有组件的文本样式。
/// </summary>
public CommentMarkStyle markStyle
{
get { return m_MarkStyle; }
set { if (PropertyUtil.SetClass(ref m_MarkStyle, value)) SetVerticesDirty(); }
}
/// <summary>
/// Get the label style of comment item.
/// ||获取注解项的文本样式。
/// </summary>
/// <param name="index">the index of item</param>
/// <returns></returns>
public LabelStyle GetLabelStyle(int index)
{
if (index >= 0 && index < items.Count)
{
var labelStyle = items[index].labelStyle;
if (labelStyle.show) return labelStyle;
}
return m_LabelStyle;
}
/// <summary>
/// Get the mark style of comment item.
/// ||获取注解项的标记样式。
/// </summary>
/// <param name="index">the index of item</param>
/// <returns></returns>
public CommentMarkStyle GetMarkStyle(int index)
{
if (index >= 0 && index < items.Count)
{
var markStyle = items[index].markStyle;
if (markStyle.show) return markStyle;
}
return m_MarkStyle;
}
/// <summary>
/// Callback handling when parameters change.
/// ||参数变更时的回调处理。
/// </summary>
public void OnChanged()
{
foreach (var item in items)
{
item.location.OnChanged();
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ec99dd6b13a3b4e9789d007f23ffa499
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,79 @@
using UnityEngine;
using UnityEngine.UI;
using XUGL;
namespace XCharts.Runtime
{
[UnityEngine.Scripting.Preserve]
internal sealed class CommentHander : MainComponentHandler<Comment>
{
private static readonly string s_CommentObjectName = "comment";
public override void InitComponent()
{
var comment = component;
comment.OnChanged();
comment.painter = null;
comment.refreshComponent = delegate ()
{
var objName = ChartCached.GetComponentObjectName(comment);
var commentObj = ChartHelper.AddObject(objName,
chart.transform,
chart.chartMinAnchor,
chart.chartMaxAnchor,
chart.chartPivot,
chart.chartSizeDelta, -1, chart.childrenNodeNames);
var siblingIndex = comment.layer == CommentLayer.Upper
? chart.topPainter.transform.GetSiblingIndex() - 1
: chart.painter.transform.GetSiblingIndex() + 1;
commentObj.SetActive(comment.show);
commentObj.transform.SetSiblingIndex(siblingIndex);
commentObj.hideFlags = chart.chartHideFlags;
ChartHelper.HideAllObject(commentObj);
for (int i = 0; i < comment.items.Count; i++)
{
var item = comment.items[i];
var labelStyle = comment.GetLabelStyle(i);
item.location.OnChanged();
var labelPos = chart.chartPosition + item.location.GetPosition(chart.chartWidth, chart.chartHeight);
var label = ChartHelper.AddChartLabel(s_CommentObjectName + i, commentObj.transform, labelStyle, chart.theme.common,
GetContent(item), Color.clear, TextAnchor.MiddleCenter);
label.SetActive(comment.show && item.show, true);
label.SetPosition(labelPos + labelStyle.offset);
item.labelObject = label;
}
};
comment.refreshComponent();
}
private string GetContent(CommentItem item)
{
if (item.content.IndexOf("{") >= 0)
{
var content = item.content;
FormatterHelper.ReplaceContent(ref content, -1, item.labelStyle.numericFormatter, null, chart);
return content;
}
else
{
return item.content;
}
}
public override void DrawUpper(VertexHelper vh)
{
for (int i = 0; i < component.items.Count; i++)
{
var item = component.items[i];
var markStyle = component.GetMarkStyle(i);
if (markStyle == null || !markStyle.show) continue;
var color = ChartHelper.IsClearColor(markStyle.lineStyle.color) ?
chart.theme.axis.splitLineColor :
markStyle.lineStyle.color;
var width = markStyle.lineStyle.width == 0 ? 1 : markStyle.lineStyle.width;
UGL.DrawBorder(vh, item.markRect, width, color);
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 45362c4eed0e54d2880f2ed359ce9385
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,73 @@
using System;
using UnityEngine;
namespace XCharts.Runtime
{
/// <summary>
/// comment of chart.
/// ||注解项。
/// </summary>
[Serializable]
public class CommentItem : ChildComponent
{
[SerializeField] private bool m_Show = true;
[SerializeField] private string m_Content = "xcharts";
[SerializeField] private Rect m_MarkRect;
[SerializeField] private CommentMarkStyle m_MarkStyle = new CommentMarkStyle() { show = false };
[SerializeField] private LabelStyle m_LabelStyle = new LabelStyle() { show = false };
[SerializeField][Since("v3.5.0")] private Location m_Location = new Location() { align = Location.Align.BottomRight, right = 0.1f, bottom = 0.05f };
public ChartLabel labelObject { get; set; }
/// <summary>
/// Set this to false to prevent this comment item from showing.
/// ||是否显示当前注解项。
/// </summary>
public bool show { get { return m_Show; } set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); } }
/// <summary>
/// content of comment.
/// ||注解的文本内容。支持模板参数,可以参考Tooltip的itemFormatter。
/// </summary>
public string content
{
get { return m_Content; }
set
{
if (PropertyUtil.SetClass(ref m_Content, value))
{
if (labelObject != null) labelObject.SetText(value);
else SetComponentDirty();
}
}
}
/// <summary>
/// the mark rect of comment.
/// ||注解区域。
/// </summary>
public Rect markRect { get { return m_MarkRect; } set { if (PropertyUtil.SetStruct(ref m_MarkRect, value)) SetVerticesDirty(); } }
/// <summary>
/// the mark rect style.
/// ||注解标记区域样式。
/// </summary>
public CommentMarkStyle markStyle { get { return m_MarkStyle; } set { if (PropertyUtil.SetClass(ref m_MarkStyle, value)) SetVerticesDirty(); } }
/// <summary>
/// The text style of all comments.
/// ||注解项的文本样式。
/// </summary>
public LabelStyle labelStyle
{
get { return m_LabelStyle; }
set { if (PropertyUtil.SetClass(ref m_LabelStyle, value)) SetComponentDirty(); }
}
/// <summary>
/// The location of comment.
/// ||Comment显示的位置。
/// </summary>
public Location location
{
get { return m_Location; }
set { if (PropertyUtil.SetClass(ref m_Location, value)) SetComponentDirty(); }
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f082815b255e546019b6b43ac20bf4cb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,27 @@
using System;
using UnityEngine;
namespace XCharts.Runtime
{
/// <summary>
/// the comment mark style.
/// ||注解项区域样式。
/// </summary>
[Serializable]
public class CommentMarkStyle : ChildComponent
{
[SerializeField] private bool m_Show = true;
[SerializeField] private LineStyle m_LineStyle;
/// <summary>
/// Set this to false to prevent this comment item from showing.
/// ||是否显示当前注解项。
/// </summary>
public bool show { get { return m_Show; } set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); } }
/// <summary>
/// line style of comment mark area.
/// ||线条样式。
/// </summary>
public LineStyle lineStyle { get { return m_LineStyle; } set { if (PropertyUtil.SetClass(ref m_LineStyle, value)) SetVerticesDirty(); } }
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 764734b787d72455782bf75bb38e465e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: