diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f259304..3ac895e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,6 +54,7 @@ ## master +* (2022.07.05) 增加`AxisName`的`onZero`参数支持设置坐标轴名称位置是否和Y轴0刻度一致 (#207) * (2022.07.02) 修复`PieChart`用代码动态创建时`Legend`不正常的问题 (#206) * (2022.07.02) 修复`YAxis`的`AxisLabel`设置`onZero`不生效的问题 * (2022.07.02) 修复`AxisLabel`代码设置`distance`属性后一直刷新的问题 diff --git a/Editor/MainComponents/AxisEditor.cs b/Editor/MainComponents/AxisEditor.cs index 652d0d39..47868ac1 100644 --- a/Editor/MainComponents/AxisEditor.cs +++ b/Editor/MainComponents/AxisEditor.cs @@ -181,6 +181,7 @@ namespace XCharts.Editor { ++EditorGUI.indentLevel; PropertyField(prop, "m_Name"); + PropertyField(prop, "m_OnZero"); PropertyField(prop, "m_LabelStyle"); --EditorGUI.indentLevel; } diff --git a/Runtime/Component/Axis/AxisHandler.cs b/Runtime/Component/Axis/AxisHandler.cs index 60ea3238..cfa52484 100644 --- a/Runtime/Component/Axis/AxisHandler.cs +++ b/Runtime/Component/Axis/AxisHandler.cs @@ -424,7 +424,8 @@ namespace XCharts var autoColor = axis.axisLine.GetColor(chart.theme.axis.lineColor); if (orient == Orient.Horizonal) { - var posY = GetAxisLineXOrY() + offset.y; + var grid = chart.GetChartComponent(axis.gridIndex); + var posY = !axis.axisName.onZero && grid != null? grid.context.y : GetAxisLineXOrY() + offset.y; switch (axis.axisName.labelStyle.position) { case LabelStyle.Position.Start: @@ -460,7 +461,8 @@ namespace XCharts } else { - var posX = GetAxisLineXOrY() + offset.x; + var grid = chart.GetChartComponent(axis.gridIndex); + var posX = !axis.axisName.onZero && grid != null? grid.context.x : GetAxisLineXOrY() + offset.x; switch (axis.axisName.labelStyle.position) { case LabelStyle.Position.Start: diff --git a/Runtime/Component/Axis/AxisName.cs b/Runtime/Component/Axis/AxisName.cs index 412df3f9..4c5cf54b 100644 --- a/Runtime/Component/Axis/AxisName.cs +++ b/Runtime/Component/Axis/AxisName.cs @@ -12,11 +12,12 @@ namespace XCharts.Runtime { [SerializeField] private bool m_Show; [SerializeField] private string m_Name; + [SerializeField][Since("v3.1.0")] private bool m_OnZero; [SerializeField] private LabelStyle m_LabelStyle = new LabelStyle(); /// /// Whether to show axis name. - /// |是否显示坐标名称。 + /// |是否显示坐标轴名称。 /// public bool show { @@ -33,6 +34,15 @@ namespace XCharts.Runtime set { if (PropertyUtil.SetClass(ref m_Name, value)) SetComponentDirty(); } } /// + /// Whether the axis name position are the same with 0 position of YAxis. + /// |坐标轴名称的位置是否保持和Y轴0刻度一致。 + /// + public bool onZero + { + get { return m_OnZero; } + set { if (PropertyUtil.SetStruct(ref m_OnZero, value)) SetComponentDirty(); } + } + /// /// The text style of axis name. /// |文本样式。 ///