diff --git a/Documentation~/zh/changelog.md b/Documentation~/zh/changelog.md index 01eb2346..3f4658a4 100644 --- a/Documentation~/zh/changelog.md +++ b/Documentation~/zh/changelog.md @@ -80,6 +80,8 @@ slug: /changelog ## master +* (2025.03.22) 增加`Comment`的`layer`设置层级 +* (2025.03.21) 优化`Comment`的坐标刷新 * (2025.03.19) 增加`Serie`的`Label`的`formatter`支持`{index}`通配符 * (2025.03.18) 增加`Bar`可添加`TitleStyle`组件支持 * (2025.03.18) 增加`LabelStyle`的`fixedX`和`fixedY`可固定label的坐标 diff --git a/Editor/MainComponents/CommentEditor.cs b/Editor/MainComponents/CommentEditor.cs index 922e44a4..f84aab98 100644 --- a/Editor/MainComponents/CommentEditor.cs +++ b/Editor/MainComponents/CommentEditor.cs @@ -9,6 +9,7 @@ namespace XCharts.Editor public override void OnInspectorGUI() { ++EditorGUI.indentLevel; + PropertyField("m_Layer"); PropertyField("m_LabelStyle"); //PropertyField("m_MarkStyle"); PropertyListField("m_Items", true); diff --git a/Runtime/Component/Comment/Comment.cs b/Runtime/Component/Comment/Comment.cs index dffabb57..7053353d 100644 --- a/Runtime/Component/Comment/Comment.cs +++ b/Runtime/Component/Comment/Comment.cs @@ -5,14 +5,33 @@ using UnityEngine; namespace XCharts.Runtime { /// - /// comment of chart. - /// ||图表注解组件。 + /// The layer of comment. + /// ||注解的显示层级。 + /// + [Since("v3.15.0")] + public enum CommentLayer + { + /// + /// The comment is display under the serie. + /// ||注解在系列下方。 + /// + Lower, + /// + /// The comment is display above the serie. + /// ||注解在系列上方。 + /// + Upper + } + /// + /// comment of chart. Used to annotate special information in the chart. + /// ||图表注解组件。用于标注图表中的特殊信息。 /// [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 m_Items = new List() { new CommentItem() }; @@ -23,6 +42,11 @@ namespace XCharts.Runtime /// public bool show { get { return m_Show; } set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); } } /// + /// The layer of comment. + /// ||注解的显示层级。 + /// + public CommentLayer layer { get { return m_Layer; } set { if (PropertyUtil.SetStruct(ref m_Layer, value)) SetComponentDirty(); } } + /// /// The items of comment. /// ||注解项。每个注解组件可以设置多个注解项。 /// @@ -45,7 +69,12 @@ namespace XCharts.Runtime get { return m_MarkStyle; } set { if (PropertyUtil.SetClass(ref m_MarkStyle, value)) SetVerticesDirty(); } } - + /// + /// Get the label style of comment item. + /// ||获取注解项的文本样式。 + /// + /// the index of item + /// public LabelStyle GetLabelStyle(int index) { if (index >= 0 && index < items.Count) @@ -55,7 +84,12 @@ namespace XCharts.Runtime } return m_LabelStyle; } - + /// + /// Get the mark style of comment item. + /// ||获取注解项的标记样式。 + /// + /// the index of item + /// public CommentMarkStyle GetMarkStyle(int index) { if (index >= 0 && index < items.Count) diff --git a/Runtime/Component/Comment/CommentHander.cs b/Runtime/Component/Comment/CommentHander.cs index ca49cbaa..82d9abc2 100644 --- a/Runtime/Component/Comment/CommentHander.cs +++ b/Runtime/Component/Comment/CommentHander.cs @@ -23,8 +23,12 @@ namespace XCharts.Runtime 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++) diff --git a/Runtime/Component/Comment/CommentItem.cs b/Runtime/Component/Comment/CommentItem.cs index 10363288..7ff933f6 100644 --- a/Runtime/Component/Comment/CommentItem.cs +++ b/Runtime/Component/Comment/CommentItem.cs @@ -11,11 +11,11 @@ namespace XCharts.Runtime public class CommentItem : ChildComponent { [SerializeField] private bool m_Show = true; - [SerializeField] private string m_Content = "comment"; + [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.TopLeft, top = 0.125f }; + [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; } diff --git a/Runtime/Internal/BaseChart.API.cs b/Runtime/Internal/BaseChart.API.cs index 7c744a2c..63cce895 100644 --- a/Runtime/Internal/BaseChart.API.cs +++ b/Runtime/Internal/BaseChart.API.cs @@ -69,6 +69,7 @@ namespace XCharts.Runtime /// public Vector3 chartPosition { get { return m_ChartPosition; } } public Rect chartRect { get { return m_ChartRect; } } + public Painter topPainter { get { return m_PainterTop; } } /// /// The callback function of chart init. /// ||图表的初始化完成回调。