From 92ee57baf81dfbd73b6e5e001c4939017d16dd7f Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Thu, 12 Aug 2021 22:16:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96`BarChart`=E8=AE=BE=E7=BD=AE`?= =?UTF-8?q?Corner`=E6=97=B6=E6=AD=A3=E8=B4=9F=E6=9F=B1=E6=9D=A1=E5=9C=86?= =?UTF-8?q?=E8=A7=92=E5=AF=B9=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/XCharts/CHANGELOG-EN.md | 1 + Assets/XCharts/CHANGELOG.md | 1 + .../Internal/CoordinateChart_DrawBar.cs | 10 ++-- Assets/XCharts/Runtime/XUGL/UGL.cs | 51 +++++++++++++++---- 4 files changed, 48 insertions(+), 15 deletions(-) diff --git a/Assets/XCharts/CHANGELOG-EN.md b/Assets/XCharts/CHANGELOG-EN.md index c2c50ded..7bb280c4 100644 --- a/Assets/XCharts/CHANGELOG-EN.md +++ b/Assets/XCharts/CHANGELOG-EN.md @@ -39,6 +39,7 @@ ## master +* (2021.08.12) Optimize `BarChart` setting `Corner` when the positive and negative columns are fillet symmetric * (2021.08.03) Fixed y axis not displaying when all data is 0 * (2021.07.29) Fixed ignored data will also participate in calculations when `ignore` is enabled (#161) * (2021.07.29) Improved `BarChart`'s `Zebra` gradient support diff --git a/Assets/XCharts/CHANGELOG.md b/Assets/XCharts/CHANGELOG.md index 149545b6..7eec2568 100644 --- a/Assets/XCharts/CHANGELOG.md +++ b/Assets/XCharts/CHANGELOG.md @@ -39,6 +39,7 @@ ## master +* (2021.08.12) 优化`BarChart`设置`Corner`时正负柱条圆角对称 * (2021.08.03) 优化`Serie`的数据全为0时Y轴不显示的问题 * (2021.07.29) 修复`Serie`开启`ignore`时被忽略的数据还会参与计算的问题 (#161) * (2021.07.29) 完善`BarChart`的`Zebra`斑马柱图渐变支持 diff --git a/Assets/XCharts/Runtime/Internal/CoordinateChart_DrawBar.cs b/Assets/XCharts/Runtime/Internal/CoordinateChart_DrawBar.cs index 49931504..512db0d5 100644 --- a/Assets/XCharts/Runtime/Internal/CoordinateChart_DrawBar.cs +++ b/Assets/XCharts/Runtime/Internal/CoordinateChart_DrawBar.cs @@ -329,17 +329,18 @@ namespace XCharts var center = new Vector3((plt.x + prb.x) / 2, (prt.y + plb.y) / 2); if (itemWidth > 0 && itemHeight > 0) { + var invert = center.x < plb.x; if (ItemStyleHelper.IsNeedCorner(itemStyle)) { UGL.DrawRoundRectangle(vh, center, itemWidth, itemHeight, areaColor, areaToColor, 0, - itemStyle.cornerRadius, isYAxis); + itemStyle.cornerRadius, isYAxis, m_Settings.cicleSmoothness, invert); } else { Internal_CheckClipAndDrawPolygon(vh, plb, plt, prt, prb, areaColor, areaToColor, serie.clip, grid); } UGL.DrawBorder(vh, center, itemWidth, itemHeight, borderWidth, itemStyle.borderColor, - itemStyle.borderToColor, 0, itemStyle.cornerRadius, isYAxis); + itemStyle.borderToColor, 0, itemStyle.cornerRadius, isYAxis, m_Settings.cicleSmoothness, invert); } } else @@ -356,10 +357,11 @@ namespace XCharts var center = new Vector3((plb.x + prt.x) / 2, (plt.y + prb.y) / 2); if (itemWidth > 0 && itemHeight > 0) { + var invert = center.y < plb.y; if (ItemStyleHelper.IsNeedCorner(itemStyle)) { UGL.DrawRoundRectangle(vh, center, itemWidth, itemHeight, areaColor, areaToColor, 0, - itemStyle.cornerRadius, isYAxis); + itemStyle.cornerRadius, isYAxis, m_Settings.cicleSmoothness, invert); } else { @@ -367,7 +369,7 @@ namespace XCharts serie.clip, grid); } UGL.DrawBorder(vh, center, itemWidth, itemHeight, borderWidth, itemStyle.borderColor, - itemStyle.borderToColor, 0, itemStyle.cornerRadius, isYAxis); + itemStyle.borderToColor, 0, itemStyle.cornerRadius, isYAxis, m_Settings.cicleSmoothness, invert); } } } diff --git a/Assets/XCharts/Runtime/XUGL/UGL.cs b/Assets/XCharts/Runtime/XUGL/UGL.cs index 4f170065..5ebc0ed8 100644 --- a/Assets/XCharts/Runtime/XUGL/UGL.cs +++ b/Assets/XCharts/Runtime/XUGL/UGL.cs @@ -483,13 +483,34 @@ namespace XUGL } private static void InitCornerRadius(float[] cornerRadius, float width, float height, bool horizontal, - ref float brLt, ref float brRt, ref float brRb, ref float brLb, ref bool needRound) + bool invert, ref float brLt, ref float brRt, ref float brRb, ref float brLb, ref bool needRound) { if (cornerRadius == null) return; - brLt = cornerRadius.Length > 0 ? cornerRadius[0] : 0; - brRt = cornerRadius.Length > 1 ? cornerRadius[1] : 0; - brRb = cornerRadius.Length > 2 ? cornerRadius[2] : 0; - brLb = cornerRadius.Length > 3 ? cornerRadius[3] : 0; + if (invert) + { + if (horizontal) + { + brLt = cornerRadius.Length > 0 ? cornerRadius[1] : 0; + brRt = cornerRadius.Length > 1 ? cornerRadius[0] : 0; + brRb = cornerRadius.Length > 2 ? cornerRadius[3] : 0; + brLb = cornerRadius.Length > 3 ? cornerRadius[2] : 0; + } + else + { + brLt = cornerRadius.Length > 0 ? cornerRadius[3] : 0; + brRt = cornerRadius.Length > 1 ? cornerRadius[2] : 0; + brRb = cornerRadius.Length > 2 ? cornerRadius[1] : 0; + brLb = cornerRadius.Length > 3 ? cornerRadius[0] : 0; + } + } + else + { + brLt = cornerRadius.Length > 0 ? cornerRadius[0] : 0; + brRt = cornerRadius.Length > 1 ? cornerRadius[1] : 0; + brRb = cornerRadius.Length > 2 ? cornerRadius[2] : 0; + brLb = cornerRadius.Length > 3 ? cornerRadius[3] : 0; + } + needRound = brLb != 0 || brRt != 0 || brRb != 0 || brLb != 0; if (needRound) { @@ -568,18 +589,22 @@ namespace XUGL /// /// /// + /// /// /// + /// + /// + /// public static void DrawRoundRectangle(VertexHelper vh, Vector3 center, float rectWidth, float rectHeight, Color32 color, Color32 toColor, float rotate = 0, float[] cornerRadius = null, bool isYAxis = false, - float smoothness = 2) + float smoothness = 2, bool invertCorner = false) { var isGradient = !UGLHelper.IsValueEqualsColor(color, toColor); var halfWid = rectWidth / 2; var halfHig = rectHeight / 2; float brLt = 0, brRt = 0, brRb = 0, brLb = 0; bool needRound = false; - InitCornerRadius(cornerRadius, rectWidth, rectHeight, isYAxis, ref brLt, ref brRt, ref brRb, + InitCornerRadius(cornerRadius, rectWidth, rectHeight, isYAxis, invertCorner, ref brLt, ref brRt, ref brRb, ref brLb, ref needRound); var tempCenter = Vector3.zero; var lbIn = new Vector3(center.x - halfWid, center.y - halfHig); @@ -811,12 +836,13 @@ namespace XUGL /// /// /// + /// public static void DrawBorder(VertexHelper vh, Vector3 center, float rectWidth, float rectHeight, float borderWidth, Color32 color, float rotate = 0, float[] cornerRadius = null, - bool horizontal = false, float smoothness = 1f) + bool horizontal = false, float smoothness = 1f, bool invertCorner = false) { DrawBorder(vh, center, rectWidth, rectHeight, borderWidth, color, s_ClearColor32, rotate, - cornerRadius, horizontal, smoothness); + cornerRadius, horizontal, smoothness, invertCorner); } /// @@ -831,9 +857,12 @@ namespace XUGL /// /// /// + /// + /// + /// public static void DrawBorder(VertexHelper vh, Vector3 center, float rectWidth, float rectHeight, float borderWidth, Color32 color, Color32 toColor, float rotate = 0, float[] cornerRadius = null, - bool horizontal = false, float smoothness = 1f) + bool horizontal = false, float smoothness = 1f, bool invertCorner = false) { if (borderWidth == 0 || UGLHelper.IsClearColor(color)) return; var halfWid = rectWidth / 2; @@ -848,7 +877,7 @@ namespace XUGL var rbOt = new Vector3(center.x + halfWid + borderWidth, center.y - halfHig - borderWidth); float brLt = 0, brRt = 0, brRb = 0, brLb = 0; bool needRound = false; - InitCornerRadius(cornerRadius, rectWidth, rectHeight, horizontal, ref brLt, ref brRt, ref brRb, + InitCornerRadius(cornerRadius, rectWidth, rectHeight, horizontal, invertCorner, ref brLt, ref brRt, ref brRb, ref brLb, ref needRound); var tempCenter = Vector3.zero; if (UGLHelper.IsClearColor(toColor))