mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-24 01:40:06 +00:00
增加Check warning检测功能
This commit is contained in:
@@ -67,6 +67,10 @@ namespace XCharts
|
||||
/// </summary>
|
||||
public Action<VertexHelper> customDrawCallback { set { m_CustomDrawCallback = value; } }
|
||||
/// <summary>
|
||||
/// 警告信息。
|
||||
/// </summary>
|
||||
public string warningInfo { get; protected set; }
|
||||
/// <summary>
|
||||
/// Set the size of chart.
|
||||
/// 设置图表的大小。
|
||||
/// </summary>
|
||||
@@ -637,5 +641,16 @@ namespace XCharts
|
||||
return np;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检测警告信息。
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string CheckWarning()
|
||||
{
|
||||
warningInfo = CheckHelper.CheckChart(this);
|
||||
Debug.LogError(warningInfo);
|
||||
return warningInfo;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1053,6 +1053,33 @@ namespace XCharts
|
||||
return serieNameList;
|
||||
}
|
||||
|
||||
internal List<string> GetLegalSerieNameList()
|
||||
{
|
||||
var list = new List<string>();
|
||||
for (int n = 0; n < m_Series.Count; n++)
|
||||
{
|
||||
var serie = m_Series[n];
|
||||
switch (serie.type)
|
||||
{
|
||||
case SerieType.Pie:
|
||||
case SerieType.Radar:
|
||||
case SerieType.Ring:
|
||||
for (int i = 0; i < serie.data.Count; i++)
|
||||
{
|
||||
var dataName = serie.data[i].name;
|
||||
if (!string.IsNullOrEmpty(dataName) && IsLegalLegendName(dataName) && !list.Contains(dataName))
|
||||
list.Add(dataName);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (!string.IsNullOrEmpty(serie.name) && !list.Contains(serie.name) && IsLegalLegendName(serie.name))
|
||||
list.Add(serie.name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置获得标志图形大小的回调
|
||||
/// </summary>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
/******************************************/
|
||||
using System.Text;
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
@@ -292,6 +293,28 @@ namespace XCharts
|
||||
else return Color.clear;
|
||||
}
|
||||
|
||||
public void CheckWarning(StringBuilder sb)
|
||||
{
|
||||
if (m_Font == null && m_CustomFont == null)
|
||||
{
|
||||
sb.AppendFormat("warning:theme->font is null");
|
||||
}
|
||||
if (m_ColorPalette.Length == 0 && m_CustomColorPalette.Count == 0)
|
||||
{
|
||||
sb.AppendFormat("warning:theme->colorPalette is empty");
|
||||
}
|
||||
for (int i = 0; i < m_ColorPalette.Length; i++)
|
||||
{
|
||||
if (m_ColorPalette[i] != Color.clear && m_ColorPalette[i].a == 0)
|
||||
sb.AppendFormat("warning:theme->colorPalette[{0}] alpha = 0\n", i);
|
||||
}
|
||||
for (int i = 0; i < m_CustomColorPalette.Count; i++)
|
||||
{
|
||||
if (m_CustomColorPalette[i] != Color.clear && m_CustomColorPalette[i].a == 0)
|
||||
sb.AppendFormat("warning:theme->colorPalette[{0}] alpha = 0\n", i);
|
||||
}
|
||||
}
|
||||
|
||||
Dictionary<int, string> _colorDic = new Dictionary<int, string>();
|
||||
/// <summary>
|
||||
/// Gets the hexadecimal color string of the specified index from the palette.
|
||||
|
||||
133
Runtime/Helper/CheckHelper.cs
Normal file
133
Runtime/Helper/CheckHelper.cs
Normal file
@@ -0,0 +1,133 @@
|
||||
using System.Linq;
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
internal static class CheckHelper
|
||||
{
|
||||
private static bool IsColorAlphaZero(Color color)
|
||||
{
|
||||
return color != Color.clear && color.a == 0;
|
||||
}
|
||||
public static string CheckChart(BaseChart chart)
|
||||
{
|
||||
var sb = ChartHelper.sb;
|
||||
sb.Length = 0;
|
||||
//sb.AppendFormat("version:{0}_{1}\n", XChartsMgr.version, XChartsMgr.date);
|
||||
CheckSize(chart, sb);
|
||||
CheckTheme(chart, sb);
|
||||
CheckTitle(chart, sb);
|
||||
CheckLegend(chart, sb);
|
||||
CheckGrid(chart, sb);
|
||||
CheckSerie(chart, sb);
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
private static void CheckSize(BaseChart chart, StringBuilder sb)
|
||||
{
|
||||
if (chart.chartWidth == 0 || chart.chartHeight == 0)
|
||||
{
|
||||
sb.Append("warning:chart width or height is 0\n");
|
||||
}
|
||||
}
|
||||
|
||||
private static void CheckTheme(BaseChart chart, StringBuilder sb)
|
||||
{
|
||||
var themeInfo = chart.themeInfo;
|
||||
themeInfo.CheckWarning(sb);
|
||||
}
|
||||
|
||||
private static void CheckTitle(BaseChart chart, StringBuilder sb)
|
||||
{
|
||||
var title = chart.title;
|
||||
if (!title.show) return;
|
||||
if (string.IsNullOrEmpty(title.text)) sb.Append("warning:title->text is null\n");
|
||||
if (title.textStyle.color != Color.clear && title.textStyle.color.a == 0)
|
||||
sb.Append("warning:title->textStyle->color alpha is 0\n");
|
||||
if (title.subTextStyle.color != Color.clear && title.subTextStyle.color.a == 0)
|
||||
sb.Append("warning:title->subTextStyle->color alpha is 0\n");
|
||||
}
|
||||
|
||||
private static void CheckLegend(BaseChart chart, StringBuilder sb)
|
||||
{
|
||||
var legend = chart.legend;
|
||||
if (!legend.show) return;
|
||||
if (legend.textStyle.color != Color.clear && legend.textStyle.color.a == 0)
|
||||
sb.Append("warning:legend->textStyle->color alpha is 0\n");
|
||||
var serieNameList = chart.series.GetLegalSerieNameList();
|
||||
Debug.LogError("namelist:" + serieNameList.Count);
|
||||
if (serieNameList.Count == 0) sb.Append("warning:legend need serie.name or serieData.name not empty\n");
|
||||
foreach (var category in legend.data)
|
||||
{
|
||||
if (!serieNameList.Contains(category))
|
||||
sb.AppendFormat("warning:legend [{0}] is invalid, must be one of serie.name or serieData.name\n", category);
|
||||
}
|
||||
}
|
||||
|
||||
private static void CheckGrid(BaseChart chart, StringBuilder sb)
|
||||
{
|
||||
if (chart is CoordinateChart)
|
||||
{
|
||||
var grid = (chart as CoordinateChart).grid;
|
||||
if (grid.left >= chart.chartWidth)
|
||||
sb.Append("warning:grid->left > chartWidth\n");
|
||||
if (grid.right >= chart.chartWidth)
|
||||
sb.Append("warning:grid->right > chartWidth\n");
|
||||
if (grid.top >= chart.chartHeight)
|
||||
sb.Append("warning:grid->top > chartHeight\n");
|
||||
if (grid.bottom >= chart.chartHeight)
|
||||
sb.Append("warning:grid->bottom > chartHeight\n");
|
||||
if (grid.left + grid.right >= chart.chartWidth)
|
||||
sb.Append("warning:grid.left + grid.right > chartWidth\n");
|
||||
if (grid.top + grid.bottom >= chart.chartHeight)
|
||||
sb.Append("warning:grid.top + grid.bottom > chartHeight\n");
|
||||
}
|
||||
}
|
||||
|
||||
private static void CheckSerie(BaseChart chart, StringBuilder sb)
|
||||
{
|
||||
foreach (var serie in chart.series.list)
|
||||
{
|
||||
if (IsColorAlphaZero(serie.itemStyle.color))
|
||||
sb.AppendFormat("warning:serie {0} itemStyle->color alpha is 0\n", serie.index);
|
||||
if (serie.itemStyle.opacity == 0)
|
||||
sb.AppendFormat("warning:serie {0} itemStyle->opacity is 0\n", serie.index);
|
||||
if (serie.itemStyle.borderWidth != 0 && IsColorAlphaZero(serie.itemStyle.borderColor))
|
||||
sb.AppendFormat("warning:serie {0} itemStyle->borderColor alpha is 0\n", serie.index);
|
||||
switch (serie.type)
|
||||
{
|
||||
case SerieType.Line:
|
||||
if (serie.lineStyle.width == 0)
|
||||
sb.AppendFormat("warning:serie {0} lineStyle->width is 0\n", serie.index);
|
||||
if (serie.lineStyle.opacity == 0)
|
||||
sb.AppendFormat("warning:serie {0} lineStyle->opacity is 0\n", serie.index);
|
||||
if (serie.lineStyle.color != Color.clear && serie.lineStyle.color.a == 0)
|
||||
sb.AppendFormat("warning:serie {0} lineStyle->color alpha is 0\n", serie.index);
|
||||
break;
|
||||
case SerieType.Bar:
|
||||
if (serie.barWidth == 0)
|
||||
sb.AppendFormat("warning:serie {0} barWidth is 0\n", serie.index);
|
||||
break;
|
||||
case SerieType.Pie:
|
||||
if (serie.radius.Length >= 2 && serie.radius[1] == 0)
|
||||
sb.AppendFormat("warning:serie {0} radius[1] is 0\n", serie.index);
|
||||
break;
|
||||
case SerieType.Scatter:
|
||||
case SerieType.EffectScatter:
|
||||
if (serie.symbol.type == SerieSymbolType.None)
|
||||
sb.AppendFormat("warning:symbol type is None");
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Runtime/Helper/CheckHelper.cs.meta
Normal file
11
Runtime/Helper/CheckHelper.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 09a50ff0a7fdb4174b4dc2d28fc08b6a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -49,6 +49,7 @@ namespace XCharts
|
||||
[SerializeField] protected Settings m_Settings = new Settings();
|
||||
[SerializeField] protected float m_Large = 1;
|
||||
[SerializeField] protected Action<VertexHelper> m_CustomDrawCallback;
|
||||
[SerializeField] protected string m_DebugInfo = "";
|
||||
|
||||
[NonSerialized] private Theme m_CheckTheme = 0;
|
||||
[NonSerialized] private float m_CheckWidth = 0;
|
||||
|
||||
Reference in New Issue
Block a user