From 4b8374b1aee4be44b9c36d1f4646ead70a01f44b Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Tue, 19 Mar 2024 22:33:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D`Pie`=E5=9C=A8=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE`ItemStyle`=E7=9A=84`opacity`=E6=97=B6=E9=A2=9C?= =?UTF-8?q?=E8=89=B2=E4=B8=8D=E5=AF=B9=E7=9A=84=E9=97=AE=E9=A2=98=20(#309)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Documentation~/zh/changelog.md | 1 + Runtime/Serie/SerieHelper.cs | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Documentation~/zh/changelog.md b/Documentation~/zh/changelog.md index 03fd4317..87946a32 100644 --- a/Documentation~/zh/changelog.md +++ b/Documentation~/zh/changelog.md @@ -74,6 +74,7 @@ slug: /changelog ## master * (2024.03.20) 增加`Tooltip`的`triggerOn`设置触发条件 +* (2024.03.19) 修复`Pie`在设置`ItemStyle`的`opacity`时颜色不对的问题 (#309) ## v3.10.2 diff --git a/Runtime/Serie/SerieHelper.cs b/Runtime/Serie/SerieHelper.cs index 61c6e4d3..e64438a2 100644 --- a/Runtime/Serie/SerieHelper.cs +++ b/Runtime/Serie/SerieHelper.cs @@ -320,7 +320,7 @@ namespace XCharts.Runtime { var style = GetItemStyle(serie, serieData, SerieState.Normal); GetColor(ref color, style.color, style.color, style.opacity, theme, index, opacity); - GetColor(ref toColor, style.toColor, color, style.opacity, theme, index, opacity); + GetColor(ref toColor, style.toColor, color, style.opacity, theme, index, opacity, true); switch (state) { case SerieState.Emphasis: @@ -342,7 +342,7 @@ namespace XCharts.Runtime else { GetColor(ref color, stateStyle.itemStyle.color, stateStyle.itemStyle.color, stateStyle.itemStyle.opacity, theme, index, opacity); - GetColor(ref toColor, stateStyle.itemStyle.toColor, color, stateStyle.itemStyle.opacity, theme, index, opacity); + GetColor(ref toColor, stateStyle.itemStyle.toColor, color, stateStyle.itemStyle.opacity, theme, index, opacity, true); } } @@ -359,7 +359,7 @@ namespace XCharts.Runtime { var style = GetItemStyle(serie, serieData, SerieState.Normal); GetColor(ref color, style.color, style.color, style.opacity, theme, index, opacity); - GetColor(ref toColor, style.toColor, color, style.opacity, theme, index, opacity); + GetColor(ref toColor, style.toColor, color, style.opacity, theme, index, opacity, true); backgroundColor = style.backgroundColor; switch (state) { @@ -383,7 +383,7 @@ namespace XCharts.Runtime { backgroundColor = stateStyle.itemStyle.backgroundColor; GetColor(ref color, stateStyle.itemStyle.color, stateStyle.itemStyle.color, stateStyle.itemStyle.opacity, theme, index, opacity); - GetColor(ref toColor, stateStyle.itemStyle.toColor, color, stateStyle.itemStyle.opacity, theme, index, opacity); + GetColor(ref toColor, stateStyle.itemStyle.toColor, color, stateStyle.itemStyle.opacity, theme, index, opacity, true); } } @@ -580,7 +580,7 @@ namespace XCharts.Runtime innerFill = areaStyle.innerFill; toTop = areaStyle.toTop; GetColor(ref color, areaStyle.color, serie.itemStyle.color, areaStyle.opacity, theme, index); - GetColor(ref toColor, areaStyle.toColor, color, areaStyle.opacity, theme, index); + GetColor(ref toColor, areaStyle.toColor, color, areaStyle.opacity, theme, index, true); switch (state) { case SerieState.Emphasis: @@ -606,7 +606,7 @@ namespace XCharts.Runtime innerFill = stateStyle.areaStyle.innerFill; toTop = stateStyle.areaStyle.toTop; GetColor(ref color, stateStyle.areaStyle.color, stateStyle.itemStyle.color, stateStyle.areaStyle.opacity, theme, index); - GetColor(ref toColor, stateStyle.areaStyle.toColor, color, stateStyle.areaStyle.opacity, theme, index); + GetColor(ref toColor, stateStyle.areaStyle.toColor, color, stateStyle.areaStyle.opacity, theme, index, true, true); } else { @@ -646,10 +646,14 @@ namespace XCharts.Runtime } public static void GetColor(ref Color32 color, Color32 checkColor, Color32 itemColor, - float opacity, ThemeStyle theme, int colorIndex, bool setOpacity = true) + float opacity, ThemeStyle theme, int colorIndex, bool setOpacity = true, bool resetOpacity = false) { if (!ChartHelper.IsClearColor(checkColor)) color = checkColor; - else if (!ChartHelper.IsClearColor(itemColor)) color = itemColor; + else if (!ChartHelper.IsClearColor(itemColor)) + { + color = itemColor; + if (resetOpacity) opacity = 1; + } if (ChartHelper.IsClearColor(color) && colorIndex >= 0) color = theme.GetColor(colorIndex); if (setOpacity) ChartHelper.SetColorOpacity(ref color, opacity); }