mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-19 06:50:18 +00:00
增加SplitArea配置坐标轴分割区域
This commit is contained in:
@@ -48,6 +48,7 @@ namespace XCharts
|
||||
SerializedProperty m_Data = prop.FindPropertyRelative("m_Data");
|
||||
SerializedProperty m_AxisName = prop.FindPropertyRelative("m_AxisName");
|
||||
SerializedProperty m_AxisTick = prop.FindPropertyRelative("m_AxisTick");
|
||||
SerializedProperty m_SplitArea = prop.FindPropertyRelative("m_SplitArea");
|
||||
SerializedProperty m_MinMaxType = prop.FindPropertyRelative("m_MinMaxType");
|
||||
SerializedProperty m_Min = prop.FindPropertyRelative("m_Min");
|
||||
SerializedProperty m_Max = prop.FindPropertyRelative("m_Max");
|
||||
@@ -110,6 +111,9 @@ namespace XCharts
|
||||
EditorGUI.PropertyField(drawRect, m_AxisTick);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
drawRect.y += EditorGUI.GetPropertyHeight(m_AxisTick);
|
||||
EditorGUI.PropertyField(drawRect, m_SplitArea);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
drawRect.y += EditorGUI.GetPropertyHeight(m_SplitArea);
|
||||
|
||||
if (type == Axis.AxisType.Category)
|
||||
{
|
||||
@@ -137,8 +141,9 @@ namespace XCharts
|
||||
SerializedProperty m_Type = prop.FindPropertyRelative("m_Type");
|
||||
SerializedProperty m_AxisTick = prop.FindPropertyRelative("m_AxisTick");
|
||||
SerializedProperty m_AxisName = prop.FindPropertyRelative("m_AxisName");
|
||||
SerializedProperty m_SplitArea = prop.FindPropertyRelative("m_SplitArea");
|
||||
float height = 0;
|
||||
height += 8 * EditorGUIUtility.singleLineHeight + 7 * EditorGUIUtility.standardVerticalSpacing;
|
||||
height += 9 * EditorGUIUtility.singleLineHeight + 8 * EditorGUIUtility.standardVerticalSpacing;
|
||||
Axis.AxisType type = (Axis.AxisType)m_Type.enumValueIndex;
|
||||
if (type == Axis.AxisType.Category)
|
||||
{
|
||||
@@ -170,6 +175,7 @@ namespace XCharts
|
||||
}
|
||||
height += EditorGUI.GetPropertyHeight(m_AxisName);
|
||||
height += EditorGUI.GetPropertyHeight(m_AxisTick);
|
||||
height += EditorGUI.GetPropertyHeight(m_SplitArea);
|
||||
return height;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(Axis.SplitArea), true)]
|
||||
public class AxisSplitAreaDrawer : PropertyDrawer
|
||||
{
|
||||
private bool m_ColorFoldout = false;
|
||||
private int m_ColorSize = 0;
|
||||
private bool m_SplitAreaToggle = 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_Color = prop.FindPropertyRelative("m_Color");
|
||||
|
||||
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_SplitAreaToggle, "Split Area", show, false);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
if (m_SplitAreaToggle)
|
||||
{
|
||||
++EditorGUI.indentLevel;
|
||||
m_ColorFoldout = EditorGUI.Foldout(drawRect, m_ColorFoldout, "Color");
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
drawRect.width = pos.width;
|
||||
if (m_ColorFoldout)
|
||||
{
|
||||
ChartEditorHelper.MakeList(ref drawRect, ref m_ColorSize, m_Color);
|
||||
}
|
||||
--EditorGUI.indentLevel;
|
||||
}
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
|
||||
{
|
||||
float height = 0;
|
||||
if (m_SplitAreaToggle)
|
||||
{
|
||||
height += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
if (m_ColorFoldout)
|
||||
{
|
||||
SerializedProperty m_Data = prop.FindPropertyRelative("m_Color");
|
||||
int num = m_Data.arraySize + 1;
|
||||
height += num * EditorGUIUtility.singleLineHeight + (num - 1) * EditorGUIUtility.standardVerticalSpacing;
|
||||
height += EditorGUIUtility.standardVerticalSpacing;
|
||||
}
|
||||
}
|
||||
return height;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 988570bd6485942da9879649ed4adb5b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -135,6 +135,49 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Split area of axis in grid area, not shown by default.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class SplitArea
|
||||
{
|
||||
[SerializeField] private bool m_Show;
|
||||
[SerializeField] private List<Color> m_Color;
|
||||
|
||||
/// <summary>
|
||||
/// Set this to true to show the splitArea.
|
||||
/// </summary>
|
||||
/// <value>false</value>
|
||||
public bool show { get { return m_Show; } set { m_Show = value; } }
|
||||
/// <summary>
|
||||
/// Color of split area. SplitArea color could also be set in color array,
|
||||
/// which the split lines would take as their colors in turns.
|
||||
/// Dark and light colors in turns are used by default.
|
||||
/// </summary>
|
||||
/// <value>['rgba(250,250,250,0.3)','rgba(200,200,200,0.3)']</value>
|
||||
public List<Color> color { get { return m_Color; } set { m_Color = value; } }
|
||||
|
||||
public static SplitArea defaultSplitArea
|
||||
{
|
||||
get
|
||||
{
|
||||
return new SplitArea()
|
||||
{
|
||||
m_Show = false,
|
||||
m_Color = new List<Color>(){
|
||||
new Color32(250,250,250,77),
|
||||
new Color32(200,200,200,77)
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public Color getColor(int index){
|
||||
var i = index % color.Count;
|
||||
return color[i];
|
||||
}
|
||||
}
|
||||
|
||||
[SerializeField] protected bool m_Show = true;
|
||||
[SerializeField] protected AxisType m_Type;
|
||||
[SerializeField] protected AxisMinMaxType m_MinMaxType;
|
||||
@@ -148,6 +191,7 @@ namespace XCharts
|
||||
[SerializeField] protected List<string> m_Data = new List<string>();
|
||||
[SerializeField] protected AxisName m_AxisName = AxisName.defaultAxisName;
|
||||
[SerializeField] protected AxisTick m_AxisTick = AxisTick.defaultTick;
|
||||
[SerializeField] protected SplitArea m_SplitArea = SplitArea.defaultSplitArea;
|
||||
|
||||
public bool show { get { return m_Show; } set { m_Show = value; } }
|
||||
public AxisType type { get { return m_Type; } set { m_Type = value; } }
|
||||
@@ -163,6 +207,7 @@ namespace XCharts
|
||||
|
||||
public AxisName axisName { get { return m_AxisName; } set { m_AxisName = value; } }
|
||||
public AxisTick axisTick { get { return m_AxisTick; } set { m_AxisTick = value; } }
|
||||
public SplitArea splitArea { get { return m_SplitArea; } set { m_SplitArea = value; } }
|
||||
|
||||
public int filterStart { get; set; }
|
||||
public int filterEnd { get; set; }
|
||||
|
||||
@@ -547,15 +547,24 @@ namespace XCharts
|
||||
#region draw tick and splitline
|
||||
if (m_YAxis.show)
|
||||
{
|
||||
for (int i = 0; i < m_YAxis.GetScaleNumber(m_DataZoom); i++)
|
||||
var scaleWidth = m_YAxis.GetScaleWidth(coordinateHig, m_DataZoom);
|
||||
var size = m_YAxis.GetScaleNumber(m_DataZoom);
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
float pX = 0;
|
||||
float pY = coordinateY + i * m_YAxis.GetScaleWidth(coordinateHig, m_DataZoom);
|
||||
float pY = coordinateY + i * scaleWidth;
|
||||
if (m_YAxis.boundaryGap && m_YAxis.axisTick.alignWithLabel)
|
||||
{
|
||||
pY -= m_YAxis.GetScaleWidth(coordinateHig, m_DataZoom) / 2;
|
||||
pY -= scaleWidth / 2;
|
||||
}
|
||||
if (m_YAxis.splitArea.show && i < size - 1)
|
||||
{
|
||||
ChartHelper.DrawPolygon(vh, new Vector2(coordinateX, pY),
|
||||
new Vector2(coordinateX + coordinateWid, pY),
|
||||
new Vector2(coordinateX + coordinateWid, pY + scaleWidth),
|
||||
new Vector2(coordinateX, pY + scaleWidth),
|
||||
m_YAxis.splitArea.getColor(i));
|
||||
}
|
||||
|
||||
if (m_YAxis.axisTick.show)
|
||||
{
|
||||
pX += zeroX - m_YAxis.axisTick.length - 2;
|
||||
@@ -571,13 +580,23 @@ namespace XCharts
|
||||
}
|
||||
if (m_XAxis.show)
|
||||
{
|
||||
for (int i = 0; i < m_XAxis.GetScaleNumber(m_DataZoom); i++)
|
||||
var scaleWidth = m_XAxis.GetScaleWidth(coordinateWid, m_DataZoom);
|
||||
var size = m_XAxis.GetScaleNumber(m_DataZoom);
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
float pX = coordinateX + i * m_XAxis.GetScaleWidth(coordinateWid, m_DataZoom);
|
||||
float pX = coordinateX + i * scaleWidth;
|
||||
float pY = 0;
|
||||
if (m_XAxis.boundaryGap && m_XAxis.axisTick.alignWithLabel)
|
||||
{
|
||||
pX -= m_XAxis.GetScaleWidth(coordinateWid, m_DataZoom) / 2;
|
||||
pX -= scaleWidth / 2;
|
||||
}
|
||||
if (m_XAxis.splitArea.show && i < size - 1)
|
||||
{
|
||||
ChartHelper.DrawPolygon(vh, new Vector2(pX, coordinateY),
|
||||
new Vector2(pX, coordinateY + coordinateHig),
|
||||
new Vector2(pX + scaleWidth, coordinateY + coordinateHig),
|
||||
new Vector2(pX + scaleWidth, coordinateY),
|
||||
m_XAxis.splitArea.getColor(i));
|
||||
}
|
||||
if (m_XAxis.axisTick.show)
|
||||
{
|
||||
|
||||
@@ -21,12 +21,13 @@ An ECharts style UGUI Charting Library for Unity
|
||||
|
||||
## 更新日志
|
||||
|
||||
* (2019.06.29)增加`AxisName`可配置坐标轴名称
|
||||
* (2019.06.30)增加`SplitArea`配置坐标轴`分割区域`
|
||||
* (2019.06.29)增加`AxisName`配置坐标轴`名称`
|
||||
* (2019.06.20)增加`AreaAlpha`控制`RadarChart`的`Area`透明度
|
||||
* (2019.06.13)增加`DataZoom`实现区域缩放
|
||||
* (2019.06.13)增加`DataZoom`实现`区域缩放`
|
||||
* (2019.06.01)增加`stepType`实现`LineChart`的`阶梯线图`
|
||||
* (2019.05.29)增加`InSameBar`实现`BarChart`的非堆叠同柱
|
||||
* (2019.05.29)增加`crossLabel`控制`Tooltip`的十字准星指示器
|
||||
* (2019.05.29)增加`InSameBar`实现`BarChart`的`非堆叠同柱`
|
||||
* (2019.05.29)增加`crossLabel`控制`Tooltip`的`十字准星指示器`
|
||||
* (2019.05.24)增加`堆叠区域图`
|
||||
* (2019.05.16)增加`AxisMinMaxType`控制坐标轴最大最小刻度
|
||||
* (2019.05.15)完善数据接口
|
||||
|
||||
Reference in New Issue
Block a user