public static void ReplaceSerieLabelContent(ref string content, string numericFormatter, double value, double total,
                                                    string serieName, 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, dataName);
                }
                else if (p == 'c' || p == 'C' || p == 'd' || p == 'D')
                {
                    var isPercent = p == 'd' || p == 'D';
                    if (isPercent)
                    {
                        if (total != 0)
                        {
                            content = content.Replace(old, ChartCached.FloatToStr(value / total * 100, numericFormatter));
                        }
                    }
                    else
                    {
                        content = content.Replace(old, ChartCached.FloatToStr(value, numericFormatter));
                    }
                }
            }
            content = TrimAndReplaceLine(content);
        }
 public static string GetFormatterContent(Tooltip tooltip, int dataIndex, Series series, ThemeInfo themeInfo,
                                          string category = null, DataZoom dataZoom = null, bool isCartesian = false, Radar radar = null)
 {
     if (string.IsNullOrEmpty(tooltip.formatter))
     {
         var sb            = ChartHelper.sb;
         var title         = tooltip.titleFormatter;
         var formatTitle   = !string.IsNullOrEmpty(title);
         var titleIsIgnroe = false;
         var needCategory  = false;
         var first         = true;
         var isScatter     = false;
         sb.Length = 0;
         if ("{i}".Equals(tooltip.titleFormatter))
         {
             title         = string.Empty;
             formatTitle   = false;
             titleIsIgnroe = true;
         }
         for (int i = 0; i < series.Count; i++)
         {
             var serie = series.GetSerie(i);
             if (serie.type == SerieType.Scatter || serie.type == SerieType.EffectScatter)
             {
                 if (serie.show && IsSelectedSerie(tooltip, serie.index))
                 {
                     isScatter = true;
                     var itemFormatter = GetItemFormatter(tooltip, serie, null);
                     if (string.IsNullOrEmpty(itemFormatter))
                     {
                         if (!first)
                         {
                             sb.Append(FormatterHelper.PH_NN);
                         }
                         InitDefaultContent(ref sb, tooltip, serie, dataIndex, category, themeInfo, dataZoom, isCartesian, radar);
                         first = false;
                         continue;
                     }
                     var itemTitle = title;
                     if (!string.IsNullOrEmpty(itemTitle))
                     {
                         FormatterHelper.ReplaceContent(ref itemTitle, dataIndex, tooltip.numericFormatter, serie, series, themeInfo, category, dataZoom);
                         sb.Append(itemTitle).Append(FormatterHelper.PH_NN);
                     }
                     var dataIndexList = tooltip.runtimeSerieIndex[serie.index];
                     foreach (var tempIndex in dataIndexList)
                     {
                         string content  = itemFormatter;
                         var    foundDot = FormatterHelper.ReplaceContent(ref content, tempIndex, tooltip.numericFormatter, serie, series, themeInfo, category, dataZoom);
                         if (!foundDot)
                         {
                             sb.Append(ChartCached.ColorToDotStr(themeInfo.GetColor(serie.index)));
                         }
                         sb.Append(content).Append(FormatterHelper.PH_NN);
                     }
                 }
             }
             else if (IsNeedTooltipSerie(serie, tooltip))
             {
                 var serieData = serie.GetSerieData(dataIndex, dataZoom);
                 if (serieData == null)
                 {
                     continue;
                 }
                 var itemFormatter = GetItemFormatter(tooltip, serie, serieData);
                 needCategory = needCategory || (serie.type == SerieType.Line || serie.type == SerieType.Bar);
                 if (formatTitle)
                 {
                     FormatterHelper.ReplaceContent(ref title, dataIndex, tooltip.numericFormatter, serie, series, themeInfo, category, dataZoom);
                 }
                 if (serie.show)
                 {
                     if (string.IsNullOrEmpty(itemFormatter) || serie.type == SerieType.Radar)
                     {
                         if (!first)
                         {
                             sb.Append(FormatterHelper.PH_NN);
                         }
                         InitDefaultContent(ref sb, tooltip, serie, dataIndex, category, themeInfo, dataZoom, isCartesian, radar);
                         first = false;
                         continue;
                     }
                     string content = itemFormatter;
                     FormatterHelper.ReplaceContent(ref content, dataIndex, tooltip.numericFormatter, serie, series, themeInfo, category, dataZoom);
                     if (!first)
                     {
                         sb.Append(FormatterHelper.PH_NN);
                     }
                     var dotColorIndex = serie.type == SerieType.Pie || serie.type == SerieType.Radar || serie.type == SerieType.Ring ? dataIndex : i;
                     sb.Append(ChartCached.ColorToDotStr(themeInfo.GetColor(dotColorIndex)));
                     sb.Append(content);
                     first = false;
                 }
             }
         }
         if (isScatter)
         {
             return(FormatterHelper.TrimAndReplaceLine(sb));
         }
         else if (string.IsNullOrEmpty(title))
         {
             if (needCategory && !titleIsIgnroe)
             {
                 return(category + FormatterHelper.PH_NN + FormatterHelper.TrimAndReplaceLine(sb));
             }
             else
             {
                 return(FormatterHelper.TrimAndReplaceLine(sb));
             }
         }
         else
         {
             title = FormatterHelper.TrimAndReplaceLine(title);
             return(title + FormatterHelper.PH_NN + FormatterHelper.TrimAndReplaceLine(sb));
         }
     }
     else
     {
         string content = tooltip.formatter;
         FormatterHelper.ReplaceContent(ref content, dataIndex, tooltip.numericFormatter, null, series, themeInfo, category, dataZoom);
         return(content);
     }
 }
        public static string GetPolarFormatterContent(Tooltip tooltip, Series series, ThemeInfo themeInfo, AngleAxis angleAxis)
        {
            if (string.IsNullOrEmpty(tooltip.formatter))
            {
                var sb = ChartHelper.sb;
                sb.Length = 0;
                var title       = tooltip.titleFormatter;
                var formatTitle = !string.IsNullOrEmpty(title);
                if ("{i}".Equals(tooltip.titleFormatter))
                {
                    title       = string.Empty;
                    formatTitle = false;
                }
                else if (string.IsNullOrEmpty(title))
                {
                    var angle = angleAxis.clockwise ? tooltip.runtimeAngle : 360 - tooltip.runtimeAngle;
                    title = ChartCached.FloatToStr(angle);
                }
                foreach (var serie in series.list)
                {
                    if (serie.show && IsSelectedSerie(tooltip, serie.index))
                    {
                        if (formatTitle)
                        {
                            FormatterHelper.ReplaceContent(ref title, 0, tooltip.numericFormatter, serie, series, themeInfo, null, null);
                        }
                        var dataIndexList = tooltip.runtimeSerieIndex[serie.index];

                        for (int i = 0; i < dataIndexList.Count; i++)
                        {
                            var   dataIndex = dataIndexList[i];
                            var   serieData = serie.GetSerieData(dataIndex);
                            var   itemFormatter = GetItemFormatter(tooltip, serie, serieData);
                            var   numericFormatter = GetItemNumericFormatter(tooltip, serie, serieData);
                            float xValue, yValue;
                            serie.GetXYData(dataIndex, null, out xValue, out yValue);
                            if (string.IsNullOrEmpty(itemFormatter))
                            {
                                sb.Append("<color=#").Append(themeInfo.GetColorStr(serie.index)).Append(">● </color>");
                                if (!string.IsNullOrEmpty(serie.name))
                                {
                                    sb.Append(serie.name).Append(": ");
                                }
                                sb.AppendFormat("{0}", ChartCached.FloatToStr(xValue, numericFormatter));
                                if (i != dataIndexList.Count - 1)
                                {
                                    sb.Append(FormatterHelper.PH_NN);
                                }
                            }
                            else
                            {
                                string content = itemFormatter;
                                FormatterHelper.ReplaceContent(ref content, dataIndex, tooltip.numericFormatter, serie, series, themeInfo, null, null);
                                var dotColorIndex = serie.type == SerieType.Pie || serie.type == SerieType.Radar || serie.type == SerieType.Ring ? dataIndex : serie.index;
                                sb.Append(ChartCached.ColorToDotStr(themeInfo.GetColor(dotColorIndex)));
                                sb.Append(content);
                            }
                        }
                        sb.Append(FormatterHelper.PH_NN);
                    }
                }
                if (string.IsNullOrEmpty(title))
                {
                    return(FormatterHelper.TrimAndReplaceLine(sb));
                }
                else
                {
                    title = FormatterHelper.TrimAndReplaceLine(title);
                    return(title + FormatterHelper.PH_NN + FormatterHelper.TrimAndReplaceLine(sb));
                }
            }
            else
            {
                string content = tooltip.formatter;
                FormatterHelper.ReplaceContent(ref content, 0, tooltip.numericFormatter, null, series, themeInfo, null, null);
                return(content);
            }
        }
