From d41c13ccd22ee029821c78938fc926aac83ebb1f Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Tue, 9 Jul 2019 22:20:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0AxisLine=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=9D=90=E6=A0=87=E8=BD=B4=E8=BD=B4=E7=BA=BF=E5=92=8C=E7=AE=AD?= =?UTF-8?q?=E5=A4=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Editor/PropertyDrawers/AxisDrawer.cs | 8 ++- .../Editor/PropertyDrawers/AxisLineDrawer.cs | 51 ++++++++++++++++ .../PropertyDrawers/AxisLineDrawer.cs.meta | 11 ++++ Assets/XCharts/Scripts/UI/Internal/Axis.cs | 37 +++++++++++ .../Scripts/UI/Internal/CoordinateChart.cs | 61 ++++++++++++------- README.md | 1 + 6 files changed, 147 insertions(+), 22 deletions(-) create mode 100644 Assets/XCharts/Scripts/Editor/PropertyDrawers/AxisLineDrawer.cs create mode 100644 Assets/XCharts/Scripts/Editor/PropertyDrawers/AxisLineDrawer.cs.meta diff --git a/Assets/XCharts/Scripts/Editor/PropertyDrawers/AxisDrawer.cs b/Assets/XCharts/Scripts/Editor/PropertyDrawers/AxisDrawer.cs index 06e83cc1..3010f09b 100644 --- a/Assets/XCharts/Scripts/Editor/PropertyDrawers/AxisDrawer.cs +++ b/Assets/XCharts/Scripts/Editor/PropertyDrawers/AxisDrawer.cs @@ -46,6 +46,7 @@ public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) SerializedProperty m_SplitLineType = prop.FindPropertyRelative("m_SplitLineType"); SerializedProperty m_BoundaryGap = prop.FindPropertyRelative("m_BoundaryGap"); SerializedProperty m_Data = prop.FindPropertyRelative("m_Data"); + SerializedProperty m_AxisLine = prop.FindPropertyRelative("m_AxisLine"); SerializedProperty m_AxisName = prop.FindPropertyRelative("m_AxisName"); SerializedProperty m_AxisTick = prop.FindPropertyRelative("m_AxisTick"); SerializedProperty m_SplitArea = prop.FindPropertyRelative("m_SplitArea"); @@ -103,6 +104,9 @@ public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) } EditorGUI.PropertyField(drawRect, m_BoundaryGap); drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + EditorGUI.PropertyField(drawRect, m_AxisLine); + drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + drawRect.y += EditorGUI.GetPropertyHeight(m_AxisLine); EditorGUI.PropertyField(drawRect, m_AxisName); drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; drawRect.y += EditorGUI.GetPropertyHeight(m_AxisName); @@ -141,11 +145,12 @@ public override float GetPropertyHeight(SerializedProperty prop, GUIContent labe { SerializedProperty m_Type = prop.FindPropertyRelative("m_Type"); SerializedProperty m_AxisTick = prop.FindPropertyRelative("m_AxisTick"); + SerializedProperty m_AxisLine = prop.FindPropertyRelative("m_AxisLine"); SerializedProperty m_AxisName = prop.FindPropertyRelative("m_AxisName"); SerializedProperty m_AxisLabel = prop.FindPropertyRelative("m_AxisLabel"); SerializedProperty m_SplitArea = prop.FindPropertyRelative("m_SplitArea"); float height = 0; - height += 9 * EditorGUIUtility.singleLineHeight + 8 * EditorGUIUtility.standardVerticalSpacing; + height += 10 * EditorGUIUtility.singleLineHeight + 9 * EditorGUIUtility.standardVerticalSpacing; Axis.AxisType type = (Axis.AxisType)m_Type.enumValueIndex; if (type == Axis.AxisType.Category) { @@ -176,6 +181,7 @@ public override float GetPropertyHeight(SerializedProperty prop, GUIContent labe } } height += EditorGUI.GetPropertyHeight(m_AxisName); + height += EditorGUI.GetPropertyHeight(m_AxisLine); height += EditorGUI.GetPropertyHeight(m_AxisTick); height += EditorGUI.GetPropertyHeight(m_AxisLabel); height += EditorGUI.GetPropertyHeight(m_SplitArea); diff --git a/Assets/XCharts/Scripts/Editor/PropertyDrawers/AxisLineDrawer.cs b/Assets/XCharts/Scripts/Editor/PropertyDrawers/AxisLineDrawer.cs new file mode 100644 index 00000000..265f39bf --- /dev/null +++ b/Assets/XCharts/Scripts/Editor/PropertyDrawers/AxisLineDrawer.cs @@ -0,0 +1,51 @@ +using UnityEditor; +using UnityEngine; + +namespace XCharts +{ + [CustomPropertyDrawer(typeof(Axis.AxisLine), true)] + public class AxisLineDrawer : PropertyDrawer + { + private bool m_AxisLineToggle = false; + + public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) + { + Rect drawRect = pos; + drawRect.height = EditorGUIUtility.singleLineHeight; + SerializedProperty show = prop.FindPropertyRelative("m_Show"); + SerializedProperty m_Symbol = prop.FindPropertyRelative("m_Symbol"); + SerializedProperty m_SymbolWidth = prop.FindPropertyRelative("m_SymbolWidth"); + SerializedProperty m_SymbolHeight = prop.FindPropertyRelative("m_SymbolHeight"); + SerializedProperty m_SymbolOffset = prop.FindPropertyRelative("m_SymbolOffset"); + SerializedProperty m_SymbolDent = prop.FindPropertyRelative("m_SymbolDent"); + + ChartEditorHelper.MakeFoldout(ref drawRect, ref m_AxisLineToggle, "Axis Line", show, false); + drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + if (m_AxisLineToggle) + { + ++EditorGUI.indentLevel; + EditorGUI.PropertyField(drawRect, m_Symbol); + drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + EditorGUI.PropertyField(drawRect, m_SymbolWidth); + drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + EditorGUI.PropertyField(drawRect, m_SymbolHeight); + drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + EditorGUI.PropertyField(drawRect, m_SymbolOffset); + drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + EditorGUI.PropertyField(drawRect, m_SymbolDent); + drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + --EditorGUI.indentLevel; + } + } + + public override float GetPropertyHeight(SerializedProperty prop, GUIContent label) + { + float height = 0; + if (m_AxisLineToggle) + { + height += 5 * EditorGUIUtility.singleLineHeight + 4 * EditorGUIUtility.standardVerticalSpacing; + } + return height; + } + } +} \ No newline at end of file diff --git a/Assets/XCharts/Scripts/Editor/PropertyDrawers/AxisLineDrawer.cs.meta b/Assets/XCharts/Scripts/Editor/PropertyDrawers/AxisLineDrawer.cs.meta new file mode 100644 index 00000000..6865bb9d --- /dev/null +++ b/Assets/XCharts/Scripts/Editor/PropertyDrawers/AxisLineDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 866eefe266c3c47809d9dff3e89be0ab +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/XCharts/Scripts/UI/Internal/Axis.cs b/Assets/XCharts/Scripts/UI/Internal/Axis.cs index af7cdd40..77d9d16a 100644 --- a/Assets/XCharts/Scripts/UI/Internal/Axis.cs +++ b/Assets/XCharts/Scripts/UI/Internal/Axis.cs @@ -59,6 +59,41 @@ public static AxisTick defaultTick } } + [System.Serializable] + public class AxisLine + { + [SerializeField] private bool m_Show; + [SerializeField] private bool m_Symbol; + [SerializeField] private float m_SymbolWidth; + [SerializeField] private float m_SymbolHeight; + [SerializeField] private float m_SymbolOffset; + [SerializeField] private float m_SymbolDent; + + public bool show { get { return m_Show; } set { m_Show = value; } } + public bool symbol { get { return m_Symbol; } set { m_Symbol = value; } } + public float symbolWidth { get { return m_SymbolWidth; } set { m_SymbolWidth = value; } } + public float symbolHeight { get { return m_SymbolHeight; } set { m_SymbolHeight = value; } } + public float symbolOffset { get { return m_SymbolOffset; } set { m_SymbolOffset = value; } } + public float symbolDent { get { return m_SymbolDent; } set { m_SymbolDent = value; } } + + public static AxisLine defaultAxisLine + { + get + { + var axisLine = new AxisLine + { + m_Show = true, + m_Symbol = false, + m_SymbolWidth = 10, + m_SymbolHeight = 15, + m_SymbolOffset = 0, + m_SymbolDent = 3, + }; + return axisLine; + } + } + } + [Serializable] public class AxisName { @@ -267,6 +302,7 @@ public override int GetHashCode() [SerializeField] protected SplitLineType m_SplitLineType = SplitLineType.Dashed; [SerializeField] protected bool m_BoundaryGap = true; [SerializeField] protected List m_Data = new List(); + [SerializeField] protected AxisLine m_AxisLine = AxisLine.defaultAxisLine; [SerializeField] protected AxisName m_AxisName = AxisName.defaultAxisName; [SerializeField] protected AxisTick m_AxisTick = AxisTick.defaultTick; [SerializeField] protected AxisLabel m_AxisLabel = AxisLabel.defaultAxisLabel; @@ -283,6 +319,7 @@ public override int GetHashCode() public bool boundaryGap { get { return m_BoundaryGap; } set { m_BoundaryGap = value; } } public List data { get { return m_Data; } } + public AxisLine axisLine { get { return m_AxisLine; } set { m_AxisLine = value; } } public AxisName axisName { get { return m_AxisName; } set { m_AxisName = value; } } public AxisTick axisTick { get { return m_AxisTick; } set { m_AxisTick = value; } } public AxisLabel axisLabel { get { return m_AxisLabel; } set { m_AxisLabel = value; } } diff --git a/Assets/XCharts/Scripts/UI/Internal/CoordinateChart.cs b/Assets/XCharts/Scripts/UI/Internal/CoordinateChart.cs index 228bcda5..1e6144ed 100644 --- a/Assets/XCharts/Scripts/UI/Internal/CoordinateChart.cs +++ b/Assets/XCharts/Scripts/UI/Internal/CoordinateChart.cs @@ -639,39 +639,58 @@ private void DrawCoordinate(VertexHelper vh) } #endregion - #region draw x,y axis - if (m_YAxis.show) + DrawXAxisLine(vh); + DrawYAxisLine(vh); + } + + private void DrawXAxisLine(VertexHelper vh) + { + if (m_XAxis.show && m_XAxis.axisLine.show) { - if (m_YAxis.type == Axis.AxisType.Value) + var lineY = zeroY; + if (m_XAxis.type == Axis.AxisType.Value) { - ChartHelper.DrawLine(vh, new Vector3(coordinateX, coordinateY - m_Coordinate.tickness), - new Vector3(coordinateX, coordinateY + coordinateHig + m_Coordinate.tickness), - m_Coordinate.tickness, m_ThemeInfo.axisLineColor); + lineY = coordinateY; } - else + var top = new Vector3(coordinateX + coordinateWid + m_Coordinate.tickness, lineY); + ChartHelper.DrawLine(vh, new Vector3(coordinateX - m_Coordinate.tickness, lineY), + top, m_Coordinate.tickness, m_ThemeInfo.axisLineColor); + if (m_XAxis.axisLine.symbol) { - ChartHelper.DrawLine(vh, new Vector3(zeroX, coordinateY - m_Coordinate.tickness), - new Vector3(zeroX, coordinateY + coordinateHig + m_Coordinate.tickness), - m_Coordinate.tickness, m_ThemeInfo.axisLineColor); + var axisLine = m_XAxis.axisLine; + top.x += m_XAxis.axisLine.symbolOffset; + var middle = new Vector3(top.x - axisLine.symbolHeight + axisLine.symbolDent, lineY); + var left = new Vector3(top.x - axisLine.symbolHeight, lineY - axisLine.symbolWidth / 2); + var right = new Vector3(top.x - axisLine.symbolHeight, lineY + axisLine.symbolWidth / 2); + ChartHelper.DrawTriangle(vh, middle, top, left, m_ThemeInfo.axisLineColor); + ChartHelper.DrawTriangle(vh, middle, top, right, m_ThemeInfo.axisLineColor); } - } - if (m_XAxis.show) + } + + private void DrawYAxisLine(VertexHelper vh) + { + if (m_YAxis.show && m_YAxis.axisLine.show) { - if (m_XAxis.type == Axis.AxisType.Value) + var lineX = zeroX; + if (m_YAxis.type == Axis.AxisType.Value) { - ChartHelper.DrawLine(vh, new Vector3(coordinateX - m_Coordinate.tickness, coordinateY), - new Vector3(coordinateX + coordinateWid + m_Coordinate.tickness, coordinateY), - m_Coordinate.tickness, m_ThemeInfo.axisLineColor); + lineX = coordinateX; } - else + var top = new Vector3(lineX, coordinateY + coordinateHig + m_Coordinate.tickness); + ChartHelper.DrawLine(vh, new Vector3(lineX, coordinateY - m_Coordinate.tickness), + top, m_Coordinate.tickness, m_ThemeInfo.axisLineColor); + if (m_YAxis.axisLine.symbol) { - ChartHelper.DrawLine(vh, new Vector3(coordinateX - m_Coordinate.tickness, zeroY), - new Vector3(coordinateX + coordinateWid + m_Coordinate.tickness, zeroY), - m_Coordinate.tickness, m_ThemeInfo.axisLineColor); + var axisLine = m_YAxis.axisLine; + top.y += m_YAxis.axisLine.symbolOffset; + var middle = new Vector3(lineX, top.y - axisLine.symbolHeight + axisLine.symbolDent); + var left = new Vector3(lineX - axisLine.symbolWidth / 2, top.y - axisLine.symbolHeight); + var right = new Vector3(lineX + axisLine.symbolWidth / 2, top.y - axisLine.symbolHeight); + ChartHelper.DrawTriangle(vh, middle, top, left, m_ThemeInfo.axisLineColor); + ChartHelper.DrawTriangle(vh, middle, top, right, m_ThemeInfo.axisLineColor); } } - #endregion } private void DrawDataZoom(VertexHelper vh) diff --git a/README.md b/README.md index 91f9a73c..6b55dc4f 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ QQ交流群:XCharts交流群(202030963) ## 更新日志 +* (2019.07.09) 增加`AxisLine`配置坐标轴轴线和箭头 * (2019.07.03)增加`AxisLabel`配置坐标轴`刻度标签` * (2019.07.02)增加`selected`等相关参数配置`PieChart`的选中效果 * (2019.06.30)增加`SplitArea`配置坐标轴`分割区域`