From 16d055abc0a1ff622ac9b35f6ddbb286a745ee6d Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Tue, 6 Sep 2022 22:54:40 +0800 Subject: [PATCH] [feature][axis] add `showStartLine` and `showEndLine` for AxisSplitLine --- CHANGELOG.md | 1 + Documentation/XChartsConfiguration-EN.md | 2 ++ Documentation/XChartsConfiguration-ZH.md | 2 ++ Editor/ChildComponents/LineDrawer.cs | 2 ++ Runtime/Component/Axis/AxisHandler.cs | 6 ++-- Runtime/Component/Axis/AxisSplitLine.cs | 32 ++++++++++++++++++-- Runtime/Component/Radar/RadarCoordHandler.cs | 2 +- 7 files changed, 41 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6567d579..0fce9944 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,6 +58,7 @@ ## master +* (2022.09.06) 增加`AxisSplitLine`的`showStartLine`和`showEndLine`参数 * (2022.09.06) 增加`Heatmap`通过`symbol`设置不同的图案的支持 * (2022.09.05) 增加`Heatmap`的`heatmapType`支持设置`Data`和`Count`两种不同映射方式的热力图 * (2022.09.05) 优化`Tooltip`在热力图为数值轴时的指示 diff --git a/Documentation/XChartsConfiguration-EN.md b/Documentation/XChartsConfiguration-EN.md index abfef096..ab523e2d 100644 --- a/Documentation/XChartsConfiguration-EN.md +++ b/Documentation/XChartsConfiguration-EN.md @@ -357,6 +357,8 @@ Split line of axis in grid area. |`interval`|||Interval of Axis splitLine. |`distance`|||The distance between the split line and axis line. |`autoColor`|||auto color. +|`showStartLine`|true|v3.3.0|Whether to show the first split line. +|`showEndLine`|true|v3.3.0|Whether to show the last split line. ## `AxisTheme` diff --git a/Documentation/XChartsConfiguration-ZH.md b/Documentation/XChartsConfiguration-ZH.md index f0c24a82..7fe54734 100644 --- a/Documentation/XChartsConfiguration-ZH.md +++ b/Documentation/XChartsConfiguration-ZH.md @@ -357,6 +357,8 @@ Inherits or Implemented: [BaseLine](#BaseLine) |`interval`|||坐标轴分隔线的显示间隔。 |`distance`|||刻度线与轴线的距离。 |`autoColor`|||自动设置颜色。 +|`showStartLine`|true|v3.3.0|是否显示第一条分割线。 +|`showEndLine`|true|v3.3.0|是否显示最后一条分割线。 ## `AxisTheme` diff --git a/Editor/ChildComponents/LineDrawer.cs b/Editor/ChildComponents/LineDrawer.cs index 002d520c..f3519bb1 100644 --- a/Editor/ChildComponents/LineDrawer.cs +++ b/Editor/ChildComponents/LineDrawer.cs @@ -44,6 +44,8 @@ namespace XCharts.Editor PropertyField(prop, "m_Interval"); PropertyField(prop, "m_Distance"); PropertyField(prop, "m_AutoColor"); + PropertyField(prop, "m_ShowStartLine"); + PropertyField(prop, "m_ShowEndLine"); } } diff --git a/Runtime/Component/Axis/AxisHandler.cs b/Runtime/Component/Axis/AxisHandler.cs index 0a86e596..47fc3c5e 100644 --- a/Runtime/Component/Axis/AxisHandler.cs +++ b/Runtime/Component/Axis/AxisHandler.cs @@ -817,11 +817,11 @@ namespace XCharts } if (axis.splitLine.show) { - if (axis.splitLine.NeedShow(i)) + if (axis.splitLine.NeedShow(i, size)) { if (orient == Orient.Horizonal) { - if (relativedAxis == null || !MathUtil.Approximately(current, relativedAxis.context.x)) + if (relativedAxis == null || !relativedAxis.axisLine.show || !MathUtil.Approximately(current, relativedAxis.context.x)) { ChartDrawer.DrawLineStyle(vh, lineType, @@ -885,7 +885,7 @@ namespace XCharts } else { - if (relativedAxis == null || !MathUtil.Approximately(current, relativedAxis.context.y)) + if (relativedAxis == null || !relativedAxis.axisLine.show || !MathUtil.Approximately(current, relativedAxis.context.y)) { ChartDrawer.DrawLineStyle(vh, lineType, diff --git a/Runtime/Component/Axis/AxisSplitLine.cs b/Runtime/Component/Axis/AxisSplitLine.cs index 8e345272..a9785e3c 100644 --- a/Runtime/Component/Axis/AxisSplitLine.cs +++ b/Runtime/Component/Axis/AxisSplitLine.cs @@ -13,6 +13,8 @@ namespace XCharts.Runtime [SerializeField] private int m_Interval; [SerializeField] private float m_Distance; [SerializeField] private bool m_AutoColor; + [SerializeField][Since("v3.3.0")] private bool m_ShowStartLine = true; + [SerializeField][Since("v3.3.0")] private bool m_ShowEndLine = true; /// /// The distance between the split line and axis line. @@ -33,6 +35,24 @@ namespace XCharts.Runtime get { return m_Interval; } set { if (PropertyUtil.SetStruct(ref m_Interval, value)) SetVerticesDirty(); } } + /// + /// Whether to show the first split line. + /// |是否显示第一条分割线。 + /// + public bool showStartLine + { + get { return m_ShowStartLine; } + set { if (PropertyUtil.SetStruct(ref m_ShowStartLine, value)) SetVerticesDirty(); } + } + /// + /// Whether to show the last split line. + /// |是否显示最后一条分割线。 + /// + public bool showEndLine + { + get { return m_ShowEndLine; } + set { if (PropertyUtil.SetStruct(ref m_ShowEndLine, value)) SetVerticesDirty(); } + } public override bool vertsDirty { get { return m_VertsDirty || m_LineStyle.anyDirty; } } public override void ClearVerticesDirty() @@ -56,6 +76,8 @@ namespace XCharts.Runtime var axisSplitLine = new AxisSplitLine(); axisSplitLine.show = show; axisSplitLine.interval = interval; + axisSplitLine.showStartLine = showStartLine; + axisSplitLine.showEndLine = showEndLine; axisSplitLine.lineStyle = lineStyle.Clone(); return axisSplitLine; } @@ -64,11 +86,17 @@ namespace XCharts.Runtime { base.Copy(splitLine); interval = splitLine.interval; + showStartLine = splitLine.showStartLine; + showEndLine = splitLine.showEndLine; } - internal bool NeedShow(int index) + internal bool NeedShow(int index, int total) { - return show && (interval == 0 || index % (interval + 1) == 0); + if (!show) return false; + if (interval != 0 && index % (interval + 1) != 0) return false; + if (!showStartLine && index == 0) return false; + if (!showEndLine && index == total - 1) return false; + return true; } } } \ No newline at end of file diff --git a/Runtime/Component/Radar/RadarCoordHandler.cs b/Runtime/Component/Radar/RadarCoordHandler.cs index 18adea9b..3ffdf003 100644 --- a/Runtime/Component/Radar/RadarCoordHandler.cs +++ b/Runtime/Component/Radar/RadarCoordHandler.cs @@ -147,7 +147,7 @@ namespace XCharts.Runtime { UGL.DrawQuadrilateral(vh, p1, p2, p3, p4, color); } - if (radar.splitLine.NeedShow(i)) + if (radar.splitLine.NeedShow(i, radar.splitNumber)) { ChartDrawer.DrawLineStyle(vh, splitLineType, splitLineWidth, p2, p3, splitLineColor); }