Exemple #4
0
        /// <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);
        }
Exemple #5
0
 public static string GetFormatterContent(Tooltip tooltip, int dataIndex, Series series, ThemeInfo themeInfo,
                                          string category = null, DataZoom dataZoom = null, bool isCartesian = false)
 {
     if (string.IsNullOrEmpty(tooltip.formatter))
     {
         var sb           = ChartHelper.sb;
         var title        = tooltip.titleFormatter;
         var formatTitle  = !string.IsNullOrEmpty(title);
         var needCategory = false;
         var first        = true;
         var isScatter    = false;
         sb.Length = 0;
         for (int i = 0; i < series.Count; i++)
         {
             var serie = series.GetSerie(i);
             if (serie.type == SerieType.Scatter || serie.type == SerieType.EffectScatter)
             {
                 if (serie.show && IsSelectedSerie(tooltip, serie.index))
                 {
                     isScatter = true;
                     var itemFormatter = GetItemFormatter(tooltip, serie, null);
                     if (string.IsNullOrEmpty(itemFormatter))
                     {
                         if (!first)
                         {
                             sb.Append(PH_NN);
                         }
                         InitDefaultContent(ref sb, tooltip, serie, dataIndex, category, themeInfo, dataZoom, isCartesian);
                         first = false;
                         continue;
                     }
                     var itemTitle = title;
                     if (!string.IsNullOrEmpty(itemTitle))
                     {
                         Replace(ref itemTitle, PH_A, i, serie.name, true);
                         sb.Append(itemTitle).Append(PH_NN);
                     }
                     var dataIndexList = tooltip.runtimeSerieDataIndex[serie.index];
                     foreach (var tempIndex in dataIndexList)
                     {
                         var    foundDot  = false;
                         var    serieData = serie.GetSerieData(tempIndex);
                         string content   = itemFormatter;
                         Replace(ref content, PH_A, i, serie.name, true);
                         Replace(ref content, PH_B, i, needCategory ? category : serieData.name, true);
                         if (itemFormatter.IndexOf(PH_I) >= 0)
                         {
                             foundDot = true;
                             Replace(ref content, PH_I, i, ChartCached.ColorToDotStr(themeInfo.GetColor(serie.index)), true);
                         }
                         for (int n = 0; n < serieData.data.Count; n++)
                         {
                             var valueStr = ChartCached.FloatToStr(serieData.GetData(n), 0, tooltip.forceENotation);
                             Replace(ref content, GetPHCC(n), i, valueStr, true);
                         }
                         if (!foundDot)
                         {
                             sb.Append(ChartCached.ColorToDotStr(themeInfo.GetColor(serie.index)));
                         }
                         sb.Append(content).Append(PH_NN);
                     }
                 }
             }
             else
             {
                 var serieData = serie.GetSerieData(dataIndex, dataZoom);
                 if (serieData == null)
                 {
                     continue;
                 }
                 var itemFormatter = GetItemFormatter(tooltip, serie, serieData);
                 var percent       = serieData.GetData(1) / serie.yTotal * 100;
                 needCategory = needCategory || (serie.type == SerieType.Line || serie.type == SerieType.Bar);
                 if (formatTitle)
                 {
                     var valueStr = ChartCached.FloatToStr(serieData.GetData(1), 0, tooltip.forceENotation);
                     Replace(ref title, PH_A, i, serie.name, true);
                     Replace(ref title, PH_B, i, needCategory ? category : serieData.name, true);
                     Replace(ref title, PH_C, i, valueStr, true);
                     Replace(ref title, PH_D, i, ChartCached.FloatToStr(percent, 1), true);
                 }
                 if (serie.show)
                 {
                     if (string.IsNullOrEmpty(itemFormatter))
                     {
                         if (!first)
                         {
                             sb.Append(PH_NN);
                         }
                         InitDefaultContent(ref sb, tooltip, serie, dataIndex, category, themeInfo, dataZoom, isCartesian);
                         first = false;
                         continue;
                     }
                     string content  = itemFormatter;
                     var    valueStr = ChartCached.FloatToStr(serieData.GetData(1), 0, tooltip.forceENotation);
                     Replace(ref content, PH_A, i, serie.name, true);
                     Replace(ref content, PH_B, i, needCategory ? category : serieData.name, true);
                     Replace(ref content, PH_C, i, valueStr, true);
                     Replace(ref content, PH_D, i, ChartCached.FloatToStr(percent, 1), true);
                     for (int n = 0; n < serieData.data.Count; n++)
                     {
                         valueStr = ChartCached.FloatToStr(serieData.GetData(n), 0, tooltip.forceENotation);
                         Replace(ref content, GetPHCC(n), i, valueStr, true);
                     }
                     if (!first)
                     {
                         sb.Append(PH_NN);
                     }
                     sb.Append(ChartCached.ColorToDotStr(themeInfo.GetColor(i)));
                     sb.Append(content);
                     first = false;
                 }
             }
         }
         if (isScatter)
         {
             return(TrimAndReplaceLine(sb));
         }
         else if (string.IsNullOrEmpty(title))
         {
             if (needCategory)
             {
                 return(category + PH_NN + TrimAndReplaceLine(sb));
             }
             else
             {
                 return(TrimAndReplaceLine(sb));
             }
         }
         else
         {
             title = title.Replace(PH_ON, PH_NN);
             title = title.Replace(PH_BR, PH_NN);
             return(title + PH_NN + TrimAndReplaceLine(sb));
         }
     }
     else
     {
         string content = tooltip.formatter;
         for (int i = 0; i < series.Count; i++)
         {
             var serie = series.GetSerie(i);
             if (serie.show)
             {
                 var needCategory = serie.type == SerieType.Line || serie.type == SerieType.Bar;
                 var serieData    = serie.GetSerieData(dataIndex, dataZoom);
                 var percent      = serieData.GetData(1) / serie.yTotal * 100;
                 Replace(ref content, PH_A, i, serie.name);
                 Replace(ref content, PH_B, i, needCategory ? category : serieData.name);
                 Replace(ref content, PH_C, i, ChartCached.FloatToStr(serieData.GetData(1), 0, tooltip.forceENotation));
                 Replace(ref content, PH_D, i, ChartCached.FloatToStr(percent, 1));
                 Replace(ref content, PH_I, i, ChartCached.ColorToDotStr(themeInfo.GetColor(i)));
                 for (int n = 0; n < serieData.data.Count; n++)
                 {
                     var valueStr = ChartCached.FloatToStr(serieData.GetData(n), 0, tooltip.forceENotation);
                     if (i == 0)
                     {
                         Replace(ref content, GetPHCC(n), i, valueStr, true);
                     }
                     Replace(ref content, GetPHCC(i, n), i, valueStr, true);
                 }
             }
         }
         content = content.Replace(PH_ON, PH_NN);
         content = content.Replace(PH_BR, PH_NN);
         return(content);
     }
 }
