diff --git a/Documentation~/zh/changelog.md b/Documentation~/zh/changelog.md index b01e6d4e..6a0ef0e6 100644 --- a/Documentation~/zh/changelog.md +++ b/Documentation~/zh/changelog.md @@ -74,6 +74,7 @@ slug: /changelog 日志详情: +* (2023.07.31) 增加`Symbol`的`EmptyTriangle`和`EmptyDiamond`的支持,优化`Symbol`表现效果 * (2023.07.31) 优化`Line`的默认配置效果 * (2023.07.27) 增加`Serie`的`minRadius`可设置最小半径 * (2023.07.26) 增加`MLValue`多样式数值 diff --git a/Runtime/Component/Label/LabelLine.cs b/Runtime/Component/Label/LabelLine.cs index 3f48c53f..02363a05 100644 --- a/Runtime/Component/Label/LabelLine.cs +++ b/Runtime/Component/Label/LabelLine.cs @@ -31,7 +31,7 @@ namespace XCharts.Runtime [SerializeField] private bool m_Show = true; [SerializeField] private LineType m_LineType = LineType.BrokenLine; [SerializeField] private Color32 m_LineColor = ChartConst.clearColor32; - [SerializeField] private float m_LineAngle = 0; + [SerializeField] private float m_LineAngle = 60; [SerializeField] private float m_LineWidth = 1.0f; [SerializeField] private float m_LineGap = 1.0f; [SerializeField] private float m_LineLength1 = 25f; @@ -44,7 +44,7 @@ namespace XCharts.Runtime m_Show = false; m_LineType = LineType.BrokenLine; m_LineColor = Color.clear; - m_LineAngle = 0; + m_LineAngle = 60; m_LineWidth = 1.0f; m_LineGap = 1.0f; m_LineLength1 = 25f; diff --git a/Runtime/Internal/Utilities/ChartDrawer.cs b/Runtime/Internal/Utilities/ChartDrawer.cs index 69b7e2c5..c4b6e42b 100644 --- a/Runtime/Internal/Utilities/ChartDrawer.cs +++ b/Runtime/Internal/Utilities/ChartDrawer.cs @@ -49,53 +49,92 @@ namespace XCharts.Runtime { if (tickness > 0) { - UGL.DrawRoundRectangle(vh, pos, symbolSize, symbolSize, color, color, 0, cornerRadius, true); + UGL.DrawRoundRectangle(vh, pos, symbolSize * 2, symbolSize * 2, color, color, 0, cornerRadius, true); UGL.DrawBorder(vh, pos, symbolSize, symbolSize, tickness, borderColor, 0, cornerRadius); } else - UGL.DrawRoundRectangle(vh, pos, symbolSize, symbolSize, color, color, 0, cornerRadius, true); + UGL.DrawRoundRectangle(vh, pos, symbolSize * 2, symbolSize * 2, color, color, 0, cornerRadius, true); } break; case SymbolType.EmptyRect: if (gap > 0) { UGL.DrawSquare(vh, pos, symbolSize + gap, backgroundColor); - UGL.DrawBorder(vh, pos, symbolSize / 2, symbolSize / 2, tickness, color); + UGL.DrawBorder(vh, pos, symbolSize * 2, symbolSize * 2, tickness, color); } else { - UGL.DrawBorder(vh, pos, symbolSize / 2, symbolSize / 2, tickness, color); + UGL.DrawBorder(vh, pos, symbolSize * 2 - tickness * 2, symbolSize * 2 - tickness * 2, tickness, color); } break; case SymbolType.Triangle: + case SymbolType.EmptyTriangle: if (gap > 0) { - UGL.DrawTriangle(vh, pos, symbolSize + gap, backgroundColor); - UGL.DrawTriangle(vh, pos, symbolSize, color, toColor); + UGL.DrawTriangle(vh, pos, symbolSize * 1.4f + gap * 2f, backgroundColor); + UGL.DrawTriangle(vh, pos, symbolSize * 1.4f, color, toColor); } else { - UGL.DrawTriangle(vh, pos, symbolSize, color, toColor); + UGL.DrawTriangle(vh, pos, symbolSize * 1.4f, color, toColor); + } + if (type == SymbolType.EmptyTriangle) + { + UGL.DrawTriangle(vh, pos, symbolSize * 1.4f - tickness * 2, backgroundColor); } break; case SymbolType.Diamond: + case SymbolType.EmptyDiamond: + var xRadius = symbolSize; + var yRadius = symbolSize * 1.5f; if (gap > 0) { - UGL.DrawDiamond(vh, pos, symbolSize + gap, backgroundColor); - UGL.DrawDiamond(vh, pos, symbolSize, color, toColor); + UGL.DrawDiamond(vh, pos, xRadius + gap, yRadius + gap, backgroundColor, backgroundColor); + UGL.DrawDiamond(vh, pos, xRadius, yRadius, color, toColor); } else { - UGL.DrawDiamond(vh, pos, symbolSize, color, toColor); + UGL.DrawDiamond(vh, pos, xRadius, yRadius, color, toColor); + } + if (type == SymbolType.EmptyDiamond) + { + UGL.DrawDiamond(vh, pos, xRadius - tickness, (symbolSize - tickness) * 1.5f, backgroundColor, backgroundColor); } break; case SymbolType.Arrow: + case SymbolType.EmptyArrow: var arrowWidth = symbolSize * 2; var arrowHeight = arrowWidth * 1.5f; var arrowOffset = 0; var arrowDent = arrowWidth / 3.3f; + if (gap > 0) + { + arrowWidth = (symbolSize + gap) * 2; + arrowHeight = arrowWidth * 1.5f; + arrowOffset = 0; + arrowDent = arrowWidth / 3.3f; + var dir = (pos - startPos).normalized; + var sharpPos = pos + gap * dir; + UGL.DrawArrow(vh, startPos, sharpPos, arrowWidth, arrowHeight, + arrowOffset, arrowDent, backgroundColor); + } + arrowWidth = symbolSize * 2; + arrowHeight = arrowWidth * 1.5f; + arrowOffset = 0; + arrowDent = arrowWidth / 3.3f; UGL.DrawArrow(vh, startPos, pos, arrowWidth, arrowHeight, arrowOffset, arrowDent, color); + if (type == SymbolType.EmptyArrow) + { + arrowWidth = (symbolSize - tickness) * 2; + arrowHeight = arrowWidth * 1.5f; + arrowOffset = 0; + arrowDent = arrowWidth / 3.3f; + var dir = (pos - startPos).normalized; + var sharpPos = pos - tickness * dir; + UGL.DrawArrow(vh, startPos, sharpPos, arrowWidth, arrowHeight, + arrowOffset, arrowDent, backgroundColor); + } break; } } diff --git a/Runtime/XUGL/UGL.cs b/Runtime/XUGL/UGL.cs index b35a9820..8dd86a63 100644 --- a/Runtime/XUGL/UGL.cs +++ b/Runtime/XUGL/UGL.cs @@ -443,10 +443,15 @@ namespace XUGL /// 渐变色2 public static void DrawDiamond(VertexHelper vh, Vector3 center, float size, Color32 color, Color32 toColor) { - var p1 = new Vector2(center.x - size, center.y); - var p2 = new Vector2(center.x, center.y + size); - var p3 = new Vector2(center.x + size, center.y); - var p4 = new Vector2(center.x, center.y - size); + DrawDiamond(vh, center, size, size, color, toColor); + } + + public static void DrawDiamond(VertexHelper vh, Vector3 center, float xRadius, float yRadius, Color32 color, Color32 toColor) + { + var p1 = new Vector2(center.x - xRadius, center.y); + var p2 = new Vector2(center.x, center.y + yRadius); + var p3 = new Vector2(center.x + xRadius, center.y); + var p4 = new Vector2(center.x, center.y - yRadius); DrawTriangle(vh, p4, p1, p2, color, color, toColor); DrawTriangle(vh, p3, p4, p2, color, color, toColor); } @@ -1327,7 +1332,7 @@ namespace XUGL if (gap > 0 && isCircle) gap = 0; radius -= borderWidth; smoothness = (smoothness < 0 ? 2f : smoothness); - int segments = (int) ((2 * Mathf.PI * radius) * (Mathf.Abs(toDegree - startDegree) / 360) / smoothness); + int segments = (int)((2 * Mathf.PI * radius) * (Mathf.Abs(toDegree - startDegree) / 360) / smoothness); if (segments < 1) segments = 1; float startAngle = startDegree * Mathf.Deg2Rad; float toAngle = toDegree * Mathf.Deg2Rad; @@ -1520,7 +1525,7 @@ namespace XUGL var needSpace = gap != 0; var diffAngle = Mathf.Abs(toDegree - startDegree) * Mathf.Deg2Rad; - int segments = (int) ((2 * Mathf.PI * outsideRadius) * (diffAngle * Mathf.Rad2Deg / 360) / smoothness); + int segments = (int)((2 * Mathf.PI * outsideRadius) * (diffAngle * Mathf.Rad2Deg / 360) / smoothness); if (segments < 1) segments = 1; float startAngle = startDegree * Mathf.Deg2Rad; float toAngle = toDegree * Mathf.Deg2Rad; @@ -1779,7 +1784,7 @@ namespace XUGL float lineWidth, Color32 lineColor, float smoothness, Direction dire = Direction.XAxis) { var dist = Vector3.Distance(sp, ep); - var segment = (int) (dist / (smoothness <= 0 ? 2f : smoothness)); + var segment = (int)(dist / (smoothness <= 0 ? 2f : smoothness)); UGLHelper.GetBezierList2(ref s_CurvesPosList, sp, ep, segment, cp1, cp2); DrawCurvesInternal(vh, s_CurvesPosList, lineWidth, lineColor, dire); } @@ -1801,15 +1806,15 @@ namespace XUGL bool closed = false) { var count = points.Count; - var size = (closed?count : count - 1); + var size = (closed ? count : count - 1); if (closed) dire = Direction.Random; for (int i = 0; i < size; i++) { var sp = points[i]; - var ep = closed?(i == size - 1 ? points[0] : points[i + 1]) : points[i + 1]; - var lsp = i > 0 ? points[i - 1] : (closed?points[count - 1] : sp); - var nep = i < points.Count - 2 ? points[i + 2] : (closed?points[(i + 2) % count] : ep); + var ep = closed ? (i == size - 1 ? points[0] : points[i + 1]) : points[i + 1]; + var lsp = i > 0 ? points[i - 1] : (closed ? points[count - 1] : sp); + var nep = i < points.Count - 2 ? points[i + 2] : (closed ? points[(i + 2) % count] : ep); var smoothness2 = smoothness; if (currProgress != float.NaN) {