diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9c4b7644..9d30d8e9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,7 @@
# 更新日志
+* (2020.05.18) 增加`chartName`属性,可通过`XChartMgr.Instance.GetChart(chartName)`获取图表
* (2020.05.16) 增加部分鼠标事件回调
* (2020.05.15) 优化自带例子,`Demo`改名为`Example`
* (2020.05.13) 增加`Serie`的`large`和`largeThreshold`参数配置折线图和柱状图的性能模式
diff --git a/Documentation/XChartsAPI.md b/Documentation/XChartsAPI.md
index a04e61d0..2e38a69b 100644
--- a/Documentation/XChartsAPI.md
+++ b/Documentation/XChartsAPI.md
@@ -11,6 +11,7 @@
* `BaseChart.legend`:图例组件`Legend`。
* `BaseChart.tooltip`:提示框组件`Tooltip`。
* `BaseChart.series`:系列列表`Series`。
+* `BaseChart.chartName`:图表的别称。
* `BaseChart.chartWidth`:图表的宽。
* `BaseChart.chartHeight`:图表的高。
* `BaseChart.forceOpenRaycastTarget`:强制开启鼠标事件检测。一般不用手动设置,内部会自动判断是否需要检测。
diff --git a/Editor/BaseChartEditor.cs b/Editor/BaseChartEditor.cs
index 3e771925..5762e884 100644
--- a/Editor/BaseChartEditor.cs
+++ b/Editor/BaseChartEditor.cs
@@ -30,7 +30,6 @@ namespace XCharts
protected SerializedProperty m_Settings;
protected SerializedProperty m_Large;
protected SerializedProperty m_ChartName;
- protected SerializedProperty m_ChartUUID;
protected float m_DefaultLabelWidth;
protected float m_DefaultFieldWidth;
@@ -43,7 +42,6 @@ namespace XCharts
m_Target = (BaseChart)target;
m_Script = serializedObject.FindProperty("m_Script");
m_ChartName = serializedObject.FindProperty("m_ChartName");
- m_ChartUUID = serializedObject.FindProperty("m_ChartUUID");
m_ChartWidth = serializedObject.FindProperty("m_ChartWidth");
m_ChartHeight = serializedObject.FindProperty("m_ChartHeight");
m_Theme = serializedObject.FindProperty("m_Theme");
@@ -79,21 +77,8 @@ namespace XCharts
protected virtual void OnStartInspectorGUI()
{
EditorGUILayout.PropertyField(m_Script);
- // EditorGUI.BeginChangeCheck();
- // EditorGUILayout.PropertyField(m_ChartName);
- // if (EditorGUI.EndChangeCheck())
- // {
- // if (XChartsMgr.Instance.ContainsChart(m_ChartName.stringValue))
- // {
- // m_ChartName.stringValue = "";
- // serializedObject.ApplyModifiedProperties();
- // }
- // else
- // {
- // m_ChartUUID.stringValue = m_ChartName.stringValue;
- // }
- // }
- // EditorGUILayout.PropertyField(m_ChartUUID);
+ EditorGUI.BeginChangeCheck();
+ EditorGUILayout.PropertyField(m_ChartName);
EditorGUILayout.PropertyField(m_ThemeInfo, true);
EditorGUILayout.PropertyField(m_Title, true);
EditorGUILayout.PropertyField(m_Legend, true);
diff --git a/Runtime/API/BaseChart_API.cs b/Runtime/API/BaseChart_API.cs
index 2a165d5c..6acc8904 100644
--- a/Runtime/API/BaseChart_API.cs
+++ b/Runtime/API/BaseChart_API.cs
@@ -27,15 +27,16 @@ namespace XCharts
get { return m_ChartName; }
set
{
- if (XChartsMgr.Instance.ContainsChart(value)) Debug.LogError("chartName repeated:" + value);
+ if (!string.IsNullOrEmpty(value) && XChartsMgr.Instance.ContainsChart(value))
+ {
+ Debug.LogError("chartName repeated:" + value);
+ }
else
{
m_ChartName = value;
- m_ChartUUID = value;
}
}
}
- public string chartUUID { get { return m_ChartUUID; } }
///
/// The theme info.
///
diff --git a/Runtime/BarChart.cs b/Runtime/BarChart.cs
index 389d7c1a..07fd575b 100644
--- a/Runtime/BarChart.cs
+++ b/Runtime/BarChart.cs
@@ -16,6 +16,12 @@ namespace XCharts
public class BarChart : CoordinateChart
{
+ protected override void Awake()
+ {
+ base.Awake();
+ XChartsMgr.Instance.AddChart(this);
+ }
+
#if UNITY_EDITOR
protected override void Reset()
{
diff --git a/Runtime/Internal/BaseChart.cs b/Runtime/Internal/BaseChart.cs
index bc6930b1..e83b4e12 100644
--- a/Runtime/Internal/BaseChart.cs
+++ b/Runtime/Internal/BaseChart.cs
@@ -41,7 +41,6 @@ namespace XCharts
protected static readonly string s_SerieTitleObjectName = "serie";
[SerializeField] protected string m_ChartName;
- [SerializeField] protected string m_ChartUUID;
[SerializeField] protected float m_ChartWidth;
[SerializeField] protected float m_ChartHeight;
[SerializeField] protected float m_ChartX;
@@ -52,22 +51,18 @@ namespace XCharts
[SerializeField] protected Tooltip m_Tooltip = Tooltip.defaultTooltip;
[SerializeField] protected Series m_Series = Series.defaultSeries;
[SerializeField] protected Settings m_Settings = new Settings();
- [SerializeField] protected float m_Large = 1;
- [SerializeField] protected string m_DebugInfo = "";
- [SerializeField] protected Action m_OnCustomDrawCallback;
- [SerializeField] protected Action m_OnPointerClick;
- [SerializeField] protected Action m_OnPointerDown;
- [SerializeField] protected Action m_OnPointerUp;
- [SerializeField] protected Action m_OnPointerEnter;
- [SerializeField] protected Action m_OnPointerExit;
- [SerializeField] protected Action m_OnBeginDrag;
- [SerializeField] protected Action m_OnDrag;
- [SerializeField] protected Action m_OnEndDrag;
- [SerializeField] protected Action m_OnScroll;
+ [NonSerialized] protected Action m_OnCustomDrawCallback;
+ [NonSerialized] protected Action m_OnPointerClick;
+ [NonSerialized] protected Action m_OnPointerDown;
+ [NonSerialized] protected Action m_OnPointerUp;
+ [NonSerialized] protected Action m_OnPointerEnter;
+ [NonSerialized] protected Action m_OnPointerExit;
+ [NonSerialized] protected Action m_OnBeginDrag;
+ [NonSerialized] protected Action m_OnDrag;
+ [NonSerialized] protected Action m_OnEndDrag;
+ [NonSerialized] protected Action m_OnScroll;
-
- [NonSerialized] private Theme m_CheckTheme = 0;
[NonSerialized] protected Vector3 m_ChartPosition = Vector3.zero;
[NonSerialized] protected Vector2 m_ChartMinAnchor;
[NonSerialized] protected Vector2 m_ChartMaxAnchor;
@@ -89,6 +84,8 @@ namespace XCharts
protected Vector2 chartAnchorMin { get { return m_ChartMaxAnchor; } }
protected Vector2 chartPivot { get { return m_ChartPivot; } }
+ private Theme m_CheckTheme = 0;
+
protected virtual void InitComponent()
{
InitTitle();
diff --git a/Runtime/Internal/CoordinateChart.cs b/Runtime/Internal/CoordinateChart.cs
index 0e6d01f4..cd65beea 100644
--- a/Runtime/Internal/CoordinateChart.cs
+++ b/Runtime/Internal/CoordinateChart.cs
@@ -225,12 +225,6 @@ namespace XCharts
case SerieType.Scatter:
case SerieType.EffectScatter:
DrawScatterSerie(vh, colorIndex, serie);
- if (vh.currentVertCount > 60000)
- {
- m_Large++;
- RefreshChart();
- return;
- }
break;
case SerieType.Heatmap:
DrawHeatmapSerie(vh, colorIndex, serie);
diff --git a/Runtime/Utility/ChartHelper.cs b/Runtime/Utility/ChartHelper.cs
index 9d8a8d2b..24002497 100644
--- a/Runtime/Utility/ChartHelper.cs
+++ b/Runtime/Utility/ChartHelper.cs
@@ -118,7 +118,7 @@ namespace XCharts
Transform obj = transform;
while (obj.transform.parent)
{
- name += "/" + obj.transform.parent.name;
+ name = obj.transform.parent.name + "/" + name;
obj = obj.transform.parent;
}
return name;
diff --git a/Runtime/Utility/XChartsMgr.cs b/Runtime/Utility/XChartsMgr.cs
index 404d659e..37bb9df8 100644
--- a/Runtime/Utility/XChartsMgr.cs
+++ b/Runtime/Utility/XChartsMgr.cs
@@ -1,4 +1,5 @@
+
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
@@ -34,7 +35,7 @@ namespace XCharts
[SerializeField] private string m_NowVersion;
[SerializeField] private string m_NewVersion;
- private Dictionary m_ChartDic = new Dictionary();
+ [SerializeField] private List m_ChartList = new List();
private static XChartsMgr m_XCharts;
public static XChartsMgr Instance
@@ -73,6 +74,7 @@ namespace XCharts
private void Awake()
{
SerieLabelPool.ClearAll();
+ m_ChartList.Clear();
}
public string changeLog { get; private set; }
@@ -238,25 +240,45 @@ namespace XCharts
public void AddChart(BaseChart chart)
{
- //TODO:
- }
-
- public BaseChart GetChart(string uuid)
- {
- return m_ChartDic[uuid];
- }
-
- public void RemoveChart(string uuid)
- {
- if (m_ChartDic.ContainsKey(uuid))
+ var sameNameChart = GetChart(chart.chartName);
+ if (sameNameChart != null)
{
- m_ChartDic.Remove(uuid);
+ var path = ChartHelper.GetFullName(sameNameChart.transform);
+ Debug.LogError("A chart named `" + chart.chartName + "` already exists:" + path);
+ }
+ if (!ContainsChart(chart))
+ {
+ m_ChartList.Add(chart);
}
}
- public bool ContainsChart(string uuid)
+ public BaseChart GetChart(string chartName)
{
- return m_ChartDic.ContainsKey(uuid);
+ if (string.IsNullOrEmpty(chartName)) return null;
+ return m_ChartList.Find(chart => chartName.Equals(chart.chartName));
+ }
+
+ public List GetCharts(string chartName)
+ {
+ if (string.IsNullOrEmpty(chartName)) return null;
+ return m_ChartList.FindAll(chart => chartName.Equals(chartName));
+ }
+
+ public void RemoveChart(string chartName)
+ {
+ if (string.IsNullOrEmpty(chartName)) return;
+ m_ChartList.RemoveAll(chart => chartName.Equals(chart.chartName));
+ }
+
+ public bool ContainsChart(string chartName)
+ {
+ if (string.IsNullOrEmpty(chartName)) return false;
+ return GetCharts(chartName) != null;
+ }
+
+ public bool ContainsChart(BaseChart chart)
+ {
+ return m_ChartList.Contains(chart);
}
}
}
\ No newline at end of file