mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-17 05:50:09 +00:00
增加AxisName可配置XY轴名称
This commit is contained in:
@@ -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