mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-25 10:20:10 +00:00
增加Axis的splitLine参数控制分割线
This commit is contained in:
@@ -65,38 +65,6 @@ namespace XCharts
|
||||
Custom
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// the type of split line.
|
||||
/// 分割线类型
|
||||
/// </summary>
|
||||
public enum SplitLineType
|
||||
{
|
||||
/// <summary>
|
||||
/// 不显示分割线
|
||||
/// </summary>
|
||||
None,
|
||||
/// <summary>
|
||||
/// 实线
|
||||
/// </summary>
|
||||
Solid,
|
||||
/// <summary>
|
||||
/// 虚线
|
||||
/// </summary>
|
||||
Dashed,
|
||||
/// <summary>
|
||||
/// 点线
|
||||
/// </summary>
|
||||
Dotted,
|
||||
/// <summary>
|
||||
/// 点划线
|
||||
/// </summary>
|
||||
DashDot,
|
||||
/// <summary>
|
||||
/// 双点划线
|
||||
/// </summary>
|
||||
DashDotDot
|
||||
}
|
||||
|
||||
[SerializeField] protected bool m_Show = true;
|
||||
[SerializeField] protected AxisType m_Type;
|
||||
[SerializeField] protected AxisMinMaxType m_MinMaxType;
|
||||
@@ -104,8 +72,6 @@ namespace XCharts
|
||||
[SerializeField] protected float m_Max;
|
||||
[SerializeField] protected int m_SplitNumber = 5;
|
||||
[SerializeField] protected float m_Interval = 0;
|
||||
[SerializeField] protected bool m_ShowSplitLine = false;
|
||||
[SerializeField] protected SplitLineType m_SplitLineType = SplitLineType.Dashed;
|
||||
[SerializeField] protected bool m_BoundaryGap = true;
|
||||
[SerializeField] protected int m_MaxCache = 0;
|
||||
[SerializeField] protected float m_LogBase = 10;
|
||||
@@ -115,6 +81,7 @@ namespace XCharts
|
||||
[SerializeField] protected AxisName m_AxisName = AxisName.defaultAxisName;
|
||||
[SerializeField] protected AxisTick m_AxisTick = AxisTick.defaultTick;
|
||||
[SerializeField] protected AxisLabel m_AxisLabel = AxisLabel.defaultAxisLabel;
|
||||
[SerializeField] protected AxisSplitLine m_SplitLine = AxisSplitLine.defaultSplitLine;
|
||||
[SerializeField] protected AxisSplitArea m_SplitArea = AxisSplitArea.defaultSplitArea;
|
||||
|
||||
[NonSerialized] private float m_ValueRange;
|
||||
@@ -156,16 +123,6 @@ namespace XCharts
|
||||
/// </summary>
|
||||
public float interval { get { return m_Interval; } set { m_Interval = value; } }
|
||||
/// <summary>
|
||||
/// showSplitLineSet this to false to prevent the splitLine from showing. value type axes are shown by default, while category type axes are hidden.
|
||||
/// 是否显示分隔线。默认数值轴显示,类目轴不显示。
|
||||
/// </summary>
|
||||
public bool showSplitLine { get { return m_ShowSplitLine; } set { m_ShowSplitLine = value; } }
|
||||
/// <summary>
|
||||
/// the type of split line.
|
||||
/// 分割线类型。
|
||||
/// </summary>
|
||||
public SplitLineType splitLineType { get { return m_SplitLineType; } set { m_SplitLineType = value; } }
|
||||
/// <summary>
|
||||
/// The boundary gap on both sides of a coordinate axis.
|
||||
/// 坐标轴两边是否留白。
|
||||
/// </summary>
|
||||
@@ -211,6 +168,11 @@ namespace XCharts
|
||||
/// </summary>
|
||||
public AxisLabel axisLabel { get { return m_AxisLabel; } set { m_AxisLabel = value; } }
|
||||
/// <summary>
|
||||
/// axis split line.
|
||||
/// 坐标轴分割线。
|
||||
/// </summary>
|
||||
public AxisSplitLine splitLine { get { return m_SplitLine; } set { m_SplitLine = value; } }
|
||||
/// <summary>
|
||||
/// axis split area.
|
||||
/// 坐标轴分割区域。
|
||||
/// </summary>
|
||||
@@ -311,8 +273,6 @@ namespace XCharts
|
||||
m_SplitNumber = other.splitNumber;
|
||||
m_Interval = other.interval;
|
||||
|
||||
m_ShowSplitLine = other.showSplitLine;
|
||||
m_SplitLineType = other.splitLineType;
|
||||
m_BoundaryGap = other.boundaryGap;
|
||||
m_AxisName.Copy(other.axisName);
|
||||
m_AxisLabel.Copy(other.axisLabel);
|
||||
@@ -830,9 +790,7 @@ namespace XCharts
|
||||
max == other.max &&
|
||||
splitNumber == other.splitNumber &&
|
||||
interval == other.interval &&
|
||||
showSplitLine == other.showSplitLine &&
|
||||
m_AxisLabel.Equals(other.axisLabel) &&
|
||||
splitLineType == other.splitLineType &&
|
||||
boundaryGap == other.boundaryGap &&
|
||||
runtimeMinValue == other.runtimeMinValue &&
|
||||
runtimeMaxValue == other.runtimeMaxValue &&
|
||||
@@ -887,10 +845,9 @@ namespace XCharts
|
||||
axis.max = max;
|
||||
axis.splitNumber = splitNumber;
|
||||
axis.interval = interval;
|
||||
|
||||
axis.showSplitLine = showSplitLine;
|
||||
axis.splitLineType = splitLineType;
|
||||
axis.boundaryGap = boundaryGap;
|
||||
|
||||
axis.splitLine.Copy(axis.splitLine);
|
||||
axis.axisName.Copy(axisName);
|
||||
axis.axisLabel.Copy(axisLabel);
|
||||
axis.data.Clear();
|
||||
@@ -910,14 +867,14 @@ namespace XCharts
|
||||
m_Min = 0,
|
||||
m_Max = 0,
|
||||
m_SplitNumber = 5,
|
||||
m_ShowSplitLine = false,
|
||||
m_SplitLineType = SplitLineType.Dashed,
|
||||
m_BoundaryGap = true,
|
||||
m_Data = new List<string>()
|
||||
{
|
||||
"x1","x2","x3","x4","x5"
|
||||
}
|
||||
};
|
||||
axis.splitLine.show = false;
|
||||
axis.splitLine.lineStyle.type = LineStyle.Type.Dashed;
|
||||
axis.axisLabel.textLimit.enable = true;
|
||||
return axis;
|
||||
}
|
||||
@@ -942,11 +899,10 @@ namespace XCharts
|
||||
axis.splitNumber = splitNumber;
|
||||
axis.interval = interval;
|
||||
|
||||
axis.showSplitLine = showSplitLine;
|
||||
axis.splitLineType = splitLineType;
|
||||
axis.boundaryGap = boundaryGap;
|
||||
axis.axisName.Copy(axisName);
|
||||
axis.axisLabel.Copy(axisLabel);
|
||||
axis.splitLine.Copy(splitLine);
|
||||
axis.data.Clear();
|
||||
if (axis.data.Capacity < data.Count) axis.data.Capacity = data.Count;
|
||||
foreach (var d in data) axis.data.Add(d);
|
||||
@@ -964,11 +920,11 @@ namespace XCharts
|
||||
m_Min = 0,
|
||||
m_Max = 0,
|
||||
m_SplitNumber = 5,
|
||||
m_ShowSplitLine = true,
|
||||
m_SplitLineType = SplitLineType.Dashed,
|
||||
m_BoundaryGap = false,
|
||||
m_Data = new List<string>(5),
|
||||
};
|
||||
axis.splitLine.show = true;
|
||||
axis.splitLine.lineStyle.type = LineStyle.Type.Dashed;
|
||||
axis.axisLabel.textLimit.enable = false;
|
||||
return axis;
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ namespace XCharts
|
||||
m_Symbol = false,
|
||||
m_SymbolWidth = 10,
|
||||
m_SymbolHeight = 15,
|
||||
m_SymbolOffset = 0,
|
||||
m_SymbolOffset = -5f,
|
||||
m_SymbolDent = 3,
|
||||
};
|
||||
return axisLine;
|
||||
|
||||
91
Runtime/Component/Sub/AxisSplitLine.cs
Normal file
91
Runtime/Component/Sub/AxisSplitLine.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
/// <summary>
|
||||
/// Split line of axis in grid area.
|
||||
/// 坐标轴在 grid 区域中的分隔线。
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class AxisSplitLine : SubComponent
|
||||
{
|
||||
[SerializeField] private bool m_Show;
|
||||
[SerializeField] private int m_Interval;
|
||||
[SerializeField] private LineStyle m_LineStyle = new LineStyle(0.7f);
|
||||
|
||||
/// <summary>
|
||||
/// Set this to true to show the split line.
|
||||
/// 是否显示分隔线。
|
||||
/// </summary>
|
||||
public bool show { get { return m_Show; } set { m_Show = value; } }
|
||||
public int interval { get { return m_Interval; } set { m_Interval = value; } }
|
||||
/// <summary>
|
||||
/// 线条样式
|
||||
/// </summary>
|
||||
public LineStyle lineStyle { get { return m_LineStyle; } set { if (value != null) m_LineStyle = value; } }
|
||||
|
||||
public static AxisSplitLine defaultSplitLine
|
||||
{
|
||||
get
|
||||
{
|
||||
return new AxisSplitLine()
|
||||
{
|
||||
m_Show = false,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public void Copy(AxisSplitLine other)
|
||||
{
|
||||
m_Show = other.show;
|
||||
m_Interval = other.interval;
|
||||
m_LineStyle.Copy(other.m_LineStyle);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj == null || GetType() != obj.GetType())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var other = (AxisSplitLine)obj;
|
||||
return m_Show == other.show &&
|
||||
m_Interval == other.interval &&
|
||||
m_LineStyle.Equals(other.lineStyle);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
|
||||
internal Color GetColor(ThemeInfo theme)
|
||||
{
|
||||
if (lineStyle.color != Color.clear)
|
||||
{
|
||||
var color = lineStyle.color;
|
||||
color.a *= lineStyle.opacity;
|
||||
return color;
|
||||
}
|
||||
else
|
||||
{
|
||||
var color = (Color)theme.axisSplitLineColor;
|
||||
color.a *= lineStyle.opacity;
|
||||
return color;
|
||||
}
|
||||
}
|
||||
|
||||
internal bool NeedShow(int index)
|
||||
{
|
||||
return interval == 0 || index % (interval + 1) == 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Runtime/Component/Sub/AxisSplitLine.cs.meta
Normal file
11
Runtime/Component/Sub/AxisSplitLine.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 62c6ea03f6ffe431a9c4730cce152c80
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -75,5 +75,49 @@ namespace XCharts
|
||||
/// 线的透明度。支持从 0 到 1 的数字,为 0 时不绘制该图形。
|
||||
/// </summary>
|
||||
public float opacity { get { return m_Opacity; } set { m_Opacity = value; } }
|
||||
|
||||
public LineStyle()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public LineStyle(float width)
|
||||
{
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
public LineStyle(LineStyle.Type type, float width)
|
||||
{
|
||||
this.type = type;
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
public void Copy(LineStyle other)
|
||||
{
|
||||
m_Show = other.show;
|
||||
m_Type = other.type;
|
||||
m_Color = other.color;
|
||||
m_Width = other.width;
|
||||
m_Opacity = other.opacity;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj == null || GetType() != obj.GetType())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var other = (LineStyle)obj;
|
||||
return m_Show == other.show &&
|
||||
m_Type == other.type &&
|
||||
m_Width == other.width &&
|
||||
m_Opacity == other.opacity &&
|
||||
ChartHelper.IsValueEqualsColor(m_Color, other.color);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user