From d3f7980a6d38eefcb2dc6685838f07219aa354fc 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 --- Scripts/Editor/PropertyDrawers/AxisDrawer.cs | 8 ++- .../Editor/PropertyDrawers/AxisLineDrawer.cs | 51 ++++++++++++++ .../PropertyDrawers/AxisLineDrawer.cs.meta | 11 +++ Scripts/UI/Internal/Axis.cs | 37 ++++++++++ Scripts/UI/Internal/CoordinateChart.cs | 69 ++++++++++++------- 5 files changed, 150 insertions(+), 26 deletions(-) create mode 100644 Scripts/Editor/PropertyDrawers/AxisLineDrawer.cs create mode 100644 Scripts/Editor/PropertyDrawers/AxisLineDrawer.cs.meta diff --git a/Scripts/Editor/PropertyDrawers/AxisDrawer.cs b/Scripts/Editor/PropertyDrawers/AxisDrawer.cs index 06e83cc1..3010f09b 100644 --- a/Scripts/Editor/PropertyDrawers/AxisDrawer.cs +++ b/Scripts/Editor/PropertyDrawers/AxisDrawer.cs @@ -46,6 +46,7 @@ namespace XCharts 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 @@ namespace XCharts } 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 @@ namespace XCharts { 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 @@ namespace XCharts } } 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/Scripts/Editor/PropertyDrawers/AxisLineDrawer.cs b/Scripts/Editor/PropertyDrawers/AxisLineDrawer.cs new file mode 100644 index 00000000..265f39bf --- /dev/null +++ b/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/Scripts/Editor/PropertyDrawers/AxisLineDrawer.cs.meta b/Scripts/Editor/PropertyDrawers/AxisLineDrawer.cs.meta new file mode 100644 index 00000000..6865bb9d --- /dev/null +++ b/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/Scripts/UI/Internal/Axis.cs b/Scripts/UI/Internal/Axis.cs index af7cdd40..77d9d16a 100644 --- a/Scripts/UI/Internal/Axis.cs +++ b/Scripts/UI/Internal/Axis.cs @@ -59,6 +59,41 @@ namespace XCharts } } + [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 @@ namespace XCharts [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 @@ namespace XCharts 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/Scripts/UI/Internal/CoordinateChart.cs b/Scripts/UI/Internal/CoordinateChart.cs index 228bcda5..1e6144ed 100644 --- a/Scripts/UI/Internal/CoordinateChart.cs +++ b/Scripts/UI/Internal/CoordinateChart.cs @@ -639,39 +639,58 @@ namespace XCharts } #endregion - #region draw x,y axis - if (m_YAxis.show) - { - if (m_YAxis.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); - } - else - { - ChartHelper.DrawLine(vh, new Vector3(zeroX, coordinateY - m_Coordinate.tickness), - new Vector3(zeroX, coordinateY + coordinateHig + m_Coordinate.tickness), - m_Coordinate.tickness, m_ThemeInfo.axisLineColor); - } + DrawXAxisLine(vh); + DrawYAxisLine(vh); + } - } - if (m_XAxis.show) + private void DrawXAxisLine(VertexHelper vh) + { + if (m_XAxis.show && m_XAxis.axisLine.show) { + var lineY = zeroY; if (m_XAxis.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); + 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(coordinateX - m_Coordinate.tickness, zeroY), - new Vector3(coordinateX + coordinateWid + m_Coordinate.tickness, zeroY), - 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); + } + } + } + + private void DrawYAxisLine(VertexHelper vh) + { + if (m_YAxis.show && m_YAxis.axisLine.show) + { + var lineX = zeroX; + if (m_YAxis.type == Axis.AxisType.Value) + { + lineX = coordinateX; + } + 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) + { + 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)