diff --git a/Scripts/ChartUtils.cs b/Scripts/ChartUtils.cs index 1df064a0..4141ee6a 100644 --- a/Scripts/ChartUtils.cs +++ b/Scripts/ChartUtils.cs @@ -157,7 +157,7 @@ namespace xcharts } public static void DrawCricle(VertexHelper vh, Vector3 p, float radius, Color color, - int segments = 0) + int segments = 0,bool fill = true) { if(segments <= 0) { @@ -166,6 +166,29 @@ namespace xcharts DrawSector(vh, p, radius, color, 0, 360, segments); } + public static void DrawCicleNotFill(VertexHelper vh, Vector3 p, float radius, float tickness, Color color, + int segments = 0) + { + if (segments <= 0) + { + segments = (int)((2 * Mathf.PI * radius) / CRICLE_SMOOTHNESS); + } + float startDegree = 0, toDegree = 360; + List vertexs = new List(); + vh.GetUIVertexStream(vertexs); + Vector3 p2, p3; + float startAngle = startDegree * Mathf.Deg2Rad; + float angle = (toDegree - startDegree) * Mathf.Deg2Rad / segments; + p2 = new Vector3(p.x + radius * Mathf.Sin(startAngle), p.y + radius * Mathf.Cos(startAngle)); + for (int i = 0; i <= segments; i++) + { + float currAngle = startAngle + i * angle; + p3 = new Vector3(p.x + radius * Mathf.Sin(currAngle), p.y + radius * Mathf.Cos(currAngle)); + DrawLine(vh, p2, p3, tickness, color); + p2 = p3; + } + } + public static void DrawSector(VertexHelper vh, Vector3 p, float radius, Color color, float startDegree, float toDegree, int segments = 0) { diff --git a/Scripts/RadarChart.cs b/Scripts/RadarChart.cs index db761d7a..96c39d62 100644 --- a/Scripts/RadarChart.cs +++ b/Scripts/RadarChart.cs @@ -14,7 +14,9 @@ namespace xcharts [System.Serializable] public class RadarInfo { + public bool cricle; public bool area; + public float radius = 100; public int splitNumber = 5; @@ -137,7 +139,14 @@ namespace xcharts { base.OnPopulateMesh(vh); UpdateRadarCenter(); - DrawRadar(vh); + if (radarInfo.cricle) + { + DrawCricleRadar(vh); + } + else + { + DrawRadar(vh); + } DrawData(vh); } @@ -232,6 +241,30 @@ namespace xcharts } } + private void DrawCricleRadar(VertexHelper vh) + { + float insideRadius = 0, outsideRadius = 0; + float block = radarInfo.radius / radarInfo.splitNumber; + int indicatorNum = radarInfo.indicatorList.Count; + Vector3 p = new Vector3(radarCenterX, radarCenterY); + Vector3 p1; + float angle = 2 * Mathf.PI / indicatorNum; + for (int i = 0; i < radarInfo.splitNumber; i++) + { + Color color = radarInfo.backgroundColorList[i % radarInfo.backgroundColorList.Count]; + outsideRadius = insideRadius + block; + ChartUtils.DrawDoughnut(vh, p, insideRadius, outsideRadius, 0, 360, color); + ChartUtils.DrawCicleNotFill(vh, p, outsideRadius, radarInfo.lineTickness, radarInfo.lineColor); + insideRadius = outsideRadius; + } + for (int j = 0; j <= indicatorNum; j++) + { + float currAngle = j * angle; + p1 = new Vector3(p.x + outsideRadius * Mathf.Sin(currAngle), p.y + outsideRadius * Mathf.Cos(currAngle)); + ChartUtils.DrawLine(vh, p, p1, radarInfo.lineTickness / 2, radarInfo.lineColor); + } + } + private void UpdateRadarCenter() { float diffX = chartWid - radarInfo.left - radarInfo.right;