public void DrawClipTriangle(VertexHelper vh, Vector3 p1, Vector3 p2, Vector3 p3, Color32 color,
                              Color32 color2, Color32 color3, bool clip, GridCoord grid)
 {
     if (!IsInChart(p1) || !IsInChart(p2) || !IsInChart(p3))
     {
         return;
     }
     if (!clip || (clip && (grid.Contains(p1) || grid.Contains(p2) || grid.Contains(p3))))
     {
         UGL.DrawTriangle(vh, p1, p2, p3, color, color2, color3);
     }
 }
        private void DrawPointer(VertexHelper vh, Serie serie, float currAngle)
        {
            if (!serie.gaugePointer.show)
            {
                return;
            }
            var pointerColor   = serie.gaugeAxis.GetPointerColor(chart.theme, serie.index, currAngle, serie.itemStyle);
            var pointerToColor = !ChartHelper.IsClearColor(serie.itemStyle.toColor) ? serie.itemStyle.toColor : pointerColor;
            var len            = serie.gaugePointer.length <1 && serie.gaugePointer.length> -1 ?
                                 serie.runtimeInsideRadius * serie.gaugePointer.length :
                                 serie.gaugePointer.length;
            var p1 = ChartHelper.GetPosition(serie.runtimeCenterPos, currAngle, len);
            var p2 = ChartHelper.GetPosition(serie.runtimeCenterPos, currAngle + 180, serie.gaugePointer.width);
            var p3 = ChartHelper.GetPosition(serie.runtimeCenterPos, currAngle - 90, serie.gaugePointer.width / 2);
            var p4 = ChartHelper.GetPosition(serie.runtimeCenterPos, currAngle + 90, serie.gaugePointer.width / 2);

            UGL.DrawTriangle(vh, p2, p3, p1, pointerColor, pointerColor, pointerToColor);
            UGL.DrawTriangle(vh, p4, p2, p1, pointerColor, pointerColor, pointerToColor);
        }
        private void DrawLegend(VertexHelper vh)
        {
            if (chart.series.Count == 0)
            {
                return;
            }
            var legend = component;

            if (!legend.show)
            {
                return;
            }
            if (legend.iconType == Legend.Type.Custom)
            {
                return;
            }
            foreach (var kv in legend.context.buttonList)
            {
                var item     = kv.Value;
                var rect     = item.GetIconRect();
                var radius   = Mathf.Min(rect.width, rect.height) / 2;
                var color    = item.GetIconColor();
                var iconType = legend.iconType;
                if (legend.iconType == Legend.Type.Auto)
                {
                    var serie = chart.GetSerie(item.legendName);
                    if (serie != null && serie is Line)
                    {
                        var sp = new Vector3(rect.center.x - rect.width / 2, rect.center.y);
                        var ep = new Vector3(rect.center.x + rect.width / 2, rect.center.y);
                        UGL.DrawLine(vh, sp, ep, chart.settings.legendIconLineWidth, color);
                        if (!serie.symbol.show)
                        {
                            continue;
                        }
                        switch (serie.symbol.type)
                        {
                        case SymbolType.None:
                            continue;

                        case SymbolType.Circle:
                            iconType = Legend.Type.Circle;
                            break;

                        case SymbolType.Diamond:
                            iconType = Legend.Type.Diamond;
                            break;

                        case SymbolType.EmptyCircle:
                            iconType = Legend.Type.EmptyCircle;
                            break;

                        case SymbolType.Rect:
                            iconType = Legend.Type.Rect;
                            break;

                        case SymbolType.Triangle:
                            iconType = Legend.Type.Triangle;
                            break;
                        }
                    }
                    else
                    {
                        iconType = Legend.Type.Rect;
                    }
                }
                switch (iconType)
                {
                case Legend.Type.Rect:
                    var cornerRadius = chart.settings.legendIconCornerRadius;
                    UGL.DrawRoundRectangle(vh, rect.center, rect.width, rect.height, color, color,
                                           0, cornerRadius, false, 0.5f);
                    break;

                case Legend.Type.Circle:
                    UGL.DrawCricle(vh, rect.center, radius, color);
                    break;

                case Legend.Type.Diamond:
                    UGL.DrawDiamond(vh, rect.center, radius, color);
                    break;

                case Legend.Type.EmptyCircle:
                    var backgroundColor = chart.GetChartBackgroundColor();
                    UGL.DrawEmptyCricle(vh, rect.center, radius, 2 * chart.settings.legendIconLineWidth,
                                        color, color, backgroundColor, 1f);
                    break;

                case Legend.Type.Triangle:
                    UGL.DrawTriangle(vh, rect.center, 1.2f * radius, color);
                    break;
                }
            }
        }
        private void DrawContinuousVisualMap(VertexHelper vh, VisualMap visualMap)
        {
            var centerPos  = chart.chartPosition + visualMap.location.GetPosition(chart.chartWidth, chart.chartHeight);
            var pos1       = Vector3.zero;
            var pos2       = Vector3.zero;
            var dir        = Vector3.zero;
            var halfWid    = visualMap.itemWidth / 2;
            var halfHig    = visualMap.itemHeight / 2;
            var xRadius    = 0f;
            var yRadius    = 0f;
            var splitNum   = visualMap.inRange.Count;
            var splitWid   = visualMap.itemHeight / (splitNum - 1);
            var isVertical = false;
            var colors     = visualMap.inRange;
            var triangeLen = chart.theme.visualMap.triangeLen;

            switch (visualMap.orient)
            {
            case Orient.Horizonal:
                pos1       = centerPos + Vector3.left * halfHig;
                pos2       = centerPos + Vector3.right * halfHig;
                dir        = Vector3.right;
                xRadius    = splitWid / 2;
                yRadius    = halfWid;
                isVertical = false;
                if (visualMap.calculable)
                {
                    var p0    = pos1 + Vector3.right * visualMap.runtimeRangeMinHeight;
                    var p1    = p0 + Vector3.up * halfWid;
                    var p2    = p0 + Vector3.up * (halfWid + triangeLen);
                    var p3    = p2 + Vector3.left * triangeLen;
                    var color = visualMap.GetColor(visualMap.rangeMin);
                    UGL.DrawTriangle(vh, p1, p2, p3, color);
                    p0    = pos1 + Vector3.right * visualMap.runtimeRangeMaxHeight;
                    p1    = p0 + Vector3.up * halfWid;
                    p2    = p0 + Vector3.up * (halfWid + triangeLen);
                    p3    = p2 + Vector3.right * triangeLen;
                    color = visualMap.GetColor(visualMap.rangeMax);
                    UGL.DrawTriangle(vh, p1, p2, p3, color);
                }
                break;

            case Orient.Vertical:
                pos1       = centerPos + Vector3.down * halfHig;
                pos2       = centerPos + Vector3.up * halfHig;
                dir        = Vector3.up;
                xRadius    = halfWid;
                yRadius    = splitWid / 2;
                isVertical = true;
                if (visualMap.calculable)
                {
                    var p0    = pos1 + Vector3.up * visualMap.runtimeRangeMinHeight;
                    var p1    = p0 + Vector3.right * halfWid;
                    var p2    = p0 + Vector3.right * (halfWid + triangeLen);
                    var p3    = p2 + Vector3.down * triangeLen;
                    var color = visualMap.GetColor(visualMap.rangeMin);
                    UGL.DrawTriangle(vh, p1, p2, p3, color);
                    p0    = pos1 + Vector3.up * visualMap.runtimeRangeMaxHeight;
                    p1    = p0 + Vector3.right * halfWid;
                    p2    = p0 + Vector3.right * (halfWid + triangeLen);
                    p3    = p2 + Vector3.up * triangeLen;
                    color = visualMap.GetColor(visualMap.rangeMax);
                    UGL.DrawTriangle(vh, p1, p2, p3, color);
                }
                break;
            }
            if (visualMap.calculable &&
                (visualMap.rangeMin > visualMap.min || visualMap.rangeMax < visualMap.max))
            {
                var rangeMin = visualMap.rangeMin;
                var rangeMax = visualMap.rangeMax;
                var diff     = (visualMap.max - visualMap.min) / (splitNum - 1);
                for (int i = 1; i < splitNum; i++)
                {
                    var splitMin = visualMap.min + (i - 1) * diff;
                    var splitMax = splitMin + diff;
                    if (rangeMin > splitMax || rangeMax < splitMin)
                    {
                        continue;
                    }
                    else if (rangeMin <= splitMin && rangeMax >= splitMax)
                    {
                        var splitPos   = pos1 + dir * (i - 1 + 0.5f) * splitWid;
                        var startColor = colors[i - 1].color;
                        var toColor    = visualMap.IsPiecewise() ? startColor : colors[i].color;
                        UGL.DrawRectangle(vh, splitPos, xRadius, yRadius, startColor, toColor, isVertical);
                    }
                    else if (rangeMin > splitMin && rangeMax >= splitMax)
                    {
                        var p0          = pos1 + dir * visualMap.runtimeRangeMinHeight;
                        var splitMaxPos = pos1 + dir * i * splitWid;
                        var splitPos    = p0 + (splitMaxPos - p0) / 2;
                        var startColor  = visualMap.GetColor(visualMap.rangeMin);
                        var toColor     = visualMap.IsPiecewise() ? startColor : colors[i].color;
                        var yRadius1    = Vector3.Distance(p0, splitMaxPos) / 2;

                        if (visualMap.orient == Orient.Vertical)
                        {
                            UGL.DrawRectangle(vh, splitPos, xRadius, yRadius1, startColor, toColor, isVertical);
                        }
                        else
                        {
                            UGL.DrawRectangle(vh, splitPos, yRadius1, yRadius, startColor, toColor, isVertical);
                        }
                    }
                    else if (rangeMax < splitMax && rangeMin <= splitMin)
                    {
                        var p0          = pos1 + dir * visualMap.runtimeRangeMaxHeight;
                        var splitMinPos = pos1 + dir * (i - 1) * splitWid;
                        var splitPos    = splitMinPos + (p0 - splitMinPos) / 2;
                        var startColor  = colors[i - 1].color;
                        var toColor     = visualMap.IsPiecewise() ? startColor : visualMap.GetColor(visualMap.rangeMax);
                        var yRadius1    = Vector3.Distance(p0, splitMinPos) / 2;

                        if (visualMap.orient == Orient.Vertical)
                        {
                            UGL.DrawRectangle(vh, splitPos, xRadius, yRadius1, startColor, toColor, isVertical);
                        }
                        else
                        {
                            UGL.DrawRectangle(vh, splitPos, yRadius1, yRadius, startColor, toColor, isVertical);
                        }
                    }
                    else
                    {
                        var p0         = pos1 + dir * visualMap.runtimeRangeMinHeight;
                        var p1         = pos1 + dir * visualMap.runtimeRangeMaxHeight;
                        var splitPos   = (p0 + p1) / 2;
                        var startColor = visualMap.GetColor(visualMap.rangeMin);
                        var toColor    = visualMap.GetColor(visualMap.rangeMax);
                        var yRadius1   = Vector3.Distance(p0, p1) / 2;

                        if (visualMap.orient == Orient.Vertical)
                        {
                            UGL.DrawRectangle(vh, splitPos, xRadius, yRadius1, startColor, toColor, isVertical);
                        }
                        else
                        {
                            UGL.DrawRectangle(vh, splitPos, yRadius1, yRadius, startColor, toColor, isVertical);
                        }
                    }
                }
            }
            else
            {
                for (int i = 1; i < splitNum; i++)
                {
                    var splitPos   = pos1 + dir * (i - 1 + 0.5f) * splitWid;
                    var startColor = colors[i - 1].color;
                    var toColor    = visualMap.IsPiecewise() ? startColor : colors[i].color;
                    UGL.DrawRectangle(vh, splitPos, xRadius, yRadius, startColor, toColor, isVertical);
                }
            }

            if (visualMap.rangeMin > visualMap.min)
            {
                var p0 = pos1 + dir * visualMap.runtimeRangeMinHeight;
                UGL.DrawRectangle(vh, pos1, p0, visualMap.itemWidth / 2, chart.theme.visualMap.backgroundColor);
            }
            if (visualMap.rangeMax < visualMap.max)
            {
                var p1 = pos1 + dir * visualMap.runtimeRangeMaxHeight;
                UGL.DrawRectangle(vh, p1, pos2, visualMap.itemWidth / 2, chart.theme.visualMap.backgroundColor);
            }

            if (visualMap.hoverLink)
            {
                if (visualMap.context.pointerIndex >= 0)
                {
                    var p0         = pos1 + dir * visualMap.runtimeRangeMinHeight;
                    var p1         = pos1 + dir * visualMap.runtimeRangeMaxHeight;
                    var pointerPos = chart.pointerPos;

                    if (visualMap.orient == Orient.Vertical)
                    {
                        var p2 = new Vector3(centerPos.x + halfWid, Mathf.Clamp(pointerPos.y + (triangeLen / 2), p0.y, p1.y));
                        var p3 = new Vector3(centerPos.x + halfWid, Mathf.Clamp(pointerPos.y - (triangeLen / 2), p0.y, p1.y));
                        var p4 = new Vector3(centerPos.x + halfWid + triangeLen / 2, pointerPos.y);
                        UGL.DrawTriangle(vh, p2, p3, p4, colors[visualMap.context.pointerIndex].color);
                    }
                    else
                    {
                        var p2 = new Vector3(Mathf.Clamp(pointerPos.x + (triangeLen / 2), p0.x, p1.x), centerPos.y + halfWid);
                        var p3 = new Vector3(Mathf.Clamp(pointerPos.x - (triangeLen / 2), p0.x, p1.x), centerPos.y + halfWid);
                        var p4 = new Vector3(pointerPos.x, centerPos.y + halfWid + triangeLen / 2);
                        UGL.DrawTriangle(vh, p2, p3, p4, colors[visualMap.context.pointerIndex].color);
                    }
                }
            }
        }
        public static void DrawSymbol(VertexHelper vh, SerieSymbolType type, float symbolSize,
                                      float tickness, Vector3 pos, Color32 color, Color32 toColor, float gap, float[] cornerRadius,
                                      Color32 backgroundColor, float smoothness, Vector3 startPos)
        {
            switch (type)
            {
            case SerieSymbolType.None:
                break;

            case SerieSymbolType.Circle:
                if (gap > 0)
                {
                    UGL.DrawDoughnut(vh, pos, symbolSize, symbolSize + gap, backgroundColor, backgroundColor, color, smoothness);
                }
                else
                {
                    UGL.DrawCricle(vh, pos, symbolSize, color, toColor, smoothness);
                }
                break;

            case SerieSymbolType.EmptyCircle:
                if (gap > 0)
                {
                    UGL.DrawCricle(vh, pos, symbolSize + gap, backgroundColor, smoothness);
                    UGL.DrawEmptyCricle(vh, pos, symbolSize, tickness, color, color, backgroundColor, smoothness);
                }
                else
                {
                    UGL.DrawEmptyCricle(vh, pos, symbolSize, tickness, color, color, backgroundColor, smoothness);
                }
                break;

            case SerieSymbolType.Rect:
                if (gap > 0)
                {
                    UGL.DrawSquare(vh, pos, symbolSize + gap, backgroundColor);
                    UGL.DrawSquare(vh, pos, symbolSize, color, toColor);
                }
                else
                {
                    UGL.DrawRoundRectangle(vh, pos, symbolSize, symbolSize, color, color, 0, cornerRadius, true);
                }
                break;

            case SerieSymbolType.Triangle:
                if (gap > 0)
                {
                    UGL.DrawTriangle(vh, pos, symbolSize + gap, backgroundColor);
                    UGL.DrawTriangle(vh, pos, symbolSize, color, toColor);
                }
                else
                {
                    UGL.DrawTriangle(vh, pos, symbolSize, color, toColor);
                }
                break;

            case SerieSymbolType.Diamond:
                if (gap > 0)
                {
                    UGL.DrawDiamond(vh, pos, symbolSize + gap, backgroundColor);
                    UGL.DrawDiamond(vh, pos, symbolSize, color, toColor);
                }
                else
                {
                    UGL.DrawDiamond(vh, pos, symbolSize, color, toColor);
                }
                break;

            case SerieSymbolType.Arrow:
                var arrowWidth  = symbolSize * 2;
                var arrowHeight = arrowWidth * 1.5f;
                var arrowOffset = 0;
                var arrowDent   = arrowWidth / 3.3f;
                UGL.DrawArrow(vh, startPos, pos, arrowWidth, arrowHeight,
                              arrowOffset, arrowDent, color);
                break;
            }
        }
示例#6
0
        private void DrawSingleRadar(VertexHelper vh, Serie serie, int i)
        {
            var startPoint = Vector3.zero;
            var toPoint    = Vector3.zero;
            var firstPoint = Vector3.zero;

            var radar          = chart.radars[serie.radarIndex];
            var indicatorNum   = radar.indicatorList.Count;
            var angle          = 2 * Mathf.PI / indicatorNum;
            var centerPos      = radar.runtimeCenterPos;
            var serieNameCount = -1;

            serie.animation.InitProgress(1, 0, 1);
            if (!chart.IsActive(i) || serie.animation.HasFadeOut())
            {
                return;
            }
            var rate               = serie.animation.GetCurrRate();
            var dataChanging       = false;
            var dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
            int key = i * 1000;

            if (!radar.runtimeDataPosList.ContainsKey(key))
            {
                radar.runtimeDataPosList.Add(i * 1000, new List <Vector3>(serie.dataCount));
            }
            else
            {
                radar.runtimeDataPosList[key].Clear();
            }
            var pointList  = radar.runtimeDataPosList[key];
            var startIndex = GetStartShowIndex(serie);
            var endIndex   = GetEndShowIndex(serie);

            SerieHelper.UpdateMinMaxData(serie, 1, radar.ceilRate);
            for (int j = 0; j < serie.data.Count; j++)
            {
                var serieData = serie.data[j];
                serieData.index = j;
                string dataName   = serieData.name;
                int    serieIndex = 0;
                if (string.IsNullOrEmpty(dataName))
                {
                    serieNameCount++;
                    serieIndex = serieNameCount;
                }
                else if (!serieNameSet.ContainsKey(dataName))
                {
                    serieNameSet.Add(dataName, serieNameCount);
                    serieNameCount++;
                    serieIndex = serieNameCount;
                }
                else
                {
                    serieIndex = serieNameSet[dataName];
                }
                if (!serieData.show)
                {
                    serieData.labelPosition = Vector3.zero;
                    continue;
                }
                var isHighlight = IsHighlight(radar, serie, serieData, j, 0);
                var areaColor   = SerieHelper.GetAreaColor(serie, chart.theme, serieIndex, isHighlight);
                var areaToColor = SerieHelper.GetAreaToColor(serie, chart.theme, serieIndex, isHighlight);
                var lineColor   = SerieHelper.GetLineColor(serie, chart.theme, serieIndex, isHighlight);
                int dataCount   = radar.indicatorList.Count;
                var index       = serieData.index;
                var p           = radar.runtimeCenterPos;
                var max         = radar.GetIndicatorMax(index);
                var value       = serieData.GetCurrData(1, dataChangeDuration);
                if (serieData.IsDataChanged())
                {
                    dataChanging = true;
                }
                if (max == 0)
                {
                    max = serie.runtimeDataMax;
                }
                var radius = (float)(max < 0 ? radar.runtimeDataRadius - radar.runtimeDataRadius * value / max
                : radar.runtimeDataRadius * value / max);
                var currAngle = (index + (radar.positionType == Radar.PositionType.Between ? 0.5f : 0)) * angle;
                radius *= rate;
                if (index == startIndex)
                {
                    startPoint = new Vector3(p.x + radius * Mathf.Sin(currAngle),
                                             p.y + radius * Mathf.Cos(currAngle));
                    firstPoint = startPoint;
                }
                else
                {
                    toPoint = new Vector3(p.x + radius * Mathf.Sin(currAngle),
                                          p.y + radius * Mathf.Cos(currAngle));
                    if (serie.areaStyle.show)
                    {
                        UGL.DrawTriangle(vh, startPoint, toPoint, p, areaColor, areaColor, areaToColor);
                    }
                    if (serie.lineStyle.show)
                    {
                        ChartDrawer.DrawLineStyle(vh, serie.lineStyle, startPoint, toPoint, lineColor,
                                                  chart.theme.serie.lineWidth, LineStyle.Type.Solid);
                    }
                    startPoint = toPoint;
                }
                serieData.labelPosition = startPoint;
                pointList.Add(startPoint);

                if (serie.areaStyle.show && j == endIndex)
                {
                    UGL.DrawTriangle(vh, startPoint, firstPoint, centerPos, areaColor, areaColor, areaToColor);
                }
                if (serie.lineStyle.show && j == endIndex)
                {
                    ChartDrawer.DrawLineStyle(vh, serie.lineStyle, startPoint, firstPoint, lineColor,
                                              chart.theme.serie.lineWidth, LineStyle.Type.Solid);
                }
            }
            if (serie.symbol.show && serie.symbol.type != SerieSymbolType.None)
            {
                for (int j = 0; j < serie.data.Count; j++)
                {
                    var serieData = serie.data[j];
                    if (!serieData.show)
                    {
                        continue;
                    }
                    var isHighlight = serie.highlighted || serieData.highlighted ||
                                      (chart.tooltip.show && chart.tooltip.runtimeDataIndex[0] == i && chart.tooltip.runtimeDataIndex[1] == j);
                    var serieIndex = serieData.index;
                    var symbolSize = isHighlight
                        ? serie.symbol.GetSelectedSize(serieData.data, chart.theme.serie.lineSymbolSelectedSize)
                        : serie.symbol.GetSize(serieData.data, chart.theme.serie.lineSymbolSize);
                    var symbolColor   = SerieHelper.GetItemColor(serie, serieData, chart.theme, serieIndex, isHighlight);
                    var symbolToColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, serieIndex, isHighlight);
                    var symbolBorder  = SerieHelper.GetSymbolBorder(serie, serieData, chart.theme, isHighlight);
                    var cornerRadius  = SerieHelper.GetSymbolCornerRadius(serie, serieData, isHighlight);
                    chart.DrawSymbol(vh, serie.symbol.type, symbolSize, symbolBorder, serieData.labelPosition, symbolColor,
                                     symbolToColor, serie.symbol.gap, cornerRadius);
                }
            }
            if (!serie.animation.IsFinish())
            {
                serie.animation.CheckProgress(1);
                chart.RefreshPainter(serie);
            }
            if (dataChanging)
            {
                chart.RefreshPainter(serie);
            }
        }
示例#7
0
        private void DrawMutipleRadar(VertexHelper vh, Serie serie, int i)
        {
            if (!serie.show)
            {
                return;
            }
            var radar = chart.GetRadar(serie.radarIndex);

            if (radar == null)
            {
                return;
            }
            var startPoint     = Vector3.zero;
            var toPoint        = Vector3.zero;
            var firstPoint     = Vector3.zero;
            var indicatorNum   = radar.indicatorList.Count;
            var angle          = 2 * Mathf.PI / indicatorNum;
            var centerPos      = radar.runtimeCenterPos;
            var serieNameCount = -1;

            serie.animation.InitProgress(1, 0, 1);
            if (!chart.IsActive(i) || serie.animation.HasFadeOut())
            {
                return;
            }
            var rate               = serie.animation.GetCurrRate();
            var dataChanging       = false;
            var dataChangeDuration = serie.animation.GetUpdateAnimationDuration();

            SerieHelper.GetAllMinMaxData(serie, radar.ceilRate);
            for (int j = 0; j < serie.data.Count; j++)
            {
                var serieData = serie.data[j];
                int key       = i * 1000 + j;
                if (!radar.runtimeDataPosList.ContainsKey(key))
                {
                    radar.runtimeDataPosList.Add(i * 1000 + j, new List <Vector3>(serieData.data.Count));
                }
                else
                {
                    radar.runtimeDataPosList[key].Clear();
                }
                string dataName   = serieData.name;
                int    serieIndex = 0;
                if (string.IsNullOrEmpty(dataName))
                {
                    serieNameCount++;
                    serieIndex = serieNameCount;
                }
                else if (!serieNameSet.ContainsKey(dataName))
                {
                    serieNameSet.Add(dataName, serieNameCount);
                    serieNameCount++;
                    serieIndex = serieNameCount;
                }
                else
                {
                    serieIndex = serieNameSet[dataName];
                }
                if (!serieData.show)
                {
                    continue;
                }
                var            isHighlight = IsHighlight(radar, serie, serieData, j, 0);
                var            areaColor   = SerieHelper.GetAreaColor(serie, chart.theme, serieIndex, isHighlight);
                var            areaToColor = SerieHelper.GetAreaToColor(serie, chart.theme, serieIndex, isHighlight);
                var            lineColor   = SerieHelper.GetLineColor(serie, chart.theme, serieIndex, isHighlight);
                var            lineWidth   = serie.lineStyle.GetWidth(chart.theme.serie.lineWidth);
                int            dataCount   = radar.indicatorList.Count;
                List <Vector3> pointList   = radar.runtimeDataPosList[key];
                for (int n = 0; n < dataCount; n++)
                {
                    if (n >= serieData.data.Count)
                    {
                        break;
                    }
                    var max   = radar.GetIndicatorMax(n);
                    var value = serieData.GetCurrData(n, dataChangeDuration);
                    if (serieData.IsDataChanged())
                    {
                        dataChanging = true;
                    }
                    if (max == 0)
                    {
                        max = serie.runtimeDataMax;
                    }
                    var radius = (float)(max < 0 ? radar.runtimeDataRadius - radar.runtimeDataRadius * value / max
                    : radar.runtimeDataRadius * value / max);
                    var currAngle = (n + (radar.positionType == Radar.PositionType.Between ? 0.5f : 0)) * angle;
                    radius *= rate;
                    if (n == 0)
                    {
                        startPoint = new Vector3(centerPos.x + radius * Mathf.Sin(currAngle),
                                                 centerPos.y + radius * Mathf.Cos(currAngle));
                        firstPoint = startPoint;
                    }
                    else
                    {
                        toPoint = new Vector3(centerPos.x + radius * Mathf.Sin(currAngle),
                                              centerPos.y + radius * Mathf.Cos(currAngle));
                        if (serie.areaStyle.show)
                        {
                            UGL.DrawTriangle(vh, startPoint, toPoint, centerPos, areaColor, areaColor, areaToColor);
                        }
                        if (serie.lineStyle.show)
                        {
                            ChartDrawer.DrawLineStyle(vh, serie.lineStyle.type, lineWidth, startPoint, toPoint, lineColor);
                        }
                        startPoint = toPoint;
                    }
                    pointList.Add(startPoint);
                }
                if (serie.areaStyle.show)
                {
                    UGL.DrawTriangle(vh, startPoint, firstPoint, centerPos, areaColor, areaColor, areaToColor);
                }
                if (serie.lineStyle.show)
                {
                    ChartDrawer.DrawLineStyle(vh, serie.lineStyle.type, lineWidth, startPoint, firstPoint, lineColor);
                }
                if (serie.symbol.show && serie.symbol.type != SerieSymbolType.None)
                {
                    for (int m = 0; m < pointList.Count; m++)
                    {
                        var point = pointList[m];
                        isHighlight = IsHighlight(radar, serie, serieData, j, m);
                        var symbolSize = isHighlight
                            ? serie.symbol.GetSelectedSize(null, chart.theme.serie.lineSymbolSelectedSize)
                            : serie.symbol.GetSize(null, chart.theme.serie.lineSymbolSize);
                        var symbolColor   = SerieHelper.GetItemColor(serie, serieData, chart.theme, serieIndex, isHighlight);
                        var symbolToColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, serieIndex, isHighlight);
                        var symbolBorder  = SerieHelper.GetSymbolBorder(serie, serieData, chart.theme, isHighlight);
                        var cornerRadius  = SerieHelper.GetSymbolCornerRadius(serie, serieData, isHighlight);
                        chart.DrawSymbol(vh, serie.symbol.type, symbolSize, symbolBorder, point, symbolColor,
                                         symbolToColor, serie.symbol.gap, cornerRadius);
                    }
                }
            }
            if (!serie.animation.IsFinish())
            {
                serie.animation.CheckProgress(1);
                chart.RefreshPainter(serie);
            }
            if (dataChanging)
            {
                chart.RefreshPainter(serie);
            }
        }
示例#8
0
        public static void DrawSymbol(VertexHelper vh, SerieSymbolType type, float symbolSize,
                                      float tickness, Vector3 pos, Color32 color, Color32 toColor, float gap, float[] cornerRadius,
                                      Color32 backgroundColor, float smoothness)
        {
            switch (type)
            {
            case SerieSymbolType.None:
                break;

            case SerieSymbolType.Circle:
                if (gap > 0)
                {
                    UGL.DrawDoughnut(vh, pos, symbolSize, symbolSize + gap, backgroundColor, backgroundColor, color, smoothness);
                }
                else
                {
                    UGL.DrawCricle(vh, pos, symbolSize, color, toColor, smoothness);
                }
                break;

            case SerieSymbolType.EmptyCircle:
                if (gap > 0)
                {
                    UGL.DrawCricle(vh, pos, symbolSize + gap, backgroundColor, smoothness);
                    UGL.DrawEmptyCricle(vh, pos, symbolSize, tickness, color, color, backgroundColor, smoothness);
                }
                else
                {
                    UGL.DrawEmptyCricle(vh, pos, symbolSize, tickness, color, color, backgroundColor, smoothness);
                }
                break;

            case SerieSymbolType.Rect:
                if (gap > 0)
                {
                    UGL.DrawSquare(vh, pos, symbolSize + gap, backgroundColor);
                    UGL.DrawSquare(vh, pos, symbolSize, color, toColor);
                }
                else
                {
                    UGL.DrawRoundRectangle(vh, pos, symbolSize, symbolSize, color, color, 0, cornerRadius, true);
                }
                break;

            case SerieSymbolType.Triangle:
                if (gap > 0)
                {
                    UGL.DrawTriangle(vh, pos, symbolSize + gap, backgroundColor);
                    UGL.DrawTriangle(vh, pos, symbolSize, color, toColor);
                }
                else
                {
                    UGL.DrawTriangle(vh, pos, symbolSize, color, toColor);
                }
                break;

            case SerieSymbolType.Diamond:
                if (gap > 0)
                {
                    UGL.DrawDiamond(vh, pos, symbolSize + gap, backgroundColor);
                    UGL.DrawDiamond(vh, pos, symbolSize, color, toColor);
                }
                else
                {
                    UGL.DrawDiamond(vh, pos, symbolSize, color, toColor);
                }
                break;
            }
        }
        private void DrawSingleRadar(VertexHelper vh)
        {
            var radar = chart.GetChartComponent <RadarCoord>(serie.radarIndex);

            if (radar == null)
            {
                return;
            }

            var indicatorNum = radar.indicatorList.Count;
            var angle        = 2 * Mathf.PI / indicatorNum;
            var centerPos    = radar.context.center;

            serie.animation.InitProgress(0, 1);
            serie.context.dataPoints.Clear();
            if (!serie.show || serie.animation.HasFadeOut())
            {
                return;
            }
            var startPoint = Vector3.zero;
            var toPoint    = Vector3.zero;
            var firstPoint = Vector3.zero;
            var lastColor  = ColorUtil.clearColor32;
            var firstColor = ColorUtil.clearColor32;

            var rate               = serie.animation.GetCurrRate();
            var dataChanging       = false;
            var dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
            var startIndex         = GetStartShowIndex(serie);
            var endIndex           = GetEndShowIndex(serie);

            SerieHelper.UpdateMinMaxData(serie, 1, radar.ceilRate);
            for (int j = 0; j < serie.data.Count; j++)
            {
                var serieData = serie.data[j];
                serieData.index = j;
                string dataName = serieData.name;

                if (!serieData.show)
                {
                    serieData.context.labelPosition = Vector3.zero;
                    continue;
                }
                var lineStyle   = SerieHelper.GetLineStyle(serie, serieData);
                var areaStyle   = SerieHelper.GetAreaStyle(serie, serieData);
                var isHighlight = serie.context.pointerEnter;
                var areaColor   = SerieHelper.GetAreaColor(serie, serieData, chart.theme, j, isHighlight);
                var areaToColor = SerieHelper.GetAreaToColor(serie, serieData, chart.theme, j, isHighlight);
                var lineColor   = SerieHelper.GetLineColor(serie, serieData, chart.theme, j, isHighlight);
                int dataCount   = radar.indicatorList.Count;
                var index       = serieData.index;
                var p           = radar.context.center;
                var max         = radar.GetIndicatorMax(index);
                var value       = serieData.GetCurrData(1, dataChangeDuration);
                if (serieData.IsDataChanged())
                {
                    dataChanging = true;
                }
                if (max == 0)
                {
                    max = serie.context.dataMax;
                }
                if (!radar.IsInIndicatorRange(j, serieData.GetData(1)))
                {
                    lineColor = radar.outRangeColor;
                }
                var radius = (float)(max < 0 ? radar.context.dataRadius - radar.context.dataRadius * value / max :
                                     radar.context.dataRadius * value / max);
                var currAngle = (index + (radar.positionType == RadarCoord.PositionType.Between ? 0.5f : 0)) * angle;
                radius *= rate;
                if (index == startIndex)
                {
                    startPoint = new Vector3(p.x + radius * Mathf.Sin(currAngle),
                                             p.y + radius * Mathf.Cos(currAngle));
                    firstPoint = startPoint;
                    lastColor  = lineColor;
                    firstColor = lineColor;
                }
                else
                {
                    toPoint = new Vector3(p.x + radius * Mathf.Sin(currAngle),
                                          p.y + radius * Mathf.Cos(currAngle));
                    if (areaStyle != null && areaStyle.show)
                    {
                        UGL.DrawTriangle(vh, startPoint, toPoint, p, areaColor, areaColor, areaToColor);
                    }
                    if (lineStyle.show)
                    {
                        if (radar.connectCenter)
                        {
                            ChartDrawer.DrawLineStyle(vh, lineStyle, startPoint, centerPos,
                                                      chart.theme.serie.lineWidth, LineStyle.Type.Solid, lastColor, lastColor);
                        }
                        ChartDrawer.DrawLineStyle(vh, lineStyle, startPoint, toPoint, chart.theme.serie.lineWidth,
                                                  LineStyle.Type.Solid, radar.lineGradient ? lastColor : lineColor, lineColor);
                    }
                    startPoint = toPoint;
                    lastColor  = lineColor;
                }
                serieData.context.position      = startPoint;
                serieData.context.labelPosition = startPoint;

                if (areaStyle != null && areaStyle.show && j == endIndex)
                {
                    UGL.DrawTriangle(vh, startPoint, firstPoint, centerPos, areaColor, areaColor, areaToColor);
                }
                if (lineStyle.show && j == endIndex)
                {
                    if (radar.connectCenter)
                    {
                        ChartDrawer.DrawLineStyle(vh, lineStyle, startPoint, centerPos,
                                                  chart.theme.serie.lineWidth, LineStyle.Type.Solid, lastColor, lastColor);
                    }
                    ChartDrawer.DrawLineStyle(vh, lineStyle, startPoint, firstPoint, chart.theme.serie.lineWidth,
                                              LineStyle.Type.Solid, lineColor, radar.lineGradient ? firstColor : lineColor);
                }
            }
            if (serie.symbol.show && serie.symbol.type != SymbolType.None)
            {
                for (int j = 0; j < serie.data.Count; j++)
                {
                    var serieData = serie.data[j];
                    if (!serieData.show)
                    {
                        continue;
                    }
                    var isHighlight = serie.highlight || serieData.context.highlight || serie.context.pointerEnter;
                    var serieIndex  = serieData.index;
                    var symbolSize  = isHighlight ?
                                      serie.symbol.GetSelectedSize(serieData.data, chart.theme.serie.lineSymbolSelectedSize) :
                                      serie.symbol.GetSize(serieData.data, chart.theme.serie.lineSymbolSize);
                    var symbolColor      = SerieHelper.GetItemColor(serie, serieData, chart.theme, serieIndex, isHighlight);
                    var symbolToColor    = SerieHelper.GetItemToColor(serie, serieData, chart.theme, serieIndex, isHighlight);
                    var symbolEmptyColor = SerieHelper.GetItemBackgroundColor(serie, serieData, chart.theme, serieIndex, isHighlight, false);
                    var symbolBorder     = SerieHelper.GetSymbolBorder(serie, serieData, chart.theme, isHighlight);
                    var borderColor      = SerieHelper.GetSymbolBorderColor(serie, serieData, chart.theme, isHighlight);
                    var cornerRadius     = SerieHelper.GetSymbolCornerRadius(serie, serieData, isHighlight);
                    if (!radar.IsInIndicatorRange(j, serieData.GetData(1)))
                    {
                        symbolColor   = radar.outRangeColor;
                        symbolToColor = radar.outRangeColor;
                    }
                    chart.DrawSymbol(vh, serie.symbol.type, symbolSize, symbolBorder, serieData.context.labelPosition, symbolColor,
                                     symbolToColor, symbolEmptyColor, borderColor, serie.symbol.gap, cornerRadius);
                }
            }
            if (!serie.animation.IsFinish())
            {
                serie.animation.CheckProgress(1);
                chart.RefreshPainter(serie);
            }
            if (dataChanging)
            {
                chart.RefreshPainter(serie);
            }
        }
        private void DrawMutipleRadar(VertexHelper vh)
        {
            if (!serie.show)
            {
                return;
            }
            m_RadarCoord = chart.GetChartComponent <RadarCoord>(serie.radarIndex);
            if (m_RadarCoord == null)
            {
                return;
            }

            serie.containerIndex       = m_RadarCoord.index;
            serie.containterInstanceId = m_RadarCoord.instanceId;

            var startPoint   = Vector3.zero;
            var toPoint      = Vector3.zero;
            var firstPoint   = Vector3.zero;
            var indicatorNum = m_RadarCoord.indicatorList.Count;
            var angle        = 2 * Mathf.PI / indicatorNum;
            var centerPos    = m_RadarCoord.context.center;

            serie.animation.InitProgress(0, 1);
            if (!serie.show || serie.animation.HasFadeOut())
            {
                return;
            }
            var rate               = serie.animation.GetCurrRate();
            var dataChanging       = false;
            var interacting        = false;
            var dataChangeDuration = serie.animation.GetUpdateAnimationDuration();

            SerieHelper.GetAllMinMaxData(serie, m_RadarCoord.ceilRate);
            for (int j = 0; j < serie.data.Count; j++)
            {
                var    serieData = serie.data[j];
                string dataName  = serieData.name;
                if (!serieData.show)
                {
                    continue;
                }
                var lineStyle   = SerieHelper.GetLineStyle(serie, serieData);
                var areaStyle   = SerieHelper.GetAreaStyle(serie, serieData);
                var symbol      = SerieHelper.GetSerieSymbol(serie, serieData);
                var isHighlight = serieData.context.highlight;
                var colorIndex  = chart.GetLegendRealShowNameIndex(serieData.legendName);
                var areaColor   = SerieHelper.GetAreaColor(serie, serieData, chart.theme, colorIndex, isHighlight);
                var areaToColor = SerieHelper.GetAreaToColor(serie, serieData, chart.theme, colorIndex, isHighlight);
                var lineColor   = SerieHelper.GetLineColor(serie, serieData, chart.theme, colorIndex, isHighlight);
                var lineWidth   = lineStyle.GetWidth(chart.theme.serie.lineWidth);
                int dataCount   = m_RadarCoord.indicatorList.Count;
                serieData.context.dataPoints.Clear();
                for (int n = 0; n < dataCount; n++)
                {
                    if (n >= serieData.data.Count)
                    {
                        break;
                    }
                    var min   = m_RadarCoord.GetIndicatorMin(n);
                    var max   = m_RadarCoord.GetIndicatorMax(n);
                    var value = serieData.GetCurrData(n, dataChangeDuration);
                    if (serieData.IsDataChanged())
                    {
                        dataChanging = true;
                    }
                    if (max == 0)
                    {
                        if (serie.data.Count > 1)
                        {
                            SerieHelper.GetMinMaxData(serie, n, out min, out max);
                            min = ChartHelper.GetMinDivisibleValue(min, 0);
                            max = ChartHelper.GetMaxDivisibleValue(max, 0);
                            if (min > 0)
                            {
                                min = 0;
                            }
                        }
                        else
                        {
                            max = serie.context.dataMax;
                        }
                    }
                    var radius    = (float)(m_RadarCoord.context.dataRadius * (value - min) / (max - min));
                    var currAngle = (n + (m_RadarCoord.positionType == RadarCoord.PositionType.Between ? 0.5f : 0)) * angle;
                    radius *= rate;
                    if (n == 0)
                    {
                        startPoint = new Vector3(centerPos.x + radius * Mathf.Sin(currAngle),
                                                 centerPos.y + radius * Mathf.Cos(currAngle));
                        firstPoint = startPoint;
                    }
                    else
                    {
                        toPoint = new Vector3(centerPos.x + radius * Mathf.Sin(currAngle),
                                              centerPos.y + radius * Mathf.Cos(currAngle));
                        if (areaStyle != null && areaStyle.show)
                        {
                            UGL.DrawTriangle(vh, startPoint, toPoint, centerPos, areaColor, areaColor, areaToColor);
                        }
                        if (lineStyle.show)
                        {
                            ChartDrawer.DrawLineStyle(vh, lineStyle.type, lineWidth, startPoint, toPoint, lineColor);
                        }
                        startPoint = toPoint;
                    }
                    serieData.context.dataPoints.Add(startPoint);
                }
                if (areaStyle != null && areaStyle.show)
                {
                    UGL.DrawTriangle(vh, startPoint, firstPoint, centerPos, areaColor, areaColor, areaToColor);
                }
                if (lineStyle.show)
                {
                    ChartDrawer.DrawLineStyle(vh, lineStyle.type, lineWidth, startPoint, firstPoint, lineColor);
                }
                if (symbol.show && symbol.type != SymbolType.None)
                {
                    for (int m = 0; m < serieData.context.dataPoints.Count; m++)
                    {
                        var point      = serieData.context.dataPoints[m];
                        var symbolSize = isHighlight ?
                                         symbol.GetSelectedSize(null, chart.theme.serie.lineSymbolSelectedSize) :
                                         symbol.GetSize(null, chart.theme.serie.lineSymbolSize);
                        if (!serieData.interact.TryGetValue(ref symbolSize, ref interacting))
                        {
                            symbolSize = isHighlight ?
                                         symbol.GetSelectedSize(serieData.data, symbolSize) :
                                         symbol.GetSize(serieData.data, symbolSize);
                            serieData.interact.SetValue(ref interacting, symbolSize);
                            symbolSize = serie.animation.GetSysmbolSize(symbolSize);
                        }
                        var symbolColor      = SerieHelper.GetItemColor(serie, serieData, chart.theme, j, isHighlight);
                        var symbolToColor    = SerieHelper.GetItemToColor(serie, serieData, chart.theme, j, isHighlight);
                        var symbolEmptyColor = SerieHelper.GetItemBackgroundColor(serie, serieData, chart.theme, j, isHighlight, false);
                        var symbolBorder     = SerieHelper.GetSymbolBorder(serie, serieData, chart.theme, isHighlight);
                        var borderColor      = SerieHelper.GetSymbolBorderColor(serie, serieData, chart.theme, isHighlight);
                        var cornerRadius     = SerieHelper.GetSymbolCornerRadius(serie, serieData, isHighlight);
                        chart.DrawSymbol(vh, symbol.type, symbolSize, symbolBorder, point, symbolColor,
                                         symbolToColor, symbolEmptyColor, borderColor, symbol.gap, cornerRadius);
                    }
                }
            }
            if (!serie.animation.IsFinish())
            {
                serie.animation.CheckProgress(1);
                chart.RefreshPainter(serie);
            }
            if (dataChanging || interacting)
            {
                chart.RefreshPainter(serie);
            }
        }