mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-25 10:20: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,
|
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);
|
DrawSector(vh, p, radius, color, segments, 0, 360);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void DrawSector(VertexHelper vh, Vector3 p, float radius, Color color,
|
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>();
|
List<UIVertex> vertexs = new List<UIVertex>();
|
||||||
vh.GetUIVertexStream(vertexs);
|
vh.GetUIVertexStream(vertexs);
|
||||||
Vector3 p2, p3;
|
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)
|
public static List<Vector3> GetBezierList(Vector3 sp, Vector3 ep, float k = 2.0f)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ namespace xcharts
|
|||||||
[System.Serializable]
|
[System.Serializable]
|
||||||
public class PieInfo
|
public class PieInfo
|
||||||
{
|
{
|
||||||
public float radius = 80f;
|
public float insideRadius = 0f;
|
||||||
|
public float outsideRadius = 80f;
|
||||||
public float space;
|
public float space;
|
||||||
public float left;
|
public float left;
|
||||||
public float right;
|
public float right;
|
||||||
@@ -65,8 +66,8 @@ namespace xcharts
|
|||||||
float value = pieInfo.dataList[i].value;
|
float value = pieInfo.dataList[i].value;
|
||||||
float degree = totalDegree * value / dataTotal;
|
float degree = totalDegree * value / dataTotal;
|
||||||
float toDegree = startDegree + degree;
|
float toDegree = startDegree + degree;
|
||||||
ChartUtils.DrawSector(vh, new Vector3(pieCenterX, pieCenterY), pieRadius, legend.GetColor(i), 360,
|
ChartUtils.DrawDoughnut(vh, new Vector3(pieCenterX, pieCenterY), pieInfo.insideRadius, pieRadius,
|
||||||
startDegree, toDegree);
|
startDegree, toDegree, legend.GetColor(i));
|
||||||
startDegree = toDegree;
|
startDegree = toDegree;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -95,7 +96,7 @@ namespace xcharts
|
|||||||
float diffX = chartWid - pieInfo.left - pieInfo.right;
|
float diffX = chartWid - pieInfo.left - pieInfo.right;
|
||||||
float diffY = chartHig - pieInfo.top - pieInfo.bottom;
|
float diffY = chartHig - pieInfo.top - pieInfo.bottom;
|
||||||
float diff = Mathf.Min(diffX, diffY);
|
float diff = Mathf.Min(diffX, diffY);
|
||||||
if(pieInfo.radius <= 0)
|
if(pieInfo.outsideRadius <= 0)
|
||||||
{
|
{
|
||||||
pieRadius = diff / 3 * 2;
|
pieRadius = diff / 3 * 2;
|
||||||
pieCenterX = pieInfo.left + pieRadius;
|
pieCenterX = pieInfo.left + pieRadius;
|
||||||
@@ -103,7 +104,7 @@ namespace xcharts
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pieRadius = pieInfo.radius;
|
pieRadius = pieInfo.outsideRadius;
|
||||||
pieCenterX = chartWid / 2;
|
pieCenterX = chartWid / 2;
|
||||||
pieCenterY = chartHig / 2;
|
pieCenterY = chartHig / 2;
|
||||||
if (pieInfo.left > 0) pieCenterX = pieInfo.left + pieRadius;
|
if (pieInfo.left > 0) pieCenterX = pieInfo.left + pieRadius;
|
||||||
|
|||||||
34
demo.unity
34
demo.unity
@@ -2097,7 +2097,7 @@ RectTransform:
|
|||||||
m_PrefabInternal: {fileID: 0}
|
m_PrefabInternal: {fileID: 0}
|
||||||
m_GameObject: {fileID: 391300565}
|
m_GameObject: {fileID: 391300565}
|
||||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||||
m_LocalPosition: {x: -630, y: -260, z: 0}
|
m_LocalPosition: {x: -610, y: -145, z: 0}
|
||||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
m_Children:
|
m_Children:
|
||||||
- {fileID: 735060314}
|
- {fileID: 735060314}
|
||||||
@@ -2927,7 +2927,7 @@ GameObject:
|
|||||||
- component: {fileID: 494086603}
|
- component: {fileID: 494086603}
|
||||||
- component: {fileID: 494086602}
|
- component: {fileID: 494086602}
|
||||||
m_Layer: 5
|
m_Layer: 5
|
||||||
m_Name: pie_chart (1)
|
m_Name: pie_chart_doughnut
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
m_Icon: {fileID: 0}
|
m_Icon: {fileID: 0}
|
||||||
m_NavMeshLayer: 0
|
m_NavMeshLayer: 0
|
||||||
@@ -2940,7 +2940,7 @@ RectTransform:
|
|||||||
m_PrefabInternal: {fileID: 0}
|
m_PrefabInternal: {fileID: 0}
|
||||||
m_GameObject: {fileID: 494086600}
|
m_GameObject: {fileID: 494086600}
|
||||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||||
m_LocalPosition: {x: -220, y: -570, z: 0}
|
m_LocalPosition: {x: -200, y: -455, z: 0}
|
||||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
m_Children:
|
m_Children:
|
||||||
- {fileID: 1006379568}
|
- {fileID: 1006379568}
|
||||||
@@ -2988,7 +2988,7 @@ MonoBehaviour:
|
|||||||
backgroundColor: {r: 0.228, g: 0.153, b: 0.259, a: 0.772}
|
backgroundColor: {r: 0.228, g: 0.153, b: 0.259, a: 0.772}
|
||||||
title:
|
title:
|
||||||
show: 1
|
show: 1
|
||||||
text: "\u997C\u56FE"
|
text: "\u73AF\u5F62\u56FE"
|
||||||
color: {r: 1, g: 1, b: 1, a: 1}
|
color: {r: 1, g: 1, b: 1, a: 1}
|
||||||
align: 2
|
align: 2
|
||||||
left: 0
|
left: 0
|
||||||
@@ -3045,7 +3045,8 @@ MonoBehaviour:
|
|||||||
color: {r: 0.04757785, g: 0.8088235, b: 0.14732738, a: 1}
|
color: {r: 0.04757785, g: 0.8088235, b: 0.14732738, a: 1}
|
||||||
seriesList: []
|
seriesList: []
|
||||||
pieInfo:
|
pieInfo:
|
||||||
radius: 80
|
insideRadius: 40
|
||||||
|
outsideRadius: 80
|
||||||
space: 0
|
space: 0
|
||||||
left: 0
|
left: 0
|
||||||
right: 0
|
right: 0
|
||||||
@@ -4390,7 +4391,7 @@ RectTransform:
|
|||||||
m_PrefabInternal: {fileID: 0}
|
m_PrefabInternal: {fileID: 0}
|
||||||
m_GameObject: {fileID: 724935906}
|
m_GameObject: {fileID: 724935906}
|
||||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
m_LocalPosition: {x: 0, y: -115.0777, z: 0}
|
||||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
m_Children:
|
m_Children:
|
||||||
- {fileID: 1297066860}
|
- {fileID: 1297066860}
|
||||||
@@ -4406,8 +4407,8 @@ RectTransform:
|
|||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
m_AnchorMin: {x: 0.5, y: 0.5}
|
m_AnchorMin: {x: 0.5, y: 0.5}
|
||||||
m_AnchorMax: {x: 0.5, y: 0.5}
|
m_AnchorMax: {x: 0.5, y: 0.5}
|
||||||
m_AnchoredPosition: {x: 0, y: 0}
|
m_AnchoredPosition: {x: 0, y: -115.07772}
|
||||||
m_SizeDelta: {x: 1280, y: 720}
|
m_SizeDelta: {x: 1280, y: 950}
|
||||||
m_Pivot: {x: 0.5, y: 0.5}
|
m_Pivot: {x: 0.5, y: 0.5}
|
||||||
--- !u!114 &724935908
|
--- !u!114 &724935908
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
@@ -4421,7 +4422,7 @@ MonoBehaviour:
|
|||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
m_Padding:
|
m_Padding:
|
||||||
m_Left: 10
|
m_Left: 30
|
||||||
m_Right: 10
|
m_Right: 10
|
||||||
m_Top: 10
|
m_Top: 10
|
||||||
m_Bottom: 0
|
m_Bottom: 0
|
||||||
@@ -4863,7 +4864,7 @@ RectTransform:
|
|||||||
m_PrefabInternal: {fileID: 0}
|
m_PrefabInternal: {fileID: 0}
|
||||||
m_GameObject: {fileID: 822231470}
|
m_GameObject: {fileID: 822231470}
|
||||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||||
m_LocalPosition: {x: 190, y: 50, z: 0}
|
m_LocalPosition: {x: 210, y: 165, z: 0}
|
||||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
m_Children:
|
m_Children:
|
||||||
- {fileID: 1010613331}
|
- {fileID: 1010613331}
|
||||||
@@ -5087,7 +5088,7 @@ RectTransform:
|
|||||||
m_PrefabInternal: {fileID: 0}
|
m_PrefabInternal: {fileID: 0}
|
||||||
m_GameObject: {fileID: 867959889}
|
m_GameObject: {fileID: 867959889}
|
||||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||||
m_LocalPosition: {x: -220, y: -260, z: 0}
|
m_LocalPosition: {x: -200, y: -145, z: 0}
|
||||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
m_Children:
|
m_Children:
|
||||||
- {fileID: 1965633316}
|
- {fileID: 1965633316}
|
||||||
@@ -5550,7 +5551,7 @@ RectTransform:
|
|||||||
m_PrefabInternal: {fileID: 0}
|
m_PrefabInternal: {fileID: 0}
|
||||||
m_GameObject: {fileID: 971243255}
|
m_GameObject: {fileID: 971243255}
|
||||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||||
m_LocalPosition: {x: -630, y: -570, z: 0}
|
m_LocalPosition: {x: -610, y: -455, z: 0}
|
||||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
m_Children:
|
m_Children:
|
||||||
- {fileID: 1380241089}
|
- {fileID: 1380241089}
|
||||||
@@ -5655,7 +5656,8 @@ MonoBehaviour:
|
|||||||
color: {r: 0.04757785, g: 0.8088235, b: 0.14732738, a: 1}
|
color: {r: 0.04757785, g: 0.8088235, b: 0.14732738, a: 1}
|
||||||
seriesList: []
|
seriesList: []
|
||||||
pieInfo:
|
pieInfo:
|
||||||
radius: 80
|
insideRadius: 0
|
||||||
|
outsideRadius: 80
|
||||||
space: 0
|
space: 0
|
||||||
left: 0
|
left: 0
|
||||||
right: 0
|
right: 0
|
||||||
@@ -6734,7 +6736,7 @@ RectTransform:
|
|||||||
m_PrefabInternal: {fileID: 0}
|
m_PrefabInternal: {fileID: 0}
|
||||||
m_GameObject: {fileID: 1297066859}
|
m_GameObject: {fileID: 1297066859}
|
||||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||||
m_LocalPosition: {x: -630, y: 50, z: 0}
|
m_LocalPosition: {x: -610, y: 165, z: 0}
|
||||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
m_Children:
|
m_Children:
|
||||||
- {fileID: 305443278}
|
- {fileID: 305443278}
|
||||||
@@ -7828,7 +7830,7 @@ RectTransform:
|
|||||||
m_PrefabInternal: {fileID: 0}
|
m_PrefabInternal: {fileID: 0}
|
||||||
m_GameObject: {fileID: 1505386461}
|
m_GameObject: {fileID: 1505386461}
|
||||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||||
m_LocalPosition: {x: -220, y: 50, z: 0}
|
m_LocalPosition: {x: -200, y: 165, z: 0}
|
||||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
m_Children:
|
m_Children:
|
||||||
- {fileID: 506873713}
|
- {fileID: 506873713}
|
||||||
@@ -10888,7 +10890,7 @@ RectTransform:
|
|||||||
m_PrefabInternal: {fileID: 0}
|
m_PrefabInternal: {fileID: 0}
|
||||||
m_GameObject: {fileID: 2117888106}
|
m_GameObject: {fileID: 2117888106}
|
||||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||||
m_LocalPosition: {x: 190, y: -260, z: 0}
|
m_LocalPosition: {x: 210, y: -145, z: 0}
|
||||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
m_Children:
|
m_Children:
|
||||||
- {fileID: 575629730}
|
- {fileID: 575629730}
|
||||||
|
|||||||
Reference in New Issue
Block a user