From da1ee0f47ba79996e327dd75c85a03ca2277836f Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Mon, 29 Jul 2019 08:01:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0Radius=E3=80=81Area=E4=B8=A4?= =?UTF-8?q?=E7=A7=8D=E5=8D=97=E4=B8=81=E6=A0=BC=E5=B0=94=E7=8E=AB=E7=91=B0?= =?UTF-8?q?=E5=9B=BE=E5=B1=95=E7=A4=BA=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PropertyDrawers/SerieLabelDrawer.cs | 4 ++- Scripts/UI/Internal/Serie.cs | 19 ++++++++++++++ Scripts/UI/PieChart.cs | 25 +++++++++++++++---- 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/Scripts/Editor/PropertyDrawers/SerieLabelDrawer.cs b/Scripts/Editor/PropertyDrawers/SerieLabelDrawer.cs index 7a199954..879c532a 100644 --- a/Scripts/Editor/PropertyDrawers/SerieLabelDrawer.cs +++ b/Scripts/Editor/PropertyDrawers/SerieLabelDrawer.cs @@ -59,7 +59,9 @@ namespace XCharts if (m_SerieLabelToggle) { height += 11 * EditorGUIUtility.singleLineHeight + 10 * EditorGUIUtility.standardVerticalSpacing; - }else{ + } + else + { height = EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; } return height; diff --git a/Scripts/UI/Internal/Serie.cs b/Scripts/UI/Internal/Serie.cs index 04a6d639..3390968d 100644 --- a/Scripts/UI/Internal/Serie.cs +++ b/Scripts/UI/Internal/Serie.cs @@ -16,10 +16,25 @@ namespace XCharts EffectScatter } +/// +/// Whether to show as Nightingale chart, which distinguishs data through radius. +/// 是否展示成南丁格尔图,通过半径区分数据大小。 +/// public enum RoseType { + /// + /// Don't show as Nightingale chart.不展示成南丁格尔玫瑰图 + /// None, + /// + /// Use central angle to show the percentage of data, radius to show data size. + /// 扇区圆心角展现数据的百分比,半径展现数据的大小。 + /// Radius, + /// + /// All the sectors will share the same central angle, the data size is shown only through radiuses. + /// 所有扇区圆心角相同,仅通过半径展现数据大小。 + /// Area } @@ -55,6 +70,10 @@ namespace XCharts public int axisIndex { get { return m_AxisIndex; } set { m_AxisIndex = value; } } public SerieSymbol symbol { get { return m_Symbol; } set { m_Symbol = value; } } public bool clickOffset { get { return m_ClickOffset; } set { m_ClickOffset = value; } } + /// + /// Whether to show as Nightingale chart. + /// 是否展示成南丁格尔图,通过半径区分数据大小。 + /// public RoseType roseType { get { return m_RoseType; } set { m_RoseType = value; } } public float space { get { return m_Space; } set { m_Space = value; } } public float[] center { get { return m_Center; } set { m_Center = value; } } diff --git a/Scripts/UI/PieChart.cs b/Scripts/UI/PieChart.cs index 3c945cc7..d821352e 100644 --- a/Scripts/UI/PieChart.cs +++ b/Scripts/UI/PieChart.cs @@ -118,6 +118,14 @@ namespace XCharts float totalDegree = 360; float startDegree = 0; + int showdataCount = 0; + if (serie.roseType == RoseType.Area) + { + foreach (var sd in serie.data) + { + if (sd.show) showdataCount++; + } + } for (int n = 0; n < data.Count; n++) { var serieData = data[n]; @@ -144,7 +152,7 @@ namespace XCharts tempData.angleList.Add(0); continue; } - float degree = totalDegree * value / tempData.dataTotal; + float degree = serie.roseType == RoseType.Area ? (totalDegree / showdataCount) : (totalDegree * value / tempData.dataTotal); float toDegree = startDegree + degree; float outSideRadius = serie.roseType > 0 ? @@ -190,7 +198,7 @@ namespace XCharts ChartHelper.DrawDoughnut(vh, center, tempData.insideRadius, outSideRadius, startDegree, toDegree, color); } - DrawLabelLine(vh, serie,tempData, outSideRadius, center, currAngle, color); + DrawLabelLine(vh, serie, tempData, outSideRadius, center, currAngle, color); isDrawPie = true; tempData.angleList.Add(toDegree); startDegree = toDegree; @@ -199,7 +207,7 @@ namespace XCharts raycastTarget = isClickOffset && isDataHighlight; } - private void DrawLabelLine(VertexHelper vh, Serie serie,PieTempData tempData, float outSideRadius, Vector2 center, float currAngle, Color color) + private void DrawLabelLine(VertexHelper vh, Serie serie, PieTempData tempData, float outSideRadius, Vector2 center, float currAngle, Color color) { if (serie.label.show && serie.label.position == SerieLabel.Position.Outside @@ -276,6 +284,14 @@ namespace XCharts float totalDegree = 360; float startDegree = 0; + int showdataCount = 0; + if (serie.roseType == RoseType.Area) + { + foreach (var sd in serie.data) + { + if (sd.show) showdataCount++; + } + } for (int n = 0; n < data.Count; n++) { var serieData = data[n]; @@ -302,7 +318,7 @@ namespace XCharts tempData.angleList.Add(0); continue; } - float degree = totalDegree * value / tempData.dataTotal; + float degree = serie.roseType == RoseType.Area ? (totalDegree / showdataCount) : (totalDegree * value / tempData.dataTotal); float toDegree = startDegree + degree; float outSideRadius = serie.roseType > 0 ? @@ -310,7 +326,6 @@ namespace XCharts tempData.outsideRadius; if (serieData.highlighted) { - //color *= 1.2f; outSideRadius += m_Pie.tooltipExtraRadius; } var offset = serie.space;