增加桑基图相关支持

This commit is contained in:
monitor1394
2023-12-09 23:22:00 +08:00
parent 1c6904f074
commit e8c8ab87aa
23 changed files with 948 additions and 34 deletions

View File

@@ -27,11 +27,16 @@ namespace XCharts.Editor
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
{
base.OnGUI(pos, prop, label);
++EditorGUI.indentLevel;
PropertyField(prop, "m_Label");
PropertyField(prop, "m_UpperLabel");
PropertyField(prop, "m_ItemStyle");
--EditorGUI.indentLevel;
if (MakeComponentFoldout(prop, "m_Depth", true))
{
++EditorGUI.indentLevel;
PropertyField(prop, "m_Depth");
PropertyField(prop, "m_Label");
PropertyField(prop, "m_UpperLabel");
PropertyField(prop, "m_LineStyle");
PropertyField(prop, "m_ItemStyle");
--EditorGUI.indentLevel;
}
}
}
}

View File

@@ -92,7 +92,7 @@ namespace XCharts.Editor
{
PropertyListField("m_Data", true, new HeaderMenuInfo("Import ECharts Axis Data", () =>
{
PraseExternalDataEditor.UpdateData(chart, null, component as Axis);
PraseExternalDataEditor.UpdateData(chart, null, component as Axis, false);
PraseExternalDataEditor.ShowWindow();
}));
}

View File

