From cdac6acd8c875a87862a0a96ecafa4d2a5d9fac9 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Tue, 9 Jul 2024 23:16:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D`Label`=E5=9C=A8=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96=E6=97=B6=E4=BC=9A=E5=A0=86=E7=A7=AF=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Component/Background/BackgroundHandler.cs | 2 +- Runtime/Internal/Object/ChartLabel.cs | 13 ++++++---- Runtime/Internal/Utilities/ChartHelper.cs | 26 ++++++++++--------- Runtime/Serie/SerieHandler.cs | 8 ++---- 4 files changed, 25 insertions(+), 24 deletions(-) diff --git a/Runtime/Component/Background/BackgroundHandler.cs b/Runtime/Component/Background/BackgroundHandler.cs index 0d780d38..bb53f759 100644 --- a/Runtime/Component/Background/BackgroundHandler.cs +++ b/Runtime/Component/Background/BackgroundHandler.cs @@ -50,7 +50,7 @@ namespace XCharts.Runtime var borderColor = component.borderStyle.GetRuntimeBorderColor(); var cornerRadius = component.borderStyle.GetRuntimeCornerRadius(); UGL.DrawRoundRectangleWithBorder(vh, chart.chartRect, backgroundColor, backgroundColor, cornerRadius, - borderWidth, borderColor); + borderWidth, borderColor, 0, 1f); } } } \ No newline at end of file diff --git a/Runtime/Internal/Object/ChartLabel.cs b/Runtime/Internal/Object/ChartLabel.cs index 50d685e7..3cb6cc01 100644 --- a/Runtime/Internal/Object/ChartLabel.cs +++ b/Runtime/Internal/Object/ChartLabel.cs @@ -56,7 +56,7 @@ namespace XCharts.Runtime protected override void Awake() { raycastTarget = false; - SetActive(true); + SetActive(false, true); } public void SetTextPadding(TextPadding padding) @@ -200,10 +200,13 @@ namespace XCharts.Runtime return m_Active; } - public void SetActive(bool flag) + public void SetActive(bool flag, bool force = false) { - m_Active = flag; - ChartHelper.SetActive(gameObject, flag); + if (m_Active == flag && !force) return; + if (ChartHelper.SetActive(gameObject, flag)) + { + m_Active = flag; + } } public void SetTextActive(bool flag) @@ -247,7 +250,7 @@ namespace XCharts.Runtime AdjustIconPos(); if (m_HideIconIfTextEmpty && isIconActive) { - ChartHelper.SetActive(m_IconImage.gameObject, !string.IsNullOrEmpty(text)); + SetIconActive(!string.IsNullOrEmpty(text)); } } return false; diff --git a/Runtime/Internal/Utilities/ChartHelper.cs b/Runtime/Internal/Utilities/ChartHelper.cs index 44298b7c..f2ba7d6b 100644 --- a/Runtime/Internal/Utilities/ChartHelper.cs +++ b/Runtime/Internal/Utilities/ChartHelper.cs @@ -41,22 +41,22 @@ namespace XCharts.Runtime return s_Builder.ToString(); } - public static void SetActive(GameObject gameObject, bool active) + public static bool SetActive(GameObject gameObject, bool active) { - if (gameObject == null) return; - SetActive(gameObject.transform, active); + if (gameObject == null) return false; + return SetActive(gameObject.transform, active); } - public static void SetActive(Image image, bool active) + public static bool SetActive(Image image, bool active) { - if (image == null) return; - SetActive(image.gameObject, active); + if (image == null) return false; + return SetActive(image.gameObject, active); } - public static void SetActive(Text text, bool active) + public static bool SetActive(Text text, bool active) { - if (text == null) return; - SetActive(text.gameObject, active); + if (text == null) return false; + return SetActive(text.gameObject, active); } /// @@ -64,12 +64,14 @@ namespace XCharts.Runtime /// /// /// - public static void SetActive(Transform transform, bool active) + public static bool SetActive(Transform transform, bool active) { - if (transform == null) return; + if (transform == null) return false; if (active) transform.localScale = Vector3.one; else transform.localScale = Vector3.zero; + return true; } + public static void HideAllObject(GameObject obj, string match = null) { if (obj == null) return; @@ -460,7 +462,7 @@ namespace XCharts.Runtime label.color = (!labelStyle.background.autoColor || autoColor == Color.clear) ? labelStyle.background.color : autoColor; label.sprite = labelStyle.background.sprite; - if(label.type != labelStyle.background.type) + if (label.type != labelStyle.background.type) label.type = labelStyle.background.type; } else diff --git a/Runtime/Serie/SerieHandler.cs b/Runtime/Serie/SerieHandler.cs index 79a716f1..e6306bcc 100644 --- a/Runtime/Serie/SerieHandler.cs +++ b/Runtime/Serie/SerieHandler.cs @@ -368,7 +368,7 @@ namespace XCharts.Runtime var textName = string.Format("{0}_{1}_{2}_{3}", s_SerieLabelObjectName, serie.index, serieData.index, i); var label = ChartHelper.AddChartLabel(textName, serieLabelRoot.transform, serieLabel, chart.theme.common, "", dataAutoColor, TextAnchor.MiddleCenter); - label.SetActive(serieLabel.show); + label.SetActive(false); serieData.context.dataLabels.Add(label); } } @@ -377,7 +377,7 @@ namespace XCharts.Runtime var textName = ChartCached.GetSerieLabelName(s_SerieLabelObjectName, serie.index, serieData.index); var label = ChartHelper.AddChartLabel(textName, serieLabelRoot.transform, serieLabel, chart.theme.common, "", dataAutoColor, TextAnchor.MiddleCenter); - label.SetActive(serieLabel.show); + label.SetActive(false); serieData.labelObject = label; } @@ -581,10 +581,6 @@ namespace XCharts.Runtime { foreach (var serieData in serie.data) { - if (serieData.labelObject == null && serieData.context.dataLabels.Count <= 0) - { - continue; - } serieData.SetLabelActive(false); } }