From 47ee421913d58c49535a86d1ef70b9768dd71918 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Wed, 20 Jul 2022 07:38:18 +0800 Subject: [PATCH] [bug][axis] fix showStartLabel and showEndLabel not work --- CHANGELOG.md | 1 + Runtime/Component/Axis/Axis.cs | 17 ++++++++++++++++- Runtime/Component/Axis/AxisHandler.cs | 8 ++++---- Runtime/Component/Axis/XAxis/XAxisHander.cs | 3 +-- Runtime/Component/Axis/YAxis/YAxisHander.cs | 2 +- Runtime/Internal/Utilities/ChartHelper.cs | 7 +------ 6 files changed, 24 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d4eadcf..ed741989 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,6 +57,7 @@ ## master +* (2022.07.20) 修复`Axis`在`Value`轴时,`AxisLabel`的`showStartLabel`和`showEndLabel`参数设置不生效的问题 * (2022.07.19) 增加`Axis`的`MinorSplitLine`设置坐标轴次分割线 * (2022.07.19) 增加`Axis`的`MinorTick`设置坐标轴次刻度 * (2022.07.17) 增加`Radar`的`smooth`参数设置平滑曲线 diff --git a/Runtime/Component/Axis/Axis.cs b/Runtime/Component/Axis/Axis.cs index fe42a520..221c2e42 100644 --- a/Runtime/Component/Axis/Axis.cs +++ b/Runtime/Component/Axis/Axis.cs @@ -555,6 +555,21 @@ namespace XCharts.Runtime return m_Position == AxisPosition.Bottom; } + public bool IsNeedShowLabel(int index, int total = 0) + { + if (total == 0) + { + total = context.labelValueList.Count; + } + var labelShow = axisLabel.show && (axisLabel.interval == 0 || index % (axisLabel.interval + 1) == 0); + if (labelShow) + { + if (!axisLabel.showStartLabel && index == 0) labelShow = false; + else if (!axisLabel.showEndLabel && index == total - 1) labelShow = false; + } + return labelShow; + } + public void SetNeedUpdateFilterData() { context.isNeedUpdateFilterData = true; @@ -831,7 +846,7 @@ namespace XCharts.Runtime public void UpdateZeroOffset(float axisLength) { - context.offset = context.minValue > 0 || context.minMaxRange == 0? + context.offset = context.minValue > 0 || context.minMaxRange == 0 ? 0 : (context.maxValue < 0 ? axisLength : diff --git a/Runtime/Component/Axis/AxisHandler.cs b/Runtime/Component/Axis/AxisHandler.cs index 3e1a4de5..8831dab5 100644 --- a/Runtime/Component/Axis/AxisHandler.cs +++ b/Runtime/Component/Axis/AxisHandler.cs @@ -296,12 +296,12 @@ namespace XCharts if (i == 0) { var dist = GetLabelPosition(0, 1).x - pos.x; - label.SetTextActive(dist > label.text.GetPreferredWidth()); + label.SetTextActive(axis.IsNeedShowLabel(i) && dist > label.text.GetPreferredWidth()); } else if (i == axis.context.labelValueList.Count - 1) { var dist = pos.x - GetLabelPosition(0, i - 1).x; - label.SetTextActive(dist > label.text.GetPreferredWidth()); + label.SetTextActive(axis.IsNeedShowLabel(i) && dist > label.text.GetPreferredWidth()); } } else @@ -309,12 +309,12 @@ namespace XCharts if (i == 0) { var dist = GetLabelPosition(0, 1).y - pos.y; - label.SetTextActive(dist > label.text.GetPreferredHeight()); + label.SetTextActive(axis.IsNeedShowLabel(i) && dist > label.text.GetPreferredHeight()); } else if (i == axis.context.labelValueList.Count - 1) { var dist = pos.y - GetLabelPosition(0, i - 1).y; - label.SetTextActive(dist > label.text.GetPreferredHeight()); + label.SetTextActive(axis.IsNeedShowLabel(i) && dist > label.text.GetPreferredHeight()); } } } diff --git a/Runtime/Component/Axis/XAxis/XAxisHander.cs b/Runtime/Component/Axis/XAxis/XAxisHander.cs index fe701798..c1b5cf14 100644 --- a/Runtime/Component/Axis/XAxis/XAxisHander.cs +++ b/Runtime/Component/Axis/XAxis/XAxisHander.cs @@ -15,7 +15,6 @@ namespace XCharts.Runtime public override void Update() { - UpdateAxisMinMaxValue(component.index, component); UpdatePointerValue(component); } @@ -31,7 +30,7 @@ namespace XCharts.Runtime private void UpdatePosition(XAxis axis) { var grid = chart.GetChartComponent(axis.gridIndex); - if (grid != null && axis is XAxis && axis.IsValue()) + if (grid != null) { var relativedAxis = chart.GetChartComponent(axis.gridIndex); axis.context.x = grid.context.x; diff --git a/Runtime/Component/Axis/YAxis/YAxisHander.cs b/Runtime/Component/Axis/YAxis/YAxisHander.cs index 1aa81a67..82c54fdd 100644 --- a/Runtime/Component/Axis/YAxis/YAxisHander.cs +++ b/Runtime/Component/Axis/YAxis/YAxisHander.cs @@ -30,7 +30,7 @@ namespace XCharts.Runtime private void UpdatePosition(YAxis axis) { var grid = chart.GetChartComponent(axis.gridIndex); - if (grid != null && axis.IsValue()) + if (grid != null) { var relativedAxis = chart.GetChartComponent(axis.gridIndex); axis.context.x = AxisHelper.GetYAxisXOrY(grid, axis, relativedAxis); diff --git a/Runtime/Internal/Utilities/ChartHelper.cs b/Runtime/Internal/Utilities/ChartHelper.cs index abf9ad4f..47c56e04 100644 --- a/Runtime/Internal/Utilities/ChartHelper.cs +++ b/Runtime/Internal/Utilities/ChartHelper.cs @@ -336,12 +336,7 @@ namespace XCharts.Runtime { var textStyle = axis.axisLabel.textStyle; var label = AddChartLabel(name, parent, axis.axisLabel, theme, content, autoColor, autoAlignment); - var labelShow = axis.axisLabel.show && (axis.axisLabel.interval == 0 || index % (axis.axisLabel.interval + 1) == 0); - if (labelShow) - { - if (!axis.axisLabel.showStartLabel && index == 0) labelShow = false; - else if (!axis.axisLabel.showEndLabel && index == total - 1) labelShow = false; - } + var labelShow = axis.IsNeedShowLabel(index, total); label.UpdateIcon(axis.axisLabel.icon, axis.GetIcon(index)); label.text.SetActive(labelShow); return label;