增加AxisLinestartExtendLengthendExtendLength设置轴线的延长线

This commit is contained in:
monitor1394
2025-09-01 23:05:49 +08:00
parent d1f424f3a1
commit dd473b7d29
4 changed files with 29 additions and 4 deletions

View File

@@ -80,6 +80,7 @@ slug: /changelog
## master ## master
* (2025.09.01) 增加`AxisLine``startExtendLength``endExtendLength`设置轴线的延长线
* (2025.08.27) 修复`Serie``TitleStyle`在数据变更时不及时刷新的问题 * (2025.08.27) 修复`Serie``TitleStyle`在数据变更时不及时刷新的问题
* (2025.05.19) 修复`TMP`开启时`Axis`运行报错 * (2025.05.19) 修复`TMP`开启时`Axis`运行报错
* (2025.04.25) 修复`MarkArea`指定`yValue``xValue`时绘制区域不准确的问题 * (2025.04.25) 修复`MarkArea`指定`yValue``xValue`时绘制区域不准确的问题

View File

@@ -29,6 +29,8 @@ namespace XCharts.Editor
{ {
base.DrawExtendeds(prop); base.DrawExtendeds(prop);
PropertyField(prop, "m_OnZero"); PropertyField(prop, "m_OnZero");
PropertyField(prop, "m_StartExtendLength");
PropertyField(prop, "m_EndExtendLength");
PropertyField(prop, "m_ShowArrow"); PropertyField(prop, "m_ShowArrow");
PropertyField(prop, "m_Arrow"); PropertyField(prop, "m_Arrow");
} }

View File

@@ -832,17 +832,19 @@ namespace XCharts
var lineWidth = axis.axisLine.GetWidth(theme.lineWidth); var lineWidth = axis.axisLine.GetWidth(theme.lineWidth);
var lineType = axis.axisLine.GetType(theme.lineType); var lineType = axis.axisLine.GetType(theme.lineType);
var lineColor = axis.axisLine.GetColor(theme.lineColor); var lineColor = axis.axisLine.GetColor(theme.lineColor);
var sExtendLength = axis.axisLine.startExtendLength;
var eExtendLength = axis.axisLine.endExtendLength;
if (orient == Orient.Horizonal) if (orient == Orient.Horizonal)
{ {
var left = new Vector3(startX - lineWidth - (inverse ? offset : 0), startY); var left = new Vector3(startX - lineWidth - (inverse ? offset : 0) - sExtendLength, startY);
var right = new Vector3(startX + axisLength + lineWidth + (!inverse ? offset : 0), startY); var right = new Vector3(startX + axisLength + lineWidth + (!inverse ? offset : 0) + eExtendLength, startY);
ChartDrawer.DrawLineStyle(vh, lineType, lineWidth, left, right, lineColor); ChartDrawer.DrawLineStyle(vh, lineType, lineWidth, left, right, lineColor);
} }
else else
{ {
var bottom = new Vector3(startX, startY - lineWidth - (inverse ? offset : 0)); var bottom = new Vector3(startX, startY - lineWidth - (inverse ? offset : 0) - sExtendLength);
var top = new Vector3(startX, startY + axisLength + lineWidth + (!inverse ? offset : 0)); var top = new Vector3(startX, startY + axisLength + lineWidth + (!inverse ? offset : 0) + eExtendLength);
ChartDrawer.DrawLineStyle(vh, lineType, lineWidth, bottom, top, lineColor); ChartDrawer.DrawLineStyle(vh, lineType, lineWidth, bottom, top, lineColor);
} }
} }

View File

@@ -10,6 +10,8 @@ namespace XCharts.Runtime
public class AxisLine : BaseLine public class AxisLine : BaseLine
{ {
[SerializeField] private bool m_OnZero; [SerializeField] private bool m_OnZero;
[SerializeField] private float m_StartExtendLength;
[SerializeField] private float m_EndExtendLength;
[SerializeField] private bool m_ShowArrow; [SerializeField] private bool m_ShowArrow;
[SerializeField] private ArrowStyle m_Arrow = new ArrowStyle(); [SerializeField] private ArrowStyle m_Arrow = new ArrowStyle();
@@ -23,6 +25,24 @@ namespace XCharts.Runtime
set { if (PropertyUtil.SetStruct(ref m_OnZero, value)) SetVerticesDirty(); } set { if (PropertyUtil.SetStruct(ref m_OnZero, value)) SetVerticesDirty(); }
} }
/// <summary> /// <summary>
/// Extend length of the axis line at the start.
/// ||轴线起点延长线长度。
/// </summary>
public float startExtendLength
{
get { return m_StartExtendLength; }
set { if (PropertyUtil.SetStruct(ref m_StartExtendLength, value)) SetVerticesDirty(); }
}
/// <summary>
/// Extend length of the axis line at the end.
/// ||轴线终点延长线长度。
/// </summary>
public float endExtendLength
{
get { return m_EndExtendLength; }
set { if (PropertyUtil.SetStruct(ref m_EndExtendLength, value)) SetVerticesDirty(); }
}
/// <summary>
/// Whether to show the arrow symbol of axis. /// Whether to show the arrow symbol of axis.
/// ||是否显示箭头。 /// ||是否显示箭头。
/// </summary> /// </summary>