Exemple #6
0
 public static string GetFormatterContent(Tooltip tooltip, int dataIndex, Series series, ThemeInfo themeInfo,
                                          string category = null, DataZoom dataZoom = null, bool isCartesian = false)
 {
     if (string.IsNullOrEmpty(tooltip.formatter))
     {
         var sb           = ChartHelper.sb;
         var title        = tooltip.titleFormatter;
         var formatTitle  = !string.IsNullOrEmpty(title);
         var needCategory = false;
         var first        = true;
         var isScatter    = false;
         sb.Length = 0;
         for (int i = 0; i < series.Count; i++)
         {
             var serie = series.GetSerie(i);
             if (serie.type == SerieType.Scatter || serie.type == SerieType.EffectScatter)
             {
                 if (serie.show && IsSelectedSerie(tooltip, serie.index))
                 {
                     isScatter = true;
                     var itemFormatter    = GetItemFormatter(tooltip, serie, null);
                     var numericFormatter = GetItemNumericFormatter(tooltip, serie, null);
                     if (string.IsNullOrEmpty(itemFormatter))
                     {
                         if (!first)
                         {
                             sb.Append(PH_NN);
                         }
                         InitDefaultContent(ref sb, tooltip, serie, dataIndex, category, themeInfo, dataZoom, isCartesian);
                         first = false;
                         continue;
                     }
                     var itemTitle = title;
                     if (!string.IsNullOrEmpty(itemTitle))
                     {
                         ReplaceContent(ref itemTitle, dataIndex, tooltip, serie, null, themeInfo, category, dataZoom, isCartesian);
                         sb.Append(itemTitle).Append(PH_NN);
                     }
                     var dataIndexList = tooltip.runtimeSerieDataIndex[serie.index];
                     foreach (var tempIndex in dataIndexList)
                     {
                         string content  = itemFormatter;
                         var    foundDot = ReplaceContent(ref content, tempIndex, tooltip, serie, null, themeInfo, category, dataZoom, isCartesian);
                         if (!foundDot)
                         {
                             sb.Append(ChartCached.ColorToDotStr(themeInfo.GetColor(serie.index)));
                         }
                         sb.Append(content).Append(PH_NN);
                     }
                 }
             }
             else
             {
                 var serieData = serie.GetSerieData(dataIndex, dataZoom);
                 if (serieData == null)
                 {
                     continue;
                 }
                 var itemFormatter = GetItemFormatter(tooltip, serie, serieData);
                 needCategory = needCategory || (serie.type == SerieType.Line || serie.type == SerieType.Bar);
                 if (formatTitle)
                 {
                     ReplaceContent(ref title, dataIndex, tooltip, null, series, themeInfo, category, dataZoom, isCartesian);
                 }
                 if (serie.show)
                 {
                     if (string.IsNullOrEmpty(itemFormatter))
                     {
                         if (!first)
                         {
                             sb.Append(PH_NN);
                         }
                         InitDefaultContent(ref sb, tooltip, serie, dataIndex, category, themeInfo, dataZoom, isCartesian);
                         first = false;
                         continue;
                     }
                     string content = itemFormatter;
                     ReplaceContent(ref content, dataIndex, tooltip, serie, null, themeInfo, category, dataZoom, isCartesian);
                     if (!first)
                     {
                         sb.Append(PH_NN);
                     }
                     sb.Append(ChartCached.ColorToDotStr(themeInfo.GetColor(i)));
                     sb.Append(content);
                     first = false;
                 }
             }
         }
         if (isScatter)
         {
             return(TrimAndReplaceLine(sb));
         }
         else if (string.IsNullOrEmpty(title))
         {
             if (needCategory)
             {
                 return(category + PH_NN + TrimAndReplaceLine(sb));
             }
             else
             {
                 return(TrimAndReplaceLine(sb));
             }
         }
         else
         {
             title = s_RegexNewLine.Replace(title, PH_NN);
             return(title + PH_NN + TrimAndReplaceLine(sb));
         }
     }
     else
     {
         string content = tooltip.formatter;
         ReplaceContent(ref content, dataIndex, tooltip, null, series, themeInfo, category, dataZoom, isCartesian);
         return(content);
     }
 }