mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-18 14:30:10 +00:00
增加环形图doughnut
This commit is contained in:
@@ -156,14 +156,22 @@ namespace xcharts
|
||||
}
|
||||
|
||||
public static void DrawCricle(VertexHelper vh, Vector3 p, float radius, Color color,
|
||||
int segments)
|
||||
int segments = 0)
|
||||
{
|
||||
if(segments <= 0)
|
||||
{
|
||||
segments = (int)((2 * Mathf.PI * radius) / 10f);
|
||||
}
|
||||
DrawSector(vh, p, radius, color, segments, 0, 360);
|
||||
}
|
||||
|
||||
public static void DrawSector(VertexHelper vh, Vector3 p, float radius, Color color,
|
||||
int segments, float startDegree, float toDegree)
|
||||
float startDegree, float toDegree, int segments = 0)
|
||||
{
|
||||
if (segments <= 0)
|
||||
{
|
||||
segments = (int)((2 * Mathf.PI * radius) / 10f);
|
||||
}
|
||||
List<UIVertex> vertexs = new List<UIVertex>();
|
||||
vh.GetUIVertexStream(vertexs);
|
||||
Vector3 p2, p3;
|
||||
@@ -179,6 +187,37 @@ namespace xcharts
|
||||
}
|
||||
}
|
||||
|
||||
public static void DrawDoughnut(VertexHelper vh,Vector3 p,float insideRadius,float outsideRadius,
|
||||
float startDegree, float toDegree, Color color, int segments = 0)
|
||||
{
|
||||
if(insideRadius<=0)
|
||||
{
|
||||
DrawSector(vh, p, outsideRadius, color,startDegree, toDegree, segments);
|
||||
return;
|
||||
}
|
||||
if (segments <= 0)
|
||||
{
|
||||
segments = (int)((2 * Mathf.PI * outsideRadius) / 10f);
|
||||
}
|
||||
List<UIVertex> vertexs = new List<UIVertex>();
|
||||
vh.GetUIVertexStream(vertexs);
|
||||
Vector3 p1, p2, p3, p4;
|
||||
float startAngle = startDegree * Mathf.Deg2Rad;
|
||||
float angle = (toDegree - startDegree) * Mathf.Deg2Rad / segments;
|
||||
p1 = new Vector3(p.x + insideRadius * Mathf.Sin(startAngle), p.y + insideRadius * Mathf.Cos(startAngle));
|
||||
p2 = new Vector3(p.x + outsideRadius * Mathf.Sin(startAngle), p.y + outsideRadius * Mathf.Cos(startAngle));
|
||||
for (int i = 0; i <= segments; i++)
|
||||
{
|
||||
float currAngle = startAngle + i * angle;
|
||||
p3 = new Vector3(p.x + outsideRadius * Mathf.Sin(currAngle), p.y + outsideRadius * Mathf.Cos(currAngle));
|
||||
p4 = new Vector3(p.x + insideRadius * Mathf.Sin(currAngle), p.y + insideRadius * Mathf.Cos(currAngle));
|
||||
|
||||
DrawPolygon(vh, p1, p2, p3, p4, color);
|
||||
p1 = p4;
|
||||
p2 = p3;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static List<Vector3> GetBezierList(Vector3 sp, Vector3 ep, float k = 2.0f)
|
||||
{
|
||||
|
||||
@@ -14,7 +14,8 @@ namespace xcharts
|
||||
[System.Serializable]
|
||||
public class PieInfo
|
||||
{
|
||||
public float radius = 80f;
|
||||
public float insideRadius = 0f;
|
||||
public float outsideRadius = 80f;
|
||||
public float space;
|
||||
public float left;
|
||||
public float right;
|
||||
@@ -65,8 +66,8 @@ namespace xcharts
|
||||
float value = pieInfo.dataList[i].value;
|
||||
float degree = totalDegree * value / dataTotal;
|
||||
float toDegree = startDegree + degree;
|
||||
ChartUtils.DrawSector(vh, new Vector3(pieCenterX, pieCenterY), pieRadius, legend.GetColor(i), 360,
|
||||
startDegree, toDegree);
|
||||
ChartUtils.DrawDoughnut(vh, new Vector3(pieCenterX, pieCenterY), pieInfo.insideRadius, pieRadius,
|
||||
startDegree, toDegree, legend.GetColor(i));
|
||||
startDegree = toDegree;
|
||||
}
|
||||
}
|
||||
@@ -95,7 +96,7 @@ namespace xcharts
|
||||
float diffX = chartWid - pieInfo.left - pieInfo.right;
|
||||
float diffY = chartHig - pieInfo.top - pieInfo.bottom;
|
||||
float diff = Mathf.Min(diffX, diffY);
|
||||
if(pieInfo.radius <= 0)
|
||||
if(pieInfo.outsideRadius <= 0)
|
||||
{
|
||||
pieRadius = diff / 3 * 2;
|
||||
pieCenterX = pieInfo.left + pieRadius;
|
||||
@@ -103,7 +104,7 @@ namespace xcharts
|
||||
}
|
||||
else
|
||||
{
|
||||
pieRadius = pieInfo.radius;
|
||||
pieRadius = pieInfo.outsideRadius;
|
||||
pieCenterX = chartWid / 2;
|
||||
pieCenterY = chartHig / 2;
|
||||
if (pieInfo.left > 0) pieCenterX = pieInfo.left + pieRadius;
|
||||
|
||||
Reference in New Issue
Block a user