diff --git a/CHANGELOG-EN.md b/CHANGELOG-EN.md index 56d6d24b..4d60ff08 100644 --- a/CHANGELOG-EN.md +++ b/CHANGELOG-EN.md @@ -1,6 +1,7 @@ # 更新日志 +* (2020.07.23) Added `RingChart` ring gradient support#75 * (2020.07.21) Added `formatter` of `AxisLabel` and `SerieLabel` to configure numeric formatting separately. * (2020.07.17) Added animation completion callback interface for `SerieAnimation`. * (2020.07.17) Optimize `Chart` under `ScrollView` without affecting the scrolling and dragging of `ScrollView`. diff --git a/CHANGELOG.md b/CHANGELOG.md index 9af85d34..f1597ab1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # 更新日志 +* (2020.07.23) 增加`RingChart`环形渐变支持#75 * (2020.07.21) 增加`AxisLabel`和`SerieLabel`的`formatter`可单独配置数值格式化#68 * (2020.07.17) 增加`SerieAnimation`动画完成回调接口 * (2020.07.17) 优化`Chart`放在`ScrollView`下时不影响`ScrollView`的滚动和拖动 diff --git a/Runtime/Internal/Utility/ChartDrawer.cs b/Runtime/Internal/Utility/ChartDrawer.cs index 50c25b95..e9c591c4 100644 --- a/Runtime/Internal/Utility/ChartDrawer.cs +++ b/Runtime/Internal/Utility/ChartDrawer.cs @@ -1160,7 +1160,7 @@ namespace XCharts roundCenter = p + roundAngleRadius * ChartHelper.GetDire(realToOutAngle); sectorStartDegree = clockwise ? roundTotalDegree : roundTotalDegree + 180; sectorToDegree = clockwise ? roundTotalDegree + 180 : roundTotalDegree + 360; - DrawSector(vh, roundCenter, roundRadius, color, sectorStartDegree, sectorToDegree, smoothness / 2); + DrawSector(vh, roundCenter, roundRadius, toColor, sectorStartDegree, sectorToDegree, smoothness / 2); if (needBorder) { DrawDoughnut(vh, roundCenter, roundRadius, roundRadius + borderWidth, borderColor, Color.clear, @@ -1169,7 +1169,8 @@ namespace XCharts e1 = ChartHelper.GetPos(p, insideRadius, realToOutAngle); e2 = ChartHelper.GetPos(p, outsideRadius, realToOutAngle); } - float segmentAngle = (realToInAngle - realStartInAngle) / segments; + var segmentAngle = (realToInAngle - realStartInAngle) / segments; + var isGradient = !ChartHelper.IsValueEqualsColor(color, toColor); for (int i = 0; i <= segments; i++) { float currAngle = realStartInAngle + i * segmentAngle; @@ -1178,7 +1179,15 @@ namespace XCharts p4 = new Vector3(p.x + insideRadius * Mathf.Sin(currAngle), p.y + insideRadius * Mathf.Cos(currAngle)); if (!ChartHelper.IsClearColor(emptyColor)) DrawTriangle(vh, p, p1, p4, emptyColor); - DrawPolygon(vh, p2, p3, p4, p1, color, toColor); + if (isGradient) + { + var tcolor = Color.Lerp(color, toColor, i * 1.0f / segments); + DrawPolygon(vh, p2, p3, p4, p1, tcolor, tcolor); + } + else + { + DrawPolygon(vh, p2, p3, p4, p1, color, color); + } p1 = p4; p2 = p3; }