Added support for {e} in Tooltip #170

This commit is contained in:
monitor1394
2021-10-29 07:05:30 +08:00
parent 6888ba96e3
commit fe702f3447
6 changed files with 15 additions and 8 deletions

View File

@@ -40,6 +40,7 @@
## master
* (2021.10.29) Added support for `{e}` in `Tooltip` #170
* (2021.09.08) Improved `RadarChart`
* (2021.09.07) Fixed bug where `label` does not disappear at the end of `PieChart` fade animation #168
* (2021.09.06) Fixed bug where `GaugeChart` changing `splitNumber` with code does not refresh `label` #167

View File

@@ -40,6 +40,7 @@
## master
* (2021.10.29) 增加`Tooltip`对通配符`{e}`的支持 #170
* (2021.09.08) 完善`RadarChart`
* (2021.09.07) 修复`PieChart`渐出动画结束时`label`没有消失的问题 #168
* (2021.09.06) 修复`GaugeChart`用代码改变`splitNumber`不会刷新`label`的问题 #167

View File

@@ -233,6 +233,7 @@
* `{b}`为当前所指示或`index``0``serie`的数据项`serieData``name`,或者类目值(如折线图的`X`轴)。
* `{c}`为当前所指示或`index``0``serie``y`维(`dimesion``1`)的数值。
* `{d}`为当前所指示或`index``0``serie``y`维(`dimesion``1`)百分比值,注意不带`%`号。
* `{e}`为当前所指示或`index``0``serie`的数据项`serieData``name`
* `{.1}`表示指定`index``1``serie`对应颜色的圆点。
* `{a1}``{b1}``{c1}`中的`1`表示指定`index``1``serie`
* `{c1:2}`表示索引为`1``serie`的当前指示数据项的第`3`个数据一个数据项有多个数据index为`2`表示第`3`个数据)。

View File

@@ -237,6 +237,7 @@ Tooltip component.
* `{b}` is the `name` of the `serieData` that is currently indicated or whose `index` is `0`, or a `category` value (such as the X-axis of a line chart).
* `{c}` is the value of a Y-dimension (`dimesion` is 1) from the `serie` that is currently indicated or whose `index` is `0`.
* `{d}` is the percentage value of Y-dimensions (`dimesion` is 1) from the `serie` that is currently indicated or whose `index` is `0`, with no `%` sign.
* `{e}` is the `name` of the `serieData` that is currently indicated or whose `index` is `0`.
* `{.1}` represents a dot from serie corresponding color that specifies `index` as `1`.
* `1` in `{a1}`, `{b1}`, `{c1}` represents a `serie` that specifies an `index` of `1`.
* `{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).

View File

@@ -101,6 +101,7 @@ namespace XCharts
/// {b} is the name of the data item serieData that is currently indicated or whose index is 0, or a category value (such as the X-axis of a line chart).
/// {c} is the value of a Y-dimension (dimesion is 1) from a Serie that is currently indicated or whose index is 0.
/// {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.
/// {e} is the name of the data item serieData that is currently indicated or whose index is 0.
/// {.1} represents a dot from serie corresponding color that specifies index as 1.
/// 1 in {a1}, {b1}, {c1} represents a serie that specifies an index of 1.
/// {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).
@@ -115,6 +116,7 @@ namespace XCharts
/// {b}为当前所指示或index为0的serie的数据项serieData的name或者类目值如折线图的X轴
/// {c}为当前所指示或index为0的serie的y维dimesion为1的数值。
/// {d}为当前所指示或index为0的serie的y维dimesion为1百分比值注意不带%号。
/// {e}为当前所指示或index为0的serie的数据项serieData的name。
/// {.1}表示指定index为1的serie对应颜色的圆点。
/// {a1}、{b1}、{c1}中的1表示指定index为1的serie。
/// {c1:2}表示索引为1的serie的当前指示数据项的第3个数据一个数据项有多个数据index为2表示第3个数据

View File

@@ -15,7 +15,7 @@ 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_Regex = new Regex(@"{([a-e|.]\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);
@@ -23,11 +23,11 @@ namespace XCharts
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-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);
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);
/// <summary>
/// 替换字符串中的通配符,支持的通配符有{.}、{a}、{b}、{c}、{d}。
/// 替换字符串中的通配符,支持的通配符有{.}、{a}、{b}、{c}、{d}、{e}
/// </summary>
/// <param name="content">要替换的字符串</param>
/// <param name="dataIndex">选中的数据项serieData索引</param>
@@ -84,15 +84,16 @@ namespace XCharts
content = content.Replace(old, serie.name);
}
}
else if (p == 'b' || p == 'B')
else if (p == 'b' || p == 'B' || p == 'e' || p == 'E')
{
var bIndex = dataIndex;
if (argsCount >= 2)
{
var args1Str = args[1].ToString();
if (s_RegexN.IsMatch(args1Str)) bIndex = int.Parse(args1Str);
if (s_RegexN.IsMatch(args1Str))
bIndex = int.Parse(args1Str);
}
var needCategory = serie.type == SerieType.Line || serie.type == SerieType.Bar;
var needCategory = (p != 'e' && p != 'E') && (serie.type == SerieType.Line || serie.type == SerieType.Bar);
if (needCategory)
{
var category = (chart as CoordinateChart).GetTooltipCategory(dataIndex, serie, dataZoom);
@@ -236,7 +237,7 @@ namespace XCharts
{
content = content.Replace(old, serieName);
}
else if (p == 'b' || p == 'B')
else if (p == 'b' || p == 'B' || p == 'c' || p == 'E')
{
content = content.Replace(old, dataName);
}