海拔图和小地图
This commit is contained in:
1 parent
45801dff22
commit
c5bd9daba2
521 files changed
+1985033
-439
No files matched your search
@@ -0,0 +1,186 @@
|
||||
/************************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 - 2021 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/************************************************/
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
public static class CheckHelper
|
||||
{
|
||||
private static bool IsColorAlphaZero(Color color)
|
||||
{
|
||||
return !ChartHelper.IsClearColor(color) && color.a == 0;
|
||||
}
|
||||
|
||||
public static string CheckChart(BaseGraph chart)
|
||||
{
|
||||
if (chart is BaseChart) return CheckChart((BaseChart)chart);
|
||||
else return string.Empty;
|
||||
}
|
||||
|
||||
public static string CheckChart(BaseChart chart)
|
||||
{
|
||||
var sb = ChartHelper.sb;
|
||||
sb.Length = 0;
|
||||
CheckName(chart, sb);
|
||||
CheckSize(chart, sb);
|
||||
CheckTheme(chart, sb);
|
||||
CheckTitle(chart, sb);
|
||||
CheckLegend(chart, sb);
|
||||
CheckGrid(chart, sb);
|
||||
CheckSerie(chart, sb);
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
sb.AppendFormat("warning:chart name is repeated: {0}\n", chart.chartName);
|
||||
}
|
||||
}
|
||||
|
||||
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 theme = chart.theme;
|
||||
theme.CheckWarning(sb);
|
||||
}
|
||||
|
||||
private static void CheckTitle(BaseChart chart, StringBuilder sb)
|
||||
{
|
||||
foreach (var title in chart.titles)
|
||||
{
|
||||
if (!title.show) return;
|
||||
if (string.IsNullOrEmpty(title.text)) sb.AppendFormat("warning:title{0}->text is null\n", title.index);
|
||||
if (IsColorAlphaZero(title.textStyle.color))
|
||||
sb.AppendFormat("warning:title{0}->textStyle->color alpha is 0\n", title.index);
|
||||
if (IsColorAlphaZero(title.subTextStyle.color))
|
||||
sb.AppendFormat("warning:title{0}->subTextStyle->color alpha is 0\n", title.index);
|
||||
}
|
||||
}
|
||||
|
||||
private static void CheckLegend(BaseChart chart, StringBuilder sb)
|
||||
{
|
||||
foreach (var legend in chart.legends)
|
||||
{
|
||||
if (!legend.show) return;
|
||||
if (IsColorAlphaZero(legend.textStyle.color))
|
||||
sb.AppendFormat("warning:legend{0}->textStyle->color alpha is 0\n", legend.index);
|
||||
var serieNameList = SeriesHelper.GetLegalSerieNameList(chart.series);
|
||||
if (serieNameList.Count == 0)
|
||||
sb.AppendFormat("warning:legend{0} need serie.name or serieData.name not empty\n", legend.index);
|
||||
foreach (var category in legend.data)
|
||||
{
|
||||
if (!serieNameList.Contains(category))
|
||||
{
|
||||
sb.AppendFormat("warning:legend{0} [{1}] is invalid, must be one of serie.name or serieData.name\n",
|
||||
legend.index, category);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void CheckGrid(BaseChart chart, StringBuilder sb)
|
||||
{
|
||||
if (chart is CoordinateChart)
|
||||
{
|
||||
foreach (var grid in (chart as CoordinateChart).grids)
|
||||
{
|
||||
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)
|
||||
{
|
||||
var allDataIsEmpty = true;
|
||||
var allDataIsZero = true;
|
||||
var allSerieIsHide = true;
|
||||
foreach (var serie in chart.series.list)
|
||||
{
|
||||
if (serie.show) allSerieIsHide = false;
|
||||
if (serie.dataCount > 0)
|
||||
{
|
||||
allDataIsEmpty = false;
|
||||
for (int i = 0; i < serie.dataCount; i++)
|
||||
{
|
||||
var serieData = serie.GetSerieData(i);
|
||||
for (int j = 1; j < serieData.data.Count; j++)
|
||||
{
|
||||
if (serieData.GetData(j) != 0)
|
||||
{
|
||||
allDataIsZero = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
var dataCount = serie.GetSerieData(0).data.Count;
|
||||
if (serie.showDataDimension > 1 && serie.showDataDimension != dataCount)
|
||||
{
|
||||
sb.AppendFormat("warning:serie {0} serieData.data.count[{1}] not match showDataDimension[{2}]\n", serie.index, dataCount, serie.showDataDimension);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.AppendFormat("warning:serie {0} no data\n", serie.index);
|
||||
}
|
||||
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.opacity == 0)
|
||||
sb.AppendFormat("warning:serie {0} lineStyle->opacity is 0\n", serie.index);
|
||||
if (IsColorAlphaZero(serie.lineStyle.color))
|
||||
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.show)
|
||||
sb.AppendFormat("warning:serie {0} symbol type is None\n", serie.index);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (allDataIsEmpty) sb.Append("warning:all serie data is empty\n");
|
||||
if (!allDataIsEmpty && allDataIsZero) sb.Append("warning:all serie data is 0\n");
|
||||
if (allSerieIsHide) sb.Append("warning:all serie is hide\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 09a50ff0a7fdb4174b4dc2d28fc08b6a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,255 @@
|
||||
/************************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 - 2021 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/************************************************/
|
||||
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using UnityEngine;
|
||||
using System.Linq;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
public static class FormatterHelper
|
||||
{
|
||||
public const string PH_NN = "\n";
|
||||
private static Regex s_Regex = new Regex(@"{([a-d|.]\d*)(:\d+(-\d+)?)?(:[c-g|x|p|r]\d*|:0\.#*)?}", RegexOptions.IgnoreCase);
|
||||
private static Regex s_RegexSub = new Regex(@"(0\.#*)|(\d+-\d+)|(\w+)|(\.)", RegexOptions.IgnoreCase);
|
||||
private static Regex s_RegexN = new Regex(@"^\d+", RegexOptions.IgnoreCase);
|
||||
private static Regex s_RegexN_N = new Regex(@"\d+-\d+", RegexOptions.IgnoreCase);
|
||||
private static Regex s_RegexFn = new Regex(@"[c-g|x|p|r]\d*|0\.#*", RegexOptions.IgnoreCase);
|
||||
private static Regex s_RegexNewLine = new Regex(@"[\\|/]+n", RegexOptions.IgnoreCase);
|
||||
private static Regex s_RegexForAxisLabel = new Regex(@"{value(:[c-g|x|p|r]\d*)?}", RegexOptions.IgnoreCase);
|
||||
private static Regex s_RegexSubForAxisLabel = new Regex(@"(value)|([c-g|x|p|r]\d*)", RegexOptions.IgnoreCase);
|
||||
private static Regex s_RegexForSerieLabel = new Regex(@"{[a-d](:[c-g|x|p|r]\d*)?}", RegexOptions.IgnoreCase);
|
||||
private static Regex s_RegexSubForSerieLabel = new Regex(@"([a-d])|([c-g|x|p|r]\d*)", RegexOptions.IgnoreCase);
|
||||
|
||||
/// <summary>
|
||||
/// 替换字符串中的通配符,支持的通配符有{.}、{a}、{b}、{c}、{d}。
|
||||
/// </summary>
|
||||
/// <param name="content">要替换的字符串</param>
|
||||
/// <param name="dataIndex">选中的数据项serieData索引</param>
|
||||
/// <param name="numericFormatter">默认的数字格式化</param>
|
||||
/// <param name="serie">选中的serie</param>
|
||||
/// <param name="series">所有serie</param>
|
||||
/// <param name="theme">用来获取指定index的颜色</param>
|
||||
/// <param name="category">选中的类目,一般用在折线图和柱状图</param>
|
||||
/// <param name="dataZoom">dataZoom</param>
|
||||
/// <returns></returns>
|
||||
public static bool ReplaceContent(ref string content, int dataIndex, string numericFormatter, Serie serie, Series series,
|
||||
ChartTheme theme, string category = null, DataZoom dataZoom = null)
|
||||
{
|
||||
var foundDot = false;
|
||||
var mc = s_Regex.Matches(content);
|
||||
foreach (var m in mc)
|
||||
{
|
||||
var old = m.ToString();
|
||||
var args = s_RegexSub.Matches(m.ToString());
|
||||
var argsCount = args.Count;
|
||||
if (argsCount <= 0) continue;
|
||||
int targetIndex = 0;
|
||||
char p = GetSerieIndex(args[0].ToString(), ref targetIndex);
|
||||
if (targetIndex >= 0)
|
||||
{
|
||||
serie = series.GetSerie(targetIndex);
|
||||
if (serie == null) continue;
|
||||
}
|
||||
else if (serie != null)
|
||||
{
|
||||
targetIndex = serie.index;
|
||||
}
|
||||
else
|
||||
{
|
||||
serie = series.GetSerie(0);
|
||||
targetIndex = 0;
|
||||
}
|
||||
if (serie == null) continue;
|
||||
if (p == '.')
|
||||
{
|
||||
var bIndex = targetIndex;
|
||||
if (argsCount >= 2)
|
||||
{
|
||||
var args1Str = args[1].ToString();
|
||||
if (s_RegexN.IsMatch(args1Str)) bIndex = int.Parse(args1Str);
|
||||
}
|
||||
content = content.Replace(old, ChartCached.ColorToDotStr(theme.GetColor(bIndex)));
|
||||
foundDot = true;
|
||||
}
|
||||
else if (p == 'a' || p == 'A')
|
||||
{
|
||||
if (argsCount == 1)
|
||||
{
|
||||
content = content.Replace(old, serie.name);
|
||||
}
|
||||
}
|
||||
else if (p == 'b' || p == 'B')
|
||||
{
|
||||
var bIndex = dataIndex;
|
||||
if (argsCount >= 2)
|
||||
{
|
||||
var args1Str = args[1].ToString();
|
||||
if (s_RegexN.IsMatch(args1Str)) bIndex = int.Parse(args1Str);
|
||||
}
|
||||
var needCategory = serie.type == SerieType.Line || serie.type == SerieType.Bar;
|
||||
if (needCategory)
|
||||
{
|
||||
content = content.Replace(old, category);
|
||||
}
|
||||
else
|
||||
{
|
||||
var serieData = serie.GetSerieData(bIndex, dataZoom);
|
||||
content = content.Replace(old, serieData.name);
|
||||
}
|
||||
}
|
||||
else if (p == 'c' || p == 'C' || p == 'd' || p == 'D')
|
||||
{
|
||||
var isPercent = p == 'd' || p == 'D';
|
||||
var bIndex = dataIndex;
|
||||
var dimensionIndex = -1;
|
||||
if (argsCount >= 2)
|
||||
{
|
||||
var args1Str = args[1].ToString();
|
||||
if (s_RegexFn.IsMatch(args1Str))
|
||||
{
|
||||
numericFormatter = args1Str;
|
||||
}
|
||||
else if (s_RegexN_N.IsMatch(args1Str))
|
||||
{
|
||||
var temp = args1Str.Split('-');
|
||||
bIndex = int.Parse(temp[0]);
|
||||
dimensionIndex = int.Parse(temp[1]);
|
||||
}
|
||||
else if (s_RegexN.IsMatch(args1Str))
|
||||
{
|
||||
dimensionIndex = int.Parse(args1Str);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("unmatch:" + args1Str);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (argsCount >= 3)
|
||||
{
|
||||
numericFormatter = args[2].ToString();
|
||||
}
|
||||
if (dimensionIndex == -1) dimensionIndex = 1;
|
||||
if (numericFormatter == string.Empty)
|
||||
{
|
||||
numericFormatter = SerieHelper.GetNumericFormatter(serie, serie.GetSerieData(bIndex));
|
||||
}
|
||||
var value = serie.GetData(bIndex, dimensionIndex, dataZoom);
|
||||
if (isPercent)
|
||||
{
|
||||
var total = serie.GetDataTotal(dimensionIndex);
|
||||
var percent = total == 0 ? 0 : value / serie.yTotal * 100;
|
||||
content = content.Replace(old, ChartCached.FloatToStr(percent, numericFormatter));
|
||||
}
|
||||
else
|
||||
{
|
||||
content = content.Replace(old, ChartCached.FloatToStr(value, numericFormatter));
|
||||
}
|
||||
}
|
||||
}
|
||||
content = s_RegexNewLine.Replace(content, PH_NN);
|
||||
return foundDot;
|
||||
}
|
||||
|
||||
private static char GetSerieIndex(string strType, ref int index)
|
||||
{
|
||||
index = -1;
|
||||
if (strType.Length > 1)
|
||||
{
|
||||
if (!int.TryParse(strType.Substring(1), out index))
|
||||
{
|
||||
index = -1;
|
||||
}
|
||||
}
|
||||
return strType.ElementAt(0);
|
||||
}
|
||||
|
||||
public static string TrimAndReplaceLine(StringBuilder sb)
|
||||
{
|
||||
return TrimAndReplaceLine(sb.ToString());
|
||||
}
|
||||
|
||||
public static string TrimAndReplaceLine(string content)
|
||||
{
|
||||
return s_RegexNewLine.Replace(content.Trim(), PH_NN);
|
||||
}
|
||||
|
||||
public static void ReplaceAxisLabelContent(ref string content, string numericFormatter, float value)
|
||||
{
|
||||
var mc = s_RegexForAxisLabel.Matches(content);
|
||||
foreach (var m in mc)
|
||||
{
|
||||
var old = m.ToString();
|
||||
var args = s_RegexSubForAxisLabel.Matches(m.ToString());
|
||||
var argsCount = args.Count;
|
||||
if (argsCount <= 0) continue;
|
||||
if (argsCount >= 2)
|
||||
{
|
||||
numericFormatter = args[1].ToString();
|
||||
}
|
||||
content = content.Replace(old, ChartCached.FloatToStr(value, numericFormatter));
|
||||
}
|
||||
content = TrimAndReplaceLine(content);
|
||||
}
|
||||
|
||||
public static void ReplaceAxisLabelContent(ref string content, string value)
|
||||
{
|
||||
var mc = s_RegexForAxisLabel.Matches(content);
|
||||
foreach (var m in mc)
|
||||
{
|
||||
var old = m.ToString();
|
||||
var args = s_RegexSubForAxisLabel.Matches(m.ToString());
|
||||
var argsCount = args.Count;
|
||||
if (argsCount <= 0) continue;
|
||||
content = content.Replace(old, value);
|
||||
}
|
||||
content = TrimAndReplaceLine(content);
|
||||
}
|
||||
|
||||
public static void ReplaceSerieLabelContent(ref string content, string numericFormatter, float value, float total,
|
||||
string serieName, string dataName)
|
||||
{
|
||||
var mc = s_RegexForSerieLabel.Matches(content);
|
||||
foreach (var m in mc)
|
||||
{
|
||||
var old = m.ToString();
|
||||
var args = s_RegexSubForSerieLabel.Matches(old);
|
||||
var argsCount = args.Count;
|
||||
if (argsCount <= 0) continue;
|
||||
var p = args[0].ToString().ElementAt(0);
|
||||
if (argsCount >= 2)
|
||||
{
|
||||
numericFormatter = args[1].ToString();
|
||||
}
|
||||
if (p == 'a' || p == 'A')
|
||||
{
|
||||
content = content.Replace(old, serieName);
|
||||
}
|
||||
else if (p == 'b' || p == 'B')
|
||||
{
|
||||
content = content.Replace(old, dataName);
|
||||
}
|
||||
else if (p == 'c' || p == 'C' || p == 'd' || p == 'D')
|
||||
{
|
||||
var isPercent = p == 'd' || p == 'D';
|
||||
if (isPercent)
|
||||
{
|
||||
var percent = total == 0 ? 0 : value / total * 100;
|
||||
content = content.Replace(old, ChartCached.FloatToStr(percent, numericFormatter));
|
||||
}
|
||||
else
|
||||
{
|
||||
content = content.Replace(old, ChartCached.FloatToStr(value, numericFormatter));
|
||||
}
|
||||
}
|
||||
}
|
||||
content = TrimAndReplaceLine(content);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0fddcb81df44148ed86496564b120261
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,233 @@
|
||||
/************************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 - 2021 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/************************************************/
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
public static class LayerHelper
|
||||
{
|
||||
private static Vector2 s_Vector0And0 = new Vector2(0, 0);
|
||||
private static Vector2 s_Vector0And0Dot5 = new Vector2(0, 0.5f);
|
||||
private static Vector2 s_Vector0And1 = new Vector2(0, 1f);
|
||||
private static Vector2 s_Vector0Dot5And1 = new Vector2(0.5f, 1f);
|
||||
private static Vector2 s_Vector0Dot5And0Dot5 = new Vector2(0.5f, 0.5f);
|
||||
private static Vector2 s_Vector0Dot5And0 = new Vector2(0.5f, 0f);
|
||||
private static Vector2 s_Vector1And1 = new Vector2(1f, 1f);
|
||||
private static Vector2 s_Vector1And0Dot5 = new Vector2(1f, 0.5f);
|
||||
private static Vector2 s_Vector1And0 = new Vector2(1f, 0);
|
||||
|
||||
internal static Vector2 ResetChartPositionAndPivot(Vector2 minAnchor, Vector2 maxAnchor, float width,
|
||||
float height, ref float chartX, ref float chartY)
|
||||
{
|
||||
if (IsLeftTop(minAnchor, maxAnchor))
|
||||
{
|
||||
chartX = 0;
|
||||
chartY = -height;
|
||||
return s_Vector0And1;
|
||||
}
|
||||
else if (IsLeftCenter(minAnchor, maxAnchor))
|
||||
{
|
||||
chartX = 0;
|
||||
chartY = -height / 2;
|
||||
return s_Vector0And0Dot5;
|
||||
}
|
||||
else if (IsLeftBottom(minAnchor, maxAnchor))
|
||||
{
|
||||
chartX = 0;
|
||||
chartY = 0;
|
||||
return s_Vector0And0;
|
||||
}
|
||||
else if (IsCenterTop(minAnchor, maxAnchor))
|
||||
{
|
||||
chartX = -width / 2;
|
||||
chartY = -height;
|
||||
return s_Vector0Dot5And1;
|
||||
}
|
||||
else if (IsCenterCenter(minAnchor, maxAnchor))
|
||||
{
|
||||
chartX = -width / 2;
|
||||
chartY = -height / 2;
|
||||
return s_Vector0Dot5And0Dot5;
|
||||
}
|
||||
else if (IsCenterBottom(minAnchor, maxAnchor))
|
||||
{
|
||||
chartX = -width / 2;
|
||||
chartY = 0;
|
||||
return s_Vector0Dot5And0;
|
||||
}
|
||||
else if (IsRightTop(minAnchor, maxAnchor))
|
||||
{
|
||||
chartX = -width;
|
||||
chartY = -height;
|
||||
return s_Vector1And1;
|
||||
}
|
||||
else if (IsRightCenter(minAnchor, maxAnchor))
|
||||
{
|
||||
chartX = -width;
|
||||
chartY = -height / 2;
|
||||
return s_Vector1And0Dot5;
|
||||
}
|
||||
else if (IsRightBottom(minAnchor, maxAnchor))
|
||||
{
|
||||
chartX = -width;
|
||||
chartY = 0;
|
||||
return s_Vector1And0;
|
||||
}
|
||||
else if (IsStretchTop(minAnchor, maxAnchor))
|
||||
{
|
||||
chartX = -width / 2;
|
||||
chartY = -height;
|
||||
return s_Vector0Dot5And1;
|
||||
}
|
||||
else if (IsStretchMiddle(minAnchor, maxAnchor))
|
||||
{
|
||||
chartX = -width / 2;
|
||||
chartY = -height / 2;
|
||||
return s_Vector0Dot5And0Dot5;
|
||||
}
|
||||
else if (IsStretchBottom(minAnchor, maxAnchor))
|
||||
{
|
||||
chartX = -width / 2;
|
||||
chartY = 0;
|
||||
return s_Vector0Dot5And0;
|
||||
}
|
||||
else if (IsStretchLeft(minAnchor, maxAnchor))
|
||||
{
|
||||
chartX = 0;
|
||||
chartY = -height / 2;
|
||||
return s_Vector0And0Dot5;
|
||||
}
|
||||
else if (IsStretchCenter(minAnchor, maxAnchor))
|
||||
{
|
||||
chartX = -width / 2;
|
||||
chartY = -height / 2;
|
||||
return s_Vector0Dot5And0Dot5;
|
||||
}
|
||||
else if (IsStretchRight(minAnchor, maxAnchor))
|
||||
{
|
||||
chartX = -width;
|
||||
chartY = -height / 2;
|
||||
return s_Vector1And0Dot5;
|
||||
}
|
||||
else if (IsStretchStrech(minAnchor, maxAnchor))
|
||||
{
|
||||
chartX = -width / 2;
|
||||
chartY = -height / 2;
|
||||
return s_Vector0Dot5And0Dot5;
|
||||
}
|
||||
chartX = 0;
|
||||
chartY = 0;
|
||||
return Vector2.zero;
|
||||
}
|
||||
|
||||
private static bool IsLeftTop(Vector2 minAnchor, Vector2 maxAnchor)
|
||||
{
|
||||
return minAnchor == s_Vector0And1 && maxAnchor == s_Vector0And1;
|
||||
}
|
||||
|
||||
private static bool IsLeftCenter(Vector2 minAnchor, Vector2 maxAnchor)
|
||||
{
|
||||
return minAnchor == s_Vector0And0Dot5 && maxAnchor == s_Vector0And0Dot5;
|
||||
}
|
||||
|
||||
private static bool IsLeftBottom(Vector2 minAnchor, Vector2 maxAnchor)
|
||||
{
|
||||
return minAnchor == Vector2.zero && maxAnchor == Vector2.zero;
|
||||
}
|
||||
|
||||
private static bool IsCenterTop(Vector2 minAnchor, Vector2 maxAnchor)
|
||||
{
|
||||
return minAnchor == s_Vector0Dot5And1 && maxAnchor == s_Vector0Dot5And1;
|
||||
}
|
||||
|
||||
private static bool IsCenterCenter(Vector2 minAnchor, Vector2 maxAnchor)
|
||||
{
|
||||
return minAnchor == s_Vector0Dot5And0Dot5 && maxAnchor == s_Vector0Dot5And0Dot5;
|
||||
}
|
||||
|
||||
private static bool IsCenterBottom(Vector2 minAnchor, Vector2 maxAnchor)
|
||||
{
|
||||
return minAnchor == s_Vector0Dot5And0 && maxAnchor == s_Vector0Dot5And0;
|
||||
}
|
||||
|
||||
private static bool IsRightTop(Vector2 minAnchor, Vector2 maxAnchor)
|
||||
{
|
||||
return minAnchor == s_Vector1And1 && maxAnchor == s_Vector1And1;
|
||||
}
|
||||
|
||||
private static bool IsRightCenter(Vector2 minAnchor, Vector2 maxAnchor)
|
||||
{
|
||||
return minAnchor == s_Vector1And0Dot5 && maxAnchor == s_Vector1And0Dot5;
|
||||
}
|
||||
|
||||
private static bool IsRightBottom(Vector2 minAnchor, Vector2 maxAnchor)
|
||||
{
|
||||
return minAnchor == s_Vector1And0 && maxAnchor == s_Vector1And0;
|
||||
}
|
||||
|
||||
private static bool IsStretchTop(Vector2 minAnchor, Vector2 maxAnchor)
|
||||
{
|
||||
return minAnchor == s_Vector0And1 && maxAnchor == s_Vector1And1;
|
||||
}
|
||||
|
||||
private static bool IsStretchMiddle(Vector2 minAnchor, Vector2 maxAnchor)
|
||||
{
|
||||
return minAnchor == s_Vector0And0Dot5 && maxAnchor == s_Vector1And0Dot5;
|
||||
}
|
||||
|
||||
private static bool IsStretchBottom(Vector2 minAnchor, Vector2 maxAnchor)
|
||||
{
|
||||
return minAnchor == s_Vector0And0 && maxAnchor == s_Vector1And0;
|
||||
}
|
||||
|
||||
private static bool IsStretchLeft(Vector2 minAnchor, Vector2 maxAnchor)
|
||||
{
|
||||
return minAnchor == s_Vector0And0 && maxAnchor == s_Vector0And1;
|
||||
}
|
||||
|
||||
private static bool IsStretchCenter(Vector2 minAnchor, Vector2 maxAnchor)
|
||||
{
|
||||
return minAnchor == s_Vector0Dot5And0 && maxAnchor == s_Vector0Dot5And1;
|
||||
}
|
||||
|
||||
private static bool IsStretchRight(Vector2 minAnchor, Vector2 maxAnchor)
|
||||
{
|
||||
return minAnchor == s_Vector1And0 && maxAnchor == s_Vector1And1;
|
||||
}
|
||||
|
||||
private static bool IsStretchStrech(Vector2 minAnchor, Vector2 maxAnchor)
|
||||
{
|
||||
return minAnchor == s_Vector0And0 && maxAnchor == s_Vector1And1;
|
||||
}
|
||||
|
||||
public static bool IsStretchPivot(RectTransform rt)
|
||||
{
|
||||
return IsStretchTop(rt.anchorMin, rt.anchorMax) ||
|
||||
IsStretchMiddle(rt.anchorMin, rt.anchorMax) ||
|
||||
IsStretchBottom(rt.anchorMin, rt.anchorMax) ||
|
||||
IsStretchLeft(rt.anchorMin, rt.anchorMax) ||
|
||||
IsStretchCenter(rt.anchorMin, rt.anchorMax) ||
|
||||
IsStretchRight(rt.anchorMin, rt.anchorMax) ||
|
||||
IsStretchStrech(rt.anchorMin, rt.anchorMax);
|
||||
}
|
||||
|
||||
public static bool IsFixedWidthHeight(RectTransform rt)
|
||||
{
|
||||
return IsLeftTop(rt.anchorMin, rt.anchorMax) ||
|
||||
IsLeftCenter(rt.anchorMin, rt.anchorMax) ||
|
||||
IsLeftBottom(rt.anchorMin, rt.anchorMax) ||
|
||||
IsCenterTop(rt.anchorMin, rt.anchorMax) ||
|
||||
IsCenterCenter(rt.anchorMin, rt.anchorMax) ||
|
||||
IsCenterBottom(rt.anchorMin, rt.anchorMax) ||
|
||||
IsRightTop(rt.anchorMin, rt.anchorMax) ||
|
||||
IsRightCenter(rt.anchorMin, rt.anchorMax) ||
|
||||
IsRightBottom(rt.anchorMin, rt.anchorMax);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b0e7e693f76fc4853a01019b644b5d88
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,89 @@
|
||||
/************************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 - 2021 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/************************************************/
|
||||
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
public static partial class SerieHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the maximum and minimum values of the specified dimension of a serie.
|
||||
/// 获得系列指定维数的最大最小值。
|
||||
/// </summary>
|
||||
/// <param name="serie">指定系列</param>
|
||||
/// <param name="dimension">指定维数</param>
|
||||
/// <param name="min">最小值</param>
|
||||
/// <param name="max">最大值</param>
|
||||
/// <param name="dataZoom">缩放组件,默认null</param>
|
||||
public static void GetMinMaxData(Serie serie, int dimension, out float min, out float max,
|
||||
DataZoom dataZoom = null)
|
||||
{
|
||||
max = float.MinValue;
|
||||
min = float.MaxValue;
|
||||
var dataList = serie.GetDataList(dataZoom);
|
||||
for (int i = 0; i < dataList.Count; i++)
|
||||
{
|
||||
var serieData = dataList[i];
|
||||
if (serieData.show && serieData.data.Count > dimension)
|
||||
{
|
||||
var value = serieData.data[dimension];
|
||||
if (value > max) max = value;
|
||||
if (value < min) min = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the maximum and minimum values of all data in the serie.
|
||||
/// 获得系列所有数据的最大最小值。
|
||||
/// </summary>
|
||||
/// <param name="serie"></param>
|
||||
/// <param name="min"></param>
|
||||
/// <param name="max"></param>
|
||||
/// <param name="dataZoom"></param>
|
||||
public static void GetMinMaxData(Serie serie, out float min, out float max, DataZoom dataZoom = null)
|
||||
{
|
||||
max = float.MinValue;
|
||||
min = float.MaxValue;
|
||||
var dataList = serie.GetDataList(dataZoom);
|
||||
for (int i = 0; i < dataList.Count; i++)
|
||||
{
|
||||
var serieData = dataList[i];
|
||||
if (serieData.show)
|
||||
{
|
||||
var count = serie.showDataDimension > serieData.data.Count
|
||||
? serieData.data.Count
|
||||
: serie.showDataDimension;
|
||||
for (int j = 0; j < count; j++)
|
||||
{
|
||||
var value = serieData.data[j];
|
||||
if (value > max) max = value;
|
||||
if (value < min) min = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the data for the specified dimension of serie are all 0.
|
||||
/// 系列指定维数的数据是否全部为0。
|
||||
/// </summary>
|
||||
/// <param name="serie">系列</param>
|
||||
/// <param name="dimension">指定维数</param>
|
||||
/// <returns></returns>
|
||||
public static bool IsAllZeroValue(Serie serie, int dimension = 1)
|
||||
{
|
||||
foreach (var serieData in serie.data)
|
||||
{
|
||||
if (serieData.GetData(dimension) != 0) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8c031417514104eebb5bbd60dd1f90fd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in new issue
Block a user