Пример #1
0
 internal string GetFormatterContent(int dataIndex, Series series, string category, ThemeInfo themeInfo = null, DataZoom dataZoom = null)
 {
     if (string.IsNullOrEmpty(m_Formatter))
     {
         if (string.IsNullOrEmpty(m_ItemFormatter))
         {
             return("");
         }
         else
         {
             var sb           = ChartHelper.sb;
             var title        = m_TitleFormatter;
             var formatTitle  = !string.IsNullOrEmpty(title);
             var needCategory = false;
             var first        = true;
             sb.Length = 0;
             for (int i = 0; i < series.Count; i++)
             {
                 var serie     = series.GetSerie(i);
                 var serieData = serie.GetSerieData(dataIndex, dataZoom);
                 var percent   = serieData.GetData(1) / serie.yTotal * 100;
                 needCategory = needCategory || (serie.type == SerieType.Line || serie.type == SerieType.Bar);
                 if (serie.show)
                 {
                     string content = m_ItemFormatter;
                     content = content.Replace("{a}", serie.name);
                     content = content.Replace("{b}", needCategory ? category : serieData.name);
                     content = content.Replace("{c}", ChartCached.FloatToStr(serieData.GetData(1), 0, m_ForceENotation));
                     content = content.Replace("{d}", ChartCached.FloatToStr(percent, 1));
                     if (!first)
                     {
                         sb.Append("\n");
                     }
                     sb.Append("<color=#").Append(themeInfo.GetColorStr(i)).Append(">● </color>");
                     sb.Append(content);
                     first = false;
                 }
                 if (formatTitle)
                 {
                     if (i == 0)
                     {
                         title = title.Replace("{a}", serie.name);
                         title = title.Replace("{b}", needCategory ? category : serieData.name);
                         title = title.Replace("{c}", ChartCached.FloatToStr(serieData.GetData(1), 0, m_ForceENotation));
                         title = title.Replace("{d}", ChartCached.FloatToStr(percent, 1));
                     }
                     title = title.Replace("{a" + i + "}", serie.name);
                     title = title.Replace("{b" + i + "}", needCategory ? category : serieData.name);
                     title = title.Replace("{c" + i + "}", ChartCached.FloatToStr(serieData.GetData(1), 0, m_ForceENotation));
                     title = title.Replace("{d" + i + "}", ChartCached.FloatToStr(percent, 1));
                 }
             }
             if (string.IsNullOrEmpty(title))
             {
                 if (needCategory)
                 {
                     return(category + "\n" + sb.ToString());
                 }
                 else
                 {
                     return(sb.ToString());
                 }
             }
             else
             {
                 title = title.Replace("\\n", "\n");
                 title = title.Replace("<br/>", "\n");
                 return(title + "\n" + sb.ToString());
             }
         }
     }
     else
     {
         string content = m_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;
                 if (i == 0)
                 {
                     content = content.Replace("{a}", serie.name);
                     content = content.Replace("{b}", needCategory ? category : serieData.name);
                     content = content.Replace("{c}", ChartCached.FloatToStr(serieData.GetData(1), 0, m_ForceENotation));
                     content = content.Replace("{d}", ChartCached.FloatToStr(percent, 1));
                 }
                 content = content.Replace("{a" + i + "}", serie.name);
                 content = content.Replace("{b" + i + "}", needCategory ? category : serieData.name);
                 content = content.Replace("{c" + i + "}", ChartCached.FloatToStr(serieData.GetData(1), 0, m_ForceENotation));
                 content = content.Replace("{d" + i + "}", ChartCached.FloatToStr(percent, 1));
             }
         }
         content = content.Replace("\\n", "\n");
         content = content.Replace("<br/>", "\n");
         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);
            }
        }
Пример #3
0
        public static void InitRadarTooltip(ref StringBuilder sb, Tooltip tooltip, Serie serie, Radar radar,
                                            ThemeInfo themeInfo)
        {
            if (!serie.show)
            {
                return;
            }
            if (serie.radarIndex != radar.index)
            {
                return;
            }
            var dataIndex = tooltip.runtimeDataIndex[1];
            var serieData = serie.GetSerieData(dataIndex);

            if (!serieData.show)
            {
                return;
            }
            var numericFormatter = GetItemNumericFormatter(tooltip, serie, serieData);

            switch (serie.radarType)
            {
            case RadarType.Multiple:
                if (radar.isAxisTooltip)
                {
                    var dimension = tooltip.runtimeDataIndex[2];
                    if (!string.IsNullOrEmpty(serie.name))
                    {
                        sb.Append(serie.name).Append("\n");
                    }
                    var total = serie.GetDataTotal(dimension);
                    var first = true;
                    for (int i = 0; i < serie.dataCount; i++)
                    {
                        var sd = serie.GetSerieData(i);
                        if (!sd.show)
                        {
                            continue;
                        }
                        var key           = sd.name;
                        var value         = sd.GetData(dimension);
                        var itemFormatter = GetItemFormatter(tooltip, serie, sd);
                        numericFormatter = GetItemNumericFormatter(tooltip, serie, sd);
                        if (!first)
                        {
                            sb.Append("\n");
                        }
                        first = false;
                        sb.Append("<color=#").Append(themeInfo.GetColorStr(i)).Append(">● </color>");
                        if (string.IsNullOrEmpty(itemFormatter))
                        {
                            if (string.IsNullOrEmpty(key))
                            {
                                key = radar.indicatorList[dataIndex].name;
                            }
                            if (string.IsNullOrEmpty(key))
                            {
                                sb.AppendFormat("{0}\n", ChartCached.FloatToStr(value, numericFormatter));
                            }
                            else
                            {
                                sb.AppendFormat("{0}: {1}\n", key, ChartCached.FloatToStr(value, numericFormatter));
                            }
                        }
                        else
                        {
                            string content = itemFormatter;
                            FormatterHelper.ReplaceSerieLabelContent(ref content, numericFormatter, value, total, serie.name, sd.name);
                            sb.Append(content);
                        }
                    }
                }
                else
                {
                    if (serie.index != tooltip.runtimeDataIndex[0])
                    {
                        return;
                    }
                    sb.Append(serieData.name);
                    for (int i = 0; i < radar.indicatorList.Count; i++)
                    {
                        string key   = radar.indicatorList[i].name;
                        float  value = serieData.GetData(i);
                        if ((i == 0 && !string.IsNullOrEmpty(serieData.name)) || i > 0)
                        {
                            sb.Append(FormatterHelper.PH_NN);
                        }
                        sb.AppendFormat("{0}: {1}", key, ChartCached.FloatToStr(value, numericFormatter));
                    }
                }
                break;

            case RadarType.Single:
                var key2           = serieData.name;
                var value2         = serieData.GetData(1);
                var total2         = serie.GetDataTotal(1);
                var itemFormatter2 = GetItemFormatter(tooltip, serie, serieData);
                if (string.IsNullOrEmpty(itemFormatter2))
                {
                    if (string.IsNullOrEmpty(key2))
                    {
                        key2 = radar.indicatorList[dataIndex].name;
                    }
                    sb.AppendFormat("{0}: {1}", key2, ChartCached.FloatToStr(value2, numericFormatter));
                }
                else
                {
                    string content = itemFormatter2;
                    FormatterHelper.ReplaceSerieLabelContent(ref content, numericFormatter, value2, total2, serie.name, serieData.name);
                    sb.Append(content);
                }

                break;
            }
        }