Skip to content

Commit

Permalink
XCharts 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
monitor1394 committed Jan 17, 2021
1 parent f5c76ce commit 5c9e52a
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 128 deletions.
13 changes: 1 addition & 12 deletions Assets/XCharts/Editor/PropertyDrawers/AxisDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ namespace XCharts
[CustomPropertyDrawer(typeof(Axis), true)]
public class AxisDrawer : BasePropertyDrawer
{
private string m_JsonDataAreaText;

public override string ClassName { get { return "Axis"; } }

public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
Expand Down Expand Up @@ -84,16 +82,7 @@ public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)

if (type == Axis.AxisType.Category)
{
m_DrawRect.width = EditorGUIUtility.labelWidth + 10;
m_DataToggles[m_KeyName] = EditorGUI.Foldout(m_DrawRect, m_DataToggles[m_KeyName], "Data");
AddSingleLineHeight();
m_DrawRect.width = pos.width;
if (m_DataToggles[m_KeyName])
{
var height = m_Heights[m_KeyName];
ChartEditorHelper.MakeList(ref m_DrawRect, ref height, ref m_DataSize, m_Data);
m_Heights[m_KeyName] = height;
}
PropertyListField(prop, "m_Data", true);
}
EditorGUI.indentLevel--;
}
Expand Down
12 changes: 12 additions & 0 deletions Assets/XCharts/Editor/PropertyDrawers/BasePropertyDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@ protected void AddSingleLineHeight()
m_DrawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
}

protected void PropertyListField(SerializedProperty prop, string relativePropName, bool showOrder = false)
{
if (IngorePropertys.Contains(relativePropName)) return;

var height = m_Heights[m_KeyName];
var toggleKeyName = m_KeyName + relativePropName;
m_DataToggles[toggleKeyName] = ChartEditorHelper.MakeListWithFoldout(ref m_DrawRect, ref height,
prop.FindPropertyRelative(relativePropName),
m_DataToggles.ContainsKey(toggleKeyName) && m_DataToggles[toggleKeyName], showOrder);
m_Heights[m_KeyName] = height;
}

protected void PropertyField(SerializedProperty prop, string relativePropName)
{
if (IngorePropertys.Contains(relativePropName)) return;
Expand Down
8 changes: 4 additions & 4 deletions Assets/XCharts/Editor/PropertyDrawers/DataZoomDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
PropertyField(prop, "m_Bottom");
PropertyField(prop, "m_LineStyle");
PropertyField(prop, "m_AreaStyle");
PropertyField(prop, "m_XAxisIndexs");
PropertyField(prop, "m_YAxisIndexs");
PropertyListField(prop, "m_XAxisIndexs", true);
PropertyListField(prop, "m_YAxisIndexs", true);
PropertyField(prop, "m_TextStyle");
}
else
{
PropertyField(prop, "m_XAxisIndexs");
PropertyField(prop, "m_YAxisIndexs");
PropertyListField(prop, "m_XAxisIndexs", true);
PropertyListField(prop, "m_YAxisIndexs", true);
}
--EditorGUI.indentLevel;
}
Expand Down
2 changes: 1 addition & 1 deletion Assets/XCharts/Editor/PropertyDrawers/ItemStyleDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
PropertyField(prop, "m_Opacity");
PropertyField(prop, "m_TooltipFormatter");
PropertyField(prop, "m_NumericFormatter");
PropertyField(prop, "m_CornerRadius");
PropertyListField(prop, "m_CornerRadius", true);
--EditorGUI.indentLevel;
}
}
Expand Down
18 changes: 2 additions & 16 deletions Assets/XCharts/Editor/PropertyDrawers/SeriesDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,15 @@ namespace XCharts
[CustomPropertyDrawer(typeof(Series), true)]
public class SeriesDrawer : PropertyDrawer
{
private int m_DataSize = 0;
private bool m_ShowJsonDataArea = false;
private string m_JsonDataAreaText;
private bool m_SeriesModuleToggle = false;

public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
{
Rect drawRect = pos;
drawRect.height = EditorGUIUtility.singleLineHeight;
SerializedProperty m_Series = prop.FindPropertyRelative("m_Series");

drawRect.width = EditorGUIUtility.labelWidth + 10;
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_SeriesModuleToggle, "Series");
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
drawRect.width = pos.width;
if (m_SeriesModuleToggle)
{
ChartEditorHelper.MakeList(ref drawRect, ref m_DataSize, m_Series, true);
}
m_SeriesModuleToggle = ChartEditorHelper.MakeListWithFoldout(ref drawRect,
m_Series, m_SeriesModuleToggle, true, true);
}

