mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-30 13:28:47 +00:00
增加SerieLabel配置饼图标签,支持Center,inside,Outside等显示位置
This commit is contained in:
File diff suppressed because it is too large
Load Diff
168086
Demo/demo_xchart.unity
168086
Demo/demo_xchart.unity
File diff suppressed because it is too large
Load Diff
@@ -28,6 +28,8 @@ namespace XCharts
|
|||||||
SerializedProperty m_Space = prop.FindPropertyRelative("m_Space");
|
SerializedProperty m_Space = prop.FindPropertyRelative("m_Space");
|
||||||
SerializedProperty m_Center = prop.FindPropertyRelative("m_Center");
|
SerializedProperty m_Center = prop.FindPropertyRelative("m_Center");
|
||||||
SerializedProperty m_Radius = prop.FindPropertyRelative("m_Radius");
|
SerializedProperty m_Radius = prop.FindPropertyRelative("m_Radius");
|
||||||
|
SerializedProperty m_Label = prop.FindPropertyRelative("m_Label");
|
||||||
|
SerializedProperty m_HighlightLabel = prop.FindPropertyRelative("m_HighlightLabel");
|
||||||
SerializedProperty m_DataDimension = prop.FindPropertyRelative("m_ShowDataDimension");
|
SerializedProperty m_DataDimension = prop.FindPropertyRelative("m_ShowDataDimension");
|
||||||
SerializedProperty m_ShowDataName = prop.FindPropertyRelative("m_ShowDataName");
|
SerializedProperty m_ShowDataName = prop.FindPropertyRelative("m_ShowDataName");
|
||||||
SerializedProperty m_Datas = prop.FindPropertyRelative("m_Data");
|
SerializedProperty m_Datas = prop.FindPropertyRelative("m_Data");
|
||||||
@@ -99,6 +101,10 @@ namespace XCharts
|
|||||||
EditorGUI.PropertyField(drawRect, m_ClickOffset);
|
EditorGUI.PropertyField(drawRect, m_ClickOffset);
|
||||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
}
|
}
|
||||||
|
EditorGUI.PropertyField(drawRect, m_Label,new GUIContent("Normal Label"));
|
||||||
|
drawRect.y += EditorGUI.GetPropertyHeight(m_Label);
|
||||||
|
EditorGUI.PropertyField(drawRect, m_HighlightLabel,new GUIContent("Highlight Label"));
|
||||||
|
drawRect.y += EditorGUI.GetPropertyHeight(m_HighlightLabel);
|
||||||
drawRect.width = EditorGUIUtility.labelWidth + 10;
|
drawRect.width = EditorGUIUtility.labelWidth + 10;
|
||||||
m_DataFoldout[index] = EditorGUI.Foldout(drawRect, m_DataFoldout[index], "Data");
|
m_DataFoldout[index] = EditorGUI.Foldout(drawRect, m_DataFoldout[index], "Data");
|
||||||
ChartEditorHelper.MakeJsonData(ref drawRect, ref m_ShowJsonDataArea, ref m_JsonDataAreaText, prop, pos.width);
|
ChartEditorHelper.MakeJsonData(ref drawRect, ref m_ShowJsonDataArea, ref m_JsonDataAreaText, prop, pos.width);
|
||||||
@@ -237,6 +243,8 @@ namespace XCharts
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
height += 6 * EditorGUIUtility.singleLineHeight + 6 * EditorGUIUtility.standardVerticalSpacing;
|
height += 6 * EditorGUIUtility.singleLineHeight + 6 * EditorGUIUtility.standardVerticalSpacing;
|
||||||
|
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Label"));
|
||||||
|
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_HighlightLabel"));
|
||||||
SerializedProperty type = prop.FindPropertyRelative("m_Type");
|
SerializedProperty type = prop.FindPropertyRelative("m_Type");
|
||||||
var serieType = (SerieType)type.enumValueIndex;
|
var serieType = (SerieType)type.enumValueIndex;
|
||||||
if (serieType == SerieType.Line
|
if (serieType == SerieType.Line
|
||||||
|
|||||||
68
Scripts/Editor/PropertyDrawers/SerieLabelDrawer.cs
Normal file
68
Scripts/Editor/PropertyDrawers/SerieLabelDrawer.cs
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace XCharts
|
||||||
|
{
|
||||||
|
[CustomPropertyDrawer(typeof(SerieLabel), true)]
|
||||||
|
public class SerieLabelDrawer : PropertyDrawer
|
||||||
|
{
|
||||||
|
private bool m_SerieLabelToggle = 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_Position = prop.FindPropertyRelative("m_Position");
|
||||||
|
SerializedProperty m_Distance = prop.FindPropertyRelative("m_Distance");
|
||||||
|
SerializedProperty m_Rotate = prop.FindPropertyRelative("m_Rotate");
|
||||||
|
SerializedProperty m_Color = prop.FindPropertyRelative("m_Color");
|
||||||
|
SerializedProperty m_FontSize = prop.FindPropertyRelative("m_FontSize");
|
||||||
|
SerializedProperty m_FontStyle = prop.FindPropertyRelative("m_FontStyle");
|
||||||
|
SerializedProperty m_Line = prop.FindPropertyRelative("m_Line");
|
||||||
|
SerializedProperty m_LineWidth = prop.FindPropertyRelative("m_LineWidth");
|
||||||
|
SerializedProperty m_LineLength1 = prop.FindPropertyRelative("m_LineLength1");
|
||||||
|
SerializedProperty m_LineLength2 = prop.FindPropertyRelative("m_LineLength2");
|
||||||
|
|
||||||
|
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_SerieLabelToggle, prop.displayName, show, false);
|
||||||
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
|
if (m_SerieLabelToggle)
|
||||||
|
{
|
||||||
|
++EditorGUI.indentLevel;
|
||||||
|
EditorGUI.PropertyField(drawRect, m_Position);
|
||||||
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
|
EditorGUI.PropertyField(drawRect, m_Distance);
|
||||||
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
|
EditorGUI.PropertyField(drawRect, m_Color);
|
||||||
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
|
EditorGUI.PropertyField(drawRect, m_Rotate);
|
||||||
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
|
EditorGUI.PropertyField(drawRect, m_FontSize);
|
||||||
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
|
EditorGUI.PropertyField(drawRect, m_FontStyle);
|
||||||
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
|
EditorGUI.PropertyField(drawRect, m_Line);
|
||||||
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
|
EditorGUI.PropertyField(drawRect, m_LineWidth);
|
||||||
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
|
EditorGUI.PropertyField(drawRect, m_LineLength1);
|
||||||
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
|
EditorGUI.PropertyField(drawRect, m_LineLength2);
|
||||||
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
|
--EditorGUI.indentLevel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
|
||||||
|
{
|
||||||
|
float height = 0;
|
||||||
|
if (m_SerieLabelToggle)
|
||||||
|
{
|
||||||
|
height += 11 * EditorGUIUtility.singleLineHeight + 10 * EditorGUIUtility.standardVerticalSpacing;
|
||||||
|
}else{
|
||||||
|
height = EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
|
}
|
||||||
|
return height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Scripts/Editor/PropertyDrawers/SerieLabelDrawer.cs.meta
Normal file
11
Scripts/Editor/PropertyDrawers/SerieLabelDrawer.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d30d82b48b553451fad726478777a02e
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -18,6 +18,7 @@ namespace XCharts
|
|||||||
{
|
{
|
||||||
private static readonly string s_TitleObjectName = "title";
|
private static readonly string s_TitleObjectName = "title";
|
||||||
private static readonly string s_LegendObjectName = "legend";
|
private static readonly string s_LegendObjectName = "legend";
|
||||||
|
private static readonly string s_SerieLabelObjectName = "label";
|
||||||
|
|
||||||
[SerializeField] protected float m_ChartWidth;
|
[SerializeField] protected float m_ChartWidth;
|
||||||
[SerializeField] protected float m_ChartHeight;
|
[SerializeField] protected float m_ChartHeight;
|
||||||
@@ -39,6 +40,7 @@ namespace XCharts
|
|||||||
[NonSerialized] private float m_CheckSerieCount = 0;
|
[NonSerialized] private float m_CheckSerieCount = 0;
|
||||||
[NonSerialized] private List<string> m_CheckSerieName = new List<string>();
|
[NonSerialized] private List<string> m_CheckSerieName = new List<string>();
|
||||||
[NonSerialized] private bool m_RefreshChart = false;
|
[NonSerialized] private bool m_RefreshChart = false;
|
||||||
|
[NonSerialized] private bool m_RefreshLabel = false;
|
||||||
|
|
||||||
protected Vector2 chartAnchorMax { get { return rectTransform.anchorMax; } }
|
protected Vector2 chartAnchorMax { get { return rectTransform.anchorMax; } }
|
||||||
protected Vector2 chartAnchorMin { get { return rectTransform.anchorMin; } }
|
protected Vector2 chartAnchorMin { get { return rectTransform.anchorMin; } }
|
||||||
@@ -61,11 +63,13 @@ namespace XCharts
|
|||||||
m_CheckTheme = m_ThemeInfo.theme;
|
m_CheckTheme = m_ThemeInfo.theme;
|
||||||
InitTitle();
|
InitTitle();
|
||||||
InitLegend();
|
InitLegend();
|
||||||
|
InitSerieLabel();
|
||||||
InitTooltip();
|
InitTooltip();
|
||||||
TransferOldVersionData();
|
TransferOldVersionData();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Start() {
|
protected override void Start()
|
||||||
|
{
|
||||||
RefreshChart();
|
RefreshChart();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,6 +81,7 @@ namespace XCharts
|
|||||||
CheckLegend();
|
CheckLegend();
|
||||||
CheckTooltip();
|
CheckTooltip();
|
||||||
CheckRefreshChart();
|
CheckRefreshChart();
|
||||||
|
CheckRefreshLabel();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnEnable()
|
protected override void OnEnable()
|
||||||
@@ -248,6 +253,34 @@ namespace XCharts
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void InitSerieLabel()
|
||||||
|
{
|
||||||
|
ChartHelper.HideAllObject(transform, s_SerieLabelObjectName);
|
||||||
|
var labelObject = ChartHelper.AddObject(s_SerieLabelObjectName, transform, chartAnchorMin,
|
||||||
|
chartAnchorMax, chartPivot, new Vector2(chartWidth, chartHeight));
|
||||||
|
int count = 0;
|
||||||
|
for (int i = 0; i < m_Series.Count; i++)
|
||||||
|
{
|
||||||
|
var serie = m_Series.series[i];
|
||||||
|
if (serie.type != SerieType.Pie) continue;
|
||||||
|
for (int j = 0; j < serie.data.Count; j++)
|
||||||
|
{
|
||||||
|
var serieData = serie.data[j];
|
||||||
|
var textName = s_SerieLabelObjectName + "_" + i + "_" + j + "_" + serieData.name;
|
||||||
|
var color = (serie.label.position == SerieLabel.Position.Inside) ? Color.white :
|
||||||
|
(Color)m_ThemeInfo.GetColor(count++);
|
||||||
|
var anchorMin = new Vector2(0.5f, 0.5f);
|
||||||
|
var anchorMax = new Vector2(0.5f, 0.5f);
|
||||||
|
var pivot = new Vector2(0.5f, 0.5f);
|
||||||
|
serieData.label = ChartHelper.AddTextObject(textName, labelObject.transform,
|
||||||
|
m_ThemeInfo.font, color, TextAnchor.MiddleCenter, anchorMin, anchorMax, pivot,
|
||||||
|
new Vector2(50, serie.label.fontSize), serie.label.fontSize);
|
||||||
|
serieData.label.text = serieData.name;
|
||||||
|
serieData.label.gameObject.SetActive(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void InitTooltip()
|
private void InitTooltip()
|
||||||
{
|
{
|
||||||
var tooltipObject = ChartHelper.AddObject("tooltip", transform, chartAnchorMin,
|
var tooltipObject = ChartHelper.AddObject("tooltip", transform, chartAnchorMin,
|
||||||
@@ -384,6 +417,20 @@ namespace XCharts
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void CheckRefreshLabel()
|
||||||
|
{
|
||||||
|
if (m_RefreshLabel)
|
||||||
|
{
|
||||||
|
m_RefreshLabel = false;
|
||||||
|
OnRefreshLabel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void OnRefreshLabel()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
protected virtual void OnSizeChanged()
|
protected virtual void OnSizeChanged()
|
||||||
{
|
{
|
||||||
InitTitle();
|
InitTitle();
|
||||||
@@ -456,6 +503,7 @@ namespace XCharts
|
|||||||
DrawBackground(vh);
|
DrawBackground(vh);
|
||||||
DrawChart(vh);
|
DrawChart(vh);
|
||||||
DrawTooltip(vh);
|
DrawTooltip(vh);
|
||||||
|
m_RefreshLabel = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void DrawChart(VertexHelper vh)
|
protected virtual void DrawChart(VertexHelper vh)
|
||||||
|
|||||||
@@ -39,7 +39,8 @@ namespace XCharts
|
|||||||
[SerializeField] private float[] m_Center = new float[2] { 0.5f, 0.5f };
|
[SerializeField] private float[] m_Center = new float[2] { 0.5f, 0.5f };
|
||||||
[SerializeField] private float[] m_Radius = new float[2] { 0, 80 };
|
[SerializeField] private float[] m_Radius = new float[2] { 0, 80 };
|
||||||
#endregion
|
#endregion
|
||||||
|
[SerializeField] private SerieLabel m_Label = new SerieLabel();
|
||||||
|
[SerializeField] private SerieLabel m_HighlightLabel = new SerieLabel();
|
||||||
[SerializeField] [Range(1, 6)] private int m_ShowDataDimension;
|
[SerializeField] [Range(1, 6)] private int m_ShowDataDimension;
|
||||||
[SerializeField] private bool m_ShowDataName;
|
[SerializeField] private bool m_ShowDataName;
|
||||||
[FormerlySerializedAs("m_Data")]
|
[FormerlySerializedAs("m_Data")]
|
||||||
@@ -58,7 +59,20 @@ namespace XCharts
|
|||||||
public float space { get { return m_Space; } set { m_Space = value; } }
|
public float space { get { return m_Space; } set { m_Space = value; } }
|
||||||
public float[] center { get { return m_Center; } set { m_Center = value; } }
|
public float[] center { get { return m_Center; } set { m_Center = value; } }
|
||||||
public float[] radius { get { return m_Radius; } set { m_Radius = value; } }
|
public float[] radius { get { return m_Radius; } set { m_Radius = value; } }
|
||||||
|
/// <summary>
|
||||||
|
/// Text label of graphic element,to explain some data information about graphic item like value, name and so on.
|
||||||
|
/// 图形上的文本标签,可用于说明图形的一些数据信息,比如值,名称等。
|
||||||
|
/// </summary>
|
||||||
|
public SerieLabel label { get { return m_Label; } set { m_Label = value; } }
|
||||||
|
public SerieLabel highlightLabel { get { return m_HighlightLabel; } set { m_HighlightLabel = value; } }
|
||||||
|
public List<float> yData { get { return m_YData; } }
|
||||||
|
public List<float> xData { get { return m_XData; } }
|
||||||
|
public List<SerieData> data { get { return m_Data; } }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The index of serie,start at 0.
|
||||||
|
/// 系列的索引,从0开始。
|
||||||
|
/// </summary>
|
||||||
public int index { get; set; }
|
public int index { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether the serie is highlighted.
|
/// Whether the serie is highlighted.
|
||||||
@@ -66,11 +80,6 @@ namespace XCharts
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool highlighted { get; set; }
|
public bool highlighted { get; set; }
|
||||||
public int dataCount { get { return m_Data.Count; } }
|
public int dataCount { get { return m_Data.Count; } }
|
||||||
|
|
||||||
public List<float> yData { get { return m_YData; } }
|
|
||||||
public List<float> xData { get { return m_XData; } }
|
|
||||||
public List<SerieData> data { get { return m_Data; } }
|
|
||||||
|
|
||||||
public int filterStart { get; set; }
|
public int filterStart { get; set; }
|
||||||
public int filterEnd { get; set; }
|
public int filterEnd { get; set; }
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
namespace XCharts
|
namespace XCharts
|
||||||
{
|
{
|
||||||
@@ -36,5 +37,10 @@ namespace XCharts
|
|||||||
/// Whether the data item is highlighted.该数据项是否被高亮,一般由鼠标悬停或图例悬停触发高亮。
|
/// Whether the data item is highlighted.该数据项是否被高亮,一般由鼠标悬停或图例悬停触发高亮。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool highlighted { get; set; }
|
public bool highlighted { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// the label of data item.该数据项的文本标签。
|
||||||
|
/// </summary>
|
||||||
|
/// <value></value>
|
||||||
|
public Text label { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
80
Scripts/UI/Internal/SerieLabel.cs
Normal file
80
Scripts/UI/Internal/SerieLabel.cs
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace XCharts
|
||||||
|
{
|
||||||
|
[System.Serializable]
|
||||||
|
/// <summary>
|
||||||
|
/// Text label of chart, to explain some data information about graphic item like value, name and so on.
|
||||||
|
/// 图形上的文本标签,可用于说明图形的一些数据信息,比如值,名称等。
|
||||||
|
/// </summary>
|
||||||
|
public class SerieLabel
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The position of label.标签的位置。
|
||||||
|
/// </summary>
|
||||||
|
public enum Position
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Outside of sectors of pie chart, which relates to corresponding sector through visual guide line.
|
||||||
|
/// 饼图扇区外侧,通过视觉引导线连到相应的扇区。
|
||||||
|
/// </summary>
|
||||||
|
Outside,
|
||||||
|
/// <summary>
|
||||||
|
/// Inside the sectors of pie chart.饼图扇区内部。
|
||||||
|
/// </summary>
|
||||||
|
Inside,
|
||||||
|
/// <summary>
|
||||||
|
/// In the center of pie chart.在饼图中心位置。
|
||||||
|
Center,
|
||||||
|
Top,
|
||||||
|
Left,
|
||||||
|
Right,
|
||||||
|
Bottom,
|
||||||
|
}
|
||||||
|
[SerializeField] private bool m_Show = false;
|
||||||
|
[SerializeField] Position m_Position;
|
||||||
|
[SerializeField] private float m_Distance;
|
||||||
|
[SerializeField] private float m_Rotate;
|
||||||
|
[SerializeField] private Color m_Color;
|
||||||
|
[SerializeField] private int m_FontSize = 18;
|
||||||
|
[SerializeField] private FontStyle m_FontStyle = FontStyle.Normal;
|
||||||
|
[SerializeField] private bool m_Line = true;
|
||||||
|
[SerializeField] private float m_LineWidth = 1.0f;
|
||||||
|
[SerializeField] private float m_LineLength1 = 25f;
|
||||||
|
[SerializeField] private float m_LineLength2 = 15f;
|
||||||
|
/// <summary>
|
||||||
|
/// Whether the label is showed.是否显示文本标签。
|
||||||
|
/// </summary>
|
||||||
|
public bool show { get { return m_Show; } set { m_Show = value; } }
|
||||||
|
/// <summary>
|
||||||
|
/// The position of label.标签的位置。
|
||||||
|
/// </summary>
|
||||||
|
public Position position { get { return m_Position; } set { m_Position = value; } }
|
||||||
|
/// <summary>
|
||||||
|
/// Distance to the host graphic element. Works when position is Top,Left,Right,Bottom.
|
||||||
|
/// 距离图形元素的距离,当position为Top,Left,Right,Bottom时有效。
|
||||||
|
/// </summary>
|
||||||
|
public float distance { get { return m_Distance; } set { m_Distance = value; } }
|
||||||
|
/// <summary>
|
||||||
|
/// Text color,If set as default ,the color will assigned as series color.
|
||||||
|
/// 自定义文字颜色,默认和系列的颜色一致。
|
||||||
|
/// </summary>
|
||||||
|
public Color color { get { return m_Color; } set { m_Color = value; } }
|
||||||
|
/// <summary>
|
||||||
|
/// Rotate label.标签旋转。
|
||||||
|
/// </summary>
|
||||||
|
public float rotate { get { return m_Rotate; } set { m_Rotate = value; } }
|
||||||
|
/// <summary>
|
||||||
|
/// font size.文字的字体大小。
|
||||||
|
/// </summary>
|
||||||
|
public int fontSize { get { return m_FontSize; } set { m_FontSize = value; } }
|
||||||
|
/// <summary>
|
||||||
|
/// font style.文字的字体风格。
|
||||||
|
/// </summary>
|
||||||
|
public FontStyle fontStyle { get { return m_FontStyle; } set { m_FontStyle = value; } }
|
||||||
|
public bool line { get { return m_Line; } set { m_Line = value; } }
|
||||||
|
public float lineWidth { get { return m_LineWidth; } set { m_LineWidth = value; } }
|
||||||
|
public float lineLength1 { get { return m_LineLength1; } set { m_LineLength1 = value; } }
|
||||||
|
public float lineLength2 { get { return m_LineLength2; } set { m_LineLength2 = value; } }
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Scripts/UI/Internal/SerieLabel.cs.meta
Normal file
11
Scripts/UI/Internal/SerieLabel.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ac43f23d6d8a143c6b200005689c17af
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -26,6 +26,7 @@ namespace XCharts
|
|||||||
|
|
||||||
private bool isDrawPie;
|
private bool isDrawPie;
|
||||||
private bool m_IsEnterLegendButtom;
|
private bool m_IsEnterLegendButtom;
|
||||||
|
private bool m_RefreshLabel;
|
||||||
private List<PieTempData> m_PieTempDataList = new List<PieTempData>();
|
private List<PieTempData> m_PieTempDataList = new List<PieTempData>();
|
||||||
|
|
||||||
public Pie pie { get { return m_Pie; } }
|
public Pie pie { get { return m_Pie; } }
|
||||||
@@ -160,9 +161,14 @@ namespace XCharts
|
|||||||
{
|
{
|
||||||
offset += m_Pie.selectedOffset;
|
offset += m_Pie.selectedOffset;
|
||||||
}
|
}
|
||||||
|
var halfDegree = (toDegree - startDegree) / 2;
|
||||||
|
float currAngle = startDegree + halfDegree;
|
||||||
|
float currRad = currAngle * Mathf.Deg2Rad;
|
||||||
|
float currSin = Mathf.Sin(currRad);
|
||||||
|
float currCos = Mathf.Cos(currRad);
|
||||||
|
var center = tempData.center;
|
||||||
if (offset > 0)
|
if (offset > 0)
|
||||||
{
|
{
|
||||||
var halfDegree = (toDegree - startDegree) / 2;
|
|
||||||
float offsetRadius = serie.space / Mathf.Sin(halfDegree * Mathf.Deg2Rad);
|
float offsetRadius = serie.space / Mathf.Sin(halfDegree * Mathf.Deg2Rad);
|
||||||
var insideRadius = tempData.insideRadius - offsetRadius;
|
var insideRadius = tempData.insideRadius - offsetRadius;
|
||||||
var outsideRadius = outSideRadius - offsetRadius;
|
var outsideRadius = outSideRadius - offsetRadius;
|
||||||
@@ -172,18 +178,19 @@ namespace XCharts
|
|||||||
if (insideRadius > 0) insideRadius += m_Pie.selectedOffset;
|
if (insideRadius > 0) insideRadius += m_Pie.selectedOffset;
|
||||||
outsideRadius += m_Pie.selectedOffset;
|
outsideRadius += m_Pie.selectedOffset;
|
||||||
}
|
}
|
||||||
float currAngle = (startDegree + halfDegree) * Mathf.Deg2Rad;
|
|
||||||
var offestCenter = new Vector3(tempData.center.x + offsetRadius * Mathf.Sin(currAngle),
|
var offestCenter = new Vector3(center.x + offsetRadius * currSin,
|
||||||
tempData.center.y + offsetRadius * Mathf.Cos(currAngle));
|
center.y + offsetRadius * currCos);
|
||||||
|
|
||||||
ChartHelper.DrawDoughnut(vh, offestCenter, insideRadius, outsideRadius,
|
ChartHelper.DrawDoughnut(vh, offestCenter, insideRadius, outsideRadius,
|
||||||
startDegree, toDegree, color);
|
startDegree, toDegree, color);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ChartHelper.DrawDoughnut(vh, tempData.center, tempData.insideRadius, outSideRadius,
|
ChartHelper.DrawDoughnut(vh, center, tempData.insideRadius, outSideRadius,
|
||||||
startDegree, toDegree, color);
|
startDegree, toDegree, color);
|
||||||
}
|
}
|
||||||
|
DrawLabelLine(vh, serie,tempData, outSideRadius, center, currAngle, color);
|
||||||
isDrawPie = true;
|
isDrawPie = true;
|
||||||
tempData.angleList.Add(toDegree);
|
tempData.angleList.Add(toDegree);
|
||||||
startDegree = toDegree;
|
startDegree = toDegree;
|
||||||
@@ -192,6 +199,221 @@ namespace XCharts
|
|||||||
raycastTarget = isClickOffset && isDataHighlight;
|
raycastTarget = isClickOffset && isDataHighlight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void DrawLabelLine(VertexHelper vh, Serie serie,PieTempData tempData, float outSideRadius, Vector2 center, float currAngle, Color color)
|
||||||
|
{
|
||||||
|
if (serie.label.show
|
||||||
|
&& serie.label.position == SerieLabel.Position.Outside
|
||||||
|
&& serie.label.line)
|
||||||
|
{
|
||||||
|
if (serie.label.color != Color.clear) color = serie.label.color;
|
||||||
|
float currSin = Mathf.Sin(currAngle * Mathf.Deg2Rad);
|
||||||
|
float currCos = Mathf.Cos(currAngle * Mathf.Deg2Rad);
|
||||||
|
var radius1 = outSideRadius;
|
||||||
|
var radius2 = tempData.outsideRadius + serie.label.lineLength1;
|
||||||
|
var pos1 = new Vector2(center.x + radius1 * currSin, center.y + radius1 * currCos);
|
||||||
|
var pos2 = new Vector2(center.x + radius2 * currSin, center.y + radius2 * currCos);
|
||||||
|
float tx, ty;
|
||||||
|
Vector2 pos3;
|
||||||
|
if (currAngle < 90)
|
||||||
|
{
|
||||||
|
ty = serie.label.lineWidth * Mathf.Cos((90 - currAngle) * Mathf.Deg2Rad);
|
||||||
|
tx = serie.label.lineWidth * Mathf.Sin((90 - currAngle) * Mathf.Deg2Rad);
|
||||||
|
pos3 = new Vector2(pos2.x - tx, pos2.y + ty - serie.label.lineWidth);
|
||||||
|
}
|
||||||
|
else if (currAngle < 180)
|
||||||
|
{
|
||||||
|
ty = serie.label.lineWidth * Mathf.Sin((180 - currAngle) * Mathf.Deg2Rad);
|
||||||
|
tx = serie.label.lineWidth * Mathf.Cos((180 - currAngle) * Mathf.Deg2Rad);
|
||||||
|
pos3 = new Vector2(pos2.x - tx, pos2.y - ty + serie.label.lineWidth);
|
||||||
|
}
|
||||||
|
else if (currAngle < 270)
|
||||||
|
{
|
||||||
|
ty = serie.label.lineWidth * Mathf.Sin((180 + currAngle) * Mathf.Deg2Rad);
|
||||||
|
tx = serie.label.lineWidth * Mathf.Cos((180 + currAngle) * Mathf.Deg2Rad);
|
||||||
|
pos3 = new Vector2(pos2.x + tx, pos2.y - ty + serie.label.lineWidth);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ty = serie.label.lineWidth * Mathf.Cos((90 + currAngle) * Mathf.Deg2Rad);
|
||||||
|
tx = serie.label.lineWidth * Mathf.Sin((90 + currAngle) * Mathf.Deg2Rad);
|
||||||
|
pos3 = new Vector2(pos2.x + tx, pos2.y + ty - serie.label.lineWidth);
|
||||||
|
}
|
||||||
|
var pos4 = new Vector2(currAngle > 180 ? pos3.x - serie.label.lineLength2 : pos3.x + serie.label.lineLength2, pos3.y);
|
||||||
|
ChartHelper.DrawLine(vh, pos1, pos2, serie.label.lineWidth, color);
|
||||||
|
ChartHelper.DrawLine(vh, pos3, pos4, serie.label.lineWidth, color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnRefreshLabel()
|
||||||
|
{
|
||||||
|
serieNameSet.Clear();
|
||||||
|
int serieNameCount = -1;
|
||||||
|
for (int i = 0; i < m_Series.Count; i++)
|
||||||
|
{
|
||||||
|
var serie = m_Series.series[i];
|
||||||
|
serie.index = i;
|
||||||
|
|
||||||
|
if (!serie.show)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
PieTempData tempData;
|
||||||
|
if (i < m_PieTempDataList.Count)
|
||||||
|
{
|
||||||
|
tempData = m_PieTempDataList[i];
|
||||||
|
tempData.angleList.Clear();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tempData = new PieTempData();
|
||||||
|
m_PieTempDataList.Add(tempData);
|
||||||
|
}
|
||||||
|
tempData.angleList.Clear();
|
||||||
|
tempData.dataMax = serie.yMax;
|
||||||
|
tempData.dataTotal = serie.yTotal;
|
||||||
|
UpdatePieCenter(serie);
|
||||||
|
var data = serie.data;
|
||||||
|
|
||||||
|
float totalDegree = 360;
|
||||||
|
float startDegree = 0;
|
||||||
|
for (int n = 0; n < data.Count; n++)
|
||||||
|
{
|
||||||
|
var serieData = data[n];
|
||||||
|
float value = serieData.data[1];
|
||||||
|
string dataName = serieData.name;
|
||||||
|
Color color;
|
||||||
|
if (string.IsNullOrEmpty(dataName))
|
||||||
|
{
|
||||||
|
serieNameCount++;
|
||||||
|
color = m_ThemeInfo.GetColor(serieNameCount);
|
||||||
|
}
|
||||||
|
else if (!serieNameSet.ContainsKey(dataName))
|
||||||
|
{
|
||||||
|
serieNameSet.Add(dataName, serieNameCount);
|
||||||
|
serieNameCount++;
|
||||||
|
color = m_ThemeInfo.GetColor(serieNameCount);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
color = m_ThemeInfo.GetColor(serieNameSet[dataName]);
|
||||||
|
}
|
||||||
|
if (!serieData.show)
|
||||||
|
{
|
||||||
|
tempData.angleList.Add(0);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
float degree = totalDegree * value / tempData.dataTotal;
|
||||||
|
float toDegree = startDegree + degree;
|
||||||
|
|
||||||
|
float outSideRadius = serie.roseType > 0 ?
|
||||||
|
tempData.insideRadius + (tempData.outsideRadius - tempData.insideRadius) * value / tempData.dataMax :
|
||||||
|
tempData.outsideRadius;
|
||||||
|
if (serieData.highlighted)
|
||||||
|
{
|
||||||
|
//color *= 1.2f;
|
||||||
|
outSideRadius += m_Pie.tooltipExtraRadius;
|
||||||
|
}
|
||||||
|
var offset = serie.space;
|
||||||
|
if (serie.clickOffset && serieData.selected)
|
||||||
|
{
|
||||||
|
offset += m_Pie.selectedOffset;
|
||||||
|
}
|
||||||
|
var halfDegree = (toDegree - startDegree) / 2;
|
||||||
|
float currAngle = startDegree + halfDegree;
|
||||||
|
if (offset > 0)
|
||||||
|
{
|
||||||
|
float offsetRadius = serie.space / Mathf.Sin(halfDegree * Mathf.Deg2Rad);
|
||||||
|
var insideRadius = tempData.insideRadius - offsetRadius;
|
||||||
|
var outsideRadius = outSideRadius - offsetRadius;
|
||||||
|
if (serie.clickOffset && serieData.selected)
|
||||||
|
{
|
||||||
|
offsetRadius += m_Pie.selectedOffset;
|
||||||
|
if (insideRadius > 0) insideRadius += m_Pie.selectedOffset;
|
||||||
|
outsideRadius += m_Pie.selectedOffset;
|
||||||
|
}
|
||||||
|
DrawLabel(serie, serieData, tempData, color, currAngle, offsetRadius, insideRadius, outsideRadius);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DrawLabel(serie, serieData, tempData, color, currAngle, 0, tempData.insideRadius, outSideRadius);
|
||||||
|
}
|
||||||
|
tempData.angleList.Add(toDegree);
|
||||||
|
startDegree = toDegree;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawLabel(Serie serie, SerieData serieData, PieTempData tempData, Color serieColor,
|
||||||
|
float currAngle, float offsetRadius, float insideRadius, float outsideRadius)
|
||||||
|
{
|
||||||
|
var isHighlight = (serieData.highlighted && serie.highlightLabel.show);
|
||||||
|
if (serie.label.show || isHighlight)
|
||||||
|
{
|
||||||
|
float rotate = 0;
|
||||||
|
bool isInsidePosition = serie.label.position == SerieLabel.Position.Inside;
|
||||||
|
if (serie.label.rotate > 0 && isInsidePosition)
|
||||||
|
{
|
||||||
|
if (currAngle > 180) rotate += 270 - currAngle;
|
||||||
|
else rotate += -(currAngle - 90);
|
||||||
|
}
|
||||||
|
Color color = serieColor;
|
||||||
|
if (isHighlight)
|
||||||
|
{
|
||||||
|
if (serie.highlightLabel.color != Color.clear) color = serie.highlightLabel.color;
|
||||||
|
}
|
||||||
|
else if (serie.label.color != Color.clear)
|
||||||
|
{
|
||||||
|
color = serie.label.color;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
color = isInsidePosition ? Color.white : serieColor;
|
||||||
|
}
|
||||||
|
var fontSize = isHighlight ? serie.highlightLabel.fontSize : serie.label.fontSize;
|
||||||
|
var fontStyle = isHighlight ? serie.highlightLabel.fontStyle : serie.label.fontStyle;
|
||||||
|
float currRad = currAngle * Mathf.Deg2Rad;
|
||||||
|
|
||||||
|
serieData.label.color = color;
|
||||||
|
serieData.label.fontSize = fontSize;
|
||||||
|
serieData.label.fontStyle = fontStyle;
|
||||||
|
|
||||||
|
serieData.label.transform.localEulerAngles = new Vector3(0, 0, rotate);
|
||||||
|
|
||||||
|
|
||||||
|
switch (serie.label.position)
|
||||||
|
{
|
||||||
|
case SerieLabel.Position.Center:
|
||||||
|
serieData.label.transform.localPosition = tempData.center;
|
||||||
|
break;
|
||||||
|
case SerieLabel.Position.Inside:
|
||||||
|
var labelRadius = offsetRadius + insideRadius + (outsideRadius - insideRadius) / 2;
|
||||||
|
var labelCenter = new Vector2(tempData.center.x + labelRadius * Mathf.Sin(currRad),
|
||||||
|
tempData.center.y + labelRadius * Mathf.Cos(currRad));
|
||||||
|
serieData.label.transform.localPosition = labelCenter;
|
||||||
|
break;
|
||||||
|
case SerieLabel.Position.Outside:
|
||||||
|
labelRadius = tempData.outsideRadius + serie.label.lineLength1;
|
||||||
|
labelCenter = new Vector2(tempData.center.x + labelRadius * Mathf.Sin(currRad),
|
||||||
|
tempData.center.y + labelRadius * Mathf.Cos(currRad));
|
||||||
|
float labelWidth = serieData.label.preferredWidth;
|
||||||
|
if (currAngle > 180)
|
||||||
|
{
|
||||||
|
serieData.label.transform.localPosition = new Vector2(labelCenter.x - serie.label.lineLength2 - 5 - labelWidth / 2, labelCenter.y);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
serieData.label.transform.localPosition = new Vector2(labelCenter.x + serie.label.lineLength2 + 5 + labelWidth / 2, labelCenter.y);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
serieData.label.gameObject.SetActive(true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
serieData.label.gameObject.SetActive(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected override void OnLegendButtonClick(int index, string legendName)
|
protected override void OnLegendButtonClick(int index, string legendName)
|
||||||
{
|
{
|
||||||
bool active = CheckDataShow(legendName);
|
bool active = CheckDataShow(legendName);
|
||||||
|
|||||||
Reference in New Issue
Block a user