mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-22 08:50:10 +00:00
增加{y}通配符用于获取Y轴的类目名
This commit is contained in:
@@ -123,13 +123,14 @@ namespace XCharts.Runtime
|
||||
/// Template placeholder have the following, some of which apply only to fixed components: <br />
|
||||
/// `{.}` : indicates the dot mark. <br />
|
||||
/// `{a}` : indicates the series name. <br />
|
||||
/// `{b}` : category value or data name. <br />
|
||||
/// `{b}` : category value of x axis or data name. <br />
|
||||
/// `{c}` : data value. <br />
|
||||
/// `{d}` : percentage. <br />
|
||||
/// `{e}` : indicates the data name. <br />
|
||||
/// `{f}` : data sum. <br />
|
||||
/// `{g}` : indicates the total number of data. <br />
|
||||
/// `{h}` : hexadecimal color value. <br />
|
||||
/// `{y}` : category value of y axis. <br />
|
||||
/// `{value}` : The value of the axis or legend. <br />
|
||||
/// The following placeholder apply to `UITable` components: <br />
|
||||
/// `{name}` : indicates the row name of the table. <br />
|
||||
@@ -151,13 +152,14 @@ namespace XCharts.Runtime
|
||||
/// 模板通配符有以下这些,部分只适用于固定的组件:<br/>
|
||||
/// `{.}`:圆点标记。<br/>
|
||||
/// `{a}`:系列名。<br/>
|
||||
/// `{b}`:类目值或数据名。<br/>
|
||||
/// `{b}`:X轴类目名或数据名。<br/>
|
||||
/// `{c}`:数据值。<br/>
|
||||
/// `{d}`:百分比。<br/>
|
||||
/// `{e}`:数据名。<br/>
|
||||
/// `{f}`:数据和。<br/>
|
||||
/// `{g}`:数据总个数。<br/>
|
||||
/// `{h}`:十六进制颜色值。<br/>
|
||||
/// `{y}`:Y轴的类目名。<br/>
|
||||
/// `{value}`:坐标轴或图例的值。<br/>
|
||||
/// 以下通配符适用UITable组件:<br/>
|
||||
/// `{name}`: 表格的行名。<br/>
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace XCharts.Runtime
|
||||
}
|
||||
|
||||
public static string GetFormatterContent(Serie serie, SerieData serieData,
|
||||
double dataValue, double dataTotal, LabelStyle serieLabel, Color color)
|
||||
double dataValue, double dataTotal, LabelStyle serieLabel, Color color, BaseChart chart = null)
|
||||
{
|
||||
if (serieLabel == null)
|
||||
{
|
||||
@@ -45,7 +45,7 @@ namespace XCharts.Runtime
|
||||
{
|
||||
var content = serieLabel.formatter;
|
||||
FormatterHelper.ReplaceSerieLabelContent(ref content, numericFormatter, serie.dataCount, dataValue,
|
||||
dataTotal, serieName, dataName, dataName, color, serieData);
|
||||
dataTotal, serieName, dataName, dataName, color, serieData, chart);
|
||||
if (serieLabel.formatterFunction == null)
|
||||
return content;
|
||||
else
|
||||
@@ -70,7 +70,5 @@ namespace XCharts.Runtime
|
||||
serieData.labelObject.text.SetColor(label.textStyle.color);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -192,6 +192,7 @@ namespace XCharts.Runtime
|
||||
/// {h} is the hexadecimal color value of serieData for the serie data item currently indicated or index 0. <br />
|
||||
/// {f} is the sum of data. <br />
|
||||
/// {g} indicates the total number of data. <br />
|
||||
/// {y} is category value of y axis. <br />
|
||||
/// {.1} represents a dot of the corresponding color with serie specified as index 1. <br />
|
||||
/// The 1 in {a1}, {b1}, {c1} represents serie where index is specified as 1. <br />
|
||||
/// {c1:2} represents the third data of the current indicator data item in serie with index 1 (one data item has multiple data, index 2 represents the third data). <br />
|
||||
@@ -210,6 +211,7 @@ namespace XCharts.Runtime
|
||||
/// {h}为当前所指示或index为0的serie的数据项serieData的十六进制颜色值。<br/>
|
||||
/// {f}为数据总和。<br/>
|
||||
/// {g}为数据总个数。<br/>
|
||||
/// {f}为value所对应的y轴的类目值。<br/>
|
||||
/// {.1}表示指定index为1的serie对应颜色的圆点。<br/>
|
||||
/// {a1}、{b1}、{c1}中的1表示指定index为1的serie。<br/>
|
||||
/// {c1:2}表示索引为1的serie的当前指示数据项的第3个数据(一个数据项有多个数据,index为2表示第3个数据)。<br/>
|
||||
@@ -229,6 +231,7 @@ namespace XCharts.Runtime
|
||||
/// {d} is the percentage value of Y-dimensions (dimesion is 1) from serie that is currently indicated or whose index is 0, with no % sign.<br/>
|
||||
/// {e} is the name of the data item serieData that is currently indicated or whose index is 0.<br/>
|
||||
/// {f} is sum of data.<br/>
|
||||
/// {y} is category value of y axis.<br/>
|
||||
/// {.1} represents a dot from serie corresponding color that specifies index as 1.<br/>
|
||||
/// 1 in {a1}, {b1}, {c1} represents a serie that specifies an index of 1.<br/>
|
||||
/// {c1:2} represents the third data from serie's current indication data item indexed to 1 (a data item has multiple data, index 2 represents the third data).<br/>
|
||||
@@ -248,11 +251,12 @@ namespace XCharts.Runtime
|
||||
/// {f}为当前所指示的serie的默认维度的数据总和。<br/>
|
||||
/// {g}为当前所指示的serie的数据总个数。<br/>
|
||||
/// {h}为当前所指示的serie的十六进制颜色值。<br/>
|
||||
/// {y}为当前所指示的serie的y轴的类目值。<br/>
|
||||
/// {c0}表示当前数据项维度为0的数据。<br/>
|
||||
/// {c1}表示当前数据项维度为1的数据。<br/>
|
||||
/// {d3}表示维度3的数据的百分比。它的分母是默认维度(一般是1维度)数据。<br/>
|
||||
/// |表示多个列的分隔。<br/>
|
||||
/// 示例:"{i}", "{.}|{a}|{c}", "{.}|{b}|{c2:f2}"
|
||||
/// 示例:"{i}", "{.}|{a}|{c}", "{.}|{b}|{c2:f2}", "{.}|{b}|{y}"
|
||||
/// </summary>
|
||||
public string itemFormatter { get { return m_ItemFormatter; } set { m_ItemFormatter = value; } }
|
||||
/// <summary>
|
||||
|
||||
@@ -43,7 +43,8 @@ namespace XCharts.Runtime
|
||||
param.category,
|
||||
param.serieData.name,
|
||||
param.color,
|
||||
param.serieData);
|
||||
param.serieData,
|
||||
chart);
|
||||
foreach (var item in content.Split('|'))
|
||||
{
|
||||
param.columns.Add(item);
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace XCharts.Runtime
|
||||
public static class FormatterHelper
|
||||
{
|
||||
public const string PH_NN = "\n";
|
||||
private static Regex s_Regex = new Regex(@"{([a-h|.]\d*)(:\d+(-\d+)?)?(:[c-g|x|p|r]\d*|:0\.#*)?}", RegexOptions.IgnoreCase);
|
||||
private static Regex s_Regex = new Regex(@"{([a-h|.|y]\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);
|
||||
@@ -16,8 +16,8 @@ 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-h|\.]\d*(:[c-g|x|p|r]\d*)?}", RegexOptions.IgnoreCase);
|
||||
private static Regex s_RegexSubForSerieLabel = new Regex(@"(\.)|([a-h]\d*)|([c-g|x|p|r]\d*)", RegexOptions.IgnoreCase);
|
||||
private static Regex s_RegexForSerieLabel = new Regex(@"{[a-h|\.|y]\d*(:[c-g|x|p|r]\d*)?}", RegexOptions.IgnoreCase);
|
||||
private static Regex s_RegexSubForSerieLabel = new Regex(@"(\.)|([a-h|y]\d*)|([c-g|x|p|r]\d*)", RegexOptions.IgnoreCase);
|
||||
|
||||
public static bool NeedFormat(string content)
|
||||
{
|
||||
@@ -25,7 +25,7 @@ namespace XCharts.Runtime
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 替换字符串中的通配符,支持的通配符有{.}、{a}、{b}、{c}、{d}、{e}、{f}、{g}、{h}。
|
||||
/// 替换字符串中的通配符,支持的通配符有{.}、{a}、{b}、{c}、{d}、{e}、{f}、{g}、{h}、{y}。
|
||||
/// </summary>
|
||||
/// <param name="content">要替换的字符串</param>
|
||||
/// <param name="dataIndex">选中的数据项serieData索引</param>
|
||||
@@ -119,6 +119,33 @@ namespace XCharts.Runtime
|
||||
{
|
||||
content = content.Replace(old, ChartCached.NumberToStr(serie.dataCount, ""));
|
||||
}
|
||||
else if (p == 'y' || p == 'Y')
|
||||
{
|
||||
if (chart != null)
|
||||
{
|
||||
var yAxis = chart.GetChartComponent<YAxis>(0);
|
||||
if (yAxis != null)
|
||||
{
|
||||
var bIndex = dataIndex;
|
||||
if (argsCount >= 2)
|
||||
{
|
||||
var args1Str = args[1].ToString();
|
||||
if (s_RegexN.IsMatch(args1Str)) bIndex = int.Parse(args1Str);
|
||||
if (s_RegexFn.IsMatch(args1Str)) numericFormatter = args1Str;
|
||||
}
|
||||
if (yAxis.IsCategory())
|
||||
{
|
||||
var yCategory = yAxis.GetData(bIndex);
|
||||
content = content.Replace(old, yCategory);
|
||||
}
|
||||
else
|
||||
{
|
||||
var value = yAxis.context.pointerValue;
|
||||
content = content.Replace(old, ChartCached.FloatToStr(value, numericFormatter));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (p == 'c' || p == 'C' || p == 'd' || p == 'D' || p == 'f' || p == 'f')
|
||||
{
|
||||
var isPercent = p == 'd' || p == 'D';
|
||||
@@ -184,7 +211,7 @@ namespace XCharts.Runtime
|
||||
}
|
||||
|
||||
public static void ReplaceSerieLabelContent(ref string content, string numericFormatter, int dataCount, double value, double total,
|
||||
string serieName, string category, string dataName, Color color, SerieData serieData)
|
||||
string serieName, string category, string dataName, Color color, SerieData serieData, BaseChart chart = null)
|
||||
{
|
||||
var mc = s_RegexForSerieLabel.Matches(content);
|
||||
foreach (var m in mc)
|
||||
@@ -253,6 +280,25 @@ namespace XCharts.Runtime
|
||||
{
|
||||
content = content.Replace(old, "#" + ChartCached.ColorToStr(color));
|
||||
}
|
||||
else if (p == 'y' || p == 'Y')
|
||||
{
|
||||
if (chart != null)
|
||||
{
|
||||
var yAxis = chart.GetChartComponent<YAxis>(0);
|
||||
if (yAxis != null)
|
||||
{
|
||||
if (yAxis.IsCategory())
|
||||
{
|
||||
var yCategory = yAxis.GetData(pIndex >= 0 ? pIndex : (int)value);
|
||||
content = content.Replace(old, yCategory);
|
||||
}
|
||||
else
|
||||
{
|
||||
content = content.Replace(old, ChartCached.NumberToStr(value, numericFormatter));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
content = TrimAndReplaceLine(content);
|
||||
}
|
||||
|
||||
@@ -503,7 +503,7 @@ namespace XCharts.Runtime
|
||||
var content = string.IsNullOrEmpty(currLabel.formatter) ?
|
||||
ChartCached.NumberToStr(value, currLabel.numericFormatter) :
|
||||
SerieLabelHelper.GetFormatterContent(serie, serieData, value, total,
|
||||
currLabel, color);
|
||||
currLabel, color, chart);
|
||||
var offset = GetSerieDataLabelOffset(serieData, currLabel);
|
||||
labelObject.SetActive(currLabel.show && !isIgnore && !serie.IsMinShowLabelValue(value));
|
||||
labelObject.SetText(content);
|
||||
@@ -525,7 +525,7 @@ namespace XCharts.Runtime
|
||||
var content = string.IsNullOrEmpty(currLabel.formatter) ?
|
||||
ChartCached.NumberToStr(value, currLabel.numericFormatter) :
|
||||
SerieLabelHelper.GetFormatterContent(serie, serieData, value, total,
|
||||
currLabel, color);
|
||||
currLabel, color, chart);
|
||||
serieData.SetLabelActive(currLabel.show && !isIgnore && !serie.IsMinShowLabelValue(value));
|
||||
serieData.labelObject.UpdateIcon(currLabel.icon);
|
||||
serieData.labelObject.SetText(content);
|
||||
|
||||
Reference in New Issue
Block a user