public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
Expand All @@ -46,10 +36,6 @@ public override float GetPropertyHeight(SerializedProperty prop, GUIContent labe
height += EditorGUI.GetPropertyHeight(m_Data.GetArrayElementAtIndex(i)) + EditorGUIUtility.standardVerticalSpacing;
}
}
if (m_ShowJsonDataArea)
{
height += EditorGUIUtility.singleLineHeight * 3 + EditorGUIUtility.standardVerticalSpacing;
}
height += 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing;
return height;
}
Expand Down
2 changes: 2 additions & 0 deletions Assets/XCharts/Editor/PropertyDrawers/ThemeDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
if (newProp.name == "m_Script") continue;
if (newProp.name == "m_ThemeName") continue;
if (newProp.name == "m_Theme") continue;

AddPropertyField(pos, newProp, ref y);

} while (newProp.NextVisible(false));
}
if (GUI.changed)
Expand Down
128 changes: 38 additions & 90 deletions Assets/XCharts/Editor/Utility/ChartEditorHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,24 +255,46 @@ public static bool MakeFoldout(ref Rect drawRect, ref Dictionary<string, bool> m
return toggle;
}

public static void MakeList(ref Rect drawRect, ref int listSize, SerializedProperty listProp, bool showOrder = false, bool showSize = true)
public static bool MakeListWithFoldout(ref Rect drawRect, SerializedProperty listProp, bool foldout, bool showOrder = false, bool showSize = true)
{
var height = 0f;
MakeList(ref drawRect, ref height, ref listSize, listProp, showOrder, showSize);
return MakeListWithFoldout(ref drawRect, ref height, listProp, foldout, showOrder, showSize);
}

public static void MakeList(ref Rect drawRect, ref float height, ref int listSize, SerializedProperty listProp, bool showOrder = false, bool showSize = true)
public static bool MakeListWithFoldout(ref Rect drawRect, ref float height, SerializedProperty listProp, bool foldout, bool showOrder = false, bool showSize = true)
{
var rawWidth = drawRect.width;
drawRect.width = EditorGUIUtility.labelWidth + 10;
bool flag = EditorGUI.Foldout(drawRect, foldout, listProp.displayName);
height += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
drawRect.width = rawWidth;
if (flag)
{
MakeList(ref drawRect, ref height, listProp, showOrder, showSize);
}
return flag;
}

public static void MakeList(ref Rect drawRect, SerializedProperty listProp, bool showOrder = false, bool showSize = true)
{
var height = 0f;
MakeList(ref drawRect, ref height, listProp, showOrder, showSize);
}

