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)