Skip to content

Commit

Permalink
增加AxisLine配置坐标轴轴线和箭头
Browse files Browse the repository at this point in the history
  • Loading branch information
monitor1394 committed Jul 9, 2019
1 parent c651f7e commit d41c13c
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 22 deletions.
8 changes: 7 additions & 1 deletion Assets/XCharts/Scripts/Editor/PropertyDrawers/AxisDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down
51 changes: 51 additions & 0 deletions Assets/XCharts/Scripts/Editor/PropertyDrawers/AxisLineDrawer.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions Assets/XCharts/Scripts/UI/Internal/Axis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -267,6 +302,7 @@ public override int GetHashCode()
[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;
Expand All @@ -283,6 +319,7 @@ public override int GetHashCode()
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; } }
Expand Down
61 changes: 40 additions & 21 deletions Assets/XCharts/Scripts/UI/Internal/CoordinateChart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ QQ交流群:XCharts交流群(202030963)

## 更新日志

* (2019.07.09) 增加`AxisLine`配置坐标轴轴线和箭头
* (2019.07.03)增加`AxisLabel`配置坐标轴`刻度标签`
* (2019.07.02)增加`selected`等相关参数配置`PieChart`的选中效果
* (2019.06.30)增加`SplitArea`配置坐标轴`分割区域`
Expand Down

0 comments on commit d41c13c

Please sign in to comment.