mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-26 10:50:08 +00:00
[refactor] refactor symbol and label
This commit is contained in:
@@ -16,6 +16,22 @@ namespace XCharts.Runtime
|
||||
private GridCoord m_SerieGrid;
|
||||
private float m_LastLineWidth = 0f;
|
||||
|
||||
public override Vector3 GetSerieDataLabelOffset(SerieData serieData, LabelStyle label)
|
||||
{
|
||||
var invert = label.autoOffset
|
||||
&& SerieHelper.IsDownPoint(serie, serieData.index)
|
||||
&& (serie.areaStyle == null || !serie.areaStyle.show);
|
||||
if (invert)
|
||||
{
|
||||
var offset = label.GetOffset(serie.context.insideRadius);
|
||||
return new Vector3(offset.x, -offset.y, offset.z);
|
||||
}
|
||||
else
|
||||
{
|
||||
return label.GetOffset(serie.context.insideRadius);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateSerieGridContext()
|
||||
{
|
||||
if (m_SerieGrid == null)
|
||||
|
||||
@@ -77,8 +77,8 @@ namespace XCharts.Runtime
|
||||
refresh = true;
|
||||
for (int j = 0; j < serie.data.Count; j++)
|
||||
{
|
||||
if (j == index) serie.data[j].selected = !serie.data[j].selected;
|
||||
else serie.data[j].selected = false;
|
||||
if (j == index) serie.data[j].context.selected = !serie.data[j].context.selected;
|
||||
else serie.data[j].context.selected = false;
|
||||
}
|
||||
if (chart.onPointerClickPie != null)
|
||||
{
|
||||
@@ -406,8 +406,7 @@ namespace XCharts.Runtime
|
||||
var labelLine = SerieHelper.GetSerieLabelLine(serie, serieData);
|
||||
if (serieLabel != null && serieLabel.show
|
||||
&& labelLine != null && labelLine.show
|
||||
&& (serieLabel.position == LabelStyle.Position.Outside
|
||||
|| serieLabel.position == LabelStyle.Position.Default))
|
||||
&& (serieLabel.IsDefaultPosition(LabelStyle.Position.Outside)))
|
||||
{
|
||||
var insideRadius = serieData.context.insideRadius;
|
||||
var outSideRadius = serieData.context.outsideRadius;
|
||||
|
||||
@@ -230,7 +230,7 @@ namespace XCharts.Runtime
|
||||
[SerializeField] private bool m_InsertDataToHead;
|
||||
|
||||
[SerializeField] private LineStyle m_LineStyle = new LineStyle();
|
||||
[SerializeField] private SymbolStyle m_Symbol = new SymbolStyle();
|
||||
[SerializeField] private SerieSymbol m_Symbol = new SerieSymbol();
|
||||
[SerializeField] private AnimationStyle m_Animation = new AnimationStyle();
|
||||
[SerializeField] private ItemStyle m_ItemStyle = new ItemStyle();
|
||||
[SerializeField] private List<SerieData> m_Data = new List<SerieData>();
|
||||
@@ -396,7 +396,7 @@ namespace XCharts.Runtime
|
||||
/// the symbol of serie data item.
|
||||
/// |标记的图形。
|
||||
/// </summary>
|
||||
public SymbolStyle symbol
|
||||
public SerieSymbol symbol
|
||||
{
|
||||
get { return m_Symbol; }
|
||||
set { if (PropertyUtil.SetClass(ref m_Symbol, value, true)) SetVerticesDirty(); }
|
||||
@@ -1586,7 +1586,8 @@ namespace XCharts.Runtime
|
||||
|
||||
public bool IsIgnoreValue(SerieData serieData, int dimension = 1)
|
||||
{
|
||||
if (serieData.ignore) return true;
|
||||
if (serieData.baseInfo != null && serieData.baseInfo.ignore)
|
||||
return true;
|
||||
return IsIgnoreValue(serieData.GetData(dimension));
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using XUGL;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
@@ -16,11 +17,12 @@ namespace XCharts.Runtime
|
||||
[SerializeField] private string m_Name;
|
||||
[SerializeField] private string m_Id;
|
||||
[SerializeField] private string m_ParentId;
|
||||
[SerializeField] private List<SerieDataBaseInfo> m_BaseInfos = new List<SerieDataBaseInfo>();
|
||||
[SerializeField] private List<ItemStyle> m_ItemStyles = new List<ItemStyle>();
|
||||
[SerializeField] private List<LabelStyle> m_Labels = new List<LabelStyle>();
|
||||
[SerializeField] private List<LabelLine> m_LabelLines = new List<LabelLine>();
|
||||
[SerializeField] private List<Emphasis> m_Emphases = new List<Emphasis>();
|
||||
[SerializeField] private List<SymbolStyle> m_Symbols = new List<SymbolStyle>();
|
||||
[SerializeField] private List<SerieSymbol> m_Symbols = new List<SerieSymbol>();
|
||||
[SerializeField] private List<LineStyle> m_LineStyles = new List<LineStyle>();
|
||||
[SerializeField] private List<AreaStyle> m_AreaStyles = new List<AreaStyle>();
|
||||
[SerializeField] private List<TitleStyle> m_TitleStyles = new List<TitleStyle>();
|
||||
@@ -28,9 +30,7 @@ namespace XCharts.Runtime
|
||||
|
||||
[NonSerialized] public SerieDataContext context = new SerieDataContext();
|
||||
[NonSerialized] public InteractData interact = new InteractData();
|
||||
[NonSerialized] private bool m_Ignore = false;
|
||||
[NonSerialized] private bool m_Selected;
|
||||
[NonSerialized] private float m_Radius;
|
||||
|
||||
public ChartLabel labelObject { get; set; }
|
||||
public ChartLabel titleObject { get; set; }
|
||||
|
||||
@@ -52,15 +52,8 @@ namespace XCharts.Runtime
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public string legendName { get { return string.IsNullOrEmpty(name) ? ChartCached.IntToStr(index) : name; } }
|
||||
/// <summary>
|
||||
/// 自定义半径。可用在饼图中自定义某个数据项的半径。
|
||||
/// </summary>
|
||||
public float radius { get { return m_Radius; } set { m_Radius = value; } }
|
||||
/// <summary>
|
||||
/// Whether the data item is selected.
|
||||
/// |该数据项是否被选中。
|
||||
/// </summary>
|
||||
public bool selected { get { return m_Selected; } set { m_Selected = value; } }
|
||||
|
||||
public SerieDataBaseInfo baseInfo { get { return m_BaseInfos.Count > 0 ? m_BaseInfos[0] : null; } }
|
||||
/// <summary>
|
||||
/// 单个数据项的标签设置。
|
||||
/// </summary>
|
||||
@@ -77,18 +70,11 @@ namespace XCharts.Runtime
|
||||
/// <summary>
|
||||
/// 单个数据项的标记设置。
|
||||
/// </summary>
|
||||
public SymbolStyle symbol { get { return m_Symbols.Count > 0 ? m_Symbols[0] : null; } }
|
||||
public SerieSymbol symbol { get { return m_Symbols.Count > 0 ? m_Symbols[0] : null; } }
|
||||
public LineStyle lineStyle { get { return m_LineStyles.Count > 0 ? m_LineStyles[0] : null; } }
|
||||
public AreaStyle areaStyle { get { return m_AreaStyles.Count > 0 ? m_AreaStyles[0] : null; } }
|
||||
public TitleStyle titleStyle { get { return m_TitleStyles.Count > 0 ? m_TitleStyles[0] : null; } }
|
||||
/// <summary>
|
||||
/// 是否忽略数据。当为 true 时,数据不进行绘制。
|
||||
/// </summary>
|
||||
public bool ignore
|
||||
{
|
||||
get { return m_Ignore; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Ignore, value)) SetVerticesDirty(); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An arbitrary dimension data list of data item.
|
||||
/// |可指定任意维数的数值列表。
|
||||
@@ -99,6 +85,8 @@ namespace XCharts.Runtime
|
||||
/// |该数据项是否要显示。
|
||||
/// </summary>
|
||||
public bool show { get { return m_Show; } set { m_Show = value; } }
|
||||
public float radius { get { return baseInfo != null ? baseInfo.radius : 0; } }
|
||||
public bool selected { get { return (baseInfo != null && baseInfo.selected) || context.selected; } }
|
||||
|
||||
private List<double> m_PreviousData = new List<double>();
|
||||
private List<float> m_DataUpdateTime = new List<float>();
|
||||
@@ -110,6 +98,7 @@ namespace XCharts.Runtime
|
||||
get
|
||||
{
|
||||
return m_VertsDirty
|
||||
|| (baseInfo != null && baseInfo.vertsDirty)
|
||||
|| (labelLine != null && labelLine.vertsDirty)
|
||||
|| (itemStyle != null && itemStyle.vertsDirty)
|
||||
|| (symbol != null && symbol.vertsDirty)
|
||||
@@ -122,6 +111,7 @@ namespace XCharts.Runtime
|
||||
get
|
||||
{
|
||||
return m_ComponentDirty
|
||||
|| (baseInfo != null && baseInfo.componentDirty)
|
||||
|| (labelStyle != null && labelStyle.componentDirty)
|
||||
|| (labelLine != null && labelLine.componentDirty)
|
||||
|| (titleStyle != null && titleStyle.componentDirty)
|
||||
@@ -132,6 +122,7 @@ namespace XCharts.Runtime
|
||||
public override void ClearVerticesDirty()
|
||||
{
|
||||
base.ClearVerticesDirty();
|
||||
if (baseInfo != null) baseInfo.ClearVerticesDirty();
|
||||
if (labelLine != null) labelLine.ClearVerticesDirty();
|
||||
if (itemStyle != null) itemStyle.ClearVerticesDirty();
|
||||
if (lineStyle != null) lineStyle.ClearVerticesDirty();
|
||||
@@ -144,6 +135,7 @@ namespace XCharts.Runtime
|
||||
public override void ClearComponentDirty()
|
||||
{
|
||||
base.ClearComponentDirty();
|
||||
if (baseInfo != null) baseInfo.ClearComponentDirty();
|
||||
if (labelLine != null) labelLine.ClearComponentDirty();
|
||||
if (itemStyle != null) itemStyle.ClearComponentDirty();
|
||||
if (lineStyle != null) lineStyle.ClearComponentDirty();
|
||||
@@ -161,14 +153,13 @@ namespace XCharts.Runtime
|
||||
labelObject = null;
|
||||
m_Name = string.Empty;
|
||||
m_Show = true;
|
||||
m_Selected = false;
|
||||
m_Radius = 0;
|
||||
context.Reset();
|
||||
interact.Reset();
|
||||
m_Data.Clear();
|
||||
m_PreviousData.Clear();
|
||||
m_DataUpdateTime.Clear();
|
||||
m_DataUpdateFlag.Clear();
|
||||
m_BaseInfos.Clear();
|
||||
m_Labels.Clear();
|
||||
m_LabelLines.Clear();
|
||||
m_ItemStyles.Clear();
|
||||
@@ -188,6 +179,12 @@ namespace XCharts.Runtime
|
||||
m_ItemStyles.Add(new ItemStyle() { show = true });
|
||||
return m_ItemStyles[0] as T;
|
||||
}
|
||||
else if (type == typeof(SerieDataBaseInfo))
|
||||
{
|
||||
if (m_BaseInfos.Count == 0)
|
||||
m_BaseInfos.Add(new SerieDataBaseInfo() { });
|
||||
return m_BaseInfos[0] as T;
|
||||
}
|
||||
else if (type == typeof(LabelStyle))
|
||||
{
|
||||
if (m_Labels.Count == 0)
|
||||
@@ -206,10 +203,10 @@ namespace XCharts.Runtime
|
||||
m_Emphases.Add(new Emphasis() { show = true });
|
||||
return m_Emphases[0] as T;
|
||||
}
|
||||
else if (type == typeof(SymbolStyle))
|
||||
else if (type == typeof(SerieSymbol))
|
||||
{
|
||||
if (m_Symbols.Count == 0)
|
||||
m_Symbols.Add(new SymbolStyle() { show = true });
|
||||
m_Symbols.Add(new SerieSymbol() { show = true });
|
||||
return m_Symbols[0] as T;
|
||||
}
|
||||
else if (type == typeof(LineStyle))
|
||||
@@ -238,6 +235,7 @@ namespace XCharts.Runtime
|
||||
|
||||
public void RemoveAllComponent()
|
||||
{
|
||||
m_BaseInfos.Clear();
|
||||
m_ItemStyles.Clear();
|
||||
m_Labels.Clear();
|
||||
m_LabelLines.Clear();
|
||||
@@ -253,13 +251,15 @@ namespace XCharts.Runtime
|
||||
var type = typeof(T);
|
||||
if (type == typeof(ItemStyle))
|
||||
m_ItemStyles.Clear();
|
||||
else if (type == typeof(SerieDataBaseInfo))
|
||||
m_BaseInfos.Clear();
|
||||
else if (type == typeof(LabelStyle))
|
||||
m_Labels.Clear();
|
||||
else if (type == typeof(LabelLine))
|
||||
m_LabelLines.Clear();
|
||||
else if (type == typeof(Emphasis))
|
||||
m_Emphases.Clear();
|
||||
else if (type == typeof(SymbolStyle))
|
||||
else if (type == typeof(SerieSymbol))
|
||||
m_Symbols.Clear();
|
||||
else if (type == typeof(LineStyle))
|
||||
m_LineStyles.Clear();
|
||||
@@ -482,18 +482,7 @@ namespace XCharts.Runtime
|
||||
|
||||
public bool IsInPolygon(Vector2 p)
|
||||
{
|
||||
if (m_PolygonPoints.Count == 0) return false;
|
||||
var inside = false;
|
||||
var j = m_PolygonPoints.Count - 1;
|
||||
for (int i = 0; i < m_PolygonPoints.Count; j = i++)
|
||||
{
|
||||
var pi = m_PolygonPoints[i];
|
||||
var pj = m_PolygonPoints[j];
|
||||
if (((pi.y <= p.y && p.y < pj.y) || (pj.y <= p.y && p.y < pi.y)) &&
|
||||
(p.x < (pj.x - pi.x) * (p.y - pi.y) / (pj.y - pi.y) + pi.x))
|
||||
inside = !inside;
|
||||
}
|
||||
return inside;
|
||||
return UGLHelper.IsPointInPolygon(p, m_PolygonPoints);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@ namespace XCharts.Runtime
|
||||
public double area;
|
||||
public float angle;
|
||||
public Vector3 offsetCenter;
|
||||
public Vector3 areaCenter;
|
||||
public float stackHeight;
|
||||
public bool isClip;
|
||||
public bool canShowLabel = true;
|
||||
@@ -57,6 +58,7 @@ namespace XCharts.Runtime
|
||||
/// |该数据项是否被高亮,一般由鼠标悬停或图例悬停触发高亮。
|
||||
/// </summary>
|
||||
public bool highlight;
|
||||
public bool selected;
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
|
||||
@@ -395,15 +395,9 @@ namespace XCharts.Runtime
|
||||
|
||||
private void UpdateLabelPosition(SerieData serieData, LabelStyle currLabel)
|
||||
{
|
||||
var isNeedInvertPositionSerie = serie is Line;
|
||||
var invert = currLabel.autoOffset
|
||||
&& isNeedInvertPositionSerie
|
||||
&& SerieHelper.IsDownPoint(serie, serieData.index)
|
||||
&& (serie.areaStyle == null || !serie.areaStyle.show);
|
||||
var labelPosition = GetSerieDataLabelPosition(serieData, currLabel);
|
||||
var offset = currLabel.GetOffset(serie.context.insideRadius);
|
||||
serieData.labelObject.SetPosition(labelPosition
|
||||
+ (invert ? -offset : offset));
|
||||
var offset = GetSerieDataLabelOffset(serieData, currLabel);
|
||||
serieData.labelObject.SetPosition(labelPosition + offset);
|
||||
}
|
||||
|
||||
public virtual Vector3 GetSerieDataLabelPosition(SerieData serieData, LabelStyle label)
|
||||
@@ -411,6 +405,11 @@ namespace XCharts.Runtime
|
||||
return serieData.context.position;
|
||||
}
|
||||
|
||||
public virtual Vector3 GetSerieDataLabelOffset(SerieData serieData, LabelStyle label)
|
||||
{
|
||||
return label.GetOffset(serie.context.insideRadius);
|
||||
}
|
||||
|
||||
public virtual Vector3 GetSerieDataTitlePosition(SerieData serieData, TitleStyle titleStyle)
|
||||
{
|
||||
return serieData.context.position;
|
||||
|
||||
Reference in New Issue
Block a user