mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-30 21:38:49 +00:00
增加Axis的mainAxis参数设置主轴可控制柱图的朝向 (#331)
This commit is contained in:
@@ -80,6 +80,8 @@ slug: /changelog
|
|||||||
|
|
||||||
## master
|
## master
|
||||||
|
|
||||||
|
* (2026.02.26) 增加`Axis`的`mainAxis`参数设置主轴可控制柱图的朝向 (#331)
|
||||||
|
* (2026.02.03) 修复`UITable`的`viewport`在不同的锚点下可能会绘制异常的问题
|
||||||
* (2026.01.15) 修复`Pie`的点击有时候不响应的问题 (#357)
|
* (2026.01.15) 修复`Pie`的点击有时候不响应的问题 (#357)
|
||||||
* (2026.01.08) 增加`DataZoom`的`minZoomRatio`替换旧的`minShowNum` (#350)
|
* (2026.01.08) 增加`DataZoom`的`minZoomRatio`替换旧的`minShowNum` (#350)
|
||||||
* (2025.11.05) 修复`Axis`的`indicatorLabel`无法隐藏的问题
|
* (2025.11.05) 修复`Axis`的`indicatorLabel`无法隐藏的问题
|
||||||
|
|||||||
@@ -102,10 +102,24 @@ namespace XCharts.Editor
|
|||||||
}
|
}
|
||||||
|
|
||||||
[ComponentEditor(typeof(XAxis))]
|
[ComponentEditor(typeof(XAxis))]
|
||||||
public class XAxisEditor : AxisEditor { }
|
public class XAxisEditor : AxisEditor
|
||||||
|
{
|
||||||
|
protected override void DrawExtendeds()
|
||||||
|
{
|
||||||
|
base.DrawExtendeds();
|
||||||
|
PropertyField("m_MainAxis");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[ComponentEditor(typeof(YAxis))]
|
[ComponentEditor(typeof(YAxis))]
|
||||||
public class YAxisEditor : AxisEditor { }
|
public class YAxisEditor : AxisEditor
|
||||||
|
{
|
||||||
|
protected override void DrawExtendeds()
|
||||||
|
{
|
||||||
|
base.DrawExtendeds();
|
||||||
|
PropertyField("m_MainAxis");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[ComponentEditor(typeof(XAxis3D))]
|
[ComponentEditor(typeof(XAxis3D))]
|
||||||
public class XAxis3DEditor : AxisEditor { }
|
public class XAxis3DEditor : AxisEditor { }
|
||||||
|
|||||||
@@ -100,6 +100,7 @@ namespace XCharts.Runtime
|
|||||||
[SerializeField] private bool m_Clockwise = true;
|
[SerializeField] private bool m_Clockwise = true;
|
||||||
[SerializeField] private bool m_InsertDataToHead;
|
[SerializeField] private bool m_InsertDataToHead;
|
||||||
[SerializeField][Since("v3.11.0")] private float m_MinCategorySpacing = 0;
|
[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<Sprite> m_Icons = new List<Sprite>();
|
||||||
[SerializeField] protected List<string> m_Data = new List<string>();
|
[SerializeField] protected List<string> m_Data = new List<string>();
|
||||||
[SerializeField] protected AxisLine m_AxisLine = AxisLine.defaultAxisLine;
|
[SerializeField] protected AxisLine m_AxisLine = AxisLine.defaultAxisLine;
|
||||||
@@ -299,6 +300,17 @@ namespace XCharts.Runtime
|
|||||||
set { if (PropertyUtil.SetStruct(ref m_Clockwise, value)) SetAllDirty(); }
|
set { if (PropertyUtil.SetStruct(ref m_Clockwise, value)) SetAllDirty(); }
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <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.
|
/// Category data, available in type: 'Category' axis.
|
||||||
/// ||类目数据,在类目轴(type: 'category')中有效。
|
/// ||类目数据,在类目轴(type: 'category')中有效。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -429,6 +429,19 @@ namespace XCharts.Runtime
|
|||||||
return true;
|
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>
|
||||||
/// 纯类目轴。
|
/// 纯类目轴。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -483,7 +496,15 @@ namespace XCharts.Runtime
|
|||||||
relativedAxis = null;
|
relativedAxis = null;
|
||||||
return false;
|
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)
|
if (isY)
|
||||||
{
|
{
|
||||||
axis = yAxis;
|
axis = yAxis;
|
||||||
|
|||||||
@@ -11,33 +11,61 @@ namespace XCharts.Runtime
|
|||||||
public virtual void GetSeriesMinMaxValue(Axis axis, int axisIndex, out double tempMinValue, out double tempMaxValue)
|
public virtual void GetSeriesMinMaxValue(Axis axis, int axisIndex, out double tempMinValue, out double tempMaxValue)
|
||||||
{
|
{
|
||||||
var needAnimationData = !axis.context.needAnimation;
|
var needAnimationData = !axis.context.needAnimation;
|
||||||
|
bool isX = false, isY = false, isZ = false;
|
||||||
|
tempMinValue = 0;
|
||||||
|
tempMaxValue = 0;
|
||||||
if (axis is XAxis3D)
|
if (axis is XAxis3D)
|
||||||
{
|
isX = true;
|
||||||
SeriesHelper.GetXMinMaxValue(this, axisIndex, axis.inverse, out tempMinValue, out tempMaxValue, false, false, needAnimationData);
|
|
||||||
}
|
|
||||||
else if (axis is ZAxis3D)
|
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)
|
else if (axis is YAxis3D)
|
||||||
{
|
{
|
||||||
SeriesHelper.GetYMinMaxValue(this, axisIndex, axis.inverse, out tempMinValue, out tempMaxValue, false, false, needAnimationData);
|
isY = true;
|
||||||
}
|
}
|
||||||
else if (IsAllAxisValue())
|
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
|
else
|
||||||
{
|
{
|
||||||
SeriesHelper.GetYMinMaxValue(this, axisIndex, axis.inverse, out tempMinValue, out tempMaxValue, false, false, needAnimationData);
|
if (axis == mainAxis)
|
||||||
|
{
|
||||||
|
isX = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
isY = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
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);
|
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);
|
AxisHelper.AdjustMinMaxValue(axis, ref tempMinValue, ref tempMaxValue, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user