mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-27 11:21:38 +00:00
增加桑基图相关支持
This commit is contained in:
@@ -309,6 +309,7 @@ namespace XCharts.Runtime
|
||||
[SerializeField] private AnimationStyle m_Animation = new AnimationStyle();
|
||||
[SerializeField] private ItemStyle m_ItemStyle = new ItemStyle();
|
||||
[SerializeField] private List<SerieData> m_Data = new List<SerieData>();
|
||||
[SerializeField] private List<SerieDataLink> m_Links = new List<SerieDataLink>();
|
||||
|
||||
[NonSerialized] internal int m_FilterStart;
|
||||
[NonSerialized] internal int m_FilterEnd;
|
||||
@@ -966,6 +967,10 @@ namespace XCharts.Runtime
|
||||
/// </summary>
|
||||
public List<SerieData> data { get { return m_Data; } }
|
||||
/// <summary>
|
||||
/// 数据节点的边。
|
||||
/// </summary>
|
||||
public List<SerieDataLink> links { get { return m_Links; } }
|
||||
/// <summary>
|
||||
/// 取色策略是否为按数据项分配。
|
||||
/// </summary>
|
||||
public bool colorByData { get { return colorBy == SerieColorBy.Data; } }
|
||||
@@ -1271,6 +1276,15 @@ namespace XCharts.Runtime
|
||||
SetVerticesDirty();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清空所有Link数据
|
||||
/// </summary>
|
||||
public void ClearLinks()
|
||||
{
|
||||
m_Links.Clear();
|
||||
SetVerticesDirty();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除指定索引的数据
|
||||
/// </summary>
|
||||
@@ -1504,6 +1518,26 @@ namespace XCharts.Runtime
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a link data.
|
||||
/// ||添加一个关系图的关系数据。
|
||||
/// </summary>
|
||||
/// <param name="sourceName"></param>
|
||||
/// <param name="targetName"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public SerieDataLink AddLink(string sourceName, string targetName, double value)
|
||||
{
|
||||
var link = new SerieDataLink();
|
||||
link.source = sourceName;
|
||||
link.target = targetName;
|
||||
link.value = value;
|
||||
m_Links.Add(link);
|
||||
SetVerticesDirty();
|
||||
labelDirty = true;
|
||||
return link;
|
||||
}
|
||||
|
||||
private void CheckMaxCache()
|
||||
{
|
||||
if (m_MaxCache <= 0) return;
|
||||
|
||||
@@ -69,6 +69,8 @@ namespace XCharts.Runtime
|
||||
}
|
||||
private bool m_Highligth;
|
||||
public bool selected;
|
||||
public double inTotalValue;
|
||||
public double outTotalValue;
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
|
||||
47
Runtime/Serie/SerieDataLink.cs
Normal file
47
Runtime/Serie/SerieDataLink.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
/// <summary>
|
||||
/// the link of serie data. Used for sankey chart. Sankey chart only supports directed acyclic graph. make sure the data link is directed acyclic graph.
|
||||
/// ||数据节点之间的连线。可用于桑基图等,桑基图只支持有向无环图,请保证数据的连线是有向无环图。
|
||||
/// </summary>
|
||||
[System.Serializable]
|
||||
[Since("v3.10.0")]
|
||||
public class SerieDataLink : ChildComponent
|
||||
{
|
||||
[SerializeField] private string m_Source;
|
||||
[SerializeField] private string m_Target;
|
||||
[SerializeField] private double m_Value;
|
||||
|
||||
/// <summary>
|
||||
/// the source node name.
|
||||
/// ||边的源节点名称。
|
||||
/// </summary>
|
||||
public string source
|
||||
{
|
||||
get { return m_Source; }
|
||||
set { m_Source = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// the target node name.
|
||||
/// ||边的目标节点名称。
|
||||
/// </summary>
|
||||
public string target
|
||||
{
|
||||
get { return m_Target; }
|
||||
set { m_Target = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// the value of link. decide the width of link.
|
||||
/// ||边的值。决定边的宽度。
|
||||
/// </summary>
|
||||
public double value
|
||||
{
|
||||
get { return m_Value; }
|
||||
set { m_Value = value; }
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Runtime/Serie/SerieDataLink.cs.meta
Normal file
11
Runtime/Serie/SerieDataLink.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7402f12ebc4aa4421939efecae53624d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -31,6 +31,7 @@ namespace XCharts.Runtime
|
||||
public virtual void OnBeginDrag(PointerEventData eventData) { }
|
||||
public virtual void OnEndDrag(PointerEventData eventData) { }
|
||||
public virtual void OnScroll(PointerEventData eventData) { }
|
||||
public virtual void OnDataUpdate() { }
|
||||
public virtual void RefreshLabelNextFrame() { }
|
||||
public virtual void RefreshLabelInternal() { }
|
||||
public virtual void ForceUpdateSerieContext() { }
|
||||
@@ -38,7 +39,8 @@ namespace XCharts.Runtime
|
||||
public virtual void UpdateTooltipSerieParams(int dataIndex, bool showCategory,
|
||||
string category, string marker,
|
||||
string itemFormatter, string numericFormatter, string ignoreDataDefaultContent,
|
||||
ref List<SerieParams> paramList, ref string title) { }
|
||||
ref List<SerieParams> paramList, ref string title)
|
||||
{ }
|
||||
public virtual void OnLegendButtonClick(int index, string legendName, bool show) { }
|
||||
public virtual void OnLegendButtonEnter(int index, string legendName) { }
|
||||
public virtual void OnLegendButtonExit(int index, string legendName) { }
|
||||
@@ -76,7 +78,7 @@ namespace XCharts.Runtime
|
||||
|
||||
internal override void SetSerie(Serie serie)
|
||||
{
|
||||
this.serie = (T) serie;
|
||||
this.serie = (T)serie;
|
||||
this.serie.context.param.serieType = typeof(T);
|
||||
m_NeedInitComponent = true;
|
||||
AnimationStyleHelper.UpdateSerieAnimation(serie);
|
||||
@@ -107,6 +109,7 @@ namespace XCharts.Runtime
|
||||
}
|
||||
if (serie.dataDirty)
|
||||
{
|
||||
OnDataUpdate();
|
||||
SeriesHelper.UpdateSerieNameList(chart, ref chart.m_LegendRealShowName);
|
||||
chart.OnSerieDataUpdate(serie.index);
|
||||
serie.OnDataUpdate();
|
||||
@@ -387,7 +390,7 @@ namespace XCharts.Runtime
|
||||
return;
|
||||
}
|
||||
InitRoot();
|
||||
var dataAutoColor = (Color) chart.GetLegendRealShowNameColor(serie.legendName);
|
||||
var dataAutoColor = (Color)chart.GetLegendRealShowNameColor(serie.legendName);
|
||||
m_EndLabel = ChartHelper.AddChartLabel(s_SerieEndLabelObjectName, m_SerieRoot.transform, serie.endLabel,
|
||||
chart.theme.common, "", dataAutoColor, TextAnchor.MiddleLeft);
|
||||
m_EndLabel.SetActive(serie.endLabel.show);
|
||||
@@ -599,7 +602,7 @@ namespace XCharts.Runtime
|
||||
var colorIndex = serie.colorByData ? serieData.index : serie.index;
|
||||
Color32 color, toColor;
|
||||
SerieHelper.GetItemColor(out color, out toColor, serie, serieData, chart.theme, colorIndex, SerieState.Normal, false);
|
||||
return (Color) color;
|
||||
return (Color)color;
|
||||
}
|
||||
|
||||
protected void UpdateCoordSerieParams(ref List<SerieParams> paramList, ref string title,
|
||||
|
||||
Reference in New Issue
Block a user