From 47caaa2113dcd102377b713537da5c4d88777815 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Tue, 18 Mar 2025 07:41:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0`LabelStyle`=E7=9A=84`fixedX`?= =?UTF-8?q?=E5=92=8C`fixedY`=E5=8F=AF=E5=9B=BA=E5=AE=9Alabel=E7=9A=84?= =?UTF-8?q?=E5=9D=90=E6=A0=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Documentation~/zh/changelog.md | 3 +++ Editor/ChildComponents/LabelStyleDrawer.cs | 2 ++ Runtime/Component/Axis/AxisHelper.cs | 7 ++++--- Runtime/Component/Label/LabelStyle.cs | 24 ++++++++++++++++++++++ Runtime/Serie/SerieHandler.cs | 2 ++ 5 files changed, 35 insertions(+), 3 deletions(-) diff --git a/Documentation~/zh/changelog.md b/Documentation~/zh/changelog.md index 10313dce..18d8d109 100644 --- a/Documentation~/zh/changelog.md +++ b/Documentation~/zh/changelog.md @@ -80,6 +80,9 @@ slug: /changelog ## master +* (2025.03.18) 增加`LabelStyle`的`fixedX`和`fixedY`可固定label的坐标 +* (2025.03.17) 增加`ItemStyle`的`backgroundGap`可设置数据项背景间隙 + ## v3.14.0 版本要点: diff --git a/Editor/ChildComponents/LabelStyleDrawer.cs b/Editor/ChildComponents/LabelStyleDrawer.cs index 359da59d..a6b760f3 100644 --- a/Editor/ChildComponents/LabelStyleDrawer.cs +++ b/Editor/ChildComponents/LabelStyleDrawer.cs @@ -24,6 +24,8 @@ namespace XCharts.Editor PropertyField(prop, "m_Rotate"); PropertyField(prop, "m_Width"); PropertyField(prop, "m_Height"); + PropertyField(prop, "m_FixedX"); + PropertyField(prop, "m_FixedY"); PropertyField(prop, "m_Icon"); PropertyField(prop, "m_Background"); PropertyField(prop, "m_TextStyle"); diff --git a/Runtime/Component/Axis/AxisHelper.cs b/Runtime/Component/Axis/AxisHelper.cs index 03fe5fdb..6131828a 100644 --- a/Runtime/Component/Axis/AxisHelper.cs +++ b/Runtime/Component/Axis/AxisHelper.cs @@ -536,9 +536,9 @@ namespace XCharts.Runtime /// /// /// - public static float GetAxisValueLength(GridCoord grid, Axis axis, float scaleWidth, double value) + public static float GetAxisValueLength(GridCoord grid, Axis axis, float scaleWidth, double value, float gap = 0) { - return GetAxisPositionInternal(grid, axis, scaleWidth, value, false, true); + return GetAxisPositionInternal(grid, axis, scaleWidth, value, false, true, gap); } /// @@ -572,10 +572,11 @@ namespace XCharts.Runtime } } - private static float GetAxisPositionInternal(GridCoord grid, Axis axis, float scaleWidth, double value, bool includeGridXY, bool realLength) + private static float GetAxisPositionInternal(GridCoord grid, Axis axis, float scaleWidth, double value, bool includeGridXY, bool realLength, float gap = 0) { var isY = axis is YAxis; var gridHeight = isY ? grid.context.height : grid.context.width; + gridHeight -= gap; var gridXY = isY ? grid.context.y : grid.context.x; if (axis.IsLog()) diff --git a/Runtime/Component/Label/LabelStyle.cs b/Runtime/Component/Label/LabelStyle.cs index d6ed4875..247f7a2f 100644 --- a/Runtime/Component/Label/LabelStyle.cs +++ b/Runtime/Component/Label/LabelStyle.cs @@ -80,6 +80,8 @@ namespace XCharts.Runtime [SerializeField] protected string m_NumericFormatter = ""; [SerializeField] protected float m_Width = 0; [SerializeField] protected float m_Height = 0; + [SerializeField][Since("v3.15.0")] protected float m_FixedX = 0; + [SerializeField][Since("v3.15.0")] protected float m_FixedY = 0; [SerializeField] protected IconStyle m_Icon = new IconStyle(); [SerializeField] protected ImageStyle m_Background = new ImageStyle(); @@ -288,6 +290,24 @@ namespace XCharts.Runtime set { if (PropertyUtil.SetStruct(ref m_AutoOffset, value)) SetAllDirty(); } } /// + /// the fixed x of label. When not 0, it will be fixed on the specified x value. + /// ||固定的X值。不为0时,会固定在指定的X值上。 + /// + public float fixedX + { + get { return m_FixedX; } + set { if (PropertyUtil.SetStruct(ref m_FixedX, value)) SetComponentDirty(); } + } + /// + /// the fixed y of label. When not 0, it will be fixed on the specified y value. + /// ||固定的Y值。不为0时,会固定在指定的Y值上。 + /// + public float fixedY + { + get { return m_FixedY; } + set { if (PropertyUtil.SetStruct(ref m_FixedY, value)) SetComponentDirty(); } + } + /// /// the sytle of background. /// ||背景图样式。 /// @@ -375,6 +395,8 @@ namespace XCharts.Runtime label.m_Height = m_Height; label.m_NumericFormatter = m_NumericFormatter; label.m_AutoOffset = m_AutoOffset; + label.m_FixedX = m_FixedX; + label.m_FixedY = m_FixedY; label.m_Icon.Copy(m_Icon); label.m_Background.Copy(m_Background); label.m_TextPadding = m_TextPadding; @@ -394,6 +416,8 @@ namespace XCharts.Runtime m_Height = label.m_Height; m_NumericFormatter = label.m_NumericFormatter; m_AutoOffset = label.m_AutoOffset; + m_FixedX = label.m_FixedX; + m_FixedY = label.m_FixedY; m_Icon.Copy(label.m_Icon); m_Background.Copy(label.m_Background); m_TextPadding = label.m_TextPadding; diff --git a/Runtime/Serie/SerieHandler.cs b/Runtime/Serie/SerieHandler.cs index 4d65f8fe..4d48299b 100644 --- a/Runtime/Serie/SerieHandler.cs +++ b/Runtime/Serie/SerieHandler.cs @@ -610,6 +610,8 @@ namespace XCharts.Runtime protected Vector3 UpdateLabelPosition(SerieData serieData, LabelStyle currLabel) { var labelPosition = GetSerieDataLabelPosition(serieData, currLabel); + if(currLabel.fixedX != 0) labelPosition.x = currLabel.fixedX; + if(currLabel.fixedY != 0) labelPosition.y = currLabel.fixedY; var offset = GetSerieDataLabelOffset(serieData, currLabel); serieData.labelObject.SetPosition(labelPosition + offset); if (currLabel.autoRotate && serieData.context.angle != 0)