From 21ffcba0c0fc3c61ffb8a010390c5222d195c511 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Tue, 15 Apr 2025 22:51:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0`AxisLabel`=E7=9A=84`showZero?= =?UTF-8?q?Label`=E8=AE=BE=E7=BD=AE=E6=98=AF=E5=90=A6=E6=98=BE=E7=A4=BA0?= =?UTF-8?q?=E5=88=BB=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Documentation~/en/api.md | 4 ++-- Documentation~/en/configuration.md | 6 ++++++ Documentation~/zh/api.md | 4 ++-- Documentation~/zh/changelog.md | 2 ++ Documentation~/zh/configuration.md | 6 ++++++ Editor/MainComponents/AxisEditor.cs | 1 + Runtime/Component/Axis/Axis.cs | 4 ++-- Runtime/Component/Axis/AxisHandler.cs | 16 ++++++++++------ Runtime/Component/Axis/AxisLabel.cs | 15 ++++++++++++++- Runtime/Internal/Utilities/ChartHelper.cs | 2 +- 10 files changed, 46 insertions(+), 14 deletions(-) diff --git a/Documentation~/en/api.md b/Documentation~/en/api.md index ea080bda..e648ee85 100644 --- a/Documentation~/en/api.md +++ b/Documentation~/en/api.md @@ -915,7 +915,7 @@ public bool IsLog() ### Axis.IsNeedShowLabel -public bool IsNeedShowLabel(int index, int total = 0) +public bool IsNeedShowLabel(int index, int total = 0, string content = null) ### Axis.IsRight @@ -1219,7 +1219,7 @@ public override string GetFormatterContent(int labelIndex, int totalIndex, doubl ### AxisLabel.IsNeedShowLabel -public bool IsNeedShowLabel(int index, int total) +public bool IsNeedShowLabel(int index, int total, string content = null) ### AxisLabel.SetRelatedText diff --git a/Documentation~/en/configuration.md b/Documentation~/en/configuration.md index a0dabd95..654a62ba 100644 --- a/Documentation~/en/configuration.md +++ b/Documentation~/en/configuration.md @@ -804,6 +804,12 @@ Whether to display the last label. Whether to display the first label. +### AxisLabel.showZeroLabel + +`bool` `true` `v3.15.0` + +Whether to display the zero label. + ### AxisLabel.textLimit [TextLimit](#textlimit) diff --git a/Documentation~/zh/api.md b/Documentation~/zh/api.md index 9dbd639e..2bf6a998 100644 --- a/Documentation~/zh/api.md +++ b/Documentation~/zh/api.md @@ -915,7 +915,7 @@ public bool IsLog() ### Axis.IsNeedShowLabel -public bool IsNeedShowLabel(int index, int total = 0) +public bool IsNeedShowLabel(int index, int total = 0, string content = null) ### Axis.IsRight @@ -1219,7 +1219,7 @@ public override string GetFormatterContent(int labelIndex, int totalIndex, doubl ### AxisLabel.IsNeedShowLabel -public bool IsNeedShowLabel(int index, int total) +public bool IsNeedShowLabel(int index, int total, string content = null) ### AxisLabel.SetRelatedText diff --git a/Documentation~/zh/changelog.md b/Documentation~/zh/changelog.md index 77b0c23e..314cf221 100644 --- a/Documentation~/zh/changelog.md +++ b/Documentation~/zh/changelog.md @@ -80,6 +80,8 @@ slug: /changelog ## master +* (2025.04.15) 增加`AxisLabel`的`showZeroLabel`设置是否显示0刻度 +* (2025.04.08) 增加`UIStatistic`的`desc`描述文本设置支持 * (2025.04.07) 修复`Gantt`甘特图在有多维数据时计算的时间区间不准确的问题 * (2025.04.07) 优化`Axis`的`Time`时间轴支持设置Custom和ceilRate * (2025.04.07) 修复`GridCoord`在设置背景色且Serie开启Clip时会覆盖图表的问题 diff --git a/Documentation~/zh/configuration.md b/Documentation~/zh/configuration.md index dc8093de..b46027bf 100644 --- a/Documentation~/zh/configuration.md +++ b/Documentation~/zh/configuration.md @@ -804,6 +804,12 @@ class in XCharts.Runtime / 继承自: [LabelStyle](#labelstyle) 是否显示第一个文本。 +### AxisLabel.showZeroLabel + +`bool` `true` `v3.15.0` + +是否显示0刻度文本。 + ### AxisLabel.textLimit [TextLimit](#textlimit) diff --git a/Editor/MainComponents/AxisEditor.cs b/Editor/MainComponents/AxisEditor.cs index 78199d65..37447578 100644 --- a/Editor/MainComponents/AxisEditor.cs +++ b/Editor/MainComponents/AxisEditor.cs @@ -164,6 +164,7 @@ namespace XCharts.Editor PropertyField(prop, "m_ShowAsPositiveNumber"); PropertyField(prop, "m_OnZero"); + PropertyField(prop, "m_ShowZeroLabel"); PropertyField(prop, "m_ShowStartLabel"); PropertyField(prop, "m_ShowEndLabel"); diff --git a/Runtime/Component/Axis/Axis.cs b/Runtime/Component/Axis/Axis.cs index 18928a63..915a9d4f 100644 --- a/Runtime/Component/Axis/Axis.cs +++ b/Runtime/Component/Axis/Axis.cs @@ -616,13 +616,13 @@ namespace XCharts.Runtime return m_Position == AxisPosition.Bottom; } - public bool IsNeedShowLabel(int index, int total = 0) + public bool IsNeedShowLabel(int index, int total = 0, string content = null) { if (total == 0) { total = context.labelValueList.Count; } - return axisLabel.IsNeedShowLabel(index, total); + return axisLabel.IsNeedShowLabel(index, total, content); } public void SetNeedUpdateFilterData() diff --git a/Runtime/Component/Axis/AxisHandler.cs b/Runtime/Component/Axis/AxisHandler.cs index 516c2dee..5cd80766 100644 --- a/Runtime/Component/Axis/AxisHandler.cs +++ b/Runtime/Component/Axis/AxisHandler.cs @@ -447,13 +447,17 @@ namespace XCharts return Math.Pow(10, n); } - internal void CheckValueLabelActive(Axis axis, int i, ChartLabel label, Vector3 pos) + internal void CheckValueLabelActive(Axis axis, int i, ChartLabel label, Vector3 pos, string content = null) { if (!axis.show || !axis.axisLabel.show) { label.SetTextActive(false); return; } + if(content == null) + { + content = label.text.text.text; + } if (axis.IsValue()) { if (orient == Orient.Horizonal) @@ -461,12 +465,12 @@ namespace XCharts if (i == 0) { var dist = GetLabelPosition(0, 1).x - pos.x; - label.SetTextActive(axis.IsNeedShowLabel(i) && dist > label.text.GetPreferredWidth()); + label.SetTextActive(axis.IsNeedShowLabel(i,0,content) && dist > label.text.GetPreferredWidth()); } else if (i == axis.context.labelValueList.Count - 1) { var dist = pos.x - GetLabelPosition(0, i - 1).x; - label.SetTextActive(axis.IsNeedShowLabel(i) && dist > label.text.GetPreferredWidth()); + label.SetTextActive(axis.IsNeedShowLabel(i,0,content) && dist > label.text.GetPreferredWidth()); } } else @@ -474,12 +478,12 @@ namespace XCharts if (i == 0) { var dist = GetLabelPosition(0, 1).y - pos.y; - label.SetTextActive(axis.IsNeedShowLabel(i) && dist > label.text.GetPreferredHeight()); + label.SetTextActive(axis.IsNeedShowLabel(i,0,content) && dist > label.text.GetPreferredHeight()); } else if (i == axis.context.labelValueList.Count - 1) { var dist = pos.y - GetLabelPosition(0, i - 1).y; - label.SetTextActive(axis.IsNeedShowLabel(i) && dist > label.text.GetPreferredHeight()); + label.SetTextActive(axis.IsNeedShowLabel(i,0,content) && dist > label.text.GetPreferredHeight()); } } } @@ -683,7 +687,7 @@ namespace XCharts var pos = GetLabelPosition(totalWidth + gapWidth, i); label.SetPosition(pos); - CheckValueLabelActive(axis, i, label, pos); + CheckValueLabelActive(axis, i, label, pos, labelName); axis.context.labelObjectList.Add(label); diff --git a/Runtime/Component/Axis/AxisLabel.cs b/Runtime/Component/Axis/AxisLabel.cs index 6479a141..2ba8f463 100644 --- a/Runtime/Component/Axis/AxisLabel.cs +++ b/Runtime/Component/Axis/AxisLabel.cs @@ -17,6 +17,7 @@ namespace XCharts.Runtime [SerializeField] private bool m_OnZero = false; [SerializeField] private bool m_ShowStartLabel = true; [SerializeField] private bool m_ShowEndLabel = true; + [SerializeField][Since("v3.15.0")] private bool m_ShowZeroLabel = true; [SerializeField] private TextLimit m_TextLimit = new TextLimit(); /// @@ -74,6 +75,15 @@ namespace XCharts.Runtime set { if (PropertyUtil.SetStruct(ref m_ShowEndLabel, value)) SetComponentDirty(); } } /// + /// Whether to display the zero label. + /// ||是否显示0刻度文本。 + /// + public bool showZeroLabel + { + get { return m_ShowZeroLabel; } + set { if (PropertyUtil.SetStruct(ref m_ShowZeroLabel, value)) SetComponentDirty(); } + } + /// /// 文本限制。 /// public TextLimit textLimit @@ -118,6 +128,7 @@ namespace XCharts.Runtime height = height, showStartLabel = showStartLabel, showEndLabel = showEndLabel, + showZeroLabel = showZeroLabel, textLimit = textLimit.Clone() }; axisLabel.textStyle.Copy(textStyle); @@ -136,6 +147,7 @@ namespace XCharts.Runtime height = axisLabel.height; showStartLabel = axisLabel.showStartLabel; showEndLabel = axisLabel.showEndLabel; + showZeroLabel = axisLabel.showZeroLabel; textLimit.Copy(axisLabel.textLimit); textStyle.Copy(axisLabel.textStyle); } @@ -171,13 +183,14 @@ namespace XCharts.Runtime return base.GetFormatterContent(labelIndex, totalIndex, value, minValue, maxValue, isLog); } - public bool IsNeedShowLabel(int index, int total) + public bool IsNeedShowLabel(int index, int total, string content = null) { var labelShow = show && (interval == 0 || index % (interval + 1) == 0); if (labelShow) { if (!showStartLabel && index == 0) labelShow = false; else if (!showEndLabel && index == total - 1) labelShow = false; + if (labelShow && content == "0") labelShow = showZeroLabel; } return labelShow; } diff --git a/Runtime/Internal/Utilities/ChartHelper.cs b/Runtime/Internal/Utilities/ChartHelper.cs index 4f862daf..9b53d2c3 100644 --- a/Runtime/Internal/Utilities/ChartHelper.cs +++ b/Runtime/Internal/Utilities/ChartHelper.cs @@ -461,7 +461,7 @@ namespace XCharts.Runtime { var textStyle = axis.axisLabel.textStyle; var label = AddChartLabel(name, parent, axis.axisLabel, theme, content, autoColor, autoAlignment); - var labelShow = axis.IsNeedShowLabel(index, total); + var labelShow = axis.IsNeedShowLabel(index, total, content); label.UpdateIcon(axis.axisLabel.icon, axis.GetIcon(index), iconDefaultColor); label.text.SetActive(labelShow); return label;