diff --git a/Documentation~/en/configuration.md b/Documentation~/en/configuration.md index 807a7430..e2804809 100644 --- a/Documentation~/en/configuration.md +++ b/Documentation~/en/configuration.md @@ -1628,6 +1628,19 @@ Grid component. > XCharts.Runtime.Pie : [Serie](#serie) +```mdx-code-block + +``` + + +|field|default|since|comment| +|--|--|--|--| +|radiusGradient|false|v3.8.1|Whether to use gradient color in pie chart. + +```mdx-code-block + +``` + ## PolarAxisTheme > XCharts.Runtime.PolarAxisTheme : [BaseAxisTheme](#baseaxistheme) diff --git a/Documentation~/zh/changelog.md b/Documentation~/zh/changelog.md index 39716713..25fca996 100644 --- a/Documentation~/zh/changelog.md +++ b/Documentation~/zh/changelog.md @@ -68,6 +68,7 @@ slug: /changelog ## master +* (2023.09.12) 增加`Pie`的`radiusGradient`可设置半径方向的渐变效果 * (2023.09.05) 优化`LabelLine`的`lineEndX`在`Pie`中的表现 * (2023.09.05) 修复`TriggerTooltip()`接口对`Ring`无效的问题 * (2023.09.05) 修复`Radar`数据全为0时绘制报错的问题 diff --git a/Documentation~/zh/configuration.md b/Documentation~/zh/configuration.md index 69c6ccf9..bb57fb03 100644 --- a/Documentation~/zh/configuration.md +++ b/Documentation~/zh/configuration.md @@ -1628,6 +1628,19 @@ Drawing grid in rectangular coordinate. Line chart, bar chart, and scatter chart > XCharts.Runtime.Pie : [Serie](#serie) +```mdx-code-block + +``` + + +|field|default|since|comment| +|--|--|--|--| +|radiusGradient|false|v3.8.1|是否开启半径方向的渐变效果。 + +```mdx-code-block + +``` + ## PolarAxisTheme > XCharts.Runtime.PolarAxisTheme : [BaseAxisTheme](#baseaxistheme) diff --git a/Editor/Series/PieEditor.cs b/Editor/Series/PieEditor.cs index 34e8633f..22df5cc3 100644 --- a/Editor/Series/PieEditor.cs +++ b/Editor/Series/PieEditor.cs @@ -22,6 +22,7 @@ namespace XCharts.Editor PropertyField("m_Ignore"); PropertyField("m_IgnoreValue"); PropertyField("m_ClickOffset"); + PropertyField("m_RadiusGradient"); }); PropertyField("m_ItemStyle"); PropertyField("m_Animation"); diff --git a/Runtime/Serie/Pie/Pie.cs b/Runtime/Serie/Pie/Pie.cs index 9d173270..864b0023 100644 --- a/Runtime/Serie/Pie/Pie.cs +++ b/Runtime/Serie/Pie/Pie.cs @@ -1,3 +1,5 @@ +using UnityEngine; + namespace XCharts.Runtime { [System.Serializable] @@ -9,9 +11,21 @@ namespace XCharts.Runtime [SerieDataExtraField("m_Ignore", "m_Selected", "m_Radius")] public class Pie : Serie { + [SerializeField][Since("v3.8.1")] private bool m_RadiusGradient = false; + public override SerieColorBy defaultColorBy { get { return SerieColorBy.Data; } } public override bool titleJustForSerie { get { return true; } } + /// + /// Whether to use gradient color in pie chart. + /// | 是否开启半径方向的渐变效果。 + /// + public bool radiusGradient + { + get { return m_RadiusGradient; } + set { if (PropertyUtil.SetStruct(ref m_RadiusGradient, value)) { SetVerticesDirty(); } } + } + public static Serie AddDefaultSerie(BaseChart chart, string serieName) { var serie = chart.AddSerie(serieName); diff --git a/Runtime/Serie/Pie/PieHandler.cs b/Runtime/Serie/Pie/PieHandler.cs index f8d9b9c1..9cbe0447 100644 --- a/Runtime/Serie/Pie/PieHandler.cs +++ b/Runtime/Serie/Pie/PieHandler.cs @@ -333,7 +333,7 @@ namespace XCharts.Runtime } } - private void DrawPie(VertexHelper vh, Serie serie) + private void DrawPie(VertexHelper vh, Pie serie) { if (!serie.show || serie.animation.HasFadeOut()) { @@ -387,7 +387,7 @@ namespace XCharts.Runtime UGL.DrawDoughnut(vh, offsetCenter, insideRadius, outsideRadius, color, toColor, Color.clear, serieData.context.startAngle, drawEndDegree, borderWidth, borderColor, serie.gap / 2, chart.settings.cicleSmoothness, - needRoundCap, true); + needRoundCap, true, serie.radiusGradient); DrawPieCenter(vh, serie, itemStyle, insideRadius); if (serie.animation.CheckDetailBreak(serieData.context.toAngle)) diff --git a/Runtime/XUGL/UGL.cs b/Runtime/XUGL/UGL.cs index 5e74590e..ee8bb548 100644 --- a/Runtime/XUGL/UGL.cs +++ b/Runtime/XUGL/UGL.cs @@ -1590,7 +1590,7 @@ namespace XUGL public static void DrawDoughnut(VertexHelper vh, Vector3 center, float insideRadius, float outsideRadius, Color32 color, Color32 toColor, Color32 emptyColor, float startDegree, float toDegree, float borderWidth, - Color32 borderColor, float gap, float smoothness, bool roundCap = false, bool clockwise = true) + Color32 borderColor, float gap, float smoothness, bool roundCap = false, bool clockwise = true, bool radiusGradient = true) { if (toDegree - startDegree == 0) return; if (gap > 0 && Mathf.Abs(toDegree - startDegree) >= 360) gap = 0; @@ -1785,10 +1785,19 @@ namespace XUGL center.y + insideRadius * Mathf.Cos(currAngle)); if (isGradient) { - var tcolor = Color32.Lerp(color, toColor, i * 1.0f / segments); - if (i == 0 && (needSpace || needBorder)) - UGL.DrawTriangle(vh, p1, p2, p3, color, tcolor, tcolor); - AddVertToVertexHelper(vh, p3, p4, tcolor, tcolor, i > 0); + if (radiusGradient) + { + if (i == 0 && (needSpace || needBorder)) + UGL.DrawTriangle(vh, p1, p2, p3, color, toColor, toColor); + AddVertToVertexHelper(vh, p3, p4, color, toColor, i > 0); + } + else + { + var tcolor = Color32.Lerp(color, toColor, i * 1.0f / segments); + if (i == 0 && (needSpace || needBorder)) + UGL.DrawTriangle(vh, p1, p2, p3, color, tcolor, tcolor); + AddVertToVertexHelper(vh, p3, p4, tcolor, tcolor, i > 0); + } } else {