mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-20 15:30:09 +00:00
增加LineArrow配置带箭头曲线
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,55 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(LineArrow), true)]
|
||||
public class LineArrowStyleDrawer : PropertyDrawer
|
||||
{
|
||||
private Dictionary<string, bool> m_LineArrowToggle = 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_Position = prop.FindPropertyRelative("m_Position");
|
||||
SerializedProperty m_Width = prop.FindPropertyRelative("m_Width");
|
||||
SerializedProperty m_Height = prop.FindPropertyRelative("m_Height");
|
||||
SerializedProperty m_Offset = prop.FindPropertyRelative("m_Offset");
|
||||
SerializedProperty m_Dent = prop.FindPropertyRelative("m_Dent");
|
||||
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_LineArrowToggle, prop, "Line Arrow", show, false);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
if (ChartEditorHelper.IsToggle(m_LineArrowToggle, prop))
|
||||
{
|
||||
++EditorGUI.indentLevel;
|
||||
EditorGUI.PropertyField(drawRect, m_Position);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_Width);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_Height);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_Offset);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_Dent);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
--EditorGUI.indentLevel;
|
||||
}
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
|
||||
{
|
||||
float height = 0;
|
||||
if (ChartEditorHelper.IsToggle(m_LineArrowToggle, prop))
|
||||
{
|
||||
height += 6 * EditorGUIUtility.singleLineHeight + 5 * EditorGUIUtility.standardVerticalSpacing;
|
||||
}
|
||||
else
|
||||
{
|
||||
height += 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing;
|
||||
}
|
||||
return height;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 817d27d232da94f6c9dab9e3d0c22631
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -24,6 +24,7 @@ namespace XCharts
|
||||
SerializedProperty m_AxisIndex = prop.FindPropertyRelative("m_AxisIndex");
|
||||
SerializedProperty m_RadarIndex = prop.FindPropertyRelative("m_RadarIndex");
|
||||
SerializedProperty m_LineStyle = prop.FindPropertyRelative("m_LineStyle");
|
||||
SerializedProperty m_LineArrow = prop.FindPropertyRelative("m_LineArrow");
|
||||
SerializedProperty m_LineType = prop.FindPropertyRelative("m_LineType");
|
||||
SerializedProperty m_BarWidth = prop.FindPropertyRelative("m_BarWidth");
|
||||
SerializedProperty m_BarGap = prop.FindPropertyRelative("m_BarGap");
|
||||
@@ -132,6 +133,11 @@ namespace XCharts
|
||||
|
||||
EditorGUI.PropertyField(drawRect, m_LineStyle);
|
||||
drawRect.y += EditorGUI.GetPropertyHeight(m_LineStyle);
|
||||
if (serieType == SerieType.Line)
|
||||
{
|
||||
EditorGUI.PropertyField(drawRect, m_LineArrow);
|
||||
drawRect.y += EditorGUI.GetPropertyHeight(m_LineArrow);
|
||||
}
|
||||
EditorGUI.PropertyField(drawRect, m_AreaStyle);
|
||||
drawRect.y += EditorGUI.GetPropertyHeight(m_AreaStyle);
|
||||
EditorGUI.PropertyField(drawRect, m_Label, new GUIContent("Normal Label"));
|
||||
@@ -299,6 +305,7 @@ namespace XCharts
|
||||
}
|
||||
if (serieType == SerieType.Line)
|
||||
{
|
||||
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_LineArrow"));
|
||||
height += 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing;
|
||||
}
|
||||
if (serieType == SerieType.Bar)
|
||||
|
||||
@@ -141,6 +141,7 @@ namespace XCharts
|
||||
[SerializeField] private SerieLabel m_Label = new SerieLabel();
|
||||
[SerializeField] private SerieLabel m_HighlightLabel = new SerieLabel();
|
||||
[SerializeField] private Animation m_Animation = new Animation();
|
||||
[SerializeField] private LineArrow m_LineArrow = new LineArrow();
|
||||
[SerializeField] [Range(1, 10)] private int m_ShowDataDimension;
|
||||
[SerializeField] private bool m_ShowDataName;
|
||||
[SerializeField] private List<SerieData> m_Data = new List<SerieData>();
|
||||
@@ -268,8 +269,18 @@ namespace XCharts
|
||||
/// 高亮时的文本标签配置。
|
||||
/// </summary>
|
||||
public SerieLabel highlightLabel { get { return m_HighlightLabel; } set { m_HighlightLabel = value; } }
|
||||
/// <summary>
|
||||
/// The start animation.
|
||||
/// 起始动画。
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public Animation animation { get { return m_Animation; } set { m_Animation = value; } }
|
||||
/// <summary>
|
||||
/// The arrow of line.
|
||||
/// 折线图的箭头
|
||||
/// </summary>
|
||||
public LineArrow lineArrow { get { return m_LineArrow; } set { m_LineArrow = value; } }
|
||||
/// <summary>
|
||||
/// 系列中的数据内容数组。SerieData可以设置1到n维数据。
|
||||
/// </summary>
|
||||
public List<SerieData> data { get { return m_Data; } }
|
||||
|
||||
@@ -859,12 +859,8 @@ namespace XCharts
|
||||
if (xAxis.axisLine.symbol)
|
||||
{
|
||||
var axisLine = xAxis.axisLine;
|
||||
top.x += xAxis.axisLine.symbolOffset;
|
||||
var middle = new Vector3(top.x - axisLine.symbolHeight + axisLine.symbolDent, lineY);
|
||||
left = new Vector3(top.x - axisLine.symbolHeight, lineY - axisLine.symbolWidth / 2);
|
||||
var right = new Vector3(top.x - axisLine.symbolHeight, lineY + axisLine.symbolWidth / 2);
|
||||
ChartHelper.DrawTriangle(vh, middle, top, left, m_ThemeInfo.axisLineColor);
|
||||
ChartHelper.DrawTriangle(vh, middle, top, right, m_ThemeInfo.axisLineColor);
|
||||
ChartHelper.DrawArrow(vh, new Vector3(coordinateX, lineY), top, axisLine.symbolWidth, axisLine.symbolHeight,
|
||||
axisLine.symbolOffset, axisLine.symbolDent, m_ThemeInfo.axisLineColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -881,12 +877,8 @@ namespace XCharts
|
||||
if (yAxis.axisLine.symbol)
|
||||
{
|
||||
var axisLine = yAxis.axisLine;
|
||||
top.y += yAxis.axisLine.symbolOffset;
|
||||
var middle = new Vector3(lineX, top.y - axisLine.symbolHeight + axisLine.symbolDent);
|
||||
var left = new Vector3(lineX - axisLine.symbolWidth / 2, top.y - axisLine.symbolHeight);
|
||||
var right = new Vector3(lineX + axisLine.symbolWidth / 2, top.y - axisLine.symbolHeight);
|
||||
ChartHelper.DrawTriangle(vh, middle, top, left, m_ThemeInfo.axisLineColor);
|
||||
ChartHelper.DrawTriangle(vh, middle, top, right, m_ThemeInfo.axisLineColor);
|
||||
ChartHelper.DrawArrow(vh, new Vector3(lineX, coordinateX), top, axisLine.symbolWidth, axisLine.symbolHeight,
|
||||
axisLine.symbolOffset, axisLine.symbolDent, m_ThemeInfo.axisLineColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
60
Assets/XCharts/Scripts/UI/Internal/LineArrow.cs
Normal file
60
Assets/XCharts/Scripts/UI/Internal/LineArrow.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class LineArrow
|
||||
{
|
||||
public enum Position
|
||||
{
|
||||
/// <summary>
|
||||
/// 末端箭头
|
||||
/// </summary>
|
||||
End,
|
||||
/// <summary>
|
||||
/// 头端箭头
|
||||
/// </summary>
|
||||
Start
|
||||
}
|
||||
[SerializeField] private bool m_Show;
|
||||
[SerializeField] Position m_Position;
|
||||
[SerializeField] private float m_Width = 10;
|
||||
[SerializeField] private float m_Height = 15;
|
||||
[SerializeField] private float m_Offset = 0;
|
||||
[SerializeField] private float m_Dent = 3;
|
||||
|
||||
/// <summary>
|
||||
/// Whether to show the arrow.
|
||||
/// 是否显示箭头。
|
||||
/// </summary>
|
||||
public bool show { get { return m_Show; } set { m_Show = value; } }
|
||||
/// <summary>
|
||||
/// The position of arrow.
|
||||
/// 箭头位置。
|
||||
/// </summary>
|
||||
public Position position { get { return m_Position; } set { m_Position = value; } }
|
||||
/// <summary>
|
||||
/// The widht of arrow.
|
||||
/// 箭头宽。
|
||||
/// </summary>
|
||||
public float width { get { return m_Width; } set { m_Width = value; } }
|
||||
/// <summary>
|
||||
/// The height of arrow.
|
||||
/// 箭头高。
|
||||
/// </summary>
|
||||
public float height { get { return m_Height; } set { m_Height = value; } }
|
||||
/// <summary>
|
||||
/// The offset of arrow.
|
||||
/// 箭头偏移。
|
||||
/// </summary>
|
||||
public float offset { get { return m_Offset; } set { m_Offset = value; } }
|
||||
/// <summary>
|
||||
/// The dent of arrow.
|
||||
/// 箭头的凹度。
|
||||
/// </summary>
|
||||
public float dent { get { return m_Dent; } set { m_Dent = value; } }
|
||||
}
|
||||
}
|
||||
11
Assets/XCharts/Scripts/UI/Internal/LineArrow.cs.meta
Normal file
11
Assets/XCharts/Scripts/UI/Internal/LineArrow.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a0814769fbf984e8ea9a8e694a023078
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -81,6 +81,7 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
DrawLinePoint(vh);
|
||||
DrawLineArrow(vh);
|
||||
if (yCategory) DrawYTooltipIndicator(vh);
|
||||
else DrawXTooltipIndicator(vh);
|
||||
}
|
||||
@@ -92,8 +93,14 @@ namespace XCharts
|
||||
var serie = m_Series.GetSerie(n);
|
||||
if (serie.type != SerieType.Line) continue;
|
||||
if (!serie.show || serie.symbol.type == SerieSymbolType.None) continue;
|
||||
for (int i = 0; i < serie.dataPoints.Count; i++)
|
||||
var count = serie.dataPoints.Count;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
if (serie.lineArrow.show)
|
||||
{
|
||||
if (serie.lineArrow.position == LineArrow.Position.Start && i == 0) continue;
|
||||
if (serie.lineArrow.position == LineArrow.Position.End && i == count - 1) continue;
|
||||
}
|
||||
Vector3 p = serie.dataPoints[i];
|
||||
bool highlight = (m_Tooltip.show && m_Tooltip.IsSelected(i)) || serie.data[i].highlighted || serie.highlighted;
|
||||
float symbolSize = highlight ? serie.symbol.selectedSize : serie.symbol.size;
|
||||
@@ -104,6 +111,38 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawLineArrow(VertexHelper vh)
|
||||
{
|
||||
for (int n = 0; n < m_Series.Count; n++)
|
||||
{
|
||||
var serie = m_Series.GetSerie(n);
|
||||
if (serie.type != SerieType.Line) continue;
|
||||
if (!serie.show || !serie.lineArrow.show) continue;
|
||||
if (serie.dataPoints.Count < 2) return;
|
||||
Color lineColor = serie.GetLineColor(m_ThemeInfo, n, false);
|
||||
|
||||
switch (serie.lineArrow.position)
|
||||
{
|
||||
case LineArrow.Position.End:
|
||||
var dataPoints = serie.GetUpSmoothList(serie.dataCount - 1);
|
||||
if (dataPoints.Count < 2) dataPoints = serie.dataPoints;
|
||||
var startPos = dataPoints[dataPoints.Count - 2];
|
||||
var arrowPos = dataPoints[dataPoints.Count - 1];
|
||||
ChartHelper.DrawArrow(vh, startPos, arrowPos, serie.lineArrow.width,
|
||||
serie.lineArrow.height, serie.lineArrow.offset, serie.lineArrow.dent, lineColor);
|
||||
break;
|
||||
case LineArrow.Position.Start:
|
||||
dataPoints = serie.GetUpSmoothList(1);
|
||||
if (dataPoints.Count < 2) dataPoints = serie.dataPoints;
|
||||
startPos = dataPoints[1];
|
||||
arrowPos = dataPoints[0];
|
||||
ChartHelper.DrawArrow(vh, startPos, arrowPos, serie.lineArrow.width,
|
||||
serie.lineArrow.height, serie.lineArrow.offset, serie.lineArrow.dent, lineColor);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawXLineSerie(VertexHelper vh, int serieIndex, Serie serie, ref List<float> seriesHig)
|
||||
{
|
||||
if (!IsActive(serie.index)) return;
|
||||
|
||||
@@ -228,6 +228,20 @@ namespace XCharts
|
||||
return labelObj;
|
||||
}
|
||||
|
||||
public static void DrawArrow(VertexHelper vh, Vector3 startPos, Vector3 arrowPos, float width,
|
||||
float height, float offset, float dent, Color32 color)
|
||||
{
|
||||
var dir = (arrowPos - startPos).normalized;
|
||||
|
||||
var sharpPos = arrowPos + (offset + height / 2) * dir;
|
||||
var middle = sharpPos + (dent - height) * dir;
|
||||
var diff = Vector3.Cross(dir, Vector3.forward).normalized * width / 2;
|
||||
var left = sharpPos - height * dir + diff;
|
||||
var right = sharpPos - height * dir - diff;
|
||||
ChartHelper.DrawTriangle(vh, middle, sharpPos, left, color);
|
||||
ChartHelper.DrawTriangle(vh, middle, sharpPos, right, color);
|
||||
}
|
||||
|
||||
public static void DrawLine(VertexHelper vh, Vector3 p1, Vector3 p2, float size, Color32 color)
|
||||
{
|
||||
if (p1 == p2) return;
|
||||
|
||||
Reference in New Issue
Block a user