mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-17 14:00:12 +00:00
增加AxisName可配置XY轴名称
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_AxisName = prop.FindPropertyRelative("m_AxisName");
|
||||
SerializedProperty m_AxisTick = prop.FindPropertyRelative("m_AxisTick");
|
||||
SerializedProperty m_MinMaxType = prop.FindPropertyRelative("m_MinMaxType");
|
||||
SerializedProperty m_Min = prop.FindPropertyRelative("m_Min");
|
||||
@@ -103,6 +104,9 @@ namespace XCharts
|
||||
}
|
||||
EditorGUI.PropertyField(drawRect, m_BoundaryGap);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_AxisName);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
drawRect.y += EditorGUI.GetPropertyHeight(m_AxisName);
|
||||
EditorGUI.PropertyField(drawRect, m_AxisTick);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
drawRect.y += EditorGUI.GetPropertyHeight(m_AxisTick);
|
||||
@@ -132,8 +136,9 @@ namespace XCharts
|
||||
{
|
||||
SerializedProperty m_Type = prop.FindPropertyRelative("m_Type");
|
||||
SerializedProperty m_AxisTick = prop.FindPropertyRelative("m_AxisTick");
|
||||
SerializedProperty m_AxisName = prop.FindPropertyRelative("m_AxisName");
|
||||
float height = 0;
|
||||
height += 7 * EditorGUIUtility.singleLineHeight + 6 * EditorGUIUtility.standardVerticalSpacing;
|
||||
height += 8 * EditorGUIUtility.singleLineHeight + 7 * EditorGUIUtility.standardVerticalSpacing;
|
||||
Axis.AxisType type = (Axis.AxisType)m_Type.enumValueIndex;
|
||||
if (type == Axis.AxisType.Category)
|
||||
{
|
||||
@@ -163,6 +168,7 @@ namespace XCharts
|
||||
height += EditorGUIUtility.singleLineHeight * 2 + EditorGUIUtility.standardVerticalSpacing;
|
||||
}
|
||||
}
|
||||
height += EditorGUI.GetPropertyHeight(m_AxisName);
|
||||
height += EditorGUI.GetPropertyHeight(m_AxisTick);
|
||||
return height;
|
||||
}
|
||||
|
||||
54
Scripts/Editor/PropertyDrawers/AxisNameDrawer.cs
Normal file
54
Scripts/Editor/PropertyDrawers/AxisNameDrawer.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(Axis.AxisName), true)]
|
||||
public class AxisNameDrawer : PropertyDrawer
|
||||
{
|
||||
private bool m_AxisNameToggle = 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_Name = prop.FindPropertyRelative("m_Name");
|
||||
SerializedProperty m_Location = prop.FindPropertyRelative("m_Location");
|
||||
SerializedProperty m_Gap = prop.FindPropertyRelative("m_Gap");
|
||||
SerializedProperty m_Rotate = prop.FindPropertyRelative("m_Rotate");
|
||||
SerializedProperty m_Color = prop.FindPropertyRelative("m_Color");
|
||||
SerializedProperty m_FontSize = prop.FindPropertyRelative("m_FontSize");
|
||||
|
||||
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_AxisNameToggle, "Axis Name", show, false);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
if (m_AxisNameToggle)
|
||||
{
|
||||
++EditorGUI.indentLevel;
|
||||
EditorGUI.PropertyField(drawRect, m_Name);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_Location);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_Gap);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_Rotate);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_FontSize);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_Color);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
--EditorGUI.indentLevel;
|
||||
}
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
|
||||
{
|
||||
float height = 0;
|
||||
if (m_AxisNameToggle)
|
||||
{
|
||||
height += 6 * EditorGUIUtility.singleLineHeight + 5 * EditorGUIUtility.standardVerticalSpacing;
|
||||
}
|
||||
return height;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Scripts/Editor/PropertyDrawers/AxisNameDrawer.cs.meta
Normal file
11
Scripts/Editor/PropertyDrawers/AxisNameDrawer.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 93f4873273d9c4d76bd651c8d774637f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -59,6 +59,82 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class AxisName
|
||||
{
|
||||
[Serializable]
|
||||
public enum Location
|
||||
{
|
||||
Start,
|
||||
Middle,
|
||||
End
|
||||
}
|
||||
[SerializeField] private bool m_Show;
|
||||
[SerializeField] private string m_Name;
|
||||
[SerializeField] private Location m_Location;
|
||||
[SerializeField] private float m_Gap;
|
||||
[SerializeField] private float m_Rotate;
|
||||
[SerializeField] private Color m_Color;
|
||||
[SerializeField] private int m_FontSize;
|
||||
|
||||
public bool show { get { return m_Show; } set { m_Show = value; } }
|
||||
public string name { get { return m_Name; } set { m_Name = value; } }
|
||||
public Location location { get { return m_Location; } set { m_Location = value; } }
|
||||
public float gap { get { return m_Gap; } set { m_Gap = value; } }
|
||||
public float rotate { get { return m_Rotate; } set { m_Rotate = value; } }
|
||||
public Color color { get { return m_Color; } set { m_Color = value; } }
|
||||
public int fontSize { get { return m_FontSize; } set { m_FontSize = value; } }
|
||||
|
||||
public static AxisName defaultAxisName
|
||||
{
|
||||
get
|
||||
{
|
||||
return new AxisName()
|
||||
{
|
||||
m_Show = false,
|
||||
m_Name = "axisName",
|
||||
m_Location = Location.End,
|
||||
m_Gap = 5,
|
||||
m_Rotate = 0,
|
||||
m_Color = Color.clear,
|
||||
m_FontSize = 18
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public void Copy(AxisName other)
|
||||
{
|
||||
m_Show = other.show;
|
||||
m_Name = other.name;
|
||||
m_Location = other.location;
|
||||
m_Gap = other.gap;
|
||||
m_Rotate = other.rotate;
|
||||
m_Color = other.color;
|
||||
m_FontSize = other.fontSize;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj == null || GetType() != obj.GetType())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var other = (AxisName)obj;
|
||||
return m_Show == other.show &&
|
||||
m_Name.Equals(other.name) &&
|
||||
m_Location == other.location &&
|
||||
m_Gap == other.gap &&
|
||||
m_Rotate == other.rotate &&
|
||||
m_Color == other.color &&
|
||||
m_FontSize == other.fontSize;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
}
|
||||
|
||||
[SerializeField] protected bool m_Show = true;
|
||||
[SerializeField] protected AxisType m_Type;
|
||||
[SerializeField] protected AxisMinMaxType m_MinMaxType;
|
||||
@@ -70,6 +146,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 AxisName m_AxisName = AxisName.defaultAxisName;
|
||||
[SerializeField] protected AxisTick m_AxisTick = AxisTick.defaultTick;
|
||||
|
||||
public bool show { get { return m_Show; } set { m_Show = value; } }
|
||||
@@ -83,6 +160,8 @@ namespace XCharts
|
||||
public SplitLineType splitLineType { get { return m_SplitLineType; } set { m_SplitLineType = value; } }
|
||||
public bool boundaryGap { get { return m_BoundaryGap; } set { m_BoundaryGap = value; } }
|
||||
public List<string> data { get { return m_Data; } }
|
||||
|
||||
public AxisName axisName { get { return m_AxisName; } set { m_AxisName = value; } }
|
||||
public AxisTick axisTick { get { return m_AxisTick; } set { m_AxisTick = value; } }
|
||||
|
||||
public int filterStart { get; set; }
|
||||
@@ -100,6 +179,7 @@ namespace XCharts
|
||||
m_ShowSplitLine = other.showSplitLine;
|
||||
m_SplitLineType = other.splitLineType;
|
||||
m_BoundaryGap = other.boundaryGap;
|
||||
m_AxisName.Copy(other.axisName);
|
||||
m_Data.Clear();
|
||||
foreach (var d in other.data) m_Data.Add(d);
|
||||
}
|
||||
@@ -283,6 +363,7 @@ namespace XCharts
|
||||
textRotation == other.textRotation &&
|
||||
splitLineType == other.splitLineType &&
|
||||
boundaryGap == other.boundaryGap &&
|
||||
axisName.Equals(other.axisName) &&
|
||||
ChartHelper.IsValueEqualsList<string>(m_Data, other.data);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@ namespace XCharts
|
||||
{
|
||||
public class CoordinateChart : BaseChart
|
||||
{
|
||||
private static readonly string s_DefaultSplitNameY = "split_y";
|
||||
private static readonly string s_DefaultSplitNameX = "split_x";
|
||||
private static readonly string s_DefaultAxisY = "axis_y";
|
||||
private static readonly string s_DefaultAxisX = "axis_x";
|
||||
private static readonly string s_DefaultDataZoom = "datazoom";
|
||||
|
||||
[SerializeField] protected Coordinate m_Coordinate = Coordinate.defaultCoordinate;
|
||||
@@ -245,16 +245,17 @@ namespace XCharts
|
||||
private void InitSplitY()
|
||||
{
|
||||
m_SplitYTextList.Clear();
|
||||
ChartHelper.HideAllObject(gameObject, "split_y");//old name
|
||||
float splitWidth = m_YAxis.GetScaleWidth(coordinateHig, m_DataZoom);
|
||||
|
||||
var titleObject = ChartHelper.AddObject(s_DefaultSplitNameY, transform, chartAnchorMin,
|
||||
var axisObj = ChartHelper.AddObject(s_DefaultAxisY, transform, chartAnchorMin,
|
||||
chartAnchorMax, chartPivot, new Vector2(chartWidth, chartHeight));
|
||||
titleObject.transform.localPosition = Vector3.zero;
|
||||
ChartHelper.HideAllObject(titleObject, s_DefaultSplitNameY);
|
||||
axisObj.transform.localPosition = Vector3.zero;
|
||||
ChartHelper.HideAllObject(axisObj, s_DefaultAxisY);
|
||||
|
||||
for (int i = 0; i < m_YAxis.GetSplitNumber(m_DataZoom); i++)
|
||||
{
|
||||
Text txt = ChartHelper.AddTextObject(s_DefaultSplitNameY + i, titleObject.transform,
|
||||
Text txt = ChartHelper.AddTextObject(s_DefaultAxisY + i, axisObj.transform,
|
||||
m_ThemeInfo.font, m_ThemeInfo.axisTextColor, TextAnchor.MiddleRight, Vector2.zero,
|
||||
Vector2.zero, new Vector2(1, 0.5f), new Vector2(m_Coordinate.left, 20),
|
||||
m_Coordinate.fontSize, m_XAxis.textRotation);
|
||||
@@ -263,20 +264,55 @@ namespace XCharts
|
||||
txt.gameObject.SetActive(m_YAxis.show);
|
||||
m_SplitYTextList.Add(txt);
|
||||
}
|
||||
if (m_YAxis.axisName.show)
|
||||
{
|
||||
var color = m_YAxis.axisName.color == Color.clear ? (Color)m_ThemeInfo.axisTextColor :
|
||||
m_YAxis.axisName.color;
|
||||
var fontSize = m_YAxis.axisName.fontSize;
|
||||
var gap = m_YAxis.axisName.gap;
|
||||
Text axisName;
|
||||
switch (m_YAxis.axisName.location)
|
||||
{
|
||||
case Axis.AxisName.Location.Start:
|
||||
axisName = ChartHelper.AddTextObject(s_DefaultAxisX + "_name", axisObj.transform,
|
||||
m_ThemeInfo.font, color, TextAnchor.MiddleCenter, new Vector2(0.5f, 0.5f),
|
||||
new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(100, 20), fontSize,
|
||||
m_YAxis.axisName.rotate);
|
||||
axisName.transform.localPosition = new Vector2(coordinateX, coordinateY - gap);
|
||||
break;
|
||||
case Axis.AxisName.Location.Middle:
|
||||
axisName = ChartHelper.AddTextObject(s_DefaultAxisX + "_name", axisObj.transform,
|
||||
m_ThemeInfo.font, color, TextAnchor.MiddleRight, new Vector2(1, 0.5f),
|
||||
new Vector2(1, 0.5f), new Vector2(1, 0.5f), new Vector2(100, 20), fontSize,
|
||||
m_YAxis.axisName.rotate);
|
||||
axisName.transform.localPosition = new Vector2(coordinateX - gap,
|
||||
coordinateY + coordinateHig / 2);
|
||||
break;
|
||||
case Axis.AxisName.Location.End:
|
||||
axisName = ChartHelper.AddTextObject(s_DefaultAxisX + "_name", axisObj.transform,
|
||||
m_ThemeInfo.font, color, TextAnchor.MiddleCenter, new Vector2(0.5f, 0.5f),
|
||||
new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(100, 20), fontSize,
|
||||
m_YAxis.axisName.rotate);
|
||||
axisName.transform.localPosition = new Vector2(coordinateX,
|
||||
coordinateY + coordinateHig + gap);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void InitSplitX()
|
||||
private void InitSplitX()
|
||||
{
|
||||
m_SplitXTextList.Clear();
|
||||
ChartHelper.HideAllObject(gameObject, "split_x");//old name
|
||||
float splitWidth = m_XAxis.GetScaleWidth(coordinateWid, m_DataZoom);
|
||||
|
||||
var titleObject = ChartHelper.AddObject(s_DefaultSplitNameX, transform, chartAnchorMin,
|
||||
var axisObj = ChartHelper.AddObject(s_DefaultAxisX, transform, chartAnchorMin,
|
||||
chartAnchorMax, chartPivot, new Vector2(chartWidth, chartHeight));
|
||||
titleObject.transform.localPosition = Vector3.zero;
|
||||
ChartHelper.HideAllObject(titleObject, s_DefaultSplitNameX);
|
||||
axisObj.transform.localPosition = Vector3.zero;
|
||||
ChartHelper.HideAllObject(axisObj, s_DefaultAxisX);
|
||||
for (int i = 0; i < m_XAxis.GetSplitNumber(m_DataZoom); i++)
|
||||
{
|
||||
Text txt = ChartHelper.AddTextObject(s_DefaultSplitNameX + i, titleObject.transform,
|
||||
Text txt = ChartHelper.AddTextObject(s_DefaultAxisX + i, axisObj.transform,
|
||||
m_ThemeInfo.font, m_ThemeInfo.axisTextColor, TextAnchor.MiddleCenter, Vector2.zero,
|
||||
Vector2.zero, new Vector2(1, 0.5f), new Vector2(splitWidth, 20),
|
||||
m_Coordinate.fontSize, m_XAxis.textRotation);
|
||||
@@ -286,6 +322,40 @@ namespace XCharts
|
||||
txt.gameObject.SetActive(m_XAxis.show);
|
||||
m_SplitXTextList.Add(txt);
|
||||
}
|
||||
if (m_XAxis.axisName.show)
|
||||
{
|
||||
var color = m_XAxis.axisName.color == Color.clear ? (Color)m_ThemeInfo.axisTextColor :
|
||||
m_XAxis.axisName.color;
|
||||
var fontSize = m_XAxis.axisName.fontSize;
|
||||
var gap = m_XAxis.axisName.gap;
|
||||
Text axisName;
|
||||
switch (m_XAxis.axisName.location)
|
||||
{
|
||||
case Axis.AxisName.Location.Start:
|
||||
axisName = ChartHelper.AddTextObject(s_DefaultAxisX + "_name", axisObj.transform,
|
||||
m_ThemeInfo.font, color, TextAnchor.MiddleRight, new Vector2(1, 0.5f),
|
||||
new Vector2(1, 0.5f), new Vector2(1, 0.5f), new Vector2(100, 20), fontSize,
|
||||
m_XAxis.axisName.rotate);
|
||||
axisName.transform.localPosition = new Vector2(coordinateX - gap, coordinateY);
|
||||
break;
|
||||
case Axis.AxisName.Location.Middle:
|
||||
axisName = ChartHelper.AddTextObject(s_DefaultAxisX + "_name", axisObj.transform,
|
||||
m_ThemeInfo.font, color, TextAnchor.MiddleCenter, new Vector2(0.5f, 0.5f),
|
||||
new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(100, 20), fontSize,
|
||||
m_XAxis.axisName.rotate);
|
||||
axisName.transform.localPosition = new Vector2(coordinateX + coordinateWid / 2,
|
||||
coordinateY - gap);
|
||||
break;
|
||||
case Axis.AxisName.Location.End:
|
||||
axisName = ChartHelper.AddTextObject(s_DefaultAxisX + "_name", axisObj.transform,
|
||||
m_ThemeInfo.font, color, TextAnchor.MiddleLeft, new Vector2(0, 0.5f),
|
||||
new Vector2(0, 0.5f), new Vector2(0, 0.5f), new Vector2(100, 20), fontSize,
|
||||
m_XAxis.axisName.rotate);
|
||||
axisName.transform.localPosition = new Vector2(coordinateX + coordinateWid + gap,
|
||||
coordinateY);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void InitDataZoom()
|
||||
|
||||
Reference in New Issue
Block a user