public static void MakeList(ref Rect drawRect, ref float height, SerializedProperty listProp, bool showOrder = false, bool showSize = true)
{
EditorGUI.indentLevel++;
listSize = listProp.arraySize;
var listSize = listProp.arraySize;
var iconWidth = 14;
var iconGap = 3f;
if (showSize)
{
if (showOrder)
{
var nameWid = 18;
var temp = INDENT_WIDTH + GAP_WIDTH;
var elementRect = new Rect(drawRect.x, drawRect.y, drawRect.width - nameWid - 1, drawRect.height);
var iconRect = new Rect(drawRect.width - nameWid + temp, drawRect.y, nameWid, drawRect.height);
var temp = INDENT_WIDTH + GAP_WIDTH + iconGap;
var elementRect = new Rect(drawRect.x, drawRect.y, drawRect.width - iconWidth - 1, drawRect.height);
var iconRect = new Rect(drawRect.width - iconWidth + temp, drawRect.y, iconWidth, drawRect.height);
if (XChartsSettings.editorBlockEnable)
{
iconRect.x += BLOCK_WIDTH;
Expand Down Expand Up @@ -335,12 +357,14 @@ public static void MakeList(ref Rect drawRect, ref float height, ref int listSiz
SerializedProperty element = listProp.GetArrayElementAtIndex(i);
if (showOrder)
{
var nameWid = 18;
var temp = INDENT_WIDTH + GAP_WIDTH;

var temp = INDENT_WIDTH + GAP_WIDTH + iconGap;
var isSerie = "Serie".Equals(element.type);
var elementRect = isSerie ? drawRect : new Rect(drawRect.x, drawRect.y, drawRect.width - 2 * nameWid, drawRect.height);
var elementRect = isSerie
? new Rect(drawRect.x, drawRect.y, drawRect.width + INDENT_WIDTH, drawRect.height)
: new Rect(drawRect.x, drawRect.y, drawRect.width - 3 * iconWidth, drawRect.height);
EditorGUI.PropertyField(elementRect, element, new GUIContent("Element " + i));
var iconRect = new Rect(drawRect.width - 3 * nameWid + temp, drawRect.y, nameWid, drawRect.height);
var iconRect = new Rect(drawRect.width - 3 * iconWidth + temp, drawRect.y, iconWidth, drawRect.height);
if (XChartsSettings.editorBlockEnable)
{
iconRect.x += BLOCK_WIDTH;
Expand All @@ -349,7 +373,7 @@ public static void MakeList(ref Rect drawRect, ref float height, ref int listSiz
{
if (i > 0) listProp.MoveArrayElement(i, i - 1);
}
iconRect = new Rect(drawRect.width - 2 * nameWid + temp, drawRect.y, nameWid, drawRect.height);
iconRect = new Rect(drawRect.width - 2 * iconWidth + temp, drawRect.y, iconWidth, drawRect.height);
if (XChartsSettings.editorBlockEnable)
{
iconRect.x += BLOCK_WIDTH;
Expand All @@ -358,7 +382,7 @@ public static void MakeList(ref Rect drawRect, ref float height, ref int listSiz
{
if (i < listProp.arraySize - 1) listProp.MoveArrayElement(i, i + 1);
}
iconRect = new Rect(drawRect.width - nameWid + temp, drawRect.y, nameWid, drawRect.height);
iconRect = new Rect(drawRect.width - iconWidth + temp, drawRect.y, iconWidth, drawRect.height);
if (XChartsSettings.editorBlockEnable)
{
iconRect.x += BLOCK_WIDTH;
Expand All @@ -384,82 +408,6 @@ public static void MakeList(ref Rect drawRect, ref float height, ref int listSiz
EditorGUI.indentLevel--;
}

public static void MakeList(ref int listSize, SerializedProperty listProp, bool showOrder = false, bool showSize = true)
{
EditorGUI.indentLevel++;
listSize = listProp.arraySize;
if (showSize)
{
if (showOrder)
{
EditorGUILayout.BeginHorizontal();
listSize = EditorGUILayout.IntField("Size", listSize);
if (GUILayout.Button(Styles.iconAdd, Styles.invisibleButton, GUILayout.MinWidth(15), GUILayout.MaxWidth(15)))
{
listProp.arraySize++;
}
listSize = listProp.arraySize;
EditorGUILayout.EndHorizontal();
}
else
{
listSize = EditorGUILayout.IntField("Size", listSize);
}
if (listSize < 0) listSize = 0;
if (listSize != listProp.arraySize)
{
while (listSize > listProp.arraySize) listProp.arraySize++;
while (listSize < listProp.arraySize) listProp.arraySize--;
}
}
if (listSize > 30)
{
SerializedProperty element;
int num = listSize > 10 ? 10 : listSize;
for (int i = 0; i < num; i++)
{
element = listProp.GetArrayElementAtIndex(i);
EditorGUILayout.PropertyField(element, true);
}
if (num >= 10)
{
EditorGUILayout.LabelField("...");
element = listProp.GetArrayElementAtIndex(listSize - 1);
EditorGUILayout.PropertyField(element, true);
}
}
else
{
for (int i = 0; i < listProp.arraySize; i++)
{
SerializedProperty element = listProp.GetArrayElementAtIndex(i);
if (showOrder)
{
EditorGUILayout.BeginHorizontal();
EditorGUILayout.PropertyField(element, true);
if (GUILayout.Button(Styles.iconUp, Styles.invisibleButton, GUILayout.MinWidth(15), GUILayout.MaxWidth(15)))
{
if (i > 0) listProp.MoveArrayElement(i, i - 1);
}
if (GUILayout.Button(Styles.iconDown, Styles.invisibleButton, GUILayout.MinWidth(15), GUILayout.MaxWidth(15)))
{
if (i < listProp.arraySize - 1) listProp.MoveArrayElement(i, i + 1);
}
if (GUILayout.Button(Styles.iconRemove, Styles.invisibleButton, GUILayout.MinWidth(15), GUILayout.MaxWidth(15)))
{
if (i < listProp.arraySize && i >= 0) listProp.DeleteArrayElementAtIndex(i);
}
EditorGUILayout.EndHorizontal();
}
else
{
EditorGUILayout.PropertyField(element, true);
}
}
}
EditorGUI.indentLevel--;
}

public static bool PropertyField(ref Rect drawRect, Dictionary<string, float> heights, string key, SerializedProperty prop)
{
if (prop == null)
Expand Down
3 changes: 3 additions & 0 deletions Assets/XCharts/Runtime/Component/Theme/ChartTheme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public class ChartTheme : ScriptableObject
[SerializeField] private Color32 m_ContrastColor;
[SerializeField] private Color32 m_BackgroundColor;

#if UNITY_2020_2
[NonReorderable]
#endif
[SerializeField] private List<Color32> m_ColorPalette = new List<Color32>(13);

[SerializeField] private ComponentTheme m_Common;
Expand Down
2 changes: 1 addition & 1 deletion Assets/XCharts/Runtime/XChartsMgr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class XChartsVersion
public class XChartsMgr : MonoBehaviour
{
internal static string _version = "2.0.0";
internal static int _versionDate = 20210110;
internal static int _versionDate = 20210117;
public static string version { get { return _version; } }
public static int versionDate { get { return _versionDate; } }
public static string fullVersion { get { return version + "_" + versionDate; } }
Expand Down
4 changes: 2 additions & 2 deletions Assets/XCharts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"name": "com.monitor1394.xcharts",
"displayName": "XCharts",
"version": "2.0.0",
"date": "20210110",
"checkdate": "20210110",
"date": "20210117",
"checkdate": "20210117",
"desc": "如果 XCharts 对您有帮助,希望您能在 Github 上点 Star 支持,非常感谢!",
"unity": "2018.3",
"description": "A charting and data visualization library for Unity.",
Expand Down
4 changes: 2 additions & 2 deletions Assets/XCharts/version.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"version": "2.0.0",
"date": "20210110",
"checkdate": "20210110",
"date": "20210117",
"checkdate": "20210117",
"desc": "如果 XCharts 对您有帮助,希望您能在 Github 上点 Star 支持,非常感谢!",
"homepage": "https://github.com/monitor1394/unity-ugui-XCharts"
}

0 comments on commit 5c9e52a

Please sign in to comment.