mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-18 06:20:15 +00:00
增加AxisLine配置坐标轴轴线和箭头
This commit is contained in:
@@ -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);
|
||||
|
||||
51
Scripts/Editor/PropertyDrawers/AxisLineDrawer.cs
Normal file
51
Scripts/Editor/PropertyDrawers/AxisLineDrawer.cs
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Scripts/Editor/PropertyDrawers/AxisLineDrawer.cs.meta
Normal file
11
Scripts/Editor/PropertyDrawers/AxisLineDrawer.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 866eefe266c3c47809d9dff3e89be0ab
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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<string> m_Data = new List<string>();
|
||||
[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<string> 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; } }
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user