Skip to content

Commit

Permalink
Fixed chart name repeat check error #183
Browse files Browse the repository at this point in the history
  • Loading branch information
monitor1394 committed Feb 21, 2022
1 parent 5c2ea52 commit c002ac0
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 6 deletions.
1 change: 1 addition & 0 deletions Assets/XCharts/CHANGELOG-EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

## branch-2.0

* (2022.02.21) Fixed chart name repeat check error #183
* (2022.02.17) Fixed bug where axis split line might be displayed outside the coordinate system #181
* (2022.02.08) Fixed {d} formatter error when value is 0
* (2022.02.08) Fixed `YAxis` `AxisLabel`'s `onZero` does not work
Expand Down
1 change: 1 addition & 0 deletions Assets/XCharts/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

## branch-2.0

* (2022.02.21) 修复`Chart``chartName`重复检测问题 #183
* (2022.02.17) 修复`Axis``SplitLine`可能会显示在坐标系外的问题 #181
* (2022.02.08) 修复数据全0时`{d}`显示不正确的问题
* (2022.02.08) 修复`YAxis``AxisLabel``onZero`参数不生效的问题
Expand Down
6 changes: 6 additions & 0 deletions Assets/XCharts/Editor/BaseChartEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ protected virtual void OnStartInspectorGUI()
EditorGUILayout.PropertyField(serializedObject.FindProperty(filed));
}
}
if (XChartsMgr.Instance.IsRepeatChartName(m_Chart, m_ChartName.stringValue))
{
EditorGUILayout.BeginHorizontal();
EditorGUILayout.HelpBox("chart name is repeated:" + m_ChartName.stringValue, MessageType.Error);
EditorGUILayout.EndHorizontal();
}
}
BlockEnd();

Expand Down
10 changes: 5 additions & 5 deletions Assets/XCharts/Runtime/Helper/CheckHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ private static bool IsColorAlphaZero(Color color)

public static string CheckChart(BaseGraph chart)
{
if(chart == null)
if (chart == null)
return string.Empty;
if (chart is BaseChart)
return CheckChart((BaseChart)chart);
Expand All @@ -28,7 +28,7 @@ public static string CheckChart(BaseGraph chart)

public static string CheckChart(BaseChart chart)
{
if(chart == null)
if (chart == null)
return string.Empty;
var sb = ChartHelper.sb;
sb.Length = 0;
Expand All @@ -45,10 +45,10 @@ public static string CheckChart(BaseChart chart)
private static void CheckName(BaseChart chart, StringBuilder sb)
{
if (string.IsNullOrEmpty(chart.chartName)) return;
var list = XChartsMgr.Instance.GetCharts(chart.chartName);
if (list.Count > 1)
if (XChartsMgr.Instance.IsRepeatChartName(chart))
{
sb.AppendFormat("warning:chart name is repeated: {0}\n", chart.chartName);
var info = XChartsMgr.Instance.GetRepeatChartNameInfo(chart, chart.chartName);
sb.AppendFormat("warning:chart name is repeated: {0}\n{1}", chart.chartName, info);
}
}

Expand Down
29 changes: 28 additions & 1 deletion Assets/XCharts/Runtime/XChartsMgr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public BaseChart GetChart(string chartName)
public List<BaseChart> GetCharts(string chartName)
{
if (string.IsNullOrEmpty(chartName)) return null;
return m_ChartList.FindAll(chart => chartName.Equals(chartName));
return m_ChartList.FindAll(chart => chartName.Equals(chart.chartName));
}

public void RemoveChart(string chartName)
Expand All @@ -299,6 +299,33 @@ public bool ContainsChart(BaseChart chart)
return m_ChartList.Contains(chart);
}

public bool IsRepeatChartName(BaseChart chart, string chartName = null)
{
if(chartName == null)
chartName = chart.chartName;
if (string.IsNullOrEmpty(chartName))
return false;
foreach (var temp in m_ChartList)
{
if (temp != chart && chartName.Equals(temp.chartName))
return true;
}
return false;
}

public string GetRepeatChartNameInfo(BaseChart chart, string chartName)
{
if (string.IsNullOrEmpty(chartName))
return string.Empty;
string result = "";
foreach (var temp in m_ChartList)
{
if (temp != chart && chartName.Equals(temp.chartName))
result += ChartHelper.GetFullName(temp.transform) + "\n";
}
return result;
}

public static void RemoveAllChartObject()
{
if (Instance.m_ChartList.Count == 0)
Expand Down

0 comments on commit c002ac0

Please sign in to comment.