Пример #1
0
 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);
     }
 }
Пример #2
0
        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);
            }
        }