@@ -0,0 +1,24 @@
using UnityEditor;
using UnityEngine;
using XCharts.Runtime;
namespace XCharts.Editor
{
[CustomPropertyDrawer(typeof(SerieDataLink), true)]
public class SerieDataLinkDrawer : BasePropertyDrawer
{
public override string ClassName { get { return "Link"; } }
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
{
base.OnGUI(pos, prop, label);
if (MakeComponentFoldout(prop, "", true))
{
++EditorGUI.indentLevel;
PropertyField(prop, "m_Source");
PropertyField(prop, "m_Target");
PropertyField(prop, "m_Value");
--EditorGUI.indentLevel;
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 877ff0f4c473d47f29e7e7e3a3eaf53b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -12,6 +12,8 @@ namespace XCharts.Editor
private bool m_DataFoldout = false;
private bool m_DataComponentFoldout = true;
private Dictionary<int, bool> m_DataElementFoldout = new Dictionary<int, bool>();
private bool m_LinksFoldout = false;
private Dictionary<int, bool> m_LinksElementFoldout = new Dictionary<int, bool>();
public override void OnInspectorGUI()
{
@@ -31,12 +33,16 @@ namespace XCharts.Editor
OnCustomInspectorGUI();
OnExtraInspectorGUI();
PropertyFieldData();
OnEndCustomInspectorGUI();
--EditorGUI.indentLevel;
}
public virtual void OnCustomInspectorGUI()
{ }
public virtual void OnEndCustomInspectorGUI()
{ }
private void OnExtraInspectorGUI()
{
foreach (var kv in Serie.extraComponentMap)
@@ -52,7 +58,7 @@ namespace XCharts.Editor
m_DataFoldout = ChartEditorHelper.DrawHeader("Data", m_DataFoldout, false, null, null,
new HeaderMenuInfo("Import ECharts Data", () =>
{
PraseExternalDataEditor.UpdateData(chart, serie, null);
PraseExternalDataEditor.UpdateData(chart, serie, null, false);
PraseExternalDataEditor.ShowWindow();
}));
if (!m_DataFoldout) return;
@@ -97,6 +103,48 @@ namespace XCharts.Editor
EditorGUI.indentLevel--;
}
protected void PropertyFieldLinks()
{
m_LinksFoldout = ChartEditorHelper.DrawHeader("Links", m_LinksFoldout, false, null, null,
new HeaderMenuInfo("Import ECharts Link", () =>
{
//PraseExternalDataEditor.UpdateData(chart, serie, null, true);
//PraseExternalDataEditor.ShowWindow();
}));
if (!m_LinksFoldout) return;
EditorGUI.indentLevel++;
var m_Links = FindProperty("m_Links");
var listSize = m_Links.arraySize;
listSize = EditorGUILayout.IntField("Size", listSize);
if (listSize < 0) listSize = 0;
if (listSize != m_Links.arraySize)
{
while (listSize > m_Links.arraySize) m_Links.arraySize++;
while (listSize < m_Links.arraySize) m_Links.arraySize--;
}
if (listSize > 30) // && !XCSettings.editorShowAllListData)
{
int num = listSize > 10 ? 10 : listSize;
for (int i = 0; i < num; i++)
{
DrawSerieDataLink(m_Links, i);
}
if (num >= 10)
{
ChartEditorHelper.DrawHeader("... ", false, false, null, null);
DrawSerieDataLink(m_Links, listSize - 1);
}
}
else
{
for (int i = 0; i < m_Links.arraySize; i++)
{
DrawSerieDataLink(m_Links, i);
}
}
EditorGUI.indentLevel--;
}
protected void PropertyFiledMore(System.Action action)
{
m_MoreFoldout = ChartEditorHelper.DrawHeader(MORE, m_MoreFoldout, false, null, null);
@@ -118,7 +166,7 @@ namespace XCharts.Editor
var serieData = m_Datas.GetArrayElementAtIndex(index);
var dataIndex = serieData.FindPropertyRelative("m_Index").intValue;
m_DataElementFoldout[index] = ChartEditorHelper.DrawHeader("SerieData " + dataIndex, flag, false, null,
delegate(Rect drawRect)
delegate (Rect drawRect)
{
//drawRect.width -= 2f;
var maxX = drawRect.xMax;
@@ -242,5 +290,38 @@ namespace XCharts.Editor
}
EditorGUI.indentLevel--;
}
private void DrawSerieDataLink(SerializedProperty m_Datas, int index)
{
bool flag;
if (!m_LinksElementFoldout.TryGetValue(index, out flag))
{
flag = false;
m_LinksElementFoldout[index] = false;
}
var dataLink = m_Datas.GetArrayElementAtIndex(index);
m_LinksElementFoldout[index] = ChartEditorHelper.DrawHeader("Link " + index, flag, false, null,
delegate (Rect drawRect)
{
var sourceIndex = dataLink.FindPropertyRelative("m_Source");
var targetIndex = dataLink.FindPropertyRelative("m_Target");
var value = dataLink.FindPropertyRelative("m_Value");
ChartEditorHelper.MakeThreeField(ref drawRect, drawRect.width, sourceIndex, targetIndex, value, "");
});
if (m_LinksElementFoldout[index])
{
DrawSerieDataLinkDetail(m_Datas, index);
}
}
private void DrawSerieDataLinkDetail(SerializedProperty m_Links, int index)
{
EditorGUI.indentLevel++;
var dataLink = m_Links.GetArrayElementAtIndex(index);
PropertyField(dataLink.FindPropertyRelative("m_Source"));
PropertyField(dataLink.FindPropertyRelative("m_Target"));
PropertyField(dataLink.FindPropertyRelative("m_Value"));
EditorGUI.indentLevel--;
}
}
}

View File

@@ -106,6 +106,23 @@ namespace XCharts.Editor
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
}
public static void MakeThreeField(ref Rect drawRect, float rectWidth, SerializedProperty prop1,
SerializedProperty prop2, SerializedProperty prop3, string name)
{
EditorGUI.LabelField(drawRect, name);
var startX = drawRect.x + EditorGUIUtility.labelWidth - EditorGUI.indentLevel * INDENT_WIDTH + GAP_WIDTH;
var diff = 13 + EditorGUI.indentLevel * 14;
var offset = diff - INDENT_WIDTH;
var tempWidth = (rectWidth - startX + diff) / 3;
var centerXRect = new Rect(startX, drawRect.y, tempWidth, drawRect.height - 1);
var centerYRect = new Rect(centerXRect.x + tempWidth - offset, drawRect.y, tempWidth - 1, drawRect.height - 1);
var centerZRect = new Rect(centerYRect.x + tempWidth - offset, drawRect.y, tempWidth - 1, drawRect.height - 1);
EditorGUI.PropertyField(centerXRect, prop1, GUIContent.none);
EditorGUI.PropertyField(centerYRect, prop2, GUIContent.none);
EditorGUI.PropertyField(centerZRect, prop3, GUIContent.none);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
}
public static void MakeVector2(ref Rect drawRect, float rectWidth, SerializedProperty prop, string name)
{
EditorGUI.LabelField(drawRect, name);

View File

@@ -11,6 +11,7 @@ namespace XCharts.Editor
private static BaseChart s_Chart;
private static Serie s_Serie;
private static Axis s_Axis;
private static bool s_LinksData;
private static PraseExternalDataEditor window;
private static string inputJsonText = "";
@@ -23,11 +24,12 @@ namespace XCharts.Editor
window.Show();
}
public static void UpdateData(BaseChart chart, Serie serie, Axis axis)
public static void UpdateData(BaseChart chart, Serie serie, Axis axis, bool linksData)
{
s_Chart = chart;
s_Serie = serie;
s_Axis = axis;
s_LinksData = linksData;
inputJsonText = UnityEngine.GUIUtility.systemCopyBuffer;
}
@@ -97,7 +99,8 @@ namespace XCharts.Editor
{
arrayData = arrayData.Trim();
if (!arrayData.StartsWith("data: Array")) return false;
serie.ClearData();
if (s_LinksData) serie.ClearLinks();
else serie.ClearData();
var list = arrayData.Split('\n');
for (int i = 1; i < list.Length; i++)
{
@@ -140,7 +143,8 @@ namespace XCharts.Editor
private static bool ParseJsonData(Serie serie, string jsonData)
{
if (!CheckJsonData(ref jsonData)) return false;
serie.ClearData();
if (s_LinksData) serie.ClearLinks();
else serie.ClearData();
if (jsonData.IndexOf("],") > -1 || jsonData.IndexOf("] ,") > -1)
{
string[] datas = jsonData.Split(new string[] { "],", "] ," }, StringSplitOptions.RemoveEmptyEntries);