mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-22 08:50:10 +00:00
增加Axis的splitLine参数控制分割线
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
|
||||
# 更新日志
|
||||
|
||||
* (2020.02.11) 增加`Tooltip`的`lineStyle`参数配置指示线样式
|
||||
* (2020.02.11) 增加`Axis`的`splitLine`参数控制分割线,去掉`showSplitLine`和`splitLineType`参数(更新时需要重新设置分割线相关设置)
|
||||
* (2020.02.10) 增加`Serie`的`clip`参数控制是否超出坐标系外裁剪(只适用于折线图、柱状图、散点图)
|
||||
* (2020.02.08) 增加`SerieSymbol`的`gap`参数控制图形标记的外留白距离
|
||||
* (2020.01.26) 增加`TextLimit`组件可以设置`AxisLabel`的文本自适应
|
||||
|
||||
@@ -197,6 +197,7 @@
|
||||
* `fontSize`:文字的字体大小。
|
||||
* `fontStyle`:文字的字体风格。
|
||||
* `forceENotation`:是否强制使用科学计数法格式化显示数值。默认为false,当小数精度大于3时才采用科学计数法。
|
||||
* `lineStyle`:指示器线条样式 [LineStyle](#LineStyle)。
|
||||
|
||||
## `DataZoom`
|
||||
|
||||
@@ -312,13 +313,6 @@
|
||||
* `max`:设定的坐标轴刻度最大值,当 `minMaxType` 为 `Custom` 时有效。
|
||||
* `splitNumber`:坐标轴的分割段数。默认为 `5`。当 `splitNumber` 设为 `0` 时,表示绘制所有的类目数据。
|
||||
* `interval`:强制设置坐标轴分割间隔。无法在类目轴中使用。设置改值时 `splitNumber` 无效。
|
||||
* `splitLineType`:分割线类型。默认为 `Dashed`。有以下五种类型:
|
||||
* `None`:不显示分割线。
|
||||
* `Solid`:实线。
|
||||
* `Dashed`:虚线。
|
||||
* `Dotted`:点线。
|
||||
* `DashDot`:点划线。
|
||||
* `DashDotDot`:双点划线。
|
||||
* `boundaryGap`:坐标轴两边是否留白。默认为 `true`。
|
||||
* `maxCache`:类目数据中可缓存的最大数据量。默认为0没有限制,大于0时超过指定值会移除旧数据再插入新数据。
|
||||
* `data`:类目数据,在类目轴(`type: 'Category'`)中有效。
|
||||
@@ -326,7 +320,8 @@
|
||||
* `axisName`:坐标轴名称相关配置 [AxisName](#AxisName)。
|
||||
* `axisTick`:坐标轴刻度相关配置 [AxisTick](#AxisTick)。
|
||||
* `axisLabel`:坐标轴刻度标签 [AxisLabel](#AxisLabel)。
|
||||
* `splitArea`:坐标轴轴线坐标轴分割区域 [SplitArea](#SplitArea)。
|
||||
* `splitLine`:坐标轴轴线坐标轴分割线 [AxisSplitLine](#SplitLine)。
|
||||
* `splitArea`:坐标轴轴线坐标轴分割区域 [AxisSplitArea](#AxisSplitArea)。
|
||||
|
||||
相关接口:
|
||||
|
||||
@@ -670,6 +665,12 @@
|
||||
* `fontSize`:坐标轴名称的文字大小。
|
||||
* `fontStyle`:坐标轴名称的文字风格。
|
||||
|
||||
## `AxisSplitLine`
|
||||
|
||||
* `show`:是否显示坐标分割线。
|
||||
* `interval`:分割线的显示间隔。0表示显示所有分割线,1表示隔一个隔显示一个分割线,以此类推。
|
||||
* `lineStyle`:线条样式 [LineStyle](#LineStyle)。
|
||||
|
||||
## `AxisSplitArea`
|
||||
|
||||
* `show`:是否显示坐标分割区域。
|
||||
|
||||
@@ -38,14 +38,13 @@ namespace XCharts
|
||||
SerializedProperty m_SplitNumber = prop.FindPropertyRelative("m_SplitNumber");
|
||||
SerializedProperty m_Interval = prop.FindPropertyRelative("m_Interval");
|
||||
SerializedProperty m_AxisLabel = prop.FindPropertyRelative("m_AxisLabel");
|
||||
SerializedProperty m_ShowSplitLine = prop.FindPropertyRelative("m_ShowSplitLine");
|
||||
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");
|
||||
SerializedProperty m_SplitLine = prop.FindPropertyRelative("m_SplitLine");
|
||||
SerializedProperty m_MinMaxType = prop.FindPropertyRelative("m_MinMaxType");
|
||||
SerializedProperty m_Min = prop.FindPropertyRelative("m_Min");
|
||||
SerializedProperty m_Max = prop.FindPropertyRelative("m_Max");
|
||||
@@ -94,23 +93,6 @@ namespace XCharts
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_Interval);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
if (m_ShowSplitLine.boolValue)
|
||||
{
|
||||
drawRect.width = EditorGUIUtility.labelWidth + 10;
|
||||
EditorGUI.PropertyField(drawRect, m_ShowSplitLine);
|
||||
//drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
drawRect.x = EditorGUIUtility.labelWidth + 35;
|
||||
drawRect.width = EditorGUIUtility.currentViewWidth - EditorGUIUtility.labelWidth - 55;
|
||||
EditorGUI.PropertyField(drawRect, m_SplitLineType, GUIContent.none);
|
||||
drawRect.x = pos.x;
|
||||
drawRect.width = pos.width;
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUI.PropertyField(drawRect, m_ShowSplitLine);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
}
|
||||
EditorGUI.PropertyField(drawRect, m_BoundaryGap);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_AxisLine);
|
||||
@@ -125,6 +107,8 @@ namespace XCharts
|
||||
EditorGUI.PropertyField(drawRect, m_AxisLabel);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
drawRect.y += EditorGUI.GetPropertyHeight(m_AxisLabel);
|
||||
EditorGUI.PropertyField(drawRect, m_SplitLine);
|
||||
drawRect.y += EditorGUI.GetPropertyHeight(m_SplitLine);
|
||||
EditorGUI.PropertyField(drawRect, m_SplitArea);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
drawRect.y += EditorGUI.GetPropertyHeight(m_SplitArea);
|
||||
@@ -159,8 +143,9 @@ namespace XCharts
|
||||
SerializedProperty m_AxisName = prop.FindPropertyRelative("m_AxisName");
|
||||
SerializedProperty m_AxisLabel = prop.FindPropertyRelative("m_AxisLabel");
|
||||
SerializedProperty m_SplitArea = prop.FindPropertyRelative("m_SplitArea");
|
||||
SerializedProperty m_SplitLine = prop.FindPropertyRelative("m_SplitLine");
|
||||
float height = 0;
|
||||
height += 11 * EditorGUIUtility.singleLineHeight + 10 * EditorGUIUtility.standardVerticalSpacing;
|
||||
height += 10 * EditorGUIUtility.singleLineHeight + 9 * EditorGUIUtility.standardVerticalSpacing;
|
||||
Axis.AxisType type = (Axis.AxisType)m_Type.enumValueIndex;
|
||||
if (type == Axis.AxisType.Category)
|
||||
{
|
||||
@@ -204,6 +189,7 @@ namespace XCharts
|
||||
height += EditorGUI.GetPropertyHeight(m_AxisTick);
|
||||
height += EditorGUI.GetPropertyHeight(m_AxisLabel);
|
||||
height += EditorGUI.GetPropertyHeight(m_SplitArea);
|
||||
height += EditorGUI.GetPropertyHeight(m_SplitLine);
|
||||
return height;
|
||||
}
|
||||
}
|
||||
|
||||
55
Assets/XCharts/Editor/PropertyDrawers/AxisSplitLineDrawer.cs
Normal file
55
Assets/XCharts/Editor/PropertyDrawers/AxisSplitLineDrawer.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(AxisSplitLine), true)]
|
||||
public class AxisSplitLineDrawer : PropertyDrawer
|
||||
{
|
||||
private Dictionary<string, bool> m_AxisSplitLineToggle = new Dictionary<string, bool>();
|
||||
|
||||
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_Interval = prop.FindPropertyRelative("m_Interval");
|
||||
SerializedProperty m_LineStyle = prop.FindPropertyRelative("m_LineStyle");
|
||||
|
||||
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_AxisSplitLineToggle, prop, "Split Line", show, false);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
if (ChartEditorHelper.IsToggle(m_AxisSplitLineToggle, prop))
|
||||
{
|
||||
++EditorGUI.indentLevel;
|
||||
EditorGUI.PropertyField(drawRect, m_Interval);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_LineStyle);
|
||||
drawRect.y += EditorGUI.GetPropertyHeight(m_LineStyle);
|
||||
--EditorGUI.indentLevel;
|
||||
}
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
|
||||
{
|
||||
float height = 0;
|
||||
if (ChartEditorHelper.IsToggle(m_AxisSplitLineToggle, prop))
|
||||
{
|
||||
height += 2 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing;
|
||||
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_LineStyle"));
|
||||
}
|
||||
else
|
||||
{
|
||||
height = EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
}
|
||||
return height;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: af473e9aba20f4f168b8f83a4db13f81
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -200,6 +200,20 @@ namespace XCharts
|
||||
{
|
||||
CheckMinMaxValue();
|
||||
}
|
||||
|
||||
public Vector3 ClampInCoordinate(Vector3 pos)
|
||||
{
|
||||
if (IsInCooridate(pos)) return pos;
|
||||
else
|
||||
{
|
||||
var np = new Vector3(pos.x, pos.y);
|
||||
if (np.x < coordinateX) np.x = coordinateX;
|
||||
if (np.x > coordinateX + coordinateWidth) np.x = coordinateX + coordinateWidth;
|
||||
if (np.y < coordinateY) np.y = coordinateY;
|
||||
if (np.y > coordinateY + coordinateHeight) np.y = coordinateY + coordinateHeight;
|
||||
return np;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
Assets/XCharts/Runtime/Component/Sub/AxisSplitLine.cs
Normal file
91
Assets/XCharts/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
Assets/XCharts/Runtime/Component/Sub/AxisSplitLine.cs.meta
Normal file
11
Assets/XCharts/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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -92,14 +92,14 @@ namespace XCharts
|
||||
{
|
||||
var xLineDiff = xAxis0.axisLine.width;
|
||||
var yLineDiff = yAxis0.axisLine.width;
|
||||
var xSplitDiff = xAxis0.axisLine.width;
|
||||
var ySplitDiff = yAxis0.axisLine.width;
|
||||
var xSplitDiff = xAxis0.splitLine.lineStyle.width;
|
||||
var ySplitDiff = yAxis0.splitLine.lineStyle.width;
|
||||
|
||||
var cpty = coordinateY + coordinateHeight + xSplitDiff;
|
||||
var cpty = coordinateY + coordinateHeight + ySplitDiff;
|
||||
var cp1 = new Vector3(coordinateX - yLineDiff, coordinateY - xLineDiff);
|
||||
var cp2 = new Vector3(coordinateX - yLineDiff, cpty);
|
||||
var cp3 = new Vector3(coordinateX + coordinateWidth + ySplitDiff, cpty);
|
||||
var cp4 = new Vector3(coordinateX + coordinateWidth + ySplitDiff, coordinateY - xLineDiff);
|
||||
var cp3 = new Vector3(coordinateX + coordinateWidth + xSplitDiff, cpty);
|
||||
var cp4 = new Vector3(coordinateX + coordinateWidth + xSplitDiff, coordinateY - xLineDiff);
|
||||
ChartDrawer.DrawPolygon(vh, cp1, cp2, cp3, cp4, m_ThemeInfo.backgroundColor);
|
||||
}
|
||||
else
|
||||
@@ -113,15 +113,15 @@ namespace XCharts
|
||||
if (!m_Series.IsAnyClipSerie()) return;
|
||||
var xLineDiff = xAxis0.axisLine.width;
|
||||
var yLineDiff = yAxis0.axisLine.width;
|
||||
var xSplitDiff = xAxis0.axisLine.width;
|
||||
var ySplitDiff = yAxis0.axisLine.width;
|
||||
var xSplitDiff = xAxis0.splitLine.lineStyle.width;
|
||||
var ySplitDiff = yAxis0.splitLine.lineStyle.width;
|
||||
var lp1 = new Vector3(0, 0);
|
||||
var lp2 = new Vector3(0, chartHeight);
|
||||
var lp3 = new Vector3(coordinateX - yLineDiff, chartHeight);
|
||||
var lp4 = new Vector3(coordinateX - yLineDiff, 0);
|
||||
ChartDrawer.DrawPolygon(vh, lp1, lp2, lp3, lp4, m_ThemeInfo.backgroundColor);
|
||||
var rp1 = new Vector3(coordinateX + coordinateWidth + ySplitDiff, 0);
|
||||
var rp2 = new Vector3(coordinateX + coordinateWidth + ySplitDiff, chartHeight);
|
||||
var rp1 = new Vector3(coordinateX + coordinateWidth + xSplitDiff, 0);
|
||||
var rp2 = new Vector3(coordinateX + coordinateWidth + xSplitDiff, chartHeight);
|
||||
var rp3 = new Vector3(chartWidth, chartHeight);
|
||||
var rp4 = new Vector3(chartWidth, 0);
|
||||
ChartDrawer.DrawPolygon(vh, rp1, rp2, rp3, rp4, m_ThemeInfo.backgroundColor);
|
||||
@@ -974,12 +974,15 @@ namespace XCharts
|
||||
new Vector2(coordinateX, pY + scaleWidth),
|
||||
yAxis.splitArea.getColor(i));
|
||||
}
|
||||
if (yAxis.showSplitLine)
|
||||
if (yAxis.splitLine.show)
|
||||
{
|
||||
if (!xAxis.axisLine.show || !xAxis.axisLine.onZero || zeroPos.y != pY)
|
||||
{
|
||||
DrawSplitLine(vh, yAxis, yAxis.splitLineType, new Vector3(coordinateX, pY),
|
||||
new Vector3(coordinateX + coordinateWidth, pY), m_ThemeInfo.axisSplitLineColor);
|
||||
if (yAxis.splitLine.NeedShow(i))
|
||||
{
|
||||
DrawSplitLine(vh, yAxis.splitLine.lineStyle, new Vector3(coordinateX, pY),
|
||||
new Vector3(coordinateX + coordinateWidth, pY), yAxis.splitLine.GetColor(m_ThemeInfo));
|
||||
}
|
||||
}
|
||||
}
|
||||
totalWidth += scaleWidth;
|
||||
@@ -994,7 +997,6 @@ namespace XCharts
|
||||
var size = yAxis.GetScaleNumber(coordinateWidth, m_DataZoom);
|
||||
var totalWidth = coordinateY;
|
||||
var xAxis = m_XAxises[yAxisIndex];
|
||||
var zeroPos = new Vector3(coordinateX + xAxis.runtimeZeroXOffset, coordinateY + yAxis.runtimeZeroYOffset);
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
var scaleWidth = yAxis.GetScaleWidth(coordinateHeight, i, m_DataZoom);
|
||||
@@ -1024,6 +1026,18 @@ namespace XCharts
|
||||
totalWidth += scaleWidth;
|
||||
}
|
||||
}
|
||||
if (yAxis.show && yAxis.axisLine.show)
|
||||
{
|
||||
var lineX = coordinateX + (yAxis.axisLine.onZero ? m_XAxises[yAxisIndex].runtimeZeroXOffset : 0);
|
||||
if (yAxis.IsValue() && yAxisIndex > 0) lineX += coordinateWidth;
|
||||
var top = new Vector3(lineX, coordinateY + coordinateHeight + yAxis.axisLine.width);
|
||||
if (yAxis.axisLine.symbol)
|
||||
{
|
||||
var axisLine = yAxis.axisLine;
|
||||
ChartDrawer.DrawArrow(vh, new Vector3(lineX, coordinateX), top, axisLine.symbolWidth, axisLine.symbolHeight,
|
||||
axisLine.symbolOffset, axisLine.symbolDent, m_ThemeInfo.axisLineColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawXAxisSplit(VertexHelper vh, int xAxisIndex, XAxis xAxis)
|
||||
@@ -1038,7 +1052,6 @@ namespace XCharts
|
||||
{
|
||||
var scaleWidth = xAxis.GetScaleWidth(coordinateWidth, i, m_DataZoom);
|
||||
float pX = totalWidth;
|
||||
float pY = 0;
|
||||
if (xAxis.boundaryGap && xAxis.axisTick.alignWithLabel)
|
||||
{
|
||||
pX -= scaleWidth / 2;
|
||||
@@ -1051,12 +1064,15 @@ namespace XCharts
|
||||
new Vector2(pX + scaleWidth, coordinateY),
|
||||
xAxis.splitArea.getColor(i));
|
||||
}
|
||||
if (xAxis.showSplitLine)
|
||||
if (xAxis.splitLine.show)
|
||||
{
|
||||
if (!yAxis.axisLine.show || !yAxis.axisLine.onZero || zeroPos.x != pX)
|
||||
{
|
||||
DrawSplitLine(vh, xAxis, xAxis.splitLineType, new Vector3(pX, coordinateY),
|
||||
new Vector3(pX, coordinateY + coordinateHeight), m_ThemeInfo.axisSplitLineColor);
|
||||
if (xAxis.splitLine.NeedShow(i))
|
||||
{
|
||||
DrawSplitLine(vh, xAxis.splitLine.lineStyle, new Vector3(pX, coordinateY),
|
||||
new Vector3(pX, coordinateY + coordinateHeight), xAxis.splitLine.GetColor(m_ThemeInfo));
|
||||
}
|
||||
}
|
||||
}
|
||||
totalWidth += scaleWidth;
|
||||
@@ -1071,7 +1087,6 @@ namespace XCharts
|
||||
var size = xAxis.GetScaleNumber(coordinateWidth, m_DataZoom);
|
||||
var totalWidth = coordinateX;
|
||||
var yAxis = m_YAxises[xAxisIndex];
|
||||
var zeroPos = new Vector3(coordinateX, coordinateY + yAxis.runtimeZeroYOffset);
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
var scaleWidth = xAxis.GetScaleWidth(coordinateWidth, i, m_DataZoom);
|
||||
@@ -1101,6 +1116,18 @@ namespace XCharts
|
||||
totalWidth += scaleWidth;
|
||||
}
|
||||
}
|
||||
if (xAxis.show && xAxis.axisLine.show)
|
||||
{
|
||||
var lineY = coordinateY + (xAxis.axisLine.onZero ? m_YAxises[xAxisIndex].runtimeZeroYOffset : 0);
|
||||
if (xAxis.IsValue() && xAxisIndex > 0) lineY += coordinateHeight;
|
||||
var top = new Vector3(coordinateX + coordinateWidth + xAxis.axisLine.width, lineY);
|
||||
if (xAxis.axisLine.symbol)
|
||||
{
|
||||
var axisLine = xAxis.axisLine;
|
||||
ChartDrawer.DrawArrow(vh, new Vector3(coordinateX, lineY), top, axisLine.symbolWidth, axisLine.symbolHeight,
|
||||
axisLine.symbolOffset, axisLine.symbolDent, m_ThemeInfo.axisLineColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawXAxisLine(VertexHelper vh, int xAxisIndex, XAxis xAxis)
|
||||
@@ -1112,12 +1139,6 @@ namespace XCharts
|
||||
var left = new Vector3(coordinateX - xAxis.axisLine.width, lineY);
|
||||
var top = new Vector3(coordinateX + coordinateWidth + xAxis.axisLine.width, lineY);
|
||||
ChartDrawer.DrawLine(vh, left, top, xAxis.axisLine.width, m_ThemeInfo.axisLineColor);
|
||||
if (xAxis.axisLine.symbol)
|
||||
{
|
||||
var axisLine = xAxis.axisLine;
|
||||
ChartDrawer.DrawArrow(vh, new Vector3(coordinateX, lineY), top, axisLine.symbolWidth, axisLine.symbolHeight,
|
||||
axisLine.symbolOffset, axisLine.symbolDent, m_ThemeInfo.axisLineColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1130,12 +1151,6 @@ namespace XCharts
|
||||
var top = new Vector3(lineX, coordinateY + coordinateHeight + yAxis.axisLine.width);
|
||||
ChartDrawer.DrawLine(vh, new Vector3(lineX, coordinateY - yAxis.axisLine.width),
|
||||
top, yAxis.axisLine.width, m_ThemeInfo.axisLineColor);
|
||||
if (yAxis.axisLine.symbol)
|
||||
{
|
||||
var axisLine = yAxis.axisLine;
|
||||
ChartDrawer.DrawArrow(vh, new Vector3(lineX, coordinateX), top, axisLine.symbolWidth, axisLine.symbolHeight,
|
||||
axisLine.symbolOffset, axisLine.symbolDent, m_ThemeInfo.axisLineColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1215,25 +1230,27 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
protected void DrawSplitLine(VertexHelper vh, Axis axis, Axis.SplitLineType type,
|
||||
protected void DrawSplitLine(VertexHelper vh, LineStyle lineStyle,
|
||||
Vector3 startPos, Vector3 endPos, Color color)
|
||||
{
|
||||
var type = lineStyle.type;
|
||||
var width = lineStyle.width;
|
||||
switch (type)
|
||||
{
|
||||
case Axis.SplitLineType.Dashed:
|
||||
ChartDrawer.DrawDashLine(vh, startPos, endPos, axis.axisLine.width, color);
|
||||
case LineStyle.Type.Dashed:
|
||||
ChartDrawer.DrawDashLine(vh, startPos, endPos, width, color);
|
||||
break;
|
||||
case Axis.SplitLineType.Dotted:
|
||||
ChartDrawer.DrawDotLine(vh, startPos, endPos, axis.axisLine.width, color);
|
||||
case LineStyle.Type.Dotted:
|
||||
ChartDrawer.DrawDotLine(vh, startPos, endPos, width, color);
|
||||
break;
|
||||
case Axis.SplitLineType.Solid:
|
||||
ChartDrawer.DrawLine(vh, startPos, endPos, axis.axisLine.width, color);
|
||||
case LineStyle.Type.Solid:
|
||||
ChartDrawer.DrawLine(vh, startPos, endPos, width, color);
|
||||
break;
|
||||
case Axis.SplitLineType.DashDot:
|
||||
ChartDrawer.DrawDashDotLine(vh, startPos, endPos, axis.axisLine.width, color);
|
||||
case LineStyle.Type.DashDot:
|
||||
ChartDrawer.DrawDashDotLine(vh, startPos, endPos, width, color);
|
||||
break;
|
||||
case Axis.SplitLineType.DashDotDot:
|
||||
ChartDrawer.DrawDashDotDotLine(vh, startPos, endPos, axis.axisLine.width, color);
|
||||
case LineStyle.Type.DashDotDot:
|
||||
ChartDrawer.DrawDashDotDotLine(vh, startPos, endPos, width, color);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1258,12 +1275,12 @@ namespace XCharts
|
||||
if (xAxis.IsValue()) pX = m_Tooltip.runtimePointerPos.x;
|
||||
Vector2 sp = new Vector2(pX, coordinateY);
|
||||
Vector2 ep = new Vector2(pX, coordinateY + coordinateHeight);
|
||||
DrawSplitLine(vh, xAxis, Axis.SplitLineType.Solid, sp, ep, m_ThemeInfo.tooltipLineColor);
|
||||
DrawSplitLine(vh, m_Tooltip.lineStyle, sp, ep, m_Tooltip.GetLineColor(m_ThemeInfo));
|
||||
if (m_Tooltip.type == Tooltip.Type.Corss)
|
||||
{
|
||||
sp = new Vector2(coordinateX, m_Tooltip.runtimePointerPos.y);
|
||||
ep = new Vector2(coordinateX + coordinateWidth, m_Tooltip.runtimePointerPos.y);
|
||||
DrawSplitLine(vh, yAxis, Axis.SplitLineType.Dashed, sp, ep, m_ThemeInfo.tooltipLineColor);
|
||||
DrawSplitLine(vh, m_Tooltip.lineStyle, sp, ep, m_Tooltip.GetLineColor(m_ThemeInfo));
|
||||
}
|
||||
break;
|
||||
case Tooltip.Type.Shadow:
|
||||
@@ -1301,12 +1318,12 @@ namespace XCharts
|
||||
float pY = coordinateY + m_Tooltip.runtimeYValues[i] * splitWidth + (yAxis.boundaryGap ? splitWidth / 2 : 0);
|
||||
Vector2 sp = new Vector2(coordinateX, pY);
|
||||
Vector2 ep = new Vector2(coordinateX + coordinateWidth, pY);
|
||||
DrawSplitLine(vh, xAxis, Axis.SplitLineType.Solid, sp, ep, m_ThemeInfo.tooltipLineColor);
|
||||
DrawSplitLine(vh, m_Tooltip.lineStyle, sp, ep, m_Tooltip.GetLineColor(m_ThemeInfo));
|
||||
if (m_Tooltip.type == Tooltip.Type.Corss)
|
||||
{
|
||||
sp = new Vector2(coordinateX, m_Tooltip.runtimePointerPos.y);
|
||||
ep = new Vector2(coordinateX + coordinateWidth, m_Tooltip.runtimePointerPos.y);
|
||||
DrawSplitLine(vh, yAxis, Axis.SplitLineType.Dashed, sp, ep, m_ThemeInfo.tooltipLineColor);
|
||||
DrawSplitLine(vh, m_Tooltip.lineStyle, sp, ep, m_Tooltip.GetLineColor(m_ThemeInfo));
|
||||
}
|
||||
break;
|
||||
case Tooltip.Type.Shadow:
|
||||
@@ -1757,7 +1774,8 @@ namespace XCharts
|
||||
Color32 color, bool clip)
|
||||
{
|
||||
if (!IsInChart(p1) || !IsInChart(p2) || !IsInChart(p3) || !IsInChart(p4)) return;
|
||||
CheckClipAndDrawPolygon(vh, p1, p2, p3, p4, color, color, clip);
|
||||
if (!clip || (clip && (IsInCooridate(p1) || IsInCooridate(p2) || IsInCooridate(p3) || IsInCooridate(p4))))
|
||||
ChartDrawer.DrawPolygon(vh, p1, p2, p3, p4, color, color);
|
||||
}
|
||||
|
||||
protected void CheckClipAndDrawPolygon(VertexHelper vh, Vector3 p, float radius, Color32 color,
|
||||
@@ -1771,12 +1789,11 @@ namespace XCharts
|
||||
protected void CheckClipAndDrawPolygon(VertexHelper vh, Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4,
|
||||
Color32 startColor, Color32 toColor, bool clip)
|
||||
{
|
||||
p1 = ClampInChart(p1);
|
||||
p2 = ClampInChart(p2);
|
||||
p3 = ClampInChart(p3);
|
||||
p4 = ClampInChart(p4);
|
||||
//if (!IsInChart(p1) || !IsInChart(p2) || !IsInChart(p3) || !IsInChart(p4)) return;
|
||||
if (!clip || (clip && (IsInCooridate(p1) || IsInCooridate(p2) || IsInCooridate(p3) || IsInCooridate(p4))))
|
||||
p1 = ClampInCoordinate(p1);
|
||||
p2 = ClampInCoordinate(p2);
|
||||
p3 = ClampInCoordinate(p3);
|
||||
p4 = ClampInCoordinate(p4);
|
||||
if (!clip || (clip && (IsInCooridate(p1) && IsInCooridate(p2) && IsInCooridate(p3) && IsInCooridate(p4))))
|
||||
ChartDrawer.DrawPolygon(vh, p1, p2, p3, p4, startColor, toColor);
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user