diff --git a/Documentation~/zh/changelog.md b/Documentation~/zh/changelog.md index 5dd34e6a..d7717f40 100644 --- a/Documentation~/zh/changelog.md +++ b/Documentation~/zh/changelog.md @@ -80,6 +80,8 @@ slug: /changelog ## master +* (2026.02.26) 增加`Axis`的`mainAxis`参数设置主轴可控制柱图的朝向 (#331) +* (2026.02.03) 修复`UITable`的`viewport`在不同的锚点下可能会绘制异常的问题 * (2026.01.15) 修复`Pie`的点击有时候不响应的问题 (#357) * (2026.01.08) 增加`DataZoom`的`minZoomRatio`替换旧的`minShowNum` (#350) * (2025.11.05) 修复`Axis`的`indicatorLabel`无法隐藏的问题 diff --git a/Editor/MainComponents/AxisEditor.cs b/Editor/MainComponents/AxisEditor.cs index 37447578..68515cc6 100644 --- a/Editor/MainComponents/AxisEditor.cs +++ b/Editor/MainComponents/AxisEditor.cs @@ -102,10 +102,24 @@ namespace XCharts.Editor } [ComponentEditor(typeof(XAxis))] - public class XAxisEditor : AxisEditor { } + public class XAxisEditor : AxisEditor + { + protected override void DrawExtendeds() + { + base.DrawExtendeds(); + PropertyField("m_MainAxis"); + } + } [ComponentEditor(typeof(YAxis))] - public class YAxisEditor : AxisEditor { } + public class YAxisEditor : AxisEditor + { + protected override void DrawExtendeds() + { + base.DrawExtendeds(); + PropertyField("m_MainAxis"); + } + } [ComponentEditor(typeof(XAxis3D))] public class XAxis3DEditor : AxisEditor { } diff --git a/Runtime/Component/Axis/Axis.cs b/Runtime/Component/Axis/Axis.cs index 527e6917..1607b460 100644 --- a/Runtime/Component/Axis/Axis.cs +++ b/Runtime/Component/Axis/Axis.cs @@ -100,6 +100,7 @@ namespace XCharts.Runtime [SerializeField] private bool m_Clockwise = true; [SerializeField] private bool m_InsertDataToHead; [SerializeField][Since("v3.11.0")] private float m_MinCategorySpacing = 0; + [SerializeField][Since("v3.15.0")] private bool m_MainAxis = false; [SerializeField] protected List m_Icons = new List(); [SerializeField] protected List m_Data = new List(); [SerializeField] protected AxisLine m_AxisLine = AxisLine.defaultAxisLine; @@ -299,6 +300,17 @@ namespace XCharts.Runtime set { if (PropertyUtil.SetStruct(ref m_Clockwise, value)) SetAllDirty(); } } /// + /// Whether it is the main axis. When both X and Y axes are of the same type, the axis set to main axis will determine the orientation, + /// such as horizontal bar chart and vertical bar chart. + /// ||是否为主轴。当XY轴类型都相同时,设置为主轴的轴会决定朝向,如横向柱图和纵向柱图。 + /// + [Since("v3.15.0")] + public bool mainAxis + { + get { return m_MainAxis; } + set { if (PropertyUtil.SetStruct(ref m_MainAxis, value)) SetAllDirty(); } + } + /// /// Category data, available in type: 'Category' axis. /// ||类目数据,在类目轴(type: 'category')中有效。 /// diff --git a/Runtime/Internal/BaseChart.Component.cs b/Runtime/Internal/BaseChart.Component.cs index c4555cf2..fccccf9e 100644 --- a/Runtime/Internal/BaseChart.Component.cs +++ b/Runtime/Internal/BaseChart.Component.cs @@ -429,6 +429,19 @@ namespace XCharts.Runtime return true; } + public Axis GetMainAxis() + { + foreach (var component in m_Components) + { + if (component is Axis) + { + var axis = component as Axis; + if (axis.show && axis.mainAxis) return axis; + } + } + return null; + } + /// /// 纯类目轴。 /// @@ -483,7 +496,15 @@ namespace XCharts.Runtime relativedAxis = null; return false; } - var isY = yAxis.IsCategory() && !xAxis.IsCategory(); + bool isY; + if (xAxis.type == yAxis.type) + { + isY = yAxis.mainAxis; + } + else + { + isY = yAxis.IsCategory() && !xAxis.IsCategory(); + } if (isY) { axis = yAxis; diff --git a/Runtime/Internal/BaseChart.Custom.cs b/Runtime/Internal/BaseChart.Custom.cs index 675cc0fa..c0a4b671 100644 --- a/Runtime/Internal/BaseChart.Custom.cs +++ b/Runtime/Internal/BaseChart.Custom.cs @@ -11,33 +11,61 @@ namespace XCharts.Runtime public virtual void GetSeriesMinMaxValue(Axis axis, int axisIndex, out double tempMinValue, out double tempMaxValue) { var needAnimationData = !axis.context.needAnimation; + bool isX = false, isY = false, isZ = false; + tempMinValue = 0; + tempMaxValue = 0; if (axis is XAxis3D) - { - SeriesHelper.GetXMinMaxValue(this, axisIndex, axis.inverse, out tempMinValue, out tempMaxValue, false, false, needAnimationData); - } + isX = true; else if (axis is ZAxis3D) { - SeriesHelper.GetZMinMaxValue(this, axisIndex, axis.inverse, out tempMinValue, out tempMaxValue, false, false, needAnimationData); + isZ = true; } else if (axis is YAxis3D) { - SeriesHelper.GetYMinMaxValue(this, axisIndex, axis.inverse, out tempMinValue, out tempMaxValue, false, false, needAnimationData); + isY = true; } else if (IsAllAxisValue()) { - if (axis is XAxis) + var mainAxis = GetMainAxis(); + if (mainAxis == null) { - SeriesHelper.GetXMinMaxValue(this, axisIndex, axis.inverse, out tempMinValue, out tempMaxValue, false, false, needAnimationData); + if (axis is XAxis) + { + isX = true; + } + else + { + isY = true; + } } else { - SeriesHelper.GetYMinMaxValue(this, axisIndex, axis.inverse, out tempMinValue, out tempMaxValue, false, false, needAnimationData); + if (axis == mainAxis) + { + isX = true; + } + else + { + isY = true; + } } } else + { + isY = true; + } + if (isX) + { + SeriesHelper.GetXMinMaxValue(this, axisIndex, axis.inverse, out tempMinValue, out tempMaxValue, false, false, needAnimationData); + } + else if (isY) { SeriesHelper.GetYMinMaxValue(this, axisIndex, axis.inverse, out tempMinValue, out tempMaxValue, false, false, needAnimationData); } + else if(isZ) + { + SeriesHelper.GetZMinMaxValue(this, axisIndex, axis.inverse, out tempMinValue, out tempMaxValue, false, false, needAnimationData); + } AxisHelper.AdjustMinMaxValue(axis, ref tempMinValue, ref tempMaxValue, true); } }