This commit is contained in:
monitor1394
2022-05-22 22:17:38 +08:00
parent 003f4da9de
commit bafe032bb9
391 changed files with 3718 additions and 2774 deletions

View File

@@ -12,7 +12,7 @@ namespace XCharts.Runtime
public static string CheckChart(BaseGraph chart)
{
if (chart is BaseChart) return CheckChart((BaseChart)chart);
if (chart is BaseChart) return CheckChart((BaseChart) chart);
else return string.Empty;
}
@@ -68,12 +68,10 @@ namespace XCharts.Runtime
}
private static void CheckLegend(BaseChart chart, StringBuilder sb)
{
}
{ }
private static void CheckGrid(BaseChart chart, StringBuilder sb)
{
}
{ }
private static void CheckSerie(BaseChart chart, StringBuilder sb)
{
@@ -121,11 +119,6 @@ namespace XCharts.Runtime
if (IsColorAlphaZero(serie.lineStyle.color))
sb.AppendFormat("warning:serie {0} lineStyle->color alpha is 0\n", serie.index);
}
else if (serie is Bar)
{
if (serie.barWidth == 0)
sb.AppendFormat("warning:serie {0} barWidth is 0\n", serie.index);
}
else if (serie is Pie)
{
if (serie.radius.Length >= 2 && serie.radius[1] == 0)

View File

@@ -1,15 +1,14 @@
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using UnityEngine;
using System.Linq;
namespace XCharts.Runtime
{
public static class FormatterHelper
{
public const string PH_NN = "\n";
private static Regex s_Regex = new Regex(@"{([a-e|.]\d*)(:\d+(-\d+)?)?(:[c-g|x|p|r]\d*|:0\.#*)?}", RegexOptions.IgnoreCase);
private static Regex s_Regex = new Regex(@"{([a-g|.]\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);
@@ -17,11 +16,16 @@ namespace XCharts.Runtime
private static Regex s_RegexNewLine = new Regex(@"[\\|/]+n|</br>|<br>|<br/>", 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-e|\.](:[c-g|x|p|r]\d*)?}", RegexOptions.IgnoreCase);
private static Regex s_RegexSubForSerieLabel = new Regex(@"(\.)|([a-e])|([c-g|x|p|r]\d*)", RegexOptions.IgnoreCase);
private static Regex s_RegexForSerieLabel = new Regex(@"{[a-g|\.](:[c-g|x|p|r]\d*)?}", RegexOptions.IgnoreCase);
private static Regex s_RegexSubForSerieLabel = new Regex(@"(\.)|([a-g])|([c-g|x|p|r]\d*)", RegexOptions.IgnoreCase);
public static bool NeedFormat(string content)
{
return content.IndexOf('{') >= 0;
}
/// <summary>
/// 替换字符串中的通配符,支持的通配符有{.}、{a}、{b}、{c}、{d}、{e}。
/// 替换字符串中的通配符,支持的通配符有{.}、{a}、{b}、{c}、{d}、{e}、{f}、{g}
/// </summary>
/// <param name="content">要替换的字符串</param>
/// <param name="dataIndex">选中的数据项serieData索引</param>
@@ -98,9 +102,14 @@ namespace XCharts.Runtime
content = content.Replace(old, serieData.name);
}
}
else if (p == 'c' || p == 'C' || p == 'd' || p == 'D')
else if (p == 'g' || p == 'G')
{
content = content.Replace(old, ChartCached.NumberToStr(serie.dataCount, ""));
}
else if (p == 'c' || p == 'C' || p == 'd' || p == 'D' || p == 'f' || p == 'f')
{
var isPercent = p == 'd' || p == 'D';
var isTotal = p == 'f' || p == 'f';
var bIndex = dataIndex;
var dimensionIndex = -1;
if (argsCount >= 2)
@@ -133,7 +142,7 @@ namespace XCharts.Runtime
if (dimensionIndex == -1) dimensionIndex = 1;
if (numericFormatter == string.Empty)
{
numericFormatter = SerieHelper.GetNumericFormatter(serie, serie.GetSerieData(bIndex));
numericFormatter = SerieHelper.GetNumericFormatter(serie, serie.GetSerieData(bIndex), "");
}
var value = serie.GetData(bIndex, dimensionIndex, dataZoom);
if (isPercent)
@@ -142,6 +151,11 @@ namespace XCharts.Runtime
var percent = total == 0 ? 0 : value / serie.yTotal * 100;
content = content.Replace(old, ChartCached.FloatToStr(percent, numericFormatter));
}
else if (isTotal)
{
var total = serie.GetDataTotal(dimensionIndex, serie.GetSerieData(bIndex));
content = content.Replace(old, ChartCached.FloatToStr(total, numericFormatter));
}
else
{
content = content.Replace(old, ChartCached.FloatToStr(value, numericFormatter));
@@ -152,6 +166,58 @@ namespace XCharts.Runtime
return foundDot;
}
public static void ReplaceSerieLabelContent(ref string content, string numericFormatter, int dataCount, double value, double total,
string serieName, string category, string dataName, Color color)
{
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 == '.')
{
content = content.Replace(old, ChartCached.ColorToDotStr(color));
}
else if (p == 'a' || p == 'A')
{
content = content.Replace(old, serieName);
}
else if (p == 'b' || p == 'B')
{
content = content.Replace(old, category);
}
else if (p == 'e' || p == 'E')
{
content = content.Replace(old, dataName);
}
else if (p == 'd' || p == 'D')
{
var rate = total == 0 ? 0 : value / total * 100;
content = content.Replace(old, ChartCached.NumberToStr(rate, numericFormatter));
}
else if (p == 'c' || p == 'C')
{
content = content.Replace(old, ChartCached.NumberToStr(value, numericFormatter));
}
else if (p == 'f' || p == 'f')
{
content = content.Replace(old, ChartCached.NumberToStr(total, numericFormatter));
}
else if (p == 'g' || p == 'G')
{
content = content.Replace(old, ChartCached.NumberToStr(dataCount, numericFormatter));
}
}
content = TrimAndReplaceLine(content);
}
private static char GetSerieIndex(string strType, ref int index)
{
index = -1;
@@ -207,48 +273,5 @@ namespace XCharts.Runtime
content = TrimAndReplaceLine(content);
}
public static void ReplaceSerieLabelContent(ref string content, string numericFormatter, double value, double total,
string serieName, string category, string dataName, Color color)
{
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 == '.')
{
content = content.Replace(old, ChartCached.ColorToDotStr(color));
}
else if (p == 'a' || p == 'A')
{
content = content.Replace(old, serieName);
}
else if (p == 'b' || p == 'B')
{
content = content.Replace(old, category);
}
else if (p == 'e' || p == 'E')
{
content = content.Replace(old, dataName);
}
else if (p == 'd' || p == 'D')
{
var rate = total == 0 ? 0 : value / total * 100;
content = content.Replace(old, ChartCached.FloatToStr(rate, numericFormatter));
}
else if (p == 'c' || p == 'C')
{
content = content.Replace(old, ChartCached.FloatToStr(value, numericFormatter));
}
}
content = TrimAndReplaceLine(content);
}
}
}

View File

@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.Reflection;
@@ -167,9 +166,9 @@ namespace XCharts.Runtime
{
var count = 0;
if (dimension > 0) count = dimension;
else count = serie.showDataDimension > serieData.data.Count
? serieData.data.Count
: serie.showDataDimension;
else count = serie.showDataDimension > serieData.data.Count ?
serieData.data.Count :
serie.showDataDimension;
for (int j = 0; j < count; j++)
{
var value = serieData.data[j];
@@ -275,7 +274,7 @@ namespace XCharts.Runtime
return color;
}
public static Color32 GetItemColor(Serie serie, SerieData serieData, ThemeStyle theme, int index, bool highlight)
public static Color32 GetItemColor(Serie serie, SerieData serieData, ThemeStyle theme, int index, bool highlight, bool opacity = true)
{
if (serie == null)
return ChartConst.clearColor32;
@@ -286,14 +285,14 @@ namespace XCharts.Runtime
if (itemStyle == null)
itemStyle = GetItemStyle(serie, serieData);
var color = ChartHelper.IsClearColor(itemStyle.color)
? theme.GetColor(index)
: itemStyle.color;
var color = ChartHelper.IsClearColor(itemStyle.color) ?
theme.GetColor(index) :
itemStyle.color;
if (highlight)
color = ChartHelper.GetHighlightColor(color);
ChartHelper.SetColorOpacity(ref color, itemStyle.opacity);
if (opacity)
ChartHelper.SetColorOpacity(ref color, itemStyle.opacity);
return color;
}
public static Color32 GetItemColor0(Serie serie, SerieData serieData, ThemeStyle theme, bool highlight, Color32 defaultColor)
@@ -307,9 +306,9 @@ namespace XCharts.Runtime
if (itemStyle == null)
itemStyle = GetItemStyle(serie, serieData);
var color = ChartHelper.IsClearColor(itemStyle.color0)
? defaultColor
: itemStyle.color0;
var color = ChartHelper.IsClearColor(itemStyle.color0) ?
defaultColor :
itemStyle.color0;
if (highlight)
color = ChartHelper.GetHighlightColor(color);
@@ -318,7 +317,7 @@ namespace XCharts.Runtime
return color;
}
public static Color32 GetItemToColor(Serie serie, SerieData serieData, ThemeStyle theme, int index, bool highlight)
public static Color32 GetItemToColor(Serie serie, SerieData serieData, ThemeStyle theme, int index, bool highlight, bool opacity = true)
{
if (serie == null)
return ChartConst.clearColor32;
@@ -332,15 +331,16 @@ namespace XCharts.Runtime
var color = itemStyle.toColor;
if (ChartHelper.IsClearColor(color))
{
color = ChartHelper.IsClearColor(itemStyle.color)
? theme.GetColor(index)
: itemStyle.color;
color = ChartHelper.IsClearColor(itemStyle.color) ?
theme.GetColor(index) :
itemStyle.color;
}
if (highlight)
color = ChartHelper.GetHighlightColor(color);
ChartHelper.SetColorOpacity(ref color, itemStyle.opacity);
if (opacity)
ChartHelper.SetColorOpacity(ref color, itemStyle.opacity);
return color;
}
@@ -385,9 +385,9 @@ namespace XCharts.Runtime
public static ItemStyle GetItemStyleEmphasis(Serie serie, SerieData serieData)
{
if (!serie.IsPerformanceMode() && serieData != null && serieData.emphasis != null && serieData.emphasis.show)
return serieData.emphasis.itemStyle;
else if (serie.emphasis != null && serie.emphasis.show) return serie.emphasis.itemStyle;
if (!serie.IsPerformanceMode() && serieData != null && serieData.emphasisItemStyle != null && serieData.emphasisItemStyle.show)
return serieData.emphasisItemStyle;
else if (serie.emphasisItemStyle != null && serie.emphasisItemStyle.show) return serie.emphasisItemStyle;
else return null;
}
@@ -396,9 +396,9 @@ namespace XCharts.Runtime
if (serieData == null) return serie.label;
if (highlight)
{
if (!serie.IsPerformanceMode() && serieData.emphasis != null && serieData.emphasis.show)
return serieData.emphasis.label;
else if (serie.emphasis != null && serie.emphasis.show) return serie.emphasis.label;
if (!serie.IsPerformanceMode() && serieData.emphasisLabel != null && serieData.emphasisLabel.show)
return serieData.emphasisLabel;
else if (serie.emphasisLabel != null && serie.emphasisLabel.show) return serie.emphasisLabel;
else return serie.label;
}
else
@@ -410,9 +410,9 @@ namespace XCharts.Runtime
public static LabelStyle GetSerieEmphasisLabel(Serie serie, SerieData serieData)
{
if (!serie.IsPerformanceMode() && serieData.emphasis != null && serieData.emphasis.show)
return serieData.emphasis.label;
else if (serie.emphasis != null && serie.emphasis.show) return serie.emphasis.label;
if (!serie.IsPerformanceMode() && serieData.emphasisLabel != null && serieData.emphasisLabel.show)
return serieData.emphasisLabel;
else if (serie.emphasisLabel != null && serie.emphasisLabel.show) return serie.emphasisLabel;
else return null;
}
@@ -420,9 +420,9 @@ namespace XCharts.Runtime
{
if (highlight)
{
if (!serie.IsPerformanceMode() && serieData.emphasis != null && serieData.emphasis.show)
return serieData.emphasis.labelLine;
else if (serie.emphasis != null && serie.emphasis.show) return serie.emphasis.labelLine;
if (!serie.IsPerformanceMode() && serieData.emphasisLabelLine != null && serieData.emphasisLabelLine.show)
return serieData.emphasisLabelLine;
else if (serie.emphasisLabelLine != null && serie.emphasisLabelLine.show) return serie.emphasisLabelLine;
else return serie.labelLine;
}
else
@@ -648,8 +648,8 @@ namespace XCharts.Runtime
var endValue = min + (max - min) * dataZoom.end / 100;
if (endValue < startValue) endValue = startValue;
if (startValue != serie.m_FilterStartValue || endValue != serie.m_FilterEndValue
|| dataZoom.minShowNum != serie.m_FilterMinShow || serie.m_NeedUpdateFilterData)
if (startValue != serie.m_FilterStartValue || endValue != serie.m_FilterEndValue ||
dataZoom.minShowNum != serie.m_FilterMinShow || serie.m_NeedUpdateFilterData)
{
serie.m_FilterStartValue = startValue;
serie.m_FilterEndValue = endValue;
@@ -690,8 +690,8 @@ namespace XCharts.Runtime
end = start + range;
if (end > data.Count) end = data.Count;
}
if (start != serie.m_FilterStart || end != serie.m_FilterEnd
|| dataZoom.minShowNum != serie.m_FilterMinShow || serie.m_NeedUpdateFilterData)
if (start != serie.m_FilterStart || end != serie.m_FilterEnd ||
dataZoom.minShowNum != serie.m_FilterMinShow || serie.m_NeedUpdateFilterData)
{
serie.m_FilterStart = start;
serie.m_FilterEnd = end;
@@ -733,7 +733,7 @@ namespace XCharts.Runtime
switch (serie.dataSortType)
{
case SerieDataSortType.Ascending:
serie.context.sortedData.Sort(delegate (SerieData data1, SerieData data2)
serie.context.sortedData.Sort(delegate(SerieData data1, SerieData data2)
{
var value1 = data1.GetData(1);
var value2 = data2.GetData(1);
@@ -743,7 +743,7 @@ namespace XCharts.Runtime
});
break;
case SerieDataSortType.Descending:
serie.context.sortedData.Sort(delegate (SerieData data1, SerieData data2)
serie.context.sortedData.Sort(delegate(SerieData data1, SerieData data2)
{
var value1 = data1.GetData(1);
var value2 = data2.GetData(1);

View File

@@ -52,7 +52,7 @@ namespace XCharts.Runtime
else
{
var content = serieLabel.formatter;
FormatterHelper.ReplaceSerieLabelContent(ref content, numericFormatter, dataValue,
FormatterHelper.ReplaceSerieLabelContent(ref content, numericFormatter, serie.dataCount, dataValue,
dataTotal, serieName, dataName, dataName, color);
return content;
}
@@ -166,8 +166,8 @@ namespace XCharts.Runtime
var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
var labelLine = SerieHelper.GetSerieLabelLine(serie, serieData);
var fontSize = serieLabel.textStyle.GetFontSize(theme);
var isOutside = serieLabel.position == LabelStyle.Position.Outside
|| serieLabel.position == LabelStyle.Position.Default;
var isOutside = serieLabel.position == LabelStyle.Position.Outside ||
serieLabel.position == LabelStyle.Position.Default;
if (!serieLabel.show) return;
if (!isOutside) return;
if (lastCheckPos == Vector3.zero)
@@ -196,8 +196,8 @@ namespace XCharts.Runtime
{
if (label == null || labelLine == null)
return serieData.context.labelPosition;
var isOutside = label.position == LabelStyle.Position.Outside
|| label.position == LabelStyle.Position.Default;
var isOutside = label.position == LabelStyle.Position.Outside ||
label.position == LabelStyle.Position.Default;
if (isOutside && labelLine.lineType != LabelLine.LineType.HorizontalLine)
{
var currAngle = serieData.context.halfAngle;

View File

@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using UnityEngine;
@@ -340,9 +339,10 @@ namespace XCharts.Runtime
for (int i = 0; i < series.Count; i++)
{
var serie = series[i];
if ((isPolar && serie.polarIndex != axisIndex)
|| (!isPolar && serie.yAxisIndex != axisIndex)
|| !serie.show) continue;
if ((isPolar && serie.polarIndex != axisIndex) ||
(!isPolar && serie.yAxisIndex != axisIndex) ||
!serie.show) continue;
var updateDuration = serie.animation.enable?serie.animation.dataChangeDuration : 0;
if (isPercentStack && SeriesHelper.IsPercentStack<Bar>(series, serie.serieName))
{
if (100 > max) max = 100;
@@ -363,7 +363,8 @@ namespace XCharts.Runtime
}
else
{
var currData = data.GetData(yValue ? 1 : 0, inverse);
//var currData = data.GetData(yValue ? 1 : 0, inverse);
var currData = data.GetCurrData(yValue ? 1 : 0, updateDuration, inverse);
if (!serie.IsIgnoreValue(currData))
{
if (currData > max) max = currData;
@@ -383,9 +384,9 @@ namespace XCharts.Runtime
for (int i = 0; i < ss.Value.Count; i++)
{
var serie = ss.Value[i];
if ((isPolar && serie.polarIndex != axisIndex)
|| (!isPolar && serie.yAxisIndex != axisIndex)
|| !serie.show) continue;
if ((isPolar && serie.polarIndex != axisIndex) ||
(!isPolar && serie.yAxisIndex != axisIndex) ||
!serie.show) continue;
var showData = serie.GetDataList(dataZoom);
if (SeriesHelper.IsPercentStack<Bar>(series, serie.stack))
{