Exemplo n.º 1
0
        private void DrawRadar(VertexHelper vh, Radar radar)
        {
            if (!radar.splitLine.show && !radar.splitArea.show)
            {
                return;
            }
            float   insideRadius = 0, outsideRadius = 0;
            float   block = radar.runtimeRadius / radar.splitNumber;
            int     indicatorNum = radar.indicatorList.Count;
            Vector3 p1, p2, p3, p4;
            Vector3 p              = radar.runtimeCenterPos;
            float   angle          = 2 * Mathf.PI / indicatorNum;
            var     lineColor      = radar.axisLine.GetColor(chart.theme.radar.lineColor);
            var     lineWidth      = radar.axisLine.GetWidth(chart.theme.radar.lineWidth);
            var     lineType       = radar.axisLine.GetType(chart.theme.radar.lineType);
            var     splitLineColor = radar.splitLine.GetColor(chart.theme.radar.splitLineColor);
            var     splitLineWidth = radar.splitLine.GetWidth(chart.theme.radar.splitLineWidth);
            var     splitLineType  = radar.splitLine.GetType(chart.theme.radar.splitLineType);

            for (int i = 0; i < radar.splitNumber; i++)
            {
                var isLast = i == radar.splitNumber - 1;
                var color  = radar.splitArea.GetColor(i, chart.theme.radar);
                outsideRadius = insideRadius + block;
                p1            = new Vector3(p.x + insideRadius * Mathf.Sin(0), p.y + insideRadius * Mathf.Cos(0));
                p2            = new Vector3(p.x + outsideRadius * Mathf.Sin(0), p.y + outsideRadius * Mathf.Cos(0));
                for (int j = 0; j <= indicatorNum; j++)
                {
                    float currAngle = j * angle;
                    p3 = new Vector3(p.x + outsideRadius * Mathf.Sin(currAngle),
                                     p.y + outsideRadius * Mathf.Cos(currAngle));
                    p4 = new Vector3(p.x + insideRadius * Mathf.Sin(currAngle),
                                     p.y + insideRadius * Mathf.Cos(currAngle));
                    if (radar.splitArea.show)
                    {
                        UGL.DrawQuadrilateral(vh, p1, p2, p3, p4, color);
                    }
                    if (radar.splitLine.NeedShow(i))
                    {
                        if (isLast)
                        {
                            ChartDrawer.DrawLineStyle(vh, lineType, lineWidth, p2, p3, lineColor);
                        }
                        else
                        {
                            ChartDrawer.DrawLineStyle(vh, splitLineType, splitLineWidth, p2, p3, splitLineColor);
                        }
                    }
                    p1 = p4;
                    p2 = p3;
                }
                insideRadius = outsideRadius;
            }
            for (int j = 0; j <= indicatorNum; j++)
            {
                float currAngle = j * angle;
                p3 = new Vector3(p.x + outsideRadius * Mathf.Sin(currAngle),
                                 p.y + outsideRadius * Mathf.Cos(currAngle));
                if (radar.splitLine.show)
                {
                    ChartDrawer.DrawLineStyle(vh, splitLineType, splitLineWidth, p, p3, splitLineColor);
                }
            }
        }
Exemplo n.º 2
0
 private Color GetLineColor(Radar radar)
 {
     return(radar.splitLine.GetColor(m_ThemeInfo));
 }
        public static void InitRadarTooltip(ref StringBuilder sb, Tooltip tooltip, Serie serie, Radar radar,
                                            ThemeInfo themeInfo)
        {
            var dataIndex = tooltip.runtimeDataIndex[1];
            var serieData = serie.GetSerieData(dataIndex);

            switch (serie.radarType)
            {
            case RadarType.Multiple:
                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("\n");
                    }
                    sb.AppendFormat("{0}: {1}", key, ChartCached.FloatToStr(value, 0, tooltip.forceENotation));
                }
                break;

            case RadarType.Single:
                string key2   = serieData.name;
                float  value2 = serieData.GetData(1);
                if (string.IsNullOrEmpty(key2))
                {
                    key2 = radar.indicatorList[dataIndex].name;
                }
                sb.AppendFormat("{0}: {1}", key2, ChartCached.FloatToStr(value2, 0, tooltip.forceENotation));
                break;
            }
        }
 public static string GetFormatterContent(Tooltip tooltip, int dataIndex, BaseChart chart, 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 < chart.series.Count; i++)
         {
             var serie = chart.series.GetSerie(i);
             if (tooltip.runtimeGridIndex >= 0 && serie.runtimeGridIndex != tooltip.runtimeGridIndex)
             {
                 continue;
             }
             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, chart, dataZoom, isCartesian, radar);
                         first = false;
                         continue;
                     }
                     var itemTitle = title;
                     if (!string.IsNullOrEmpty(itemTitle))
                     {
                         FormatterHelper.ReplaceContent(ref itemTitle, dataIndex, tooltip.numericFormatter, serie, chart, 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, chart, dataZoom);
                         if (!foundDot)
                         {
                             sb.Append(ChartCached.ColorToDotStr(chart.theme.GetColor(serie.index)));
                         }
                         sb.Append(content).Append(FormatterHelper.PH_NN);
                     }
                 }
             }
             else if (IsNeedTooltipSerie(serie, tooltip))
             {
                 var itemFormatter = string.Empty;
                 if (serie.type == SerieType.Gauge)
                 {
                     var serieData = serie.GetSerieData(0, dataZoom);
                     if (serieData == null)
                     {
                         continue;
                     }
                     itemFormatter = GetItemFormatter(tooltip, serie, serieData);
                 }
                 else
                 {
                     var serieData = serie.GetSerieData(dataIndex, dataZoom);
                     if (serieData == null)
                     {
                         continue;
                     }
                     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, chart, 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, chart, dataZoom, isCartesian, radar);
                         first = false;
                         continue;
                     }
                     string content = itemFormatter;
                     FormatterHelper.ReplaceContent(ref content, dataIndex, tooltip.numericFormatter, serie, chart, 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(chart.theme.GetColor(dotColorIndex)));
                     sb.Append(content);
                     first = false;
                 }
             }
         }
         if (isScatter)
         {
             return(FormatterHelper.TrimAndReplaceLine(sb));
         }
         else if (string.IsNullOrEmpty(title))
         {
             if (needCategory && !titleIsIgnroe)
             {
                 var category = (chart as CoordinateChart).GetTooltipCategory(dataIndex, dataZoom);
                 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, chart, dataZoom);
         return(content);
     }
 }
        public static void InitRadarTooltip(ref StringBuilder sb, Tooltip tooltip, Serie serie, Radar radar,
                                            ChartTheme theme)
        {
            if (radar == null)
            {
                return;
            }
            if (!serie.show)
            {
                return;
            }
            if (tooltip.runtimeGridIndex >= 0)
            {
                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(theme.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, theme.GetColor(i));
                            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, theme.GetColor(serie.index));
                    sb.Append(content);
                }
                break;
            }
        }
 /// <summary>
 /// 添加雷达坐标系组件。
 /// </summary>
 public void AddRadar(Radar radar)
 {
     m_Radars.Add(radar);
 }