diff --git a/Assets/XCharts/Editor/PropertyDrawers/AngleAxisDrawer.cs b/Assets/XCharts/Editor/PropertyDrawers/AngleAxisDrawer.cs index 76c1e8ab..233ddfc6 100644 --- a/Assets/XCharts/Editor/PropertyDrawers/AngleAxisDrawer.cs +++ b/Assets/XCharts/Editor/PropertyDrawers/AngleAxisDrawer.cs @@ -16,11 +16,11 @@ namespace XCharts protected override void DrawExtended(ref Rect drawRect, SerializedProperty prop) { SerializedProperty m_StartAngle = prop.FindPropertyRelative("m_StartAngle"); - //SerializedProperty m_Clockwise = prop.FindPropertyRelative("m_Clockwise"); + SerializedProperty m_Clockwise = prop.FindPropertyRelative("m_Clockwise"); EditorGUI.PropertyField(drawRect, m_StartAngle); drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - //EditorGUI.PropertyField(drawRect, m_Clockwise); - //drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + EditorGUI.PropertyField(drawRect, m_Clockwise); + drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; } protected override string GetDisplayName(string displayName) @@ -34,7 +34,7 @@ namespace XCharts protected override float GetExtendedHeight() { - return 1 * EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + return 2 * EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; } } } \ No newline at end of file diff --git a/Assets/XCharts/Runtime/Component/Main/Axis.cs b/Assets/XCharts/Runtime/Component/Main/Axis.cs index 0b63f5e4..6aa7063a 100644 --- a/Assets/XCharts/Runtime/Component/Main/Axis.cs +++ b/Assets/XCharts/Runtime/Component/Main/Axis.cs @@ -78,6 +78,7 @@ namespace XCharts [SerializeField] protected bool m_LogBaseE = false; [SerializeField] protected int m_CeilRate = 0; [SerializeField] protected bool m_Inverse = false; + [SerializeField] private bool m_Clockwise = true; [SerializeField] protected List m_Data = new List(); [SerializeField] protected AxisLine m_AxisLine = AxisLine.defaultAxisLine; [SerializeField] protected AxisName m_AxisName = AxisName.defaultAxisName; @@ -206,6 +207,15 @@ namespace XCharts set { if (m_Type == AxisType.Value && PropertyUtility.SetStruct(ref m_Inverse, value)) SetAllDirty(); } } /// + /// Whether the positive position of axis is in clockwise. True for clockwise by default. + /// 刻度增长是否按顺时针,默认顺时针。 + /// + public bool clockwise + { + get { return m_Clockwise; } + set { if (PropertyUtility.SetStruct(ref m_Clockwise, value)) SetAllDirty(); } + } + /// /// Category data, available in type: 'Category' axis. /// 类目数据,在类目轴(type: 'category')中有效。 /// @@ -843,7 +853,7 @@ namespace XCharts public class AngleAxis : Axis { [SerializeField] private float m_StartAngle = 90; - [SerializeField] private bool m_Clockwise = true; + /// /// Starting angle of axis. 90 degrees by default, standing for top position of center. 0 degree stands for right position of center. /// 起始刻度的角度,默认为 90 度,即圆心的正上方。0 度为圆心的正右方。 @@ -853,16 +863,7 @@ namespace XCharts get { return m_StartAngle; } set { if (PropertyUtility.SetStruct(ref m_StartAngle, value)) SetAllDirty(); } } - /// - /// Whether the positive position of axis is in clockwise. True for clockwise by default. - /// 刻度增长是否按顺时针,默认顺时针。 - /// - public bool clockWise - { - get { return m_Clockwise; } - set { if (PropertyUtility.SetStruct(ref m_Clockwise, value)) SetAllDirty(); } - } - + public float runtimeStartAngle { get; set; } public static AngleAxis defaultAngleAxis diff --git a/Assets/XCharts/Runtime/Internal/Helper/AxisHelper.cs b/Assets/XCharts/Runtime/Internal/Helper/AxisHelper.cs index a1b720c9..4fb3591f 100644 --- a/Assets/XCharts/Runtime/Internal/Helper/AxisHelper.cs +++ b/Assets/XCharts/Runtime/Internal/Helper/AxisHelper.cs @@ -120,6 +120,7 @@ namespace XCharts else { value = (minValue + (maxValue - minValue) * index / (split - 1)); + if (!axis.clockwise && value != minValue) value = maxValue - value; } if (axis.inverse) { diff --git a/Assets/XCharts/Runtime/Internal/Helper/TooltipHelper.cs b/Assets/XCharts/Runtime/Internal/Helper/TooltipHelper.cs index 80136452..1556287b 100644 --- a/Assets/XCharts/Runtime/Internal/Helper/TooltipHelper.cs +++ b/Assets/XCharts/Runtime/Internal/Helper/TooltipHelper.cs @@ -181,13 +181,14 @@ namespace XCharts tooltip.UpdateContentPos(pos); } - public static string GetPolarFormatterContent(Tooltip tooltip, Series series, ThemeInfo themeInfo) + public static string GetPolarFormatterContent(Tooltip tooltip, Series series, ThemeInfo themeInfo, AngleAxis angleAxis) { if (string.IsNullOrEmpty(tooltip.formatter)) { var sb = ChartHelper.sb; sb.Length = 0; - sb.Append(tooltip.runtimeAngle).Append("\n"); + var angle = angleAxis.clockwise ? tooltip.runtimeAngle : 360 - tooltip.runtimeAngle; + sb.Append(angle).Append("\n"); foreach (var serie in series.list) { if (serie.show && IsSelectedSerie(tooltip, serie.index)) diff --git a/Assets/XCharts/Runtime/PolarChart.cs b/Assets/XCharts/Runtime/PolarChart.cs index 0a925bf0..48d58072 100644 --- a/Assets/XCharts/Runtime/PolarChart.cs +++ b/Assets/XCharts/Runtime/PolarChart.cs @@ -486,10 +486,19 @@ namespace XCharts private Vector3 GetPolarPos(SerieData serieData, float min, float max, float polarRadius) { - var angle = m_AngleAxis.runtimeStartAngle + serieData.GetData(1); + var angle = 0f; + if (!m_AngleAxis.clockwise) + { + angle = m_AngleAxis.runtimeStartAngle - serieData.GetData(1); + } + else + { + angle = m_AngleAxis.runtimeStartAngle + serieData.GetData(1); + } + angle = (angle + 360) % 360; var value = serieData.GetData(0); var radius = (value - min) / (max - min) * polarRadius; - serieData.runtimeAngle = (angle + 360) % 360; + serieData.runtimeAngle = angle; serieData.runtimePosition = ChartHelper.GetPos(m_Polar.runtimeCenterPos, radius, angle, true); return serieData.runtimePosition; } @@ -583,7 +592,7 @@ namespace XCharts var showTooltip = m_Tooltip.isAnySerieDataIndex(); if (showTooltip) { - var content = TooltipHelper.GetPolarFormatterContent(m_Tooltip, m_Series, m_ThemeInfo); + var content = TooltipHelper.GetPolarFormatterContent(m_Tooltip, m_Series, m_ThemeInfo, m_AngleAxis); TooltipHelper.SetContentAndPosition(tooltip, content, chartRect); } m_Tooltip.SetActive(showTooltip);