diff --git a/CHANGELOG.md b/CHANGELOG.md index 51abe90f..211de884 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,7 +50,12 @@ ## master -* (2022.04.13) 增加`VisualMap`的`workOnLine`和`workOnArea`以支持是对折线还是区域映射的功能 #191 +* (2022.04.17) 修复`Bar`在数值为负数时动画无效的问题 +* (2022.04.17) 增加`ItemStyle`的`BorderGap`支持设置边框间距 +* (2022.04.16) 优化`Bar`的`Border`和`Capsule`胶囊柱图 +* (2022.04.15) 增加`Liquid`对`Round Rect`圆角矩形水位图的支持 +* (2022.04.14) 增加`Line`对`EndLabel`的支持 +* (2022.04.13) 增加`VisualMap`的`workOnLine`和`workOnArea`支持折线和区域映射功能 (#191) * (2022.04.12) 优化`Radar`支持`Area`区域触发`Tooltip` * (2022.04.09) 优化`VisualMap` * (2022.04.09) 优化`Tooltip` diff --git a/Editor/ChildComponents/ItemStyleDrawer.cs b/Editor/ChildComponents/ItemStyleDrawer.cs index 87560daa..d41dd7ac 100644 --- a/Editor/ChildComponents/ItemStyleDrawer.cs +++ b/Editor/ChildComponents/ItemStyleDrawer.cs @@ -24,6 +24,7 @@ namespace XCharts.Editor PropertyField(prop, "m_CenterColor"); PropertyField(prop, "m_CenterGap"); PropertyField(prop, "m_BorderWidth"); + PropertyField(prop, "m_BorderGap"); PropertyField(prop, "m_BorderColor"); PropertyField(prop, "m_BorderColor0"); PropertyField(prop, "m_BorderToColor"); diff --git a/Runtime/Component/Animation/AnimationStyle.cs b/Runtime/Component/Animation/AnimationStyle.cs index 0a860d18..15b80509 100644 --- a/Runtime/Component/Animation/AnimationStyle.cs +++ b/Runtime/Component/Animation/AnimationStyle.cs @@ -532,12 +532,15 @@ namespace XCharts.Runtime isEnd = true; } } - else if (currHig - destProgress > 0) + else { - currHig = destProgress; - isEnd = true; + if ((destProgress - startProgress > 0 && currHig > destProgress) + || (destProgress - startProgress < 0 && currHig < destProgress)) + { + currHig = destProgress; + isEnd = true; + } } - SetDataCurrProgress(dataIndex, currHig); return currHig; } diff --git a/Runtime/Component/Animation/AnimationStyleHelper.cs b/Runtime/Component/Animation/AnimationStyleHelper.cs index fe0c5955..6f6e9bfd 100644 --- a/Runtime/Component/Animation/AnimationStyleHelper.cs +++ b/Runtime/Component/Animation/AnimationStyleHelper.cs @@ -18,7 +18,7 @@ namespace XCharts.Runtime return destProgress; } var isDataAnimationEnd = true; - float currHig = serie.animation.CheckItemProgress(dataIndex, destProgress, ref isDataAnimationEnd, startPorgress); + var currHig = serie.animation.CheckItemProgress(dataIndex, destProgress, ref isDataAnimationEnd, startPorgress); if (!isDataAnimationEnd) { serie.animation.context.isAllItemAnimationEnd = false; diff --git a/Runtime/Component/Child/ItemStyle.cs b/Runtime/Component/Child/ItemStyle.cs index 4d9a3abb..51f1adc8 100644 --- a/Runtime/Component/Child/ItemStyle.cs +++ b/Runtime/Component/Child/ItemStyle.cs @@ -18,6 +18,7 @@ namespace XCharts.Runtime [SerializeField] private Color32 m_CenterColor; [SerializeField] private float m_CenterGap; [SerializeField] private float m_BorderWidth = 0; + [SerializeField] private float m_BorderGap = 0; [SerializeField] private Color32 m_BorderColor; [SerializeField] private Color32 m_BorderColor0; [SerializeField] private Color32 m_BorderToColor; @@ -39,6 +40,7 @@ namespace XCharts.Runtime m_CenterColor = Color.clear; m_CenterGap = 0; m_BorderWidth = 0; + m_BorderGap = 0; m_BorderColor = Color.clear; m_BorderColor0 = Color.clear; m_BorderToColor = Color.clear; @@ -164,6 +166,14 @@ namespace XCharts.Runtime set { if (PropertyUtil.SetStruct(ref m_BorderWidth, value)) SetVerticesDirty(); } } /// + /// 边框间隙。 + /// + public float borderGap + { + get { return m_BorderGap; } + set { if (PropertyUtil.SetStruct(ref m_BorderGap, value)) SetVerticesDirty(); } + } + /// /// 透明度。支持从 0 到 1 的数字,为 0 时不绘制该图形。 /// public float opacity @@ -326,14 +336,11 @@ namespace XCharts.Runtime } return color; } - } - public static class ItemStyleHelper - { - public static bool IsNeedCorner(ItemStyle itemStyle) + public bool IsNeedCorner() { - if (itemStyle.cornerRadius == null) return false; - foreach (var value in itemStyle.cornerRadius) + if (m_CornerRadius == null) return false; + foreach (var value in m_CornerRadius) { if (value != 0) return true; } diff --git a/Runtime/Serie/Bar/BarHandler.cs b/Runtime/Serie/Bar/BarHandler.cs index 998fb616..005e9bd6 100644 --- a/Runtime/Serie/Bar/BarHandler.cs +++ b/Runtime/Serie/Bar/BarHandler.cs @@ -11,6 +11,7 @@ namespace XCharts.Runtime { List> m_StackSerieData = new List>(); private GridCoord m_SerieGrid; + private float[] m_CapusleDefaultCornerRadius = new float[] { 1, 1, 1, 1 }; public override void Update() { @@ -200,6 +201,8 @@ namespace XCharts.Runtime var value = axis.IsCategory() ? i : serieData.GetData(0, axis.inverse); var relativedValue = serieData.GetCurrData(1, dataChangeDuration, relativedAxis.inverse, yMinValue, yMaxValue); var borderWidth = relativedValue == 0 ? 0 : itemStyle.runtimeBorderWidth; + var borderGap = relativedValue == 0 ? 0 : itemStyle.borderGap; + var borderGapAndWidth = borderWidth + borderGap; if (!serieData.interact.TryGetColor(ref areaColor, ref areaToColor, ref interacting)) { @@ -228,27 +231,30 @@ namespace XCharts.Runtime out plb, out plt, out prt, out prb, out top); serieData.context.stackHeight = barHig; serieData.context.position = top; - serieData.context.rect = Rect.MinMaxRect(plb.x, plb.y, prb.x, prt.y); + serieData.context.rect = Rect.MinMaxRect(plb.x + borderGapAndWidth, plb.y + borderGapAndWidth, + prt.x - borderGapAndWidth, prt.y - borderGapAndWidth); + serieData.context.backgroundRect = isY + ? Rect.MinMaxRect(m_SerieGrid.context.x, plb.y, m_SerieGrid.context.x + relativedAxisLength, prt.y) + : Rect.MinMaxRect(plb.x, m_SerieGrid.context.y, prb.x, m_SerieGrid.context.y + relativedAxisLength); + if (!serie.clip || (serie.clip && m_SerieGrid.Contains(top))) serie.context.dataPoints.Add(top); else continue; + if (serie.show && currHig != 0 && !serie.placeHolder) { switch (serie.barType) { case BarType.Normal: + case BarType.Capsule: DrawNormalBar(vh, serie, serieData, itemStyle, colorIndex, highlight, gap, barWidth, - pX, pY, plb, plt, prt, prb, isY, m_SerieGrid, axis, areaColor, areaToColor); + pX, pY, plb, plt, prt, prb, isY, m_SerieGrid, axis, areaColor, areaToColor, relativedValue); break; case BarType.Zebra: DrawZebraBar(vh, serie, serieData, itemStyle, colorIndex, highlight, gap, barWidth, pX, pY, plb, plt, prt, prb, isY, m_SerieGrid, axis, areaColor, areaToColor); break; - case BarType.Capsule: - DrawCapsuleBar(vh, serie, serieData, itemStyle, colorIndex, highlight, gap, barWidth, - pX, pY, plb, plt, prt, prb, isY, m_SerieGrid, axis, areaColor, areaToColor); - break; } } if (serie.animation.CheckDetailBreak(top, isY)) @@ -324,37 +330,37 @@ namespace XCharts.Runtime { if (yValue < 0) { - plt = new Vector3(pX - borderWidth, pY + gap + barWidth - borderWidth); - prt = new Vector3(pX + currHig + borderWidth, pY + gap + barWidth - borderWidth); - prb = new Vector3(pX + currHig + borderWidth, pY + gap + borderWidth); - plb = new Vector3(pX - borderWidth, pY + gap + borderWidth); + plt = new Vector3(pX + currHig, pY + gap + barWidth); + prt = new Vector3(pX, pY + gap + barWidth); + prb = new Vector3(pX, pY + gap); + plb = new Vector3(pX + currHig, pY + gap); } else { - plt = new Vector3(pX + borderWidth, pY + gap + barWidth - borderWidth); - prt = new Vector3(pX + currHig - borderWidth, pY + gap + barWidth - borderWidth); - prb = new Vector3(pX + currHig - borderWidth, pY + gap + borderWidth); - plb = new Vector3(pX + borderWidth, pY + gap + borderWidth); + plt = new Vector3(pX, pY + gap + barWidth); + prt = new Vector3(pX + currHig, pY + gap + barWidth); + prb = new Vector3(pX + currHig, pY + gap); + plb = new Vector3(pX, pY + gap); } - top = new Vector3(pX + currHig - borderWidth, pY + gap + barWidth / 2); + top = new Vector3(pX + currHig, pY + gap + barWidth / 2); } else { if (yValue < 0) { - plb = new Vector3(pX + gap + borderWidth, pY - borderWidth); - plt = new Vector3(pX + gap + borderWidth, pY + currHig - borderWidth); - prt = new Vector3(pX + gap + barWidth - borderWidth, pY + currHig - borderWidth); - prb = new Vector3(pX + gap + barWidth - borderWidth, pY - borderWidth); + plb = new Vector3(pX + gap, pY + currHig); + plt = new Vector3(pX + gap, pY); + prt = new Vector3(pX + gap + barWidth, pY); + prb = new Vector3(pX + gap + barWidth, pY + currHig); } else { - plb = new Vector3(pX + gap + borderWidth, pY + borderWidth); - plt = new Vector3(pX + gap + borderWidth, pY + currHig - borderWidth); - prt = new Vector3(pX + gap + barWidth - borderWidth, pY + currHig - borderWidth); - prb = new Vector3(pX + gap + barWidth - borderWidth, pY + borderWidth); + plb = new Vector3(pX + gap, pY); + plt = new Vector3(pX + gap, pY + currHig); + prt = new Vector3(pX + gap + barWidth, pY + currHig); + prb = new Vector3(pX + gap + barWidth, pY); } - top = new Vector3(pX + gap + barWidth / 2, pY + currHig - borderWidth); + top = new Vector3(pX + gap + barWidth / 2, pY + currHig); } if (serie.clip) { @@ -368,66 +374,30 @@ namespace XCharts.Runtime private void DrawNormalBar(VertexHelper vh, Serie serie, SerieData serieData, ItemStyle itemStyle, int colorIndex, bool highlight, float gap, float barWidth, float pX, float pY, Vector3 plb, Vector3 plt, Vector3 prt, - Vector3 prb, bool isYAxis, GridCoord grid, Axis axis, Color32 areaColor, Color32 areaToColor) + Vector3 prb, bool isYAxis, GridCoord grid, Axis axis, Color32 areaColor, Color32 areaToColor, double value) { - DrawBarBackground(vh, serie, serieData, itemStyle, colorIndex, highlight, pX, pY, gap, barWidth, isYAxis, grid, axis); var borderWidth = itemStyle.runtimeBorderWidth; - if (isYAxis) + var backgroundColor = SerieHelper.GetItemBackgroundColor(serie, serieData, chart.theme, colorIndex, highlight, false); + var cornerRadius = serie.barType == BarType.Capsule && !itemStyle.IsNeedCorner() + ? m_CapusleDefaultCornerRadius + : itemStyle.cornerRadius; + var invert = value < 0; + if (!ChartHelper.IsClearColor(backgroundColor)) { - if (serie.clip) - { - prb = chart.ClampInGrid(grid, prb); - plb = chart.ClampInGrid(grid, plb); - plt = chart.ClampInGrid(grid, plt); - prt = chart.ClampInGrid(grid, prt); - } - var itemWidth = Mathf.Abs(prb.x - plt.x); - var itemHeight = Mathf.Abs(prt.y - plb.y); - 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, chart.settings.cicleSmoothness, invert); - } - else - { - chart.DrawClipPolygon(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, chart.settings.cicleSmoothness, invert); - } + UGL.DrawRoundRectangle(vh, serieData.context.backgroundRect, backgroundColor, backgroundColor, 0, + cornerRadius, isYAxis, chart.settings.cicleSmoothness, invert); + } + UGL.DrawRoundRectangle(vh, serieData.context.rect, areaColor, areaToColor, 0, + cornerRadius, isYAxis, chart.settings.cicleSmoothness, invert); + if (serie.barType == BarType.Capsule) + { + UGL.DrawBorder(vh, serieData.context.backgroundRect, borderWidth, itemStyle.borderColor, + 0, cornerRadius, isYAxis, chart.settings.cicleSmoothness, invert, -borderWidth); } else { - if (serie.clip) - { - prb = chart.ClampInGrid(grid, prb); - plb = chart.ClampInGrid(grid, plb); - plt = chart.ClampInGrid(grid, plt); - prt = chart.ClampInGrid(grid, prt); - } - var itemWidth = Mathf.Abs(prt.x - plb.x); - var itemHeight = Mathf.Abs(plt.y - prb.y); - 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, chart.settings.cicleSmoothness, invert); - } - else - { - chart.DrawClipPolygon(vh, ref prb, ref plb, ref plt, ref prt, areaColor, areaToColor, - serie.clip, grid); - } - UGL.DrawBorder(vh, center, itemWidth, itemHeight, borderWidth, itemStyle.borderColor, - itemStyle.borderToColor, 0, itemStyle.cornerRadius, isYAxis, chart.settings.cicleSmoothness, invert); - } + UGL.DrawBorder(vh, serieData.context.rect, borderWidth, itemStyle.borderColor, + 0, cornerRadius, isYAxis, chart.settings.cicleSmoothness, invert, itemStyle.borderGap); } } @@ -435,7 +405,12 @@ namespace XCharts.Runtime bool highlight, float gap, float barWidth, float pX, float pY, Vector3 plb, Vector3 plt, Vector3 prt, Vector3 prb, bool isYAxis, GridCoord grid, Axis axis, Color32 barColor, Color32 barToColor) { - DrawBarBackground(vh, serie, serieData, itemStyle, colorIndex, highlight, pX, pY, gap, barWidth, isYAxis, grid, axis); + var backgroundColor = SerieHelper.GetItemBackgroundColor(serie, serieData, chart.theme, colorIndex, highlight, false); + if (!ChartHelper.IsClearColor(backgroundColor)) + { + UGL.DrawRoundRectangle(vh, serieData.context.backgroundRect, backgroundColor, backgroundColor, 0, + null, isYAxis, chart.settings.cicleSmoothness, false); + } if (isYAxis) { plt = (plb + plt) / 2; @@ -451,212 +426,5 @@ namespace XCharts.Runtime barColor, barToColor, serie.clip, grid, grid.context.height); } } - - private void DrawCapsuleBar(VertexHelper vh, Serie serie, SerieData serieData, ItemStyle itemStyle, int colorIndex, - bool highlight, float gap, float barWidth, float pX, float pY, Vector3 plb, Vector3 plt, Vector3 prt, - Vector3 prb, bool isYAxis, GridCoord grid, Axis axis, Color32 areaColor, Color32 areaToColor) - { - DrawBarBackground(vh, serie, serieData, itemStyle, colorIndex, highlight, pX, pY, gap, barWidth, isYAxis, grid, axis); - var borderWidth = itemStyle.runtimeBorderWidth; - var radius = barWidth / 2 - borderWidth; - var isGradient = !ChartHelper.IsValueEqualsColor(areaColor, areaToColor); - if (isYAxis) - { - var diff = Vector3.right * radius; - if (plt.x < prt.x) - { - var pcl = (plt + plb) / 2 + diff; - var pcr = (prt + prb) / 2 - diff; - if (pcr.x > pcl.x) - { - if (isGradient) - { - var barLen = prt.x - plt.x; - var rectStartColor = Color32.Lerp(areaColor, areaToColor, radius / barLen); - var rectEndColor = Color32.Lerp(areaColor, areaToColor, (barLen - radius) / barLen); - chart.DrawClipPolygon(vh, plb + diff, plt + diff, prt - diff, prb - diff, rectStartColor, - rectEndColor, serie.clip, grid); - UGL.DrawSector(vh, pcl, radius, areaColor, rectStartColor, 180, 360, 1, isYAxis); - UGL.DrawSector(vh, pcr, radius, rectEndColor, areaToColor, 0, 180, 1, isYAxis); - } - else - { - chart.DrawClipPolygon(vh, plb + diff, plt + diff, prt - diff, prb - diff, areaColor, - areaToColor, serie.clip, grid); - UGL.DrawSector(vh, pcl, radius, areaColor, 180, 360); - UGL.DrawSector(vh, pcr, radius, areaToColor, 0, 180); - } - } - } - else if (plt.x > prt.x) - { - var pcl = (plt + plb) / 2 - diff; - var pcr = (prt + prb) / 2 + diff; - if (pcr.x < pcl.x) - { - if (isGradient) - { - var barLen = plt.x - prt.x; - var rectStartColor = Color32.Lerp(areaColor, areaToColor, radius / barLen); - var rectEndColor = Color32.Lerp(areaColor, areaToColor, (barLen - radius) / barLen); - chart.DrawClipPolygon(vh, plb - diff, plt - diff, prt + diff, prb + diff, rectStartColor, - rectEndColor, serie.clip, grid); - UGL.DrawSector(vh, pcl, radius, rectStartColor, areaColor, 0, 180, 1, isYAxis); - UGL.DrawSector(vh, pcr, radius, areaToColor, rectEndColor, 180, 360, 1, isYAxis); - } - else - { - chart.DrawClipPolygon(vh, plb - diff, plt - diff, prt + diff, prb + diff, areaColor, - areaToColor, serie.clip, grid); - UGL.DrawSector(vh, pcl, radius, areaColor, 0, 180); - UGL.DrawSector(vh, pcr, radius, areaToColor, 180, 360); - } - } - } - } - else - { - var diff = Vector3.up * radius; - if (plt.y > plb.y) - { - var pct = (plt + prt) / 2 - diff; - var pcb = (plb + prb) / 2 + diff; - if (pct.y > pcb.y) - { - if (isGradient) - { - var barLen = plt.y - plb.y; - var rectStartColor = Color32.Lerp(areaColor, areaToColor, radius / barLen); - var rectEndColor = Color32.Lerp(areaColor, areaToColor, (barLen - radius) / barLen); - chart.DrawClipPolygon(vh, prb + diff, plb + diff, plt - diff, prt - diff, rectStartColor, - rectEndColor, serie.clip, grid); - UGL.DrawSector(vh, pct, radius, rectEndColor, areaToColor, 270, 450, 1, isYAxis); - UGL.DrawSector(vh, pcb, radius, rectStartColor, areaColor, 90, 270, 1, isYAxis); - } - else - { - chart.DrawClipPolygon(vh, prb + diff, plb + diff, plt - diff, prt - diff, areaColor, - areaToColor, serie.clip, grid); - UGL.DrawSector(vh, pct, radius, areaToColor, 270, 450); - UGL.DrawSector(vh, pcb, radius, areaColor, 90, 270); - } - } - } - else if (plt.y < plb.y) - { - var pct = (plt + prt) / 2 + diff; - var pcb = (plb + prb) / 2 - diff; - if (pct.y < pcb.y) - { - if (isGradient) - { - var barLen = plb.y - plt.y; - var rectStartColor = Color32.Lerp(areaColor, areaToColor, radius / barLen); - var rectEndColor = Color32.Lerp(areaColor, areaToColor, (barLen - radius) / barLen); - chart.DrawClipPolygon(vh, prb - diff, plb - diff, plt + diff, prt + diff, rectStartColor, - rectEndColor, serie.clip, grid); - UGL.DrawSector(vh, pct, radius, rectEndColor, areaToColor, 90, 270, 1, isYAxis); - UGL.DrawSector(vh, pcb, radius, rectStartColor, areaColor, 270, 450, 1, isYAxis); - } - else - { - chart.DrawClipPolygon(vh, prb - diff, plb - diff, plt + diff, prt + diff, areaColor, - areaToColor, serie.clip, grid); - UGL.DrawSector(vh, pct, radius, areaToColor, 90, 270); - UGL.DrawSector(vh, pcb, radius, areaColor, 270, 450); - } - } - } - } - } - - private void DrawBarBackground(VertexHelper vh, Serie serie, SerieData serieData, ItemStyle itemStyle, - int colorIndex, bool highlight, float pX, float pY, float gap, float barWidth, bool isYAxis, - GridCoord grid, Axis axis) - { - var color = SerieHelper.GetItemBackgroundColor(serie, serieData, chart.theme, colorIndex, highlight, false); - if (ChartHelper.IsClearColor(color)) return; - if (isYAxis) - { - var axisWidth = axis.axisLine.GetWidth(chart.theme.axis.lineWidth); - Vector3 plt = new Vector3(grid.context.x + axisWidth, pY + gap + barWidth); - Vector3 prt = new Vector3(grid.context.x + axisWidth + grid.context.width, pY + gap + barWidth); - Vector3 prb = new Vector3(grid.context.x + axisWidth + grid.context.width, pY + gap); - Vector3 plb = new Vector3(grid.context.x + axisWidth, pY + gap); - if (serie.barType == BarType.Capsule) - { - var radius = barWidth / 2; - var diff = Vector3.right * radius; - var pcl = (plt + plb) / 2 + diff; - var pcr = (prt + prb) / 2 - diff; - chart.DrawClipPolygon(vh, plb + diff, plt + diff, prt - diff, prb - diff, color, color, serie.clip, grid); - UGL.DrawSector(vh, pcl, radius, color, 180, 360); - UGL.DrawSector(vh, pcr, radius, color, 0, 180); - if (itemStyle.NeedShowBorder()) - { - var borderWidth = itemStyle.borderWidth; - var borderColor = itemStyle.borderColor; - var smoothness = chart.settings.cicleSmoothness; - var inRadius = radius - borderWidth; - var outRadius = radius; - var p1 = plb + diff + Vector3.up * borderWidth / 2; - var p2 = prb - diff + Vector3.up * borderWidth / 2; - var p3 = plt + diff - Vector3.up * borderWidth / 2; - var p4 = prt - diff - Vector3.up * borderWidth / 2; - UGL.DrawLine(vh, p1, p2, borderWidth / 2, borderColor); - UGL.DrawLine(vh, p3, p4, borderWidth / 2, borderColor); - UGL.DrawDoughnut(vh, pcl, inRadius, outRadius, borderColor, ChartConst.clearColor32, - 180, 360, smoothness); - UGL.DrawDoughnut(vh, pcr, inRadius, outRadius, borderColor, ChartConst.clearColor32, - 0, 180, smoothness); - } - } - else - { - chart.DrawClipPolygon(vh, ref plb, ref plt, ref prt, ref prb, color, color, serie.clip, grid); - } - } - else - { - var axisWidth = axis.axisLine.GetWidth(chart.theme.axis.lineWidth); - Vector3 plb = new Vector3(pX + gap, grid.context.y + axisWidth); - Vector3 plt = new Vector3(pX + gap, grid.context.y + grid.context.height + axisWidth); - Vector3 prt = new Vector3(pX + gap + barWidth, grid.context.y + grid.context.height + axisWidth); - Vector3 prb = new Vector3(pX + gap + barWidth, grid.context.y + axisWidth); - if (serie.barType == BarType.Capsule) - { - var radius = barWidth / 2; - var diff = Vector3.up * radius; - var pct = (plt + prt) / 2 - diff; - var pcb = (plb + prb) / 2 + diff; - chart.DrawClipPolygon(vh, prb + diff, plb + diff, plt - diff, prt - diff, color, color, - serie.clip, grid); - UGL.DrawSector(vh, pct, radius, color, 270, 450); - UGL.DrawSector(vh, pcb, radius, color, 90, 270); - if (itemStyle.NeedShowBorder()) - { - var borderWidth = itemStyle.borderWidth; - var borderColor = itemStyle.borderColor; - var smoothness = chart.settings.cicleSmoothness; - var inRadius = radius - borderWidth; - var outRadius = radius; - var p1 = plb + diff + Vector3.right * borderWidth / 2; - var p2 = plt - diff + Vector3.right * borderWidth / 2; - var p3 = prb + diff - Vector3.right * borderWidth / 2; - var p4 = prt - diff - Vector3.right * borderWidth / 2; - UGL.DrawLine(vh, p1, p2, borderWidth / 2, borderColor); - UGL.DrawLine(vh, p3, p4, borderWidth / 2, borderColor); - UGL.DrawDoughnut(vh, pct, inRadius, outRadius, borderColor, ChartConst.clearColor32, - 270, 450, smoothness); - UGL.DrawDoughnut(vh, pcb, inRadius, outRadius, borderColor, ChartConst.clearColor32, - 90, 270, smoothness); - } - } - else - { - chart.DrawClipPolygon(vh, ref prb, ref plb, ref plt, ref prt, color, color, serie.clip, grid); - } - } - } } } \ No newline at end of file diff --git a/Runtime/Serie/Bar/SimplifiedBarHandler.cs b/Runtime/Serie/Bar/SimplifiedBarHandler.cs index fe1820a4..342ed8d8 100644 --- a/Runtime/Serie/Bar/SimplifiedBarHandler.cs +++ b/Runtime/Serie/Bar/SimplifiedBarHandler.cs @@ -321,7 +321,7 @@ namespace XCharts.Runtime if (itemWidth > 0 && itemHeight > 0) { var invert = center.x < plb.x; - if (ItemStyleHelper.IsNeedCorner(itemStyle)) + if (itemStyle.IsNeedCorner()) { UGL.DrawRoundRectangle(vh, center, itemWidth, itemHeight, areaColor, areaToColor, 0, itemStyle.cornerRadius, isYAxis, chart.settings.cicleSmoothness, invert); @@ -349,7 +349,7 @@ namespace XCharts.Runtime if (itemWidth > 0 && itemHeight > 0) { var invert = center.y < plb.y; - if (ItemStyleHelper.IsNeedCorner(itemStyle)) + if (itemStyle.IsNeedCorner()) { UGL.DrawRoundRectangle(vh, center, itemWidth, itemHeight, areaColor, areaToColor, 0, itemStyle.cornerRadius, isYAxis, chart.settings.cicleSmoothness, invert); diff --git a/Runtime/Serie/Candlestick/CandlestickHandler.cs b/Runtime/Serie/Candlestick/CandlestickHandler.cs index 3ffdd8c4..a66f0de0 100644 --- a/Runtime/Serie/Candlestick/CandlestickHandler.cs +++ b/Runtime/Serie/Candlestick/CandlestickHandler.cs @@ -171,7 +171,7 @@ namespace XCharts.Runtime { if (itemWidth > 0 && itemHeight > 0) { - if (ItemStyleHelper.IsNeedCorner(itemStyle)) + if (itemStyle.IsNeedCorner()) { UGL.DrawRoundRectangle(vh, center, itemWidth, itemHeight, areaColor, areaColor, 0, itemStyle.cornerRadius, isYAxis, 0.5f); diff --git a/Runtime/Serie/Candlestick/SimplifiedCandlestickHandler.cs b/Runtime/Serie/Candlestick/SimplifiedCandlestickHandler.cs index df9d7c9f..94afc492 100644 --- a/Runtime/Serie/Candlestick/SimplifiedCandlestickHandler.cs +++ b/Runtime/Serie/Candlestick/SimplifiedCandlestickHandler.cs @@ -171,7 +171,7 @@ namespace XCharts.Runtime { if (itemWidth > 0 && itemHeight > 0) { - if (ItemStyleHelper.IsNeedCorner(itemStyle)) + if (itemStyle.IsNeedCorner()) { UGL.DrawRoundRectangle(vh, center, itemWidth, itemHeight, areaColor, areaColor, 0, itemStyle.cornerRadius, isYAxis, 0.5f); diff --git a/Runtime/Serie/SerieDataContext.cs b/Runtime/Serie/SerieDataContext.cs index 319b6f1d..fea5bac3 100644 --- a/Runtime/Serie/SerieDataContext.cs +++ b/Runtime/Serie/SerieDataContext.cs @@ -40,6 +40,7 @@ namespace XCharts.Runtime /// 绘制区域。 /// public Rect rect; + public Rect backgroundRect; public Rect subRect; public int level; public SerieData parent; diff --git a/Runtime/XUGL/UGL.cs b/Runtime/XUGL/UGL.cs index 44ebe653..e53590be 100644 --- a/Runtime/XUGL/UGL.cs +++ b/Runtime/XUGL/UGL.cs @@ -723,6 +723,14 @@ namespace XUGL } } + public static void DrawRoundRectangle(VertexHelper vh, Rect rect, + Color32 color, Color32 toColor, float rotate = 0, float[] cornerRadius = null, bool isYAxis = false, + float smoothness = 2, bool invert = false) + { + DrawRoundRectangle(vh, rect.center, rect.width, rect.height, color, toColor, rotate, cornerRadius, + isYAxis, smoothness, invert); + } + /// /// 绘制圆角矩形 /// @@ -734,19 +742,25 @@ 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, bool invertCorner = false) + Color32 color, Color32 toColor, float rotate = 0, float[] cornerRadius = null, bool horizontal = false, + float smoothness = 2, bool invert = false) { + if (invert) + { + var temp = toColor; + toColor = color; + color = temp; + } 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, invertCorner, ref brLt, ref brRt, ref brRb, + InitCornerRadius(cornerRadius, rectWidth, rectHeight, horizontal, invert, ref brLt, ref brRt, ref brRb, ref brLb, ref needRound); var tempCenter = Vector3.zero; var lbIn = new Vector3(center.x - halfWid, center.y - halfHig); @@ -788,7 +802,7 @@ namespace XUGL lbIn2 = roundLb + brLb * Vector3.down; } - if (isYAxis) + if (horizontal) { var maxLeft = Mathf.Max(brLt, brLb); var maxRight = Mathf.Max(brRt, brRb); @@ -818,10 +832,10 @@ namespace XUGL if (roundRbLeft.x < roundLb.x) roundRbLeft.x = roundLb.x; if (!isGradient) { - DrawSector(vh, roundLt, brLt, color, color, 270, 360, 1, isYAxis, smoothness); - DrawSector(vh, roundRt, brRt, toColor, toColor, 0, 90, 1, isYAxis, smoothness); - DrawSector(vh, roundRb, brRb, toColor, toColor, 90, 180, 1, isYAxis, smoothness); - DrawSector(vh, roundLb, brLb, color, color, 180, 270, 1, isYAxis, smoothness); + DrawSector(vh, roundLt, brLt, color, color, 270, 360, 1, horizontal, smoothness); + DrawSector(vh, roundRt, brRt, toColor, toColor, 0, 90, 1, horizontal, smoothness); + DrawSector(vh, roundRb, brRb, toColor, toColor, 90, 180, 1, horizontal, smoothness); + DrawSector(vh, roundLb, brLb, color, color, 180, 270, 1, horizontal, smoothness); DrawQuadrilateral(vh, ltIn, ltInRight, lbInRight, lbIn, color, color); DrawQuadrilateral(vh, lbIn2, roundLb, roundLbRight, lbIn2Right, color, color); @@ -850,10 +864,10 @@ namespace XUGL var upRightColor = Color32.Lerp(tempRightColor, toColor, (maxRight - brRt) / maxRight); var downRightColor = Color32.Lerp(tempRightColor, toColor, (maxRight - brRb) / maxRight); - DrawSector(vh, roundLt, brLt, color, upLeftColor, 270, 360, 1, isYAxis, smoothness); - DrawSector(vh, roundRt, brRt, upRightColor, toColor, 0, 90, 1, isYAxis, smoothness); - DrawSector(vh, roundRb, brRb, downRightColor, toColor, 90, 180, 1, isYAxis, smoothness); - DrawSector(vh, roundLb, brLb, color, downLeftColor, 180, 270, 1, isYAxis, smoothness); + DrawSector(vh, roundLt, brLt, color, upLeftColor, 270, 360, 1, horizontal, smoothness); + DrawSector(vh, roundRt, brRt, upRightColor, toColor, 0, 90, 1, horizontal, smoothness); + DrawSector(vh, roundRb, brRb, downRightColor, toColor, 90, 180, 1, horizontal, smoothness); + DrawSector(vh, roundLb, brLb, color, downLeftColor, 180, 270, 1, horizontal, smoothness); DrawQuadrilateral(vh, lbIn, ltIn, ltInRight, lbInRight, color, tempLeftColor); DrawQuadrilateral(vh, lbIn2, roundLb, roundLbRight, lbIn2Right, downLeftColor, @@ -912,10 +926,10 @@ namespace XUGL if (!isGradient) { - DrawSector(vh, roundLt, brLt, toColor, toColor, 270, 360, 1, isYAxis, smoothness); - DrawSector(vh, roundRt, brRt, toColor, toColor, 0, 90, 1, isYAxis, smoothness); - DrawSector(vh, roundRb, brRb, color, color, 90, 180, 1, isYAxis, smoothness); - DrawSector(vh, roundLb, brLb, color, color, 180, 270, 1, isYAxis, smoothness); + DrawSector(vh, roundLt, brLt, toColor, toColor, 270, 360, 1, horizontal, smoothness); + DrawSector(vh, roundRt, brRt, toColor, toColor, 0, 90, 1, horizontal, smoothness); + DrawSector(vh, roundRb, brRb, color, color, 90, 180, 1, horizontal, smoothness); + DrawSector(vh, roundLb, brLb, color, color, 180, 270, 1, horizontal, smoothness); DrawQuadrilateral(vh, ltIn2, rtIn, rtInDown, ltIn2Down, toColor, toColor); DrawQuadrilateral(vh, ltIn, roundLt, roundLtDown, ltInDown, toColor, toColor); @@ -938,10 +952,10 @@ namespace XUGL var leftDownColor = Color32.Lerp(color, tempDownColor, brLb / maxdown); var rightDownColor = Color32.Lerp(color, tempDownColor, brRb / maxdown); - DrawSector(vh, roundLt, brLt, leftUpColor, toColor, 270, 360, 1, isYAxis, smoothness); - DrawSector(vh, roundRt, brRt, rightUpColor, toColor, 0, 90, 1, isYAxis, smoothness); - DrawSector(vh, roundRb, brRb, rightDownColor, color, 90, 180, 1, isYAxis, smoothness); - DrawSector(vh, roundLb, brLb, leftDownColor, color, 180, 270, 1, isYAxis, smoothness); + DrawSector(vh, roundLt, brLt, leftUpColor, toColor, 270, 360, 1, horizontal, smoothness); + DrawSector(vh, roundRt, brRt, rightUpColor, toColor, 0, 90, 1, horizontal, smoothness); + DrawSector(vh, roundRb, brRb, rightDownColor, color, 90, 180, 1, horizontal, smoothness); + DrawSector(vh, roundLb, brLb, leftDownColor, color, 180, 270, 1, horizontal, smoothness); DrawQuadrilateral(vh, ltIn2, rtIn, rtInDown, ltIn2Down, toColor, tempUpColor); DrawQuadrilateral(vh, ltIn, roundLt, roundLtDown, ltInDown, leftUpColor, @@ -963,10 +977,10 @@ namespace XUGL } else { - if (isYAxis) + if (horizontal) DrawQuadrilateral(vh, lbIn, ltIn, rtIn, rbIn, color, toColor); else - DrawQuadrilateral(vh, lbIn, ltIn, rtIn, rbIn, toColor, color); + DrawQuadrilateral(vh, rbIn, lbIn, ltIn, rtIn, color, toColor); } } @@ -982,12 +996,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 invertCorner = false) + bool horizontal = false, float smoothness = 1f, bool invertCorner = false, float extWidth = 0) { DrawBorder(vh, center, rectWidth, rectHeight, borderWidth, color, s_ClearColor32, rotate, - cornerRadius, horizontal, smoothness, invertCorner); + cornerRadius, horizontal, smoothness, invertCorner, extWidth); } /// @@ -1002,12 +1017,13 @@ namespace XUGL /// /// /// + /// public static void DrawBorder(VertexHelper vh, Rect rect, float borderWidth, Color32 color, float rotate = 0, float[] cornerRadius = null, - bool horizontal = false, float smoothness = 1f, bool invertCorner = false) + bool horizontal = false, float smoothness = 1f, bool invertCorner = false, float extWidth = 0) { DrawBorder(vh, rect.center, rect.width, rect.height, borderWidth, color, s_ClearColor32, rotate, - cornerRadius, horizontal, smoothness, invertCorner); + cornerRadius, horizontal, smoothness, invertCorner, extWidth); } /// @@ -1025,9 +1041,10 @@ 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 invertCorner = false) + bool horizontal = false, float smoothness = 1f, bool invertCorner = false, float extWidth = 0) { if (borderWidth == 0 || UGLHelper.IsClearColor(color)) return; var halfWid = rectWidth / 2; @@ -1059,9 +1076,10 @@ namespace XUGL var rtOt2 = rtOt; var rbIn2 = rbIn; var rbOt2 = rbOt; - if (brLt > 0) + //if (brLt > 0) { tempCenter = new Vector3(center.x - halfWid + brLt, center.y + halfHig - brLt); + brLt += extWidth; DrawDoughnut(vh, tempCenter, brLt, brLt + borderWidth, horizontal ? color : toColor, s_ClearColor32, 270, 360, smoothness); ltIn = tempCenter + brLt * Vector3.left; @@ -1069,18 +1087,20 @@ namespace XUGL ltIn2 = tempCenter + brLt * Vector3.up; ltOt2 = tempCenter + (brLt + borderWidth) * Vector3.up; } - if (brRt > 0) + //if (brRt > 0) { tempCenter = new Vector3(center.x + halfWid - brRt, center.y + halfHig - brRt); + brRt += extWidth; DrawDoughnut(vh, tempCenter, brRt, brRt + borderWidth, toColor, s_ClearColor32, 0, 90, smoothness); rtIn = tempCenter + brRt * Vector3.up; rtOt = tempCenter + (brRt + borderWidth) * Vector3.up; rtIn2 = tempCenter + brRt * Vector3.right; rtOt2 = tempCenter + (brRt + borderWidth) * Vector3.right; } - if (brRb > 0) + //if (brRb > 0) { tempCenter = new Vector3(center.x + halfWid - brRb, center.y - halfHig + brRb); + brRb += extWidth; DrawDoughnut(vh, tempCenter, brRb, brRb + borderWidth, horizontal ? toColor : color, s_ClearColor32, 90, 180, smoothness); rbIn = tempCenter + brRb * Vector3.right; @@ -1088,9 +1108,10 @@ namespace XUGL rbIn2 = tempCenter + brRb * Vector3.down; rbOt2 = tempCenter + (brRb + borderWidth) * Vector3.down; } - if (brLb > 0) + //if (brLb > 0) { tempCenter = new Vector3(center.x - halfWid + brLb, center.y - halfHig + brLb); + brLb += extWidth; DrawDoughnut(vh, tempCenter, brLb, brLb + borderWidth, color, s_ClearColor32, 180, 270, smoothness); lbIn = tempCenter + brLb * Vector3.left; lbOt = tempCenter + (brLb + borderWidth) * Vector3.left;