From 4bf5d916d211f642d2a5b61d467977cf65d6732a Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Wed, 14 Apr 2021 08:59:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=A4=9A=E5=9D=90=E6=A0=87?= =?UTF-8?q?=E8=BD=B4=E7=9A=84=E6=94=AF=E6=8C=81=20#132?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG-EN.md | 3 ++ CHANGELOG.md | 3 ++ Documentation/XCharts配置项手册.md | 2 ++ Documentation/xcharts-configuration-EN.md | 2 ++ Editor/PropertyDrawers/LineDrawer.cs | 2 ++ Runtime/Component/Sub/AxisTick.cs | 26 +++++++++++++++ Runtime/Internal/CoordinateChart.cs | 40 ++++++++++++++++------- 7 files changed, 66 insertions(+), 12 deletions(-) diff --git a/CHANGELOG-EN.md b/CHANGELOG-EN.md index 3c24566c..70c3c341 100644 --- a/CHANGELOG-EN.md +++ b/CHANGELOG-EN.md @@ -34,6 +34,9 @@ ## Latest +* (2021.04.13) Add the `ShowStarttick` and '`ShowEndTick` parameters of 'AxisTick' to control whether the first and last ticks are displayed +* (2021.04.13) Improved multi-axis support #132 + ## v2.1.1 * (2021.04.13) Define the code and clear `Warning` diff --git a/CHANGELOG.md b/CHANGELOG.md index 132ea69f..393c9b88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,9 @@ ## Latest +* (2021.04.13) 增加`AxisTick`的`ShowStartTick`和`ShowEndTick`参数控制第一个和最后一个刻度是否显示 +* (2021.04.13) 完善多坐标轴的支持 #132 + ## v2.1.1 * (2021.04.13) 整理代码,清除`Warning` diff --git a/Documentation/XCharts配置项手册.md b/Documentation/XCharts配置项手册.md index 1ec65948..7980cd9c 100644 --- a/Documentation/XCharts配置项手册.md +++ b/Documentation/XCharts配置项手册.md @@ -879,6 +879,8 @@ K线图系列。 * `inside`:坐标轴刻度是否朝内,默认朝外。 * `length`:坐标轴刻度的长度。 * `width`:坐标轴刻度的宽度。默认为0时宽度和坐标轴一致。 +* `showStartTick`:是否显示第一个刻度。 +* `showEndTick`:是否显示最后一个刻度。 ## `Emphasis` diff --git a/Documentation/xcharts-configuration-EN.md b/Documentation/xcharts-configuration-EN.md index e24991ee..4c541140 100644 --- a/Documentation/xcharts-configuration-EN.md +++ b/Documentation/xcharts-configuration-EN.md @@ -772,6 +772,8 @@ K线图系列。 * `inside`: 坐标轴刻度是否朝内,默认朝外。 * `length`: 坐标轴刻度的长度。 * `width`: 坐标轴刻度的宽度。默认为0时宽度和坐标轴一致。 +* `showStartTick`:是否显示第一个刻度。 +* `showEndTick`:是否显示最后一个刻度。 ## `Emphasis` diff --git a/Editor/PropertyDrawers/LineDrawer.cs b/Editor/PropertyDrawers/LineDrawer.cs index 76588e11..952c715e 100644 --- a/Editor/PropertyDrawers/LineDrawer.cs +++ b/Editor/PropertyDrawers/LineDrawer.cs @@ -59,6 +59,8 @@ namespace XCharts base.DrawExtendeds(prop); PropertyField(prop, "m_AlignWithLabel"); PropertyField(prop, "m_Inside"); + PropertyField(prop, "m_ShowStartTick"); + PropertyField(prop, "m_ShowEndTick"); } } diff --git a/Runtime/Component/Sub/AxisTick.cs b/Runtime/Component/Sub/AxisTick.cs index 94a51d26..01753289 100644 --- a/Runtime/Component/Sub/AxisTick.cs +++ b/Runtime/Component/Sub/AxisTick.cs @@ -19,6 +19,8 @@ namespace XCharts { [SerializeField] private bool m_AlignWithLabel; [SerializeField] private bool m_Inside; + [SerializeField] private bool m_ShowStartTick; + [SerializeField] private bool m_ShowEndTick; /// /// Align axis tick with label, which is available only when boundaryGap is set to be true in category axis. @@ -38,6 +40,24 @@ namespace XCharts get { return m_Inside; } set { if (PropertyUtil.SetStruct(ref m_Inside, value)) SetVerticesDirty(); } } + /// + /// Whether to display the first tick. + /// 是否显示第一个刻度。 + /// + public bool showStartTick + { + get { return m_ShowStartTick; } + set { if (PropertyUtil.SetStruct(ref m_ShowStartTick, value)) SetVerticesDirty(); } + } + /// + /// Whether to display the last tick. + /// 是否显示最后一个刻度。 + /// + public bool showEndTick + { + get { return m_ShowEndTick; } + set { if (PropertyUtil.SetStruct(ref m_ShowEndTick, value)) SetVerticesDirty(); } + } public static AxisTick defaultTick { @@ -48,6 +68,8 @@ namespace XCharts m_Show = true, m_AlignWithLabel = false, m_Inside = false, + m_ShowStartTick = false, + m_ShowEndTick = true }; return tick; } @@ -59,6 +81,8 @@ namespace XCharts axisTick.show = show; axisTick.alignWithLabel = alignWithLabel; axisTick.inside = inside; + axisTick.showStartTick = showStartTick; + axisTick.showEndTick = showEndTick; axisTick.lineStyle = lineStyle.Clone(); return axisTick; } @@ -68,6 +92,8 @@ namespace XCharts show = axisTick.show; alignWithLabel = axisTick.alignWithLabel; inside = axisTick.inside; + showStartTick = axisTick.showStartTick; + showEndTick = axisTick.showEndTick; } } } \ No newline at end of file diff --git a/Runtime/Internal/CoordinateChart.cs b/Runtime/Internal/CoordinateChart.cs index 6ce8235c..7df5ac91 100644 --- a/Runtime/Internal/CoordinateChart.cs +++ b/Runtime/Internal/CoordinateChart.cs @@ -826,13 +826,14 @@ namespace XCharts { posX = startX - yAxis.axisLabel.margin; } + posX += yAxis.offset; return new Vector3(posX, grid.runtimeY + scaleWid, 0); } private Vector3 GetLabelXPosition(float scaleWid, int i, int xAxisIndex, XAxis xAxis) { var grid = GetAxisGridOrDefault(xAxis); - var startY = grid.runtimeY + xAxis.offset + (xAxis.axisLabel.onZero ? m_YAxes[xAxisIndex].runtimeZeroYOffset : 0); + var startY = grid.runtimeY + (xAxis.axisLabel.onZero ? m_YAxes[xAxisIndex].runtimeZeroYOffset : 0); if (xAxis.IsTop()) startY += grid.runtimeHeight; var posY = 0f; var inside = xAxis.axisLabel.inside; @@ -845,6 +846,7 @@ namespace XCharts { posY = startY - xAxis.axisLabel.margin - fontSize / 2; } + posY += xAxis.offset; return new Vector3(grid.runtimeX + scaleWid, posY); } @@ -1067,15 +1069,22 @@ namespace XCharts for (int i = 0; i < size; i++) { var scaleWidth = AxisHelper.GetScaleWidth(yAxis, grid.runtimeHeight, i + 1, dataZoom); - float pX = 0; - float pY = totalWidth; - if (yAxis.boundaryGap && yAxis.axisTick.alignWithLabel) + if (i == 0 && !yAxis.axisTick.showStartTick) { - pY -= scaleWidth / 2; + totalWidth += scaleWidth; + continue; } - if (yAxis.axisTick.show && i > 0) + if (i == size - 1 && !yAxis.axisTick.showEndTick) { - var startX = grid.runtimeX + GetYAxisOnZeroOffset(yAxis); + totalWidth += scaleWidth; + continue; + } + if (yAxis.axisTick.show) + { + float pX = 0; + float pY = totalWidth; + if (yAxis.boundaryGap && yAxis.axisTick.alignWithLabel) pY -= scaleWidth / 2; + var startX = grid.runtimeX + GetYAxisOnZeroOffset(yAxis) + yAxis.offset; startX -= yAxis.axisLine.GetWidth(m_Theme.axis.lineWidth); if (yAxis.IsValue() && yAxis.IsRight()) startX += grid.runtimeWidth; bool inside = yAxis.axisTick.inside; @@ -1176,14 +1185,21 @@ namespace XCharts for (int i = 0; i < size; i++) { var scaleWidth = AxisHelper.GetScaleWidth(xAxis, grid.runtimeWidth, i + 1, dataZoom); - float pX = totalWidth; - float pY = 0; - if (xAxis.boundaryGap && xAxis.axisTick.alignWithLabel) + if (i == 0 && !xAxis.axisTick.showStartTick) { - pX -= scaleWidth / 2; + totalWidth += scaleWidth; + continue; } - if (xAxis.axisTick.show && i > 0) + if (i == size - 1 && !xAxis.axisTick.showEndTick) { + totalWidth += scaleWidth; + continue; + } + if (xAxis.axisTick.show) + { + float pX = totalWidth; + float pY = 0; + if (xAxis.boundaryGap && xAxis.axisTick.alignWithLabel) pX -= scaleWidth / 2; var startY = grid.runtimeY + xAxis.offset - xAxis.axisLine.GetWidth(m_Theme.axis.lineWidth); if (xAxis.IsTop()) startY += grid.runtimeHeight; else startY += GetXAxisOnZeroOffset(xAxis);