增加AxismainAxis参数设置主轴可控制柱图的朝向 (#331)

This commit is contained in:
monitor1394
2026-02-26 08:47:51 +08:00
parent 90e9187808
commit 92abee1a6c
5 changed files with 88 additions and 11 deletions

View File

@@ -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`无法隐藏的问题

View File

@@ -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 { }

View File

@@ -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<Sprite> m_Icons = new List<Sprite>();
[SerializeField] protected List<string> m_Data = new List<string>();
[SerializeField] protected AxisLine m_AxisLine = AxisLine.defaultAxisLine;
@@ -299,6 +300,17 @@ namespace XCharts.Runtime
set { if (PropertyUtil.SetStruct(ref m_Clockwise, value)) SetAllDirty(); }
}
/// <summary>
/// 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轴类型都相同时设置为主轴的轴会决定朝向如横向柱图和纵向柱图。
/// </summary>
[Since("v3.15.0")]
public bool mainAxis
{
get { return m_MainAxis; }
set { if (PropertyUtil.SetStruct(ref m_MainAxis, value)) SetAllDirty(); }
}
/// <summary>
/// Category data, available in type: 'Category' axis.
/// ||类目数据在类目轴type: 'category')中有效。
/// </summary>

View File

@@ -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;
}
/// <summary>
/// 纯类目轴。
/// </summary>
@@ -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;

View File

@@ -11,32 +11,60 @@ 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())
{
var mainAxis = GetMainAxis();
if (mainAxis == null)
{
if (axis is XAxis)
{
isX = true;
}
else
{
isY = true;
}
}
else
{
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
else if (isY)
{
SeriesHelper.GetYMinMaxValue(this, axisIndex, axis.inverse, out tempMinValue, out tempMaxValue, false, false, needAnimationData);
}
}
else
else if(isZ)
{
SeriesHelper.GetYMinMaxValue(this, axisIndex, axis.inverse, out tempMinValue, out tempMaxValue, false, false, needAnimationData);
SeriesHelper.GetZMinMaxValue(this, axisIndex, axis.inverse, out tempMinValue, out tempMaxValue, false, false, needAnimationData);
}
AxisHelper.AdjustMinMaxValue(axis, ref tempMinValue, ref tempMaxValue, true);
}