mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-20 15:30:09 +00:00
[feature][tooltip] support {c0} for itemFormatter (#205)
This commit is contained in:
@@ -18,7 +18,7 @@ namespace XCharts.Runtime
|
||||
{
|
||||
var content = serieLabel.formatter;
|
||||
FormatterHelper.ReplaceSerieLabelContent(ref content, numericFormatter, serie.dataCount, data.runtimeValue,
|
||||
0, serie.serieName, data.name, data.name, Color.clear);
|
||||
0, serie.serieName, data.name, data.name, Color.clear, null);
|
||||
return content;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,7 +140,23 @@ namespace XCharts.Runtime
|
||||
/// The placeholder {I} can be set separately to indicate that the title is ignored and not displayed.
|
||||
/// Template see itemFormatter.
|
||||
/// |提示框标题内容的字符串模版格式器。支持用 \n 换行。可以单独设置占位符{i}表示忽略不显示title。
|
||||
/// 模板变量参考Toolip的itemFormatter。
|
||||
/// 模板变量有{.}、{a}、{b}、{c}、{d}、{e}、{f}、{g}。</br>
|
||||
/// {.}为当前所指示或index为0的serie的对应颜色的圆点。</br>
|
||||
/// {a}为当前所指示或index为0的serie的系列名name。</br>
|
||||
/// {b}为当前所指示或index为0的serie的数据项serieData的name,或者类目值(如折线图的X轴)。</br>
|
||||
/// {c}为当前所指示或index为0的serie的y维(dimesion为1)的数值。</br>
|
||||
/// {d}为当前所指示或index为0的serie的y维(dimesion为1)百分比值,注意不带%号。</br>
|
||||
/// {e}为当前所指示或index为0的serie的数据项serieData的name。</br>
|
||||
/// {f}为数据总和。</br>
|
||||
/// {g}为数据总个数。</br>
|
||||
/// {.1}表示指定index为1的serie对应颜色的圆点。</br>
|
||||
/// {a1}、{b1}、{c1}中的1表示指定index为1的serie。</br>
|
||||
/// {c1:2}表示索引为1的serie的当前指示数据项的第3个数据(一个数据项有多个数据,index为2表示第3个数据)。</br>
|
||||
/// {c1:2-2}表示索引为1的serie的第3个数据项的第3个数据(也就是要指定第几个数据项时必须要指定第几个数据)。</br>
|
||||
/// {d1:2:f2}表示单独指定了数值的格式化字符串为f2(不指定时用numericFormatter)。</br>
|
||||
/// {d:0.##} 表示单独指定了数值的格式化字符串为 0.## (用于百分比,保留2位有效数同时又能避免使用 f2 而出现的类似于"100.00%"的情况 )。</br>
|
||||
/// 示例:"{a}:{c}"、"{a1}:{c1:f1}"、"{a1}:{c1:0:f1}"、"{a1}:{c1:1-1:f1}"
|
||||
/// </summary>
|
||||
/// </summary>
|
||||
public string titleFormatter { get { return m_TitleFormatter; } set { m_TitleFormatter = value; } }
|
||||
/// <summary>
|
||||
@@ -160,22 +176,21 @@ namespace XCharts.Runtime
|
||||
/// {d1:2: F2} indicates that a formatted string with a value specified separately is F2 (numericFormatter is used when numericFormatter is not specified).</br>
|
||||
/// {d:0.##} indicates that a formatted string with a value specified separately is 0.## (used for percentage, reserved 2 valid digits while avoiding the situation similar to "100.00%" when using f2 ).</br>
|
||||
/// Example: "{a}, {c}", "{a1}, {c1: f1}", "{a1}, {c1:0: f1}", "{a1} : {c1:1-1: f1}"</br>
|
||||
/// |提示框单个serie或数据项内容的字符串模版格式器。支持用 \n 换行。
|
||||
/// 模板变量有{.}、{a}、{b}、{c}、{d}、{e}、{f}。</br>
|
||||
/// {.}为当前所指示或index为0的serie的对应颜色的圆点。</br>
|
||||
/// {a}为当前所指示或index为0的serie的系列名name。</br>
|
||||
/// {b}为当前所指示或index为0的serie的数据项serieData的name,或者类目值(如折线图的X轴)。</br>
|
||||
/// {c}为当前所指示或index为0的serie的y维(dimesion为1)的数值。</br>
|
||||
/// {d}为当前所指示或index为0的serie的y维(dimesion为1)百分比值,注意不带%号。</br>
|
||||
/// {e}为当前所指示或index为0的serie的数据项serieData的name。</br>
|
||||
/// {f}为数据总和。</br>
|
||||
/// {.1}表示指定index为1的serie对应颜色的圆点。</br>
|
||||
/// {a1}、{b1}、{c1}中的1表示指定index为1的serie。</br>
|
||||
/// {c1:2}表示索引为1的serie的当前指示数据项的第3个数据(一个数据项有多个数据,index为2表示第3个数据)。</br>
|
||||
/// {c1:2-2}表示索引为1的serie的第3个数据项的第3个数据(也就是要指定第几个数据项时必须要指定第几个数据)。</br>
|
||||
/// {d1:2:f2}表示单独指定了数值的格式化字符串为f2(不指定时用numericFormatter)。</br>
|
||||
/// {d:0.##} 表示单独指定了数值的格式化字符串为 0.## (用于百分比,保留2位有效数同时又能避免使用 f2 而出现的类似于"100.00%"的情况 )。</br>
|
||||
/// 示例:"{a}:{c}"、"{a1}:{c1:f1}"、"{a1}:{c1:0:f1}"、"{a1}:{c1:1-1:f1}"
|
||||
/// |提示框单个serie或数据项内容的字符串模版格式器。支持用 \n 换行。用|来表示多个列的分隔。
|
||||
/// 模板变量有{.}、{a}、{b}、{c}、{d}、{e}、{f}、{g}。</br>
|
||||
/// {i}或-表示忽略当前项。
|
||||
/// {.}为当前所指示的serie或数据项的对应颜色的圆点。</br>
|
||||
/// {a}为当前所指示的serie或数据项的系列名name。</br>
|
||||
/// {b}为当前所指示的serie或数据项的数据项serieData的name,或者类目值(如折线图的X轴)。</br>
|
||||
/// {c}为当前所指示的serie或数据项的y维(dimesion为1)的数值。</br>
|
||||
/// {d}为当前所指示的serie或数据项的y维(dimesion为1)百分比值,注意不带%号。</br>
|
||||
/// {e}为当前所指示的serie或数据项的数据项serieData的name。</br>
|
||||
/// {f}为当前所指示的serie的默认维度的数据总和。</br>
|
||||
/// {g}为当前所指示的serie的数据总个数。</br>
|
||||
/// {c0}表示当前数据项维度为0的数据。</br>
|
||||
/// {c1}表示当前数据项维度为1的数据。</br>
|
||||
/// |表示多个列的分隔。<br>
|
||||
/// 示例:"{i}", "{.}|{a}|{c}", "{.}|{b}|{c2:f2}"
|
||||
/// </summary>
|
||||
public string itemFormatter { get { return m_ItemFormatter; } set { m_ItemFormatter = value; } }
|
||||
/// <summary>
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace XCharts.Runtime
|
||||
{
|
||||
if (!string.IsNullOrEmpty(tooltip.titleFormatter))
|
||||
{
|
||||
if (tooltip.titleFormatter.Equals("{i}", StringComparison.CurrentCultureIgnoreCase))
|
||||
if (IsIgnoreFormatter(tooltip.titleFormatter))
|
||||
{
|
||||
tooltip.context.data.title = string.Empty;
|
||||
}
|
||||
@@ -23,7 +23,7 @@ namespace XCharts.Runtime
|
||||
for (int i = tooltip.context.data.param.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var param = tooltip.context.data.param[i];
|
||||
if (TooltipHelper.IsIgnoreItemFormatter(param.itemFormatter))
|
||||
if (IsIgnoreFormatter(param.itemFormatter))
|
||||
{
|
||||
tooltip.context.data.param.RemoveAt(i);
|
||||
}
|
||||
@@ -42,7 +42,8 @@ namespace XCharts.Runtime
|
||||
param.serieName,
|
||||
param.category,
|
||||
param.serieData.name,
|
||||
param.color);
|
||||
param.color,
|
||||
param.serieData);
|
||||
foreach (var item in content.Split('|'))
|
||||
{
|
||||
param.columns.Add(item);
|
||||
@@ -51,9 +52,9 @@ namespace XCharts.Runtime
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsIgnoreItemFormatter(string itemFormatter)
|
||||
public static bool IsIgnoreFormatter(string itemFormatter)
|
||||
{
|
||||
return "-".Equals(itemFormatter);
|
||||
return "-".Equals(itemFormatter) ||"{i}".Equals(itemFormatter, StringComparison.CurrentCultureIgnoreCase);
|
||||
}
|
||||
|
||||
public static void LimitInRect(Tooltip tooltip, Rect chartRect)
|
||||
|
||||
@@ -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-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);
|
||||
private static Regex s_RegexForSerieLabel = new Regex(@"{[a-g|\.]\d*(:[c-g|x|p|r]\d*)?}", RegexOptions.IgnoreCase);
|
||||
private static Regex s_RegexSubForSerieLabel = new Regex(@"(\.)|([a-g]\d*)|([c-g|x|p|r]\d*)", RegexOptions.IgnoreCase);
|
||||
|
||||
public static bool NeedFormat(string content)
|
||||
{
|
||||
@@ -41,6 +41,7 @@ namespace XCharts.Runtime
|
||||
{
|
||||
var foundDot = false;
|
||||
var mc = s_Regex.Matches(content);
|
||||
Debug.LogError("context:" + content);
|
||||
foreach (var m in mc)
|
||||
{
|
||||
var old = m.ToString();
|
||||
@@ -167,7 +168,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)
|
||||
string serieName, string category, string dataName, Color color, SerieData serieData)
|
||||
{
|
||||
var mc = s_RegexForSerieLabel.Matches(content);
|
||||
foreach (var m in mc)
|
||||
@@ -176,7 +177,13 @@ namespace XCharts.Runtime
|
||||
var args = s_RegexSubForSerieLabel.Matches(old);
|
||||
var argsCount = args.Count;
|
||||
if (argsCount <= 0) continue;
|
||||
var p = args[0].ToString().ElementAt(0);
|
||||
var pstr = args[0].ToString();
|
||||
var p = pstr.ElementAt(0);
|
||||
var pIndex = -1;
|
||||
if (pstr.Length > 1)
|
||||
{
|
||||
int.TryParse(pstr.Substring(1, pstr.Length - 1), out pIndex);
|
||||
}
|
||||
if (argsCount >= 2)
|
||||
{
|
||||
numericFormatter = args[1].ToString();
|
||||
@@ -204,7 +211,10 @@ namespace XCharts.Runtime
|
||||
}
|
||||
else if (p == 'c' || p == 'C')
|
||||
{
|
||||
content = content.Replace(old, ChartCached.NumberToStr(value, numericFormatter));
|
||||
if (pIndex >= 0 && serieData != null)
|
||||
content = content.Replace(old, ChartCached.NumberToStr(serieData.GetData(pIndex), numericFormatter));
|
||||
else
|
||||
content = content.Replace(old, ChartCached.NumberToStr(value, numericFormatter));
|
||||
}
|
||||
else if (p == 'f' || p == 'f')
|
||||
{
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace XCharts.Runtime
|
||||
{
|
||||
var content = serieLabel.formatter;
|
||||
FormatterHelper.ReplaceSerieLabelContent(ref content, numericFormatter, serie.dataCount, dataValue,
|
||||
dataTotal, serieName, dataName, dataName, color);
|
||||
dataTotal, serieName, dataName, dataName, color, serieData);
|
||||
return content;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -439,17 +439,12 @@ namespace XCharts.Runtime
|
||||
float currCos = Mathf.Cos(currAngle * Mathf.Deg2Rad);
|
||||
var radius1 = labelLine.lineType == LabelLine.LineType.HorizontalLine ?
|
||||
serie.context.outsideRadius : outSideRadius;
|
||||
var radius2 = serie.context.outsideRadius + labelLine.lineLength1;
|
||||
var radius3 = insideRadius + (outSideRadius - insideRadius) / 2;
|
||||
if (radius1 < serie.context.insideRadius) radius1 = serie.context.insideRadius;
|
||||
radius1 -= 0.1f;
|
||||
var pos0 = new Vector3(center.x + radius3 * currSin, center.y + radius3 * currCos);
|
||||
var pos1 = new Vector3(center.x + radius1 * currSin, center.y + radius1 * currCos);
|
||||
var pos2 = serieData.context.labelPosition;
|
||||
if (pos2.x == 0)
|
||||
{
|
||||
//pos2 = new Vector3(center.x + radius2 * currSin, center.y + radius2 * currCos);
|
||||
}
|
||||
Vector3 pos4, pos6;
|
||||
var horizontalLineCircleRadius = labelLine.lineWidth * 4f;
|
||||
var lineCircleDiff = horizontalLineCircleRadius - 0.3f;
|
||||
|
||||
@@ -510,7 +510,7 @@ namespace XCharts.Runtime
|
||||
return;
|
||||
|
||||
itemFormatter = SerieHelper.GetItemFormatter(serie, serieData, itemFormatter);
|
||||
if (serie.placeHolder || TooltipHelper.IsIgnoreItemFormatter(itemFormatter))
|
||||
if (serie.placeHolder || TooltipHelper.IsIgnoreFormatter(itemFormatter))
|
||||
return;
|
||||
|
||||
var param = serie.context.param;
|
||||
@@ -550,7 +550,7 @@ namespace XCharts.Runtime
|
||||
return;
|
||||
|
||||
itemFormatter = SerieHelper.GetItemFormatter(serie, serieData, itemFormatter);
|
||||
if (serie.placeHolder || TooltipHelper.IsIgnoreItemFormatter(itemFormatter))
|
||||
if (serie.placeHolder || TooltipHelper.IsIgnoreFormatter(itemFormatter))
|
||||
return;
|
||||
|
||||
var colorIndex = chart.GetLegendRealShowNameIndex(serieData.name);
|
||||
|
||||
Reference in New Issue
Block a user