Пример #1
0
        private void DrawXCategory(VertexHelper vh)
        {
            var            stackSeries  = m_Series.GetStackSeries();
            int            seriesCount  = stackSeries.Count;
            float          scaleWid     = m_XAxis.GetDataWidth(coordinateWid, m_DataZoom);
            int            serieCount   = 0;
            List <Vector3> points       = new List <Vector3>();
            List <Vector3> smoothPoints = new List <Vector3>();
            List <Color>   colorList    = new List <Color>();
            int            dataCount    = 0;

            for (int j = 0; j < seriesCount; j++)
            {
                var seriesCurrHig = new Dictionary <int, float>();
                var serieList     = stackSeries[j];

                for (int n = 0; n < serieList.Count; n++)
                {
                    Serie serie = serieList[n];
                    if (!IsActive(serie.name))
                    {
                        continue;
                    }
                    List <Vector3> lastPoints       = new List <Vector3>();
                    List <Vector3> lastSmoothPoints = new List <Vector3>();
                    List <float>   serieData        = serie.GetData(m_DataZoom);

                    Color   color    = m_ThemeInfo.GetColor(serieCount);
                    Vector3 lp       = Vector3.zero;
                    Vector3 np       = Vector3.zero;
                    float   startX   = zeroX + (m_XAxis.boundaryGap ? scaleWid / 2 : 0);
                    int     maxCount = maxShowDataNumber > 0 ?
                                       (maxShowDataNumber > serieData.Count ? serieData.Count : maxShowDataNumber)
                        : serieData.Count;
                    dataCount = (maxCount - minShowDataNumber);
                    if (m_Line.area && points.Count > 0)
                    {
                        if (!m_Line.smooth && points.Count > 0)
                        {
                            for (int m = points.Count - dataCount; m < points.Count; m++)
                            {
                                lastPoints.Add(points[m]);
                            }
                        }
                        else if (m_Line.smooth && smoothPoints.Count > 0)
                        {
                            for (int m = 0; m < smoothPoints.Count; m++)
                            {
                                lastSmoothPoints.Add(smoothPoints[m]);
                            }
                            smoothPoints.Clear();
                        }
                    }
                    int smoothPointCount = 1;
                    int xcount           = xAxis.data.Count;
                    for (int i = minShowDataNumber; i < maxCount; i++)
                    {
                        if (!seriesCurrHig.ContainsKey(i))
                        {
                            seriesCurrHig[i] = 0;
                        }
                        float value = serieData[i];

                        float pX = startX + i * scaleWid;
                        if (drawtype == "RightToLeft")
                        {
                            pX = startX + (xcount - i) * scaleWid;
                        }

                        float pY      = seriesCurrHig[i] + coordinateY + m_Coordinate.tickness;
                        float dataHig = (value - minValue) / (maxValue - minValue) * coordinateHig;
                        np = new Vector3(pX, pY + dataHig);

                        if (i > 0)
                        {
                            if (m_Line.step)
                            {
                                Vector2 middle1, middle2;
                                switch (m_Line.stepTpe)
                                {
                                case Line.StepType.Start:
                                    middle1 = new Vector2(lp.x, np.y + m_Line.tickness);
                                    middle2 = new Vector2(lp.x - m_Line.tickness, np.y);
                                    ChartHelper.DrawLine(vh, lp, middle1, m_Line.tickness, color);
                                    ChartHelper.DrawLine(vh, middle2, np, m_Line.tickness, color);
                                    if (m_Line.area)
                                    {
                                        Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f);
                                        ChartHelper.DrawPolygon(vh, new Vector2(middle1.x, zeroY), middle1, np,
                                                                new Vector2(np.x, zeroY), areaColor);
                                    }
                                    break;

                                case Line.StepType.Middle:
                                    middle1 = new Vector2((lp.x + np.x) / 2 + m_Line.tickness, lp.y);
                                    middle2 = new Vector2((lp.x + np.x) / 2 - m_Line.tickness, np.y);
                                    ChartHelper.DrawLine(vh, lp, middle1, m_Line.tickness, color);
                                    ChartHelper.DrawLine(vh, new Vector2(middle1.x - m_Line.tickness, middle1.y),
                                                         new Vector2(middle2.x + m_Line.tickness, middle2.y), m_Line.tickness, color);
                                    ChartHelper.DrawLine(vh, middle2, np, m_Line.tickness, color);
                                    if (m_Line.area)
                                    {
                                        Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f);
                                        ChartHelper.DrawPolygon(vh, new Vector2(lp.x, zeroY), lp, middle1,
                                                                new Vector2(middle1.x, zeroY), areaColor);
                                        ChartHelper.DrawPolygon(vh, new Vector2(middle2.x + 2 * m_Line.tickness, zeroY),
                                                                new Vector2(middle2.x + 2 * m_Line.tickness, middle2.y), np,
                                                                new Vector2(np.x, zeroY), areaColor);
                                    }
                                    break;

                                case Line.StepType.End:
                                    middle1 = new Vector2(np.x + m_Line.tickness, lp.y);
                                    middle2 = new Vector2(np.x, lp.y);
                                    ChartHelper.DrawLine(vh, lp, middle1, m_Line.tickness, color);
                                    ChartHelper.DrawLine(vh, middle2, np, m_Line.tickness, color);
                                    if (m_Line.area)
                                    {
                                        Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f);
                                        ChartHelper.DrawPolygon(vh, new Vector2(lp.x, zeroY), lp,
                                                                new Vector2(middle1.x - m_Line.tickness, middle1.y),
                                                                new Vector2(middle1.x - m_Line.tickness, zeroY), areaColor);
                                    }
                                    break;
                                }
                            }
                            else if (m_Line.smooth)
                            {
                                var     list = ChartHelper.GetBezierList(lp, np, m_Line.smoothStyle);
                                Vector3 start, to;
                                start = list[0];
                                for (int k = 1; k < list.Length; k++)
                                {
                                    smoothPoints.Add(list[k]);
                                    to = list[k];
                                    ChartHelper.DrawLine(vh, start, to, m_Line.tickness, color);

                                    if (m_Line.area)
                                    {
                                        Vector3 alp = new Vector3(start.x, start.y - m_Line.tickness);
                                        Vector3 anp = new Vector3(to.x, to.y - m_Line.tickness);
                                        Vector3 tnp = serieCount > 0 ?
                                                      (smoothPointCount > lastSmoothPoints.Count - 1 ?
                                                       new Vector3(lastSmoothPoints[lastSmoothPoints.Count - 1].x,
                                                                   lastSmoothPoints[lastSmoothPoints.Count - 1].y + m_Line.tickness) :
                                                       new Vector3(lastSmoothPoints[smoothPointCount].x,
                                                                   lastSmoothPoints[smoothPointCount].y + m_Line.tickness)) :
                                                      new Vector3(to.x, zeroY + m_Coordinate.tickness);
                                        Vector3 tlp = serieCount > 0 ?
                                                      (smoothPointCount > lastSmoothPoints.Count - 1 ?
                                                       new Vector3(lastSmoothPoints[lastSmoothPoints.Count - 2].x,
                                                                   lastSmoothPoints[lastSmoothPoints.Count - 2].y + m_Line.tickness) :
                                                       new Vector3(lastSmoothPoints[smoothPointCount - 1].x,
                                                                   lastSmoothPoints[smoothPointCount - 1].y + m_Line.tickness)) :
                                                      new Vector3(start.x, zeroY + m_Coordinate.tickness);
                                        Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f);
                                        ChartHelper.DrawPolygon(vh, alp, anp, tnp, tlp, areaColor);
                                    }
                                    smoothPointCount++;
                                    start = to;
                                }
                            }
                            else
                            {
                                ChartHelper.DrawLine(vh, lp, np, m_Line.tickness, color);
                                if (m_Line.area)
                                {
                                    Vector3 alp       = new Vector3(lp.x, lp.y - m_Line.tickness);
                                    Vector3 anp       = new Vector3(np.x, np.y - m_Line.tickness);
                                    Color   areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f);
                                    var     cross     = ChartHelper.GetIntersection(lp, np, new Vector3(zeroX, zeroY),
                                                                                    new Vector3(zeroX + coordinateWid, zeroY));
                                    if (cross == Vector3.zero)
                                    {
                                        Vector3 tnp = serieCount > 0 ?
                                                      new Vector3(lastPoints[i].x, lastPoints[i].y + m_Line.tickness) :
                                                      new Vector3(np.x, zeroY + m_Coordinate.tickness);
                                        Vector3 tlp = serieCount > 0 ?
                                                      new Vector3(lastPoints[i - 1].x, lastPoints[i - 1].y + m_Line.tickness) :
                                                      new Vector3(lp.x, zeroY + m_Coordinate.tickness);
                                        ChartHelper.DrawPolygon(vh, alp, anp, tnp, tlp, areaColor);
                                    }
                                    else
                                    {
                                        Vector3 cross1 = new Vector3(cross.x, cross.y + (alp.y > zeroY ? m_Coordinate.tickness : -m_Coordinate.tickness));
                                        Vector3 cross2 = new Vector3(cross.x, cross.y + (anp.y > zeroY ? m_Coordinate.tickness : -m_Coordinate.tickness));
                                        Vector3 xp1    = new Vector3(alp.x, zeroY + (alp.y > zeroY ? m_Coordinate.tickness : -m_Coordinate.tickness));
                                        Vector3 xp2    = new Vector3(anp.x, zeroY + (anp.y > zeroY ? m_Coordinate.tickness : -m_Coordinate.tickness));
                                        ChartHelper.DrawTriangle(vh, alp, cross1, xp1, areaColor);
                                        ChartHelper.DrawTriangle(vh, anp, cross2, xp2, areaColor);
                                    }
                                }
                            }
                        }
                        if (m_Line.point)
                        {
                            points.Add(np);
                            colorList.Add(color);
                        }
                        seriesCurrHig[i] += dataHig;
                        lp = np;
                    }
                    if (serie.show)
                    {
                        serieCount++;
                    }
                }
                // draw point
                if (m_Line.point)
                {
                    for (int i = 0; i < points.Count; i++)
                    {
                        Vector3 p        = points[i];
                        float   pointWid = m_Line.pointWidth;
                        if (m_Tooltip.show && i % dataCount == m_Tooltip.dataIndex - 1)
                        {
                            pointWid = pointWid * 1.8f;
                        }
                        if (m_Theme == Theme.Dark)
                        {
                            ChartHelper.DrawCricle(vh, p, pointWid, colorList[i],
                                                   (int)m_Line.pointWidth * 5);
                        }
                        else
                        {
                            ChartHelper.DrawCricle(vh, p, pointWid, Color.white);
                            ChartHelper.DrawDoughnut(vh, p, pointWid - m_Line.tickness,
                                                     pointWid, 0, 360, colorList[i]);
                        }
                    }
                }
            }

            //draw tooltip line
            if (m_Tooltip.show && m_Tooltip.dataIndex > 0)
            {
                float splitWidth = m_XAxis.GetSplitWidth(coordinateWid, m_DataZoom);
                float px         = zeroX + (m_Tooltip.dataIndex - 1) * splitWidth
                                   + (m_XAxis.boundaryGap ? splitWidth / 2 : 0);
                Vector2 sp = new Vector2(px, coordinateY);
                Vector2 ep = new Vector2(px, coordinateY + coordinateHig);
                ChartHelper.DrawLine(vh, sp, ep, m_Coordinate.tickness, m_ThemeInfo.tooltipLineColor);
                if (m_Tooltip.crossLabel)
                {
                    sp = new Vector2(zeroX, m_Tooltip.pointerPos.y);
                    ep = new Vector2(zeroX + coordinateWid, m_Tooltip.pointerPos.y);
                    DrawSplitLine(vh, true, Axis.SplitLineType.Dashed, sp, ep, m_ThemeInfo.tooltipLineColor);
                }
            }
        }
 private void DrawMakLineData(VertexHelper vh, MarkLineData data, SerieAnimation animation, Serie serie,
                              Grid grid, Color32 serieColor, Vector3 sp, Vector3 ep)
 {
     if (!animation.IsFinish())
     {
         ep = Vector3.Lerp(sp, ep, animation.GetCurrDetail());
     }
     data.runtimeCurrentEndPosition = ep;
     if (sp != Vector3.zero || ep != Vector3.zero)
     {
         m_RefreshLabel = true;
         chart.ClampInChart(ref sp);
         chart.ClampInChart(ref ep);
         var theme     = chart.theme.axis;
         var lineColor = ChartHelper.IsClearColor(data.lineStyle.color) ? serieColor : data.lineStyle.color;
         var lineWidth = data.lineStyle.width == 0 ? theme.lineWidth : data.lineStyle.width;
         ChartDrawer.DrawLineStyle(vh, data.lineStyle, sp, ep, lineWidth, LineStyle.Type.Dashed, lineColor, lineColor);
         if (data.startSymbol != null && data.startSymbol.show)
         {
             DrawMarkLineSymbol(vh, data.startSymbol, serie, grid, chart.theme, sp, sp, lineColor);
         }
         if (data.endSymbol != null && data.endSymbol.show)
         {
             DrawMarkLineSymbol(vh, data.endSymbol, serie, grid, chart.theme, ep, sp, lineColor);
         }
     }
 }
Пример #3
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;
                    }
                    float max   = radar.GetIndicatorMax(n);
                    float value = serieData.GetCurrData(n, dataChangeDuration);
                    if (serieData.IsDataChanged())
                    {
                        dataChanging = true;
                    }
                    if (max == 0)
                    {
                        max = serie.runtimeDataMax;
                    }
                    var radius = 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);
            }
        }
Пример #4
0
        private void DrawPie(VertexHelper vh, Serie serie)
        {
            var data = serie.data;

            serie.animation.InitProgress(data.Count, 0, 360);
            if (!serie.show || serie.animation.HasFadeOut())
            {
                return;
            }
            bool dataChanging = false;

            for (int n = 0; n < data.Count; n++)
            {
                var serieData = data[n];
                if (!serieData.show)
                {
                    continue;
                }
                var itemStyle = SerieHelper.GetItemStyle(serie, serieData, serieData.highlighted);
                if (serieData.IsDataChanged())
                {
                    dataChanging = true;
                }
                var serieNameCount = chart.m_LegendRealShowName.IndexOf(serieData.legendName);
                var color          = SerieHelper.GetItemColor(serie, serieData, chart.theme, serieNameCount,
                                                              serieData.highlighted);
                var toColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, serieNameCount,
                                                         serieData.highlighted);
                var borderWidth = itemStyle.borderWidth;
                var borderColor = itemStyle.borderColor;

                if (serie.pieClickOffset && serieData.selected)
                {
                    var drawEndDegree = serieData.runtimePieCurrAngle;
                    var needRoundCap  = serie.roundCap && serieData.runtimePieInsideRadius > 0;
                    UGL.DrawDoughnut(vh, serieData.runtiemPieOffsetCenter, serieData.runtimePieInsideRadius,
                                     serieData.runtimePieOutsideRadius, color, toColor, Color.clear, serieData.runtimePieStartAngle,
                                     drawEndDegree, borderWidth, borderColor, serie.pieSpace / 2, chart.settings.cicleSmoothness,
                                     needRoundCap, true);
                }
                else
                {
                    var drawEndDegree = serieData.runtimePieCurrAngle;
                    var needRoundCap  = serie.roundCap && serieData.runtimePieInsideRadius > 0;
                    UGL.DrawDoughnut(vh, serie.runtimeCenterPos, serieData.runtimePieInsideRadius,
                                     serieData.runtimePieOutsideRadius, color, toColor, Color.clear, serieData.runtimePieStartAngle,
                                     drawEndDegree, borderWidth, borderColor, serie.pieSpace / 2, chart.settings.cicleSmoothness,
                                     needRoundCap, true);
                    DrawPieCenter(vh, serie, itemStyle, serieData.runtimePieInsideRadius);
                }
                if (!serie.animation.CheckDetailBreak(serieData.runtimePieToAngle))
                {
                    serie.animation.SetDataFinish(n);
                }
                else
                {
                    break;
                }
            }
            if (!serie.animation.IsFinish())
            {
                serie.animation.CheckProgress(360);
                serie.animation.CheckSymbol(serie.symbol.GetSize(null, chart.theme.serie.lineSymbolSize));
                chart.RefreshPainter(serie);
            }
            if (dataChanging)
            {
                chart.RefreshPainter(serie);
            }
            chart.raycastTarget = IsAnyPieClickOffset() || IsAnyPieDataHighlight();
        }
Пример #5
0
        private void DrawPieLabel(Serie serie, int dataIndex, SerieData serieData, Color serieColor)
        {
            if (serieData.labelObject == null)
            {
                return;
            }
            var currAngle   = serieData.runtimePieHalfAngle;
            var isHighlight = (serieData.highlighted && serie.emphasis.label.show);
            var serieLabel  = SerieHelper.GetSerieLabel(serie, serieData);
            var showLabel   = ((serieLabel.show || isHighlight) && serieData.canShowLabel);

            if (showLabel || serieData.iconStyle.show)
            {
                serieData.SetLabelActive(showLabel);
                float rotate           = 0;
                bool  isInsidePosition = serieLabel.position == SerieLabel.Position.Inside;
                if (serieLabel.textStyle.rotate > 0 && isInsidePosition)
                {
                    if (currAngle > 180)
                    {
                        rotate += 270 - currAngle;
                    }
                    else
                    {
                        rotate += -(currAngle - 90);
                    }
                }
                Color color = serieColor;
                if (isHighlight)
                {
                    if (!ChartHelper.IsClearColor(serie.emphasis.label.textStyle.color))
                    {
                        color = serie.emphasis.label.textStyle.color;
                    }
                }
                else if (!ChartHelper.IsClearColor(serieLabel.textStyle.color))
                {
                    color = serieLabel.textStyle.color;
                }
                else
                {
                    color = isInsidePosition ? Color.white : serieColor;
                }
                var fontSize = isHighlight
                    ? serie.emphasis.label.textStyle.GetFontSize(chart.theme.common)
                    : serieLabel.textStyle.GetFontSize(chart.theme.common);
                var fontStyle = isHighlight
                    ? serie.emphasis.label.textStyle.fontStyle
                    : serieLabel.textStyle.fontStyle;

                serieData.labelObject.label.SetColor(color);
                serieData.labelObject.label.SetFontSize(fontSize);
                serieData.labelObject.label.SetFontStyle(fontStyle);
                serieData.labelObject.SetLabelRotate(rotate);
                if (!string.IsNullOrEmpty(serieLabel.formatter))
                {
                    var value   = serieData.data[1];
                    var total   = serie.yTotal;
                    var content = SerieLabelHelper.GetFormatterContent(serie, serieData, value, total,
                                                                       serieLabel, serieColor);
                    if (serieData.labelObject.SetText(content))
                    {
                        chart.RefreshPainter(serie);
                    }
                }
                else
                {
                    if (serieData.labelObject.SetText(serieData.name))
                    {
                        chart.RefreshPainter(serie);
                    }
                }
                serieData.labelObject.SetPosition(SerieLabelHelper.GetRealLabelPosition(serieData, serieLabel));
                if (showLabel)
                {
                    serieData.labelObject.SetLabelPosition(serieLabel.offset);
                }
                else
                {
                    serieData.SetLabelActive(false);
                }
            }
            else
            {
                serieData.SetLabelActive(false);
            }
            serieData.labelObject.UpdateIcon(serieData.iconStyle);
        }
        protected void DrawHeatmapSerie(VertexHelper vh, int colorIndex, Serie serie)
        {
            if (serie.animation.HasFadeOut())
            {
                return;
            }
            var yAxis  = m_YAxises[serie.axisIndex];
            var xAxis  = m_XAxises[serie.axisIndex];
            var xCount = xAxis.data.Count;
            var yCount = yAxis.data.Count;
            var xWidth = coordinateWidth / xCount;
            var yWidth = coordinateHeight / yCount;

            var zeroX       = coordinateX;
            var zeroY       = coordinateY;
            var dataList    = serie.GetDataList();
            var rangeMin    = m_VisualMap.rangeMin;
            var rangeMax    = m_VisualMap.rangeMax;
            var color       = m_ThemeInfo.GetColor(serie.index);
            var borderWidth = serie.itemStyle.show ? serie.itemStyle.borderWidth : 0;
            var borderColor = serie.itemStyle.opacity > 0 ? serie.itemStyle.borderColor : Color.clear;

            borderColor.a *= serie.itemStyle.opacity;
            serie.dataPoints.Clear();
            serie.animation.InitProgress(1, 0, xCount);
            var animationIndex     = serie.animation.GetCurrIndex();
            var dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
            var dataChanging       = false;

            for (int i = 0; i < xCount; i++)
            {
                for (int j = 0; j < yCount; j++)
                {
                    var dataIndex = i * yCount + j;
                    if (dataIndex >= dataList.Count)
                    {
                        continue;
                    }
                    var serieData = dataList[dataIndex];
                    var dimension = m_VisualMap.enable && m_VisualMap.dimension > 0 ? m_VisualMap.dimension - 1 :
                                    serieData.data.Count - 1;
                    if (serie.IsIgnoreIndex(dataIndex, dimension))
                    {
                        serie.dataPoints.Add(Vector3.zero);
                        continue;
                    }
                    var value = serieData.GetCurrData(dimension, dataChangeDuration, yAxis.inverse);
                    if (serieData.IsDataChanged())
                    {
                        dataChanging = true;
                    }
                    var pos = new Vector3(zeroX + (i + 0.5f) * xWidth, zeroY + (j + 0.5f) * yWidth);
                    serie.dataPoints.Add(pos);
                    serieData.canShowLabel = false;
                    if (value == 0)
                    {
                        continue;
                    }
                    if (m_VisualMap.enable)
                    {
                        if ((value < rangeMin && rangeMin != m_VisualMap.min) ||
                            (value > rangeMax && rangeMax != m_VisualMap.max))
                        {
                            continue;
                        }
                        if (!m_VisualMap.IsInSelectedValue(value))
                        {
                            continue;
                        }
                        color = m_VisualMap.GetColor(value);
                    }
                    if (animationIndex >= 0 && i > animationIndex)
                    {
                        continue;
                    }
                    serieData.canShowLabel = true;
                    var emphasis = (m_Tooltip.show && i == (int)m_Tooltip.runtimeXValues[0] && j == (int)m_Tooltip.runtimeYValues[0]) ||
                                   m_VisualMap.runtimeSelectedIndex > 0;
                    var rectWid = xWidth - 2 * borderWidth;
                    var rectHig = yWidth - 2 * borderWidth;
                    ChartDrawer.DrawPolygon(vh, pos, rectWid / 2, rectHig / 2, color);
                    if (borderWidth > 0 && borderColor != Color.clear)
                    {
                        ChartDrawer.DrawBorder(vh, pos, rectWid, rectHig, borderWidth, borderColor);
                    }
                    if (m_VisualMap.hoverLink && emphasis && serie.emphasis.show && serie.emphasis.itemStyle.borderWidth > 0)
                    {
                        var emphasisBorderWidth = serie.emphasis.itemStyle.borderWidth;
                        var emphasisBorderColor = serie.emphasis.itemStyle.opacity > 0 ? serie.emphasis.itemStyle.borderColor : Color.clear;
                        ChartDrawer.DrawBorder(vh, pos, rectWid, rectHig, emphasisBorderWidth, emphasisBorderColor);
                    }
                }
            }
            if (!serie.animation.IsFinish())
            {
                serie.animation.CheckProgress(xCount);
                m_IsPlayingAnimation = true;
                RefreshChart();
            }
            if (dataChanging)
            {
                RefreshChart();
            }
        }
        protected void DrawYBarSerie(VertexHelper vh, Serie serie, int colorIndex, ref List <float> seriesHig)
        {
            if (!IsActive(serie.name))
            {
                return;
            }
            var xAxis = m_XAxises[serie.axisIndex];
            var yAxis = m_YAxises[serie.axisIndex];

            if (!yAxis.show)
            {
                yAxis = m_YAxises[(serie.axisIndex + 1) % m_YAxises.Count];
            }

            float categoryWidth = yAxis.GetDataWidth(coordinateHeight, m_DataZoom);
            float barGap        = GetBarGap();
            float totalBarWidth = GetBarTotalWidth(categoryWidth, barGap);
            float barWidth      = serie.GetBarWidth(categoryWidth);
            float offset        = (categoryWidth - totalBarWidth) / 2;
            float barGapWidth   = barWidth + barWidth * barGap;
            float space         = serie.barGap == -1 ? offset : offset + m_BarLastOffset;

            var showData = serie.GetDataList(m_DataZoom);
            int maxCount = serie.maxShow > 0 ?
                           (serie.maxShow > showData.Count ? showData.Count : serie.maxShow)
                : showData.Count;

            if (seriesHig.Count < serie.minShow)
            {
                for (int i = 0; i < serie.minShow; i++)
                {
                    seriesHig.Add(0);
                }
            }
            var isPercentStack = m_Series.IsPercentStack(serie.stack, SerieType.Bar);

            for (int i = serie.minShow; i < maxCount; i++)
            {
                if (i >= seriesHig.Count)
                {
                    seriesHig.Add(0);
                }
                float value = showData[i].data[1];
                float pX    = seriesHig[i] + coordinateX + xAxis.zeroXOffset + yAxis.axisLine.width;
                float pY    = coordinateY + +i * categoryWidth;
                if (!yAxis.boundaryGap)
                {
                    pY -= categoryWidth / 2;
                }

                var barHig     = 0f;
                var valueTotal = 0f;
                if (isPercentStack)
                {
                    valueTotal    = GetSameStackTotalValue(serie.stack, i);
                    barHig        = value / valueTotal * coordinateWidth;
                    seriesHig[i] += barHig;
                }
                else
                {
                    valueTotal = xAxis.maxValue - xAxis.minValue;
                    barHig     = (xAxis.minValue > 0 ? value - xAxis.minValue : value)
                                 / valueTotal * coordinateWidth;
                    seriesHig[i] += barHig;
                }

                float currHig = CheckAnimation(serie, i, barHig);

                Vector3 p1 = new Vector3(pX, pY + space + barWidth);
                Vector3 p2 = new Vector3(pX + currHig, pY + space + barWidth);
                Vector3 p3 = new Vector3(pX + currHig, pY + space);
                Vector3 p4 = new Vector3(pX, pY + space);
                serie.dataPoints.Add(new Vector3(pX + currHig, pY + space + barWidth / 2));
                var highlight = (m_Tooltip.show && m_Tooltip.IsSelected(i)) ||
                                serie.data[i].highlighted ||
                                serie.highlighted;
                if (serie.show)
                {
                    Color areaColor   = serie.GetAreaColor(m_ThemeInfo, colorIndex, highlight);
                    Color areaToColor = serie.GetAreaToColor(m_ThemeInfo, colorIndex, highlight);
                    if (serie.barType == BarType.Zebra)
                    {
                        p1 = (p4 + p1) / 2;
                        p2 = (p2 + p3) / 2;
                        ChartDrawer.DrawZebraLine(vh, p1, p2, barWidth / 2, serie.barZebraWidth, serie.barZebraGap, areaColor);
                    }
                    else
                    {
                        ChartDrawer.DrawPolygon(vh, p4, p1, p2, p3, areaColor, areaToColor);
                    }
                }
            }
            if (!m_Series.IsStack(serie.stack, SerieType.Bar))
            {
                m_BarLastOffset += barGapWidth;
            }
        }
Пример #8
0
 public static bool CanShowLabel(Serie serie, SerieData serieData, SerieLabel label, int dimesion)
 {
     return(serie.show && serieData.canShowLabel && !serie.IsIgnoreValue(serieData.GetData(dimesion)));
 }
Пример #9
0
 public void RefreshPainter(Serie serie)
 {
     RefreshPainter(GetPainterIndexBySerie(serie));
 }
Пример #10
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="themeInfo">用来获取指定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,
                                          ThemeInfo themeInfo, 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(themeInfo.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);
        }
        protected void DrawHeatmapSerie(VertexHelper vh, int colorIndex, Serie serie)
        {
            if (serie.animation.HasFadeOut())
            {
                return;
            }
            var yAxis  = m_YAxes[serie.yAxisIndex];
            var xAxis  = m_XAxes[serie.xAxisIndex];
            var grid   = GetSerieGridOrDefault(serie);
            var xCount = xAxis.data.Count;
            var yCount = yAxis.data.Count;
            var xWidth = grid.runtimeWidth / xCount;
            var yWidth = grid.runtimeHeight / yCount;

            var zeroX       = grid.runtimeX;
            var zeroY       = grid.runtimeY;
            var dataList    = serie.GetDataList();
            var rangeMin    = visualMap.rangeMin;
            var rangeMax    = visualMap.rangeMax;
            var color       = m_Theme.GetColor(serie.index);
            var borderWidth = serie.itemStyle.show ? serie.itemStyle.borderWidth : 0;
            var borderColor = serie.itemStyle.opacity > 0 ? serie.itemStyle.borderColor : ChartConst.clearColor32;

            borderColor.a = (byte)(borderColor.a * serie.itemStyle.opacity);
            serie.dataPoints.Clear();
            serie.animation.InitProgress(1, 0, xCount);
            var animationIndex     = serie.animation.GetCurrIndex();
            var dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
            var dataChanging       = false;

            for (int i = 0; i < xCount; i++)
            {
                for (int j = 0; j < yCount; j++)
                {
                    var dataIndex = i * yCount + j;
                    if (dataIndex >= dataList.Count)
                    {
                        continue;
                    }
                    var serieData = dataList[dataIndex];
                    var dimension = VisualMapHelper.GetDimension(visualMap, serieData.data.Count);
                    if (serie.IsIgnoreIndex(dataIndex, dimension))
                    {
                        serie.dataPoints.Add(Vector3.zero);
                        continue;
                    }
                    var value = serieData.GetCurrData(dimension, dataChangeDuration, yAxis.inverse, yAxis.runtimeMinValue, yAxis.runtimeMaxValue);
                    if (serieData.IsDataChanged())
                    {
                        dataChanging = true;
                    }
                    var pos = new Vector3(zeroX + (i + 0.5f) * xWidth, zeroY + (j + 0.5f) * yWidth);
                    serie.dataPoints.Add(pos);
                    serieData.canShowLabel = false;
                    if (value == 0)
                    {
                        continue;
                    }
                    if (visualMap.enable)
                    {
                        if ((value < rangeMin && rangeMin != visualMap.min) ||
                            (value > rangeMax && rangeMax != visualMap.max))
                        {
                            continue;
                        }
                        if (!visualMap.IsInSelectedValue(value))
                        {
                            continue;
                        }
                        color = visualMap.GetColor(value);
                    }
                    if (animationIndex >= 0 && i > animationIndex)
                    {
                        continue;
                    }
                    serieData.canShowLabel = true;
                    var emphasis = (tooltip.show && i == (int)tooltip.runtimeXValues[0] && j == (int)tooltip.runtimeYValues[0]) ||
                                   visualMap.runtimeSelectedIndex > 0;
                    var rectWid = xWidth - 2 * borderWidth;
                    var rectHig = yWidth - 2 * borderWidth;
                    UGL.DrawRectangle(vh, pos, rectWid / 2, rectHig / 2, color);
                    if (borderWidth > 0 && !ChartHelper.IsClearColor(borderColor))
                    {
                        UGL.DrawBorder(vh, pos, rectWid, rectHig, borderWidth, borderColor);
                    }
                    if (visualMap.hoverLink && emphasis && serie.emphasis.show && serie.emphasis.itemStyle.borderWidth > 0)
                    {
                        var emphasisBorderWidth = serie.emphasis.itemStyle.borderWidth;
                        var emphasisBorderColor = serie.emphasis.itemStyle.opacity > 0 ? serie.emphasis.itemStyle.borderColor : ChartConst.clearColor32;
                        UGL.DrawBorder(vh, pos, rectWid, rectHig, emphasisBorderWidth, emphasisBorderColor);
                    }
                }
            }
            if (!serie.animation.IsFinish())
            {
                serie.animation.CheckProgress(xCount);
                m_IsPlayingAnimation = true;
                RefreshPainter(serie);
            }
            if (dataChanging)
            {
                RefreshPainter(serie);
            }
        }
Пример #12
0
        private void DrawYLineSerie(VertexHelper vh, int serieIndex, Color color, Serie serie, ref int dataCount,
                                    ref List <Vector3> points, ref List <int> pointSerieIndexs, ref List <float> seriesHig)
        {
            if (!IsActive(serie.index))
            {
                return;
            }
            lastPoints.Clear();
            lastSmoothPoints.Clear();
            smoothPoints.Clear();

            Vector3 lp    = Vector3.zero;
            Vector3 np    = Vector3.zero;
            var     xAxis = m_XAxises[serie.axisIndex];
            var     yAxis = m_YAxises[serie.axisIndex];

            if (!yAxis.show)
            {
                yAxis = m_YAxises[(serie.axisIndex + 1) % m_YAxises.Count];
            }
            float scaleWid = yAxis.GetDataWidth(coordinateHig, m_DataZoom);
            float startY   = coordinateY + (yAxis.boundaryGap ? scaleWid / 2 : 0);
            int   maxCount = maxShowDataNumber > 0 ?
                             (maxShowDataNumber > serie.yData.Count ? serie.yData.Count : maxShowDataNumber)
                : serie.yData.Count;

            dataCount = (maxCount - minShowDataNumber);
            if (m_Line.area && points.Count > 0)
            {
                if (!m_Line.smooth && points.Count > 0)
                {
                    for (int m = points.Count - dataCount; m < points.Count; m++)
                    {
                        lastPoints.Add(points[m]);
                    }
                }
                else if (m_Line.smooth && smoothPoints.Count > 0)
                {
                    for (int m = 0; m < smoothPoints.Count; m++)
                    {
                        lastSmoothPoints.Add(smoothPoints[m]);
                    }
                    smoothPoints.Clear();
                }
            }
            int smoothPointCount = 1;

            if (seriesHig.Count < minShowDataNumber)
            {
                for (int i = 0; i < minShowDataNumber; i++)
                {
                    seriesHig.Add(0);
                }
            }
            for (int i = minShowDataNumber; i < maxCount; i++)
            {
                if (i >= seriesHig.Count)
                {
                    seriesHig.Add(0);
                }
                float value   = serie.yData[i];
                float pY      = startY + i * scaleWid;
                float pX      = seriesHig[i] + coordinateX + m_Coordinate.tickness;
                float dataHig = (value - xAxis.minValue) / (xAxis.maxValue - xAxis.minValue) * coordinateWid;
                np = new Vector3(pX + dataHig, pY);
                if (i > 0)
                {
                    if (m_Line.step)
                    {
                        Vector2 middle1, middle2;
                        switch (m_Line.stepTpe)
                        {
                        case Line.StepType.Start:
                            middle1 = new Vector2(np.x, lp.y);
                            middle2 = new Vector2(np.x, lp.y - m_Line.tickness);
                            ChartHelper.DrawLine(vh, lp, middle1, m_Line.tickness, color);
                            ChartHelper.DrawLine(vh, middle2, np, m_Line.tickness, color);
                            if (m_Line.area)
                            {
                                Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f);
                                ChartHelper.DrawPolygon(vh, new Vector2(coordinateX, middle1.y), middle1, np,
                                                        new Vector2(coordinateX, np.y), areaColor);
                            }
                            break;

                        case Line.StepType.Middle:
                            middle1 = new Vector2(lp.x, (lp.y + np.y) / 2 + m_Line.tickness);
                            middle2 = new Vector2(np.x, (lp.y + np.y) / 2 - m_Line.tickness);
                            ChartHelper.DrawLine(vh, lp, middle1, m_Line.tickness, color);
                            ChartHelper.DrawLine(vh, new Vector2(middle1.x, middle1.y - m_Line.tickness),
                                                 new Vector2(middle2.x, middle2.y + m_Line.tickness), m_Line.tickness, color);
                            ChartHelper.DrawLine(vh, middle2, np, m_Line.tickness, color);
                            if (m_Line.area)
                            {
                                Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f);
                                ChartHelper.DrawPolygon(vh, new Vector2(coordinateX, lp.y), lp, middle1,
                                                        new Vector2(coordinateX, middle1.y), areaColor);
                                ChartHelper.DrawPolygon(vh, new Vector2(coordinateX, middle2.y + 2 * m_Line.tickness),
                                                        new Vector2(middle2.x, middle2.y + 2 * m_Line.tickness), np,
                                                        new Vector2(coordinateX, np.y), areaColor);
                            }
                            break;

                        case Line.StepType.End:
                            middle1 = new Vector2(np.x, lp.y);
                            middle2 = new Vector2(np.x, lp.y - m_Line.tickness);
                            ChartHelper.DrawLine(vh, lp, middle1, m_Line.tickness, color);
                            ChartHelper.DrawLine(vh, middle2, np, m_Line.tickness, color);
                            if (m_Line.area)
                            {
                                Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f);
                                ChartHelper.DrawPolygon(vh, new Vector2(coordinateX, lp.y), middle1,
                                                        new Vector2(np.x, np.y),
                                                        new Vector2(coordinateX, np.y), areaColor);
                            }
                            break;
                        }
                    }
                    else if (m_Line.smooth)
                    {
                        ChartHelper.GetBezierListVertical(ref smoothSegmentPoints, lp, np, m_Line.smoothStyle);
                        Vector3 start, to;
                        start = smoothSegmentPoints[0];
                        for (int k = 1; k < smoothSegmentPoints.Count; k++)
                        {
                            smoothPoints.Add(smoothSegmentPoints[k]);
                            to = smoothSegmentPoints[k];
                            ChartHelper.DrawLine(vh, start, to, m_Line.tickness, color);

                            if (m_Line.area)
                            {
                                Vector3 alp = new Vector3(start.x, start.y - m_Line.tickness);
                                Vector3 anp = new Vector3(to.x, to.y - m_Line.tickness);
                                Vector3 tnp = serieIndex > 0 ?
                                              (smoothPointCount > lastSmoothPoints.Count - 1 ?
                                               new Vector3(lastSmoothPoints[lastSmoothPoints.Count - 1].x,
                                                           lastSmoothPoints[lastSmoothPoints.Count - 1].y + m_Line.tickness) :
                                               new Vector3(lastSmoothPoints[smoothPointCount].x,
                                                           lastSmoothPoints[smoothPointCount].y + m_Line.tickness)) :
                                              new Vector3(coordinateX + m_Coordinate.tickness, to.y);
                                Vector3 tlp = serieIndex > 0 ?
                                              (smoothPointCount > lastSmoothPoints.Count - 1 ?
                                               new Vector3(lastSmoothPoints[lastSmoothPoints.Count - 2].x,
                                                           lastSmoothPoints[lastSmoothPoints.Count - 2].y + m_Line.tickness) :
                                               new Vector3(lastSmoothPoints[smoothPointCount - 1].x,
                                                           lastSmoothPoints[smoothPointCount - 1].y + m_Line.tickness)) :
                                              new Vector3(coordinateX + m_Coordinate.tickness, start.y);
                                Color areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f);
                                ChartHelper.DrawPolygon(vh, alp, anp, tnp, tlp, areaColor);
                            }
                            smoothPointCount++;
                            start = to;
                        }
                    }
                    else
                    {
                        ChartHelper.DrawLine(vh, lp, np, m_Line.tickness, color);
                        if (m_Line.area)
                        {
                            Vector3 alp       = new Vector3(lp.x, lp.y);
                            Vector3 anp       = new Vector3(np.x, np.y);
                            Color   areaColor = new Color(color.r, color.g, color.b, color.a * 0.75f);
                            var     cross     = ChartHelper.GetIntersection(lp, np, new Vector3(coordinateX, coordinateY),
                                                                            new Vector3(coordinateX, coordinateY + coordinateHig));
                            if (cross == Vector3.zero)
                            {
                                Vector3 tnp = serieIndex > 0 ?
                                              new Vector3(lastPoints[i].x + m_Coordinate.tickness, lastPoints[i].y) :
                                              new Vector3(coordinateX + m_Coordinate.tickness, np.y);
                                Vector3 tlp = serieIndex > 0 ?
                                              new Vector3(lastPoints[i - 1].x + m_Coordinate.tickness, lastPoints[i - 1].y) :
                                              new Vector3(coordinateX + m_Coordinate.tickness, lp.y);
                                ChartHelper.DrawPolygon(vh, alp, anp, tnp, tlp, areaColor);
                            }
                            else
                            {
                                Vector3 cross1 = new Vector3(cross.x + (alp.x > coordinateX ? m_Coordinate.tickness : -m_Coordinate.tickness), cross.y);
                                Vector3 cross2 = new Vector3(cross.x + (anp.x > coordinateX ? m_Coordinate.tickness : -m_Coordinate.tickness), cross.y);
                                Vector3 xp1    = new Vector3(coordinateX + (alp.x > coordinateX ? m_Coordinate.tickness : -m_Coordinate.tickness), alp.y);
                                Vector3 xp2    = new Vector3(coordinateX + (anp.x > coordinateX ? m_Coordinate.tickness : -m_Coordinate.tickness), anp.y);
                                ChartHelper.DrawTriangle(vh, alp, cross1, xp1, areaColor);
                                ChartHelper.DrawTriangle(vh, anp, cross2, xp2, areaColor);
                            }
                        }
                    }
                }
                if (serie.symbol.type != SerieSymbolType.None || m_Line.area)
                {
                    points.Add(np);
                    pointSerieIndexs.Add(serie.index);
                }
                seriesHig[i] += dataHig;
                lp            = np;
            }
        }
Пример #13
0
        private void DrawLabel(Serie serie, int dataIndex, SerieData serieData, PieTempData tempData, Color serieColor,
                               float currAngle, float offsetRadius, float insideRadius, float outsideRadius)
        {
            if (serieData.labelText == null)
            {
                return;
            }
            var isHighlight = (serieData.highlighted && serie.highlightLabel.show);

            if ((serie.label.show || isHighlight) && serieData.canShowLabel)
            {
                serieData.SetLabelActive(true);
                float rotate           = 0;
                bool  isInsidePosition = serie.label.position == SerieLabel.Position.Inside;
                if (serie.label.rotate > 0 && isInsidePosition)
                {
                    if (currAngle > 180)
                    {
                        rotate += 270 - currAngle;
                    }
                    else
                    {
                        rotate += -(currAngle - 90);
                    }
                }
                Color color = serieColor;
                if (isHighlight)
                {
                    if (serie.highlightLabel.color != Color.clear)
                    {
                        color = serie.highlightLabel.color;
                    }
                }
                else if (serie.label.color != Color.clear)
                {
                    color = serie.label.color;
                }
                else
                {
                    color = isInsidePosition ? Color.white : serieColor;
                }
                var   fontSize  = isHighlight ? serie.highlightLabel.fontSize : serie.label.fontSize;
                var   fontStyle = isHighlight ? serie.highlightLabel.fontStyle : serie.label.fontStyle;
                float currRad   = currAngle * Mathf.Deg2Rad;

                serieData.labelText.color     = color;
                serieData.labelText.fontSize  = fontSize;
                serieData.labelText.fontStyle = fontStyle;

                serieData.labelRect.transform.localEulerAngles = new Vector3(0, 0, rotate);

                switch (serie.label.position)
                {
                case SerieLabel.Position.Center:
                    serieData.labelPosition = tempData.center;
                    break;

                case SerieLabel.Position.Inside:
                    var labelRadius = offsetRadius + insideRadius + (outsideRadius - insideRadius) / 2;
                    var labelCenter = new Vector2(tempData.center.x + labelRadius * Mathf.Sin(currRad),
                                                  tempData.center.y + labelRadius * Mathf.Cos(currRad));
                    serieData.labelPosition = labelCenter;
                    break;

                case SerieLabel.Position.Outside:
                    labelRadius = tempData.outsideRadius + serie.label.lineLength1;
                    labelCenter = new Vector2(tempData.center.x + labelRadius * Mathf.Sin(currRad),
                                              tempData.center.y + labelRadius * Mathf.Cos(currRad));
                    float labelWidth = serieData.labelText.preferredWidth;
                    if (currAngle > 180)
                    {
                        serieData.labelPosition = new Vector2(labelCenter.x - serie.label.lineLength2 - 5 - labelWidth / 2, labelCenter.y);
                    }
                    else
                    {
                        serieData.labelPosition = new Vector2(labelCenter.x + serie.label.lineLength2 + 5 + labelWidth / 2, labelCenter.y);
                    }
                    break;
                }
                if (!string.IsNullOrEmpty(serie.label.formatter))
                {
                    var value   = serieData.data[1];
                    var total   = serie.yTotal;
                    var content = serie.label.GetFormatterContent(serie.name, serieData.name, value, total);
                    serieData.SetLabelText(content);
                }
                serieData.SetLabelPosition(serieData.labelPosition);
            }
            else
            {
                serieData.SetLabelActive(false);
            }
        }
Пример #14
0
        private void DrawLabel(Serie serie, int dataIndex, SerieData serieData, Color serieColor)
        {
            if (serieData.labelText == null)
            {
                return;
            }
            var currAngle   = serieData.runtimePieHalfAngle;
            var isHighlight = (serieData.highlighted && serie.emphasis.label.show);
            var serieLabel  = SerieHelper.GetSerieLabel(serie, serieData);
            var showLabel   = ((serieLabel.show || isHighlight) && serieData.canShowLabel);

            if (showLabel || serieData.iconStyle.show)
            {
                serieData.SetLabelActive(showLabel);
                float rotate           = 0;
                bool  isInsidePosition = serieLabel.position == SerieLabel.Position.Inside;
                if (serieLabel.rotate > 0 && isInsidePosition)
                {
                    if (currAngle > 180)
                    {
                        rotate += 270 - currAngle;
                    }
                    else
                    {
                        rotate += -(currAngle - 90);
                    }
                }
                Color color = serieColor;
                if (isHighlight)
                {
                    if (serie.emphasis.label.color != Color.clear)
                    {
                        color = serie.emphasis.label.color;
                    }
                }
                else if (serieLabel.color != Color.clear)
                {
                    color = serieLabel.color;
                }
                else
                {
                    color = isInsidePosition ? Color.white : serieColor;
                }
                var fontSize  = isHighlight ? serie.emphasis.label.fontSize : serieLabel.fontSize;
                var fontStyle = isHighlight ? serie.emphasis.label.fontStyle : serieLabel.fontStyle;

                serieData.labelText.color     = color;
                serieData.labelText.fontSize  = fontSize;
                serieData.labelText.fontStyle = fontStyle;

                serieData.labelRect.transform.localEulerAngles = new Vector3(0, 0, rotate);

                UpdateLabelPostion(serie, serieData);
                if (!string.IsNullOrEmpty(serieLabel.formatter))
                {
                    var value   = serieData.data[1];
                    var total   = serie.yTotal;
                    var content = serieLabel.GetFormatterContent(serie.name, serieData.name, value, total);
                    if (serieData.SetLabelText(content))
                    {
                        RefreshChart();
                    }
                }
                else
                {
                    if (serieData.SetLabelText(serieData.name))
                    {
                        RefreshChart();
                    }
                }
                serieData.SetGameObjectPosition(serieData.labelPosition);
                if (showLabel)
                {
                    serieData.SetLabelPosition(serieLabel.offset);
                }
                else
                {
                    serieData.SetLabelActive(false);
                }
            }
            else
            {
                serieData.SetLabelActive(false);
            }
            serieData.UpdateIcon();
        }
Пример #15
0
        private void DrawBarBackground(VertexHelper vh, Serie serie, SerieData serieData, ItemStyle itemStyle, int colorIndex,
                                       bool highlight, float pX, float pY, float space, float barWidth, bool isYAxis)
        {
            Color color = SerieHelper.GetItemBackgroundColor(serie, serieData, m_ThemeInfo, colorIndex, highlight, false);

            if (ChartHelper.IsClearColor(color))
            {
                return;
            }
            if (isYAxis)
            {
                var     axis      = m_YAxises[serie.axisIndex];
                var     axisWidth = axis.axisLine.width;
                Vector3 plt       = new Vector3(m_CoordinateX + axisWidth, pY + space + barWidth);
                Vector3 prt       = new Vector3(m_CoordinateX + axisWidth + m_CoordinateWidth, pY + space + barWidth);
                Vector3 prb       = new Vector3(m_CoordinateX + axisWidth + m_CoordinateWidth, pY + space);
                Vector3 plb       = new Vector3(m_CoordinateX + axisWidth, pY + space);
                if (serie.barType == BarType.Capsule)
                {
                    var radius = barWidth / 2;
                    var diff   = Vector3.right * radius;
                    var pcl    = (plt + plb) / 2 + diff;
                    var pcr    = (prt + prb) / 2 - diff;
                    CheckClipAndDrawPolygon(vh, plb + diff, plt + diff, prt - diff, prb - diff, color, color, serie.clip);
                    ChartDrawer.DrawSector(vh, pcl, radius, color, 180, 360);
                    ChartDrawer.DrawSector(vh, pcr, radius, color, 0, 180);
                    if (itemStyle.NeedShowBorder())
                    {
                        var borderWidth = itemStyle.borderWidth;
                        var borderColor = itemStyle.borderColor;
                        var smoothness  = m_Settings.cicleSmoothness;
                        var inRadius    = radius - borderWidth;
                        var outRadius   = radius;
                        var p1          = plb + diff + Vector3.up * borderWidth / 2;
                        var p2          = prb - diff + Vector3.up * borderWidth / 2;
                        var p3          = plt + diff - Vector3.up * borderWidth / 2;
                        var p4          = prt - diff - Vector3.up * borderWidth / 2;
                        ChartDrawer.DrawLine(vh, p1, p2, borderWidth / 2, borderColor);
                        ChartDrawer.DrawLine(vh, p3, p4, borderWidth / 2, borderColor);
                        ChartDrawer.DrawDoughnut(vh, pcl, inRadius, outRadius, borderColor, Color.clear, 180, 360, smoothness);
                        ChartDrawer.DrawDoughnut(vh, pcr, inRadius, outRadius, borderColor, Color.clear, 0, 180, smoothness);
                    }
                }
                else
                {
                    CheckClipAndDrawPolygon(vh, ref plb, ref plt, ref prt, ref prb, color, color, serie.clip);
                }
            }
            else
            {
                var     axis      = m_XAxises[serie.axisIndex];
                var     axisWidth = axis.axisLine.width;
                Vector3 plb       = new Vector3(pX + space, m_CoordinateY + axisWidth);
                Vector3 plt       = new Vector3(pX + space, m_CoordinateY + m_CoordinateHeight + axisWidth);
                Vector3 prt       = new Vector3(pX + space + barWidth, m_CoordinateY + m_CoordinateHeight + axisWidth);
                Vector3 prb       = new Vector3(pX + space + barWidth, m_CoordinateY + axisWidth);
                if (serie.barType == BarType.Capsule)
                {
                    var radius = barWidth / 2;
                    var diff   = Vector3.up * radius;
                    var pct    = (plt + prt) / 2 - diff;
                    var pcb    = (plb + prb) / 2 + diff;
                    CheckClipAndDrawPolygon(vh, prb + diff, plb + diff, plt - diff, prt - diff, color, color, serie.clip);
                    ChartDrawer.DrawSector(vh, pct, radius, color, 270, 450);
                    ChartDrawer.DrawSector(vh, pcb, radius, color, 90, 270);
                    if (itemStyle.NeedShowBorder())
                    {
                        var borderWidth = itemStyle.borderWidth;
                        var borderColor = itemStyle.borderColor;
                        var smoothness  = m_Settings.cicleSmoothness;
                        var inRadius    = radius - borderWidth;
                        var outRadius   = radius;
                        var p1          = plb + diff + Vector3.right * borderWidth / 2;
                        var p2          = plt - diff + Vector3.right * borderWidth / 2;
                        var p3          = prb + diff - Vector3.right * borderWidth / 2;
                        var p4          = prt - diff - Vector3.right * borderWidth / 2;
                        ChartDrawer.DrawLine(vh, p1, p2, borderWidth / 2, borderColor);
                        ChartDrawer.DrawLine(vh, p3, p4, borderWidth / 2, borderColor);
                        ChartDrawer.DrawDoughnut(vh, pct, inRadius, outRadius, borderColor, Color.clear, 270, 450, smoothness);
                        ChartDrawer.DrawDoughnut(vh, pcb, inRadius, outRadius, borderColor, Color.clear, 90, 270, smoothness);
                    }
                }
                else
                {
                    CheckClipAndDrawPolygon(vh, ref prb, ref plb, ref plt, ref prt, color, color, serie.clip);
                }
            }
        }
Пример #16
0
        protected void DrawScatterSerie(VertexHelper vh, int colorIndex, Serie serie)
        {
            if (serie.animation.HasFadeOut())
            {
                return;
            }
            if (!serie.show)
            {
                return;
            }
            var yAxis    = m_YAxes[serie.yAxisIndex];
            var xAxis    = m_XAxes[serie.xAxisIndex];
            var grid     = GetSerieGridOrDefault(serie);
            int maxCount = serie.maxShow > 0 ?
                           (serie.maxShow > serie.dataCount ? serie.dataCount : serie.maxShow)
                : serie.dataCount;

            serie.animation.InitProgress(1, 0, 1);
            var rate = serie.animation.GetCurrRate();
            var dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
            var dataChanging       = false;
            var dataList           = serie.GetDataList(dataZoom);

            foreach (var serieData in dataList)
            {
                var symbol = SerieHelper.GetSerieSymbol(serie, serieData);
                if (!symbol.ShowSymbol(serieData.index, maxCount))
                {
                    continue;
                }
                var   highlight    = serie.highlighted || serieData.highlighted;
                var   color        = SerieHelper.GetItemColor(serie, serieData, m_Theme, colorIndex, highlight);
                var   toColor      = SerieHelper.GetItemToColor(serie, serieData, m_Theme, colorIndex, highlight);
                var   symbolBorder = SerieHelper.GetSymbolBorder(serie, serieData, m_Theme, highlight);
                var   cornerRadius = SerieHelper.GetSymbolCornerRadius(serie, serieData, highlight);
                float xValue       = serieData.GetCurrData(0, dataChangeDuration, xAxis.inverse);
                float yValue       = serieData.GetCurrData(1, dataChangeDuration, yAxis.inverse);
                if (serieData.IsDataChanged())
                {
                    dataChanging = true;
                }
                float pX       = grid.runtimeX + xAxis.axisLine.GetWidth(m_Theme.axis.lineWidth);
                float pY       = grid.runtimeY + yAxis.axisLine.GetWidth(m_Theme.axis.lineWidth);
                float xDataHig = GetDataHig(xAxis, xValue, grid.runtimeWidth);
                float yDataHig = GetDataHig(yAxis, yValue, grid.runtimeHeight);
                var   pos      = new Vector3(pX + xDataHig, pY + yDataHig);
                serie.dataPoints.Add(pos);
                serieData.runtimePosition = pos;
                var   datas      = serieData.data;
                float symbolSize = 0;
                if (serie.highlighted || serieData.highlighted)
                {
                    symbolSize = symbol.GetSelectedSize(datas, m_Theme.serie.scatterSymbolSelectedSize);
                }
                else
                {
                    symbolSize = symbol.GetSize(datas, m_Theme.serie.scatterSymbolSize);
                }
                symbolSize *= rate;
                if (symbolSize > 100)
                {
                    symbolSize = 100;
                }
                if (serie.type == SerieType.EffectScatter)
                {
                    for (int count = 0; count < symbol.animationSize.Count; count++)
                    {
                        var nowSize = symbol.animationSize[count];
                        color.a = (byte)(255 * (symbolSize - nowSize) / symbolSize);
                        DrawSymbol(vh, symbol.type, nowSize, symbolBorder, pos, color, toColor, symbol.gap, cornerRadius);
                    }
                    RefreshPainter(serie);
                }
                else
                {
                    DrawSymbol(vh, symbol.type, symbolSize, symbolBorder, pos, color, toColor, symbol.gap, cornerRadius);
                }
            }
            if (!serie.animation.IsFinish())
            {
                serie.animation.CheckProgress(1);
                m_IsPlayingAnimation = true;
                RefreshPainter(serie);
            }
            if (dataChanging)
            {
                RefreshPainter(serie);
            }
        }
Пример #17
0
        protected void UpdateLabelPostion(Serie serie, SerieData serieData)
        {
            if (serieData.labelObject == null)
            {
                return;
            }
            var currAngle     = serieData.runtimePieHalfAngle;
            var currRad       = currAngle * Mathf.Deg2Rad;
            var offsetRadius  = serieData.runtimePieOffsetRadius;
            var insideRadius  = serieData.runtimePieInsideRadius;
            var outsideRadius = serieData.runtimePieOutsideRadius;
            var serieLabel    = SerieHelper.GetSerieLabel(serie, serieData);

            switch (serieLabel.position)
            {
            case SerieLabel.Position.Center:
                serieData.labelPosition = serie.runtimeCenterPos;
                break;

            case SerieLabel.Position.Inside:
                var labelRadius = offsetRadius + insideRadius + (outsideRadius - insideRadius) / 2;
                var labelCenter = new Vector2(serie.runtimeCenterPos.x + labelRadius * Mathf.Sin(currRad),
                                              serie.runtimeCenterPos.y + labelRadius * Mathf.Cos(currRad));
                serieData.labelPosition = labelCenter;
                break;

            case SerieLabel.Position.Outside:
                if (serieLabel.lineType == SerieLabel.LineType.HorizontalLine)
                {
                    var radius1 = serie.runtimeOutsideRadius;
                    var radius3 = insideRadius + (outsideRadius - insideRadius) / 2;
                    var currSin = Mathf.Sin(currRad);
                    var currCos = Mathf.Cos(currRad);
                    var pos0    = new Vector3(serie.runtimeCenterPos.x + radius3 * currSin, serie.runtimeCenterPos.y + radius3 * currCos);
                    if (currAngle > 180)
                    {
                        currSin = Mathf.Sin((360 - currAngle) * Mathf.Deg2Rad);
                        currCos = Mathf.Cos((360 - currAngle) * Mathf.Deg2Rad);
                    }
                    var r4 = Mathf.Sqrt(radius1 * radius1 - Mathf.Pow(currCos * radius3, 2)) - currSin * radius3;
                    r4 += serieLabel.lineLength1 + serieLabel.lineWidth * 4;
                    r4 += serieData.labelObject.label.preferredWidth / 2;
                    serieData.labelPosition = pos0 + (currAngle > 180 ? Vector3.left : Vector3.right) * r4;
                }
                else
                {
                    labelRadius = serie.runtimeOutsideRadius + serieLabel.lineLength1;
                    labelCenter = new Vector2(serie.runtimeCenterPos.x + labelRadius * Mathf.Sin(currRad),
                                              serie.runtimeCenterPos.y + labelRadius * Mathf.Cos(currRad));
                    float labelWidth = serieData.labelObject.label.preferredWidth;
                    if (currAngle > 180)
                    {
                        serieData.labelPosition = new Vector2(labelCenter.x - serieLabel.lineLength2 - 5 - labelWidth / 2, labelCenter.y);
                    }
                    else
                    {
                        serieData.labelPosition = new Vector2(labelCenter.x + serieLabel.lineLength2 + 5 + labelWidth / 2, labelCenter.y);
                    }
                }
                break;
            }
        }
Пример #18
0
        private static void InitCoordinateTooltip(ref StringBuilder sb, Tooltip tooltip, Serie serie, int index,
                                                  ThemeInfo themeInfo, bool isCartesian, DataZoom dataZoom = null)
        {
            string key = serie.name;
            float  xValue, yValue;

            serie.GetXYData(index, dataZoom, out xValue, out yValue);
            var isIngore         = serie.IsIgnorePoint(index);
            var serieData        = serie.GetSerieData(index, dataZoom);
            var numericFormatter = GetItemNumericFormatter(tooltip, serie, serieData);

            if (isCartesian)
            {
                if (serieData != null && serieData.highlighted)
                {
                    sb.Append(key).Append(!string.IsNullOrEmpty(key) ? " : " : "");
                    sb.Append("[").Append(ChartCached.FloatToStr(xValue, numericFormatter)).Append(",")
                    .Append(ChartCached.FloatToStr(yValue, numericFormatter)).Append("]");
                }
            }
            else
            {
                var valueTxt = isIngore ? tooltip.ignoreDataDefaultContent :
                               ChartCached.FloatToStr(yValue, numericFormatter);
                sb.Append("<color=#").Append(themeInfo.GetColorStr(serie.index)).Append(">● </color>")
                .Append(key).Append(!string.IsNullOrEmpty(key) ? " : " : "")
                .Append(valueTxt);
            }
        }
Пример #19
0
        protected override void DrawChart(VertexHelper vh)
        {
            base.DrawChart(vh);
            if (m_YAxis.type == Axis.AxisType.Category)
            {
                var   stackSeries = m_Series.GetStackSeries();
                int   seriesCount = stackSeries.Count;
                float scaleWid    = m_YAxis.GetDataWidth(coordinateHig, m_DataZoom);
                float barWid      = m_Bar.barWidth > 1 ? m_Bar.barWidth : scaleWid * m_Bar.barWidth;
                float offset      = m_Bar.inSameBar ?
                                    (scaleWid - barWid - m_Bar.space * (seriesCount - 1)) / 2 :
                                    (scaleWid - barWid * seriesCount - m_Bar.space * (seriesCount - 1)) / 2;
                int serieCount = 0;
                for (int j = 0; j < seriesCount; j++)
                {
                    var seriesCurrHig = new Dictionary <int, float>();
                    var serieList     = stackSeries[j];
                    for (int n = 0; n < serieList.Count; n++)
                    {
                        Serie serie = serieList[n];
                        if (!m_Legend.IsActive(serie.name))
                        {
                            continue;
                        }
                        Color color    = m_ThemeInfo.GetColor(serieCount);
                        int   maxCount = maxShowDataNumber > 0 ?
                                         (maxShowDataNumber > serie.data.Count ? serie.data.Count : maxShowDataNumber)
                            : serie.data.Count;
                        for (int i = minShowDataNumber; i < maxCount; i++)
                        {
                            if (!seriesCurrHig.ContainsKey(i))
                            {
                                seriesCurrHig[i] = 0;
                            }
                            float value = serie.data[i];
                            float pX    = seriesCurrHig[i] + zeroX + m_Coordinate.tickness;
                            float pY    = coordinateY + i * scaleWid;
                            if (!m_YAxis.boundaryGap)
                            {
                                pY -= scaleWid / 2;
                            }
                            float barHig = (minValue > 0 ? value - minValue : value)
                                           / (maxValue - minValue) * coordinateWid;
                            float space = m_Bar.inSameBar ? offset :
                                          offset + j * (barWid + m_Bar.space);
                            seriesCurrHig[i] += barHig;
                            Vector3 p1 = new Vector3(pX, pY + space + barWid);
                            Vector3 p2 = new Vector3(pX + barHig, pY + space + barWid);
                            Vector3 p3 = new Vector3(pX + barHig, pY + space);
                            Vector3 p4 = new Vector3(pX, pY + space);
                            if (serie.show)
                            {
                                ChartHelper.DrawPolygon(vh, p1, p2, p3, p4, color);
                            }
                        }
                        if (serie.show)
                        {
                            serieCount++;
                        }
                    }
                }
                if (m_Tooltip.show && m_Tooltip.dataIndex > 0)
                {
                    if (m_Tooltip.crossLabel)
                    {
                        Vector3 sp = new Vector2(m_Tooltip.pointerPos.x, zeroY);
                        Vector3 ep = new Vector2(m_Tooltip.pointerPos.x, zeroY + coordinateHig);
                        DrawSplitLine(vh, false, Axis.SplitLineType.Dashed, sp, ep, m_ThemeInfo.tooltipLineColor);
                        float splitWidth = m_YAxis.GetSplitWidth(coordinateHig, m_DataZoom);
                        float pY         = zeroY + (m_Tooltip.dataIndex - 1) * splitWidth +
                                           (m_YAxis.boundaryGap ? splitWidth / 2 : 0);
                        sp = new Vector2(coordinateX, pY);
                        ep = new Vector2(coordinateX + coordinateWid, pY);
                        DrawSplitLine(vh, true, Axis.SplitLineType.Dashed, sp, ep, m_ThemeInfo.tooltipLineColor);
                    }
                    else
                    {
                        float tooltipSplitWid = scaleWid < 1 ? 1 : scaleWid;
                        float pX = coordinateX + coordinateWid;
                        float pY = coordinateY + scaleWid * (m_Tooltip.dataIndex - 1) -
                                   (m_YAxis.boundaryGap ? 0 : scaleWid / 2);
                        Vector3 p1 = new Vector3(coordinateX, pY);
                        Vector3 p2 = new Vector3(coordinateX, pY + tooltipSplitWid);
                        Vector3 p3 = new Vector3(pX, pY + tooltipSplitWid);
                        Vector3 p4 = new Vector3(pX, pY);
                        ChartHelper.DrawPolygon(vh, p1, p2, p3, p4, m_ThemeInfo.tooltipFlagAreaColor);
                    }
                }
            }
            else
            {
                var   stackSeries = m_Series.GetStackSeries();
                int   seriesCount = stackSeries.Count;
                float scaleWid    = m_XAxis.GetDataWidth(coordinateWid, m_DataZoom);
                float barWid      = m_Bar.barWidth > 1 ? m_Bar.barWidth : scaleWid * m_Bar.barWidth;
                float offset      = m_Bar.inSameBar ?
                                    (scaleWid - barWid - m_Bar.space * (seriesCount - 1)) / 2 :
                                    (scaleWid - barWid * seriesCount - m_Bar.space * (seriesCount - 1)) / 2;
                int serieCount = 0;
                for (int j = 0; j < seriesCount; j++)
                {
                    var seriesCurrHig = new Dictionary <int, float>();
                    var serieList     = stackSeries[j];
                    for (int n = 0; n < serieList.Count; n++)
                    {
                        Serie serie = serieList[n];
                        if (!m_Legend.IsActive(serie.name))
                        {
                            continue;
                        }
                        Color        color    = m_ThemeInfo.GetColor(serieCount);
                        List <float> showData = serie.GetData(m_DataZoom);
                        int          maxCount = maxShowDataNumber > 0 ?
                                                (maxShowDataNumber > showData.Count ? showData.Count : maxShowDataNumber)
                            : showData.Count;
                        for (int i = minShowDataNumber; i < maxCount; i++)
                        {
                            if (!seriesCurrHig.ContainsKey(i))
                            {
                                seriesCurrHig[i] = 0;
                            }
                            float value = showData[i];
                            float pX    = zeroX + i * scaleWid;
                            if (!m_XAxis.boundaryGap)
                            {
                                pX -= scaleWid / 2;
                            }
                            float pY     = seriesCurrHig[i] + zeroY + m_Coordinate.tickness;
                            float barHig = (minValue > 0 ? value - minValue : value)
                                           / (maxValue - minValue) * coordinateHig;
                            seriesCurrHig[i] += barHig;
                            float space = m_Bar.inSameBar ? offset :
                                          offset + j * (barWid + m_Bar.space);
                            Vector3 p1 = new Vector3(pX + space, pY);
                            Vector3 p2 = new Vector3(pX + space, pY + barHig);
                            Vector3 p3 = new Vector3(pX + space + barWid, pY + barHig);
                            Vector3 p4 = new Vector3(pX + space + barWid, pY);
                            if (serie.show)
                            {
                                ChartHelper.DrawPolygon(vh, p1, p2, p3, p4, color);
                            }
                        }
                        if (serie.show)
                        {
                            serieCount++;
                        }
                    }
                }
                if (m_Tooltip.show && m_Tooltip.dataIndex > 0)
                {
                    if (m_Tooltip.crossLabel)
                    {
                        Vector3 sp = new Vector2(zeroX, m_Tooltip.pointerPos.y);
                        Vector3 ep = new Vector2(zeroX + coordinateWid, m_Tooltip.pointerPos.y);
                        DrawSplitLine(vh, true, Axis.SplitLineType.Dashed, sp, ep, m_ThemeInfo.tooltipLineColor);

                        float splitWidth = m_XAxis.GetSplitWidth(coordinateWid, m_DataZoom);
                        float px         = zeroX + (m_Tooltip.dataIndex - 1) * splitWidth
                                           + (m_XAxis.boundaryGap ? splitWidth / 2 : 0);
                        sp = new Vector2(px, coordinateY);
                        ep = new Vector2(px, coordinateY + coordinateHig);
                        DrawSplitLine(vh, false, Axis.SplitLineType.Dashed, sp, ep, m_ThemeInfo.tooltipLineColor);
                    }
                    else
                    {
                        float tooltipSplitWid = scaleWid < 1 ? 1 : scaleWid;
                        float pX = coordinateX + scaleWid * (m_Tooltip.dataIndex - 1) -
                                   (m_XAxis.boundaryGap ? 0 : scaleWid / 2);
                        float   pY = coordinateY + coordinateHig;
                        Vector3 p1 = new Vector3(pX, coordinateY);
                        Vector3 p2 = new Vector3(pX, pY);
                        Vector3 p3 = new Vector3(pX + tooltipSplitWid, pY);
                        Vector3 p4 = new Vector3(pX + tooltipSplitWid, coordinateY);
                        ChartHelper.DrawPolygon(vh, p1, p2, p3, p4, m_ThemeInfo.tooltipFlagAreaColor);
                    }
                }
            }
        }
Пример #20
0
        private static void InitDefaultContent(ref StringBuilder sb, Tooltip tooltip, Serie serie, int index,
                                               string category, ThemeInfo themeInfo = null, DataZoom dataZoom = null, bool isCartesian = false)
        {
            switch (serie.type)
            {
            case SerieType.Line:
            case SerieType.Bar:
                InitCoordinateTooltip(ref sb, tooltip, serie, index, themeInfo, isCartesian, dataZoom);
                break;

            case SerieType.Scatter:
            case SerieType.EffectScatter:
                InitScatterTooltip(ref sb, tooltip, serie, index, themeInfo);
                break;

            case SerieType.Radar:
                break;

            case SerieType.Pie:
                InitPieTooltip(ref sb, tooltip, serie, index, themeInfo);
                break;

            case SerieType.Ring:
                InitRingTooltip(ref sb, tooltip, serie, index, themeInfo);
                break;

            case SerieType.Heatmap:
                break;

            case SerieType.Gauge:
                break;
            }
        }
Пример #21
0
        private void UpdateRuntimeData(Serie serie)
        {
            var data = serie.data;

            serie.runtimeDataMax      = serie.yMax;
            serie.runtimePieDataTotal = serie.yTotal;

            SerieHelper.UpdateCenter(serie, chart.chartPosition, chart.chartWidth, chart.chartHeight);
            float totalDegree      = 0;
            float startDegree      = 0;
            float zeroReplaceValue = 0;
            int   showdataCount    = 0;

            foreach (var sd in serie.data)
            {
                if (sd.show && serie.pieRoseType == RoseType.Area)
                {
                    showdataCount++;
                }
                sd.canShowLabel = false;
            }
            float dataChangeDuration      = serie.animation.GetUpdateAnimationDuration();
            bool  isAllZeroValue          = SerieHelper.IsAllZeroValue(serie, 1);
            var   dataTotalFilterMinAngle = serie.runtimePieDataTotal;

            if (isAllZeroValue)
            {
                totalDegree               = 360;
                zeroReplaceValue          = totalDegree / data.Count;
                serie.runtimeDataMax      = zeroReplaceValue;
                serie.runtimePieDataTotal = 360;
            }
            else
            {
                dataTotalFilterMinAngle = GetTotalAngle(serie, serie.runtimePieDataTotal, ref totalDegree);
            }
            serie.animation.InitProgress(data.Count, 0, 360);
            for (int n = 0; n < data.Count; n++)
            {
                var serieData = data[n];
                serieData.index = n;
                float value = isAllZeroValue ? zeroReplaceValue : serieData.GetCurrData(1, dataChangeDuration);
                serieData.runtimePieStartAngle = startDegree;
                serieData.runtimePieToAngle    = startDegree;
                serieData.runtimePieHalfAngle  = startDegree;
                serieData.runtimePieCurrAngle  = startDegree;
                if (!serieData.show)
                {
                    continue;
                }
                float degree = serie.pieRoseType == RoseType.Area
                    ? (totalDegree / showdataCount)
                    : (totalDegree * value / dataTotalFilterMinAngle);
                if (serie.minAngle > 0 && degree < serie.minAngle)
                {
                    degree = serie.minAngle;
                }
                serieData.runtimePieToAngle       = startDegree + degree;
                serieData.runtimePieOutsideRadius = serie.pieRoseType > 0 ?
                                                    serie.runtimeInsideRadius +
                                                    (serie.runtimeOutsideRadius - serie.runtimeInsideRadius) * value / serie.runtimeDataMax :
                                                    serie.runtimeOutsideRadius;
                if (serieData.highlighted)
                {
                    serieData.runtimePieOutsideRadius += chart.theme.serie.pieTooltipExtraRadius;
                }
                var offset = 0f;
                if (serie.pieClickOffset && serieData.selected)
                {
                    offset += chart.theme.serie.pieSelectedOffset;
                }
                if (serie.animation.CheckDetailBreak(serieData.runtimePieToAngle))
                {
                    serieData.runtimePieCurrAngle = serie.animation.GetCurrDetail();
                }
                else
                {
                    serieData.runtimePieCurrAngle = serieData.runtimePieToAngle;
                }
                var halfDegree = (serieData.runtimePieToAngle - startDegree) / 2;
                serieData.runtimePieHalfAngle    = startDegree + halfDegree;
                serieData.runtiemPieOffsetCenter = serie.runtimeCenterPos;
                serieData.runtimePieInsideRadius = serie.runtimeInsideRadius;
                if (offset > 0)
                {
                    var currRad = serieData.runtimePieHalfAngle * Mathf.Deg2Rad;
                    var currSin = Mathf.Sin(currRad);
                    var currCos = Mathf.Cos(currRad);
                    serieData.runtimePieOffsetRadius   = 0;
                    serieData.runtimePieInsideRadius  -= serieData.runtimePieOffsetRadius;
                    serieData.runtimePieOutsideRadius -= serieData.runtimePieOffsetRadius;
                    if (serie.pieClickOffset && serieData.selected)
                    {
                        serieData.runtimePieOffsetRadius += chart.theme.serie.pieSelectedOffset;
                        if (serieData.runtimePieInsideRadius > 0)
                        {
                            serieData.runtimePieInsideRadius += chart.theme.serie.pieSelectedOffset;
                        }
                        serieData.runtimePieOutsideRadius += chart.theme.serie.pieSelectedOffset;
                    }
                    serieData.runtiemPieOffsetCenter = new Vector3(
                        serie.runtimeCenterPos.x + serieData.runtimePieOffsetRadius * currSin,
                        serie.runtimeCenterPos.y + serieData.runtimePieOffsetRadius * currCos);
                }
                serieData.canShowLabel = serieData.runtimePieCurrAngle >= serieData.runtimePieHalfAngle;
                startDegree            = serieData.runtimePieToAngle;
                SerieLabelHelper.UpdatePieLabelPosition(serie, serieData);
            }
            SerieLabelHelper.AvoidLabelOverlap(serie);
        }
Пример #22
0
        private static void InitScatterTooltip(ref StringBuilder sb, Tooltip tooltip, Serie serie, int index,
                                               ThemeInfo themeInfo)
        {
            if (!tooltip.runtimeSerieDataIndex.ContainsKey(serie.index))
            {
                return;
            }
            var dataIndexList = tooltip.runtimeSerieDataIndex[serie.index];

            if (!string.IsNullOrEmpty(serie.name))
            {
                sb.Append(serie.name).Append(PH_NN);
            }
            for (int i = 0; i < dataIndexList.Count; i++)
            {
                var   dataIndex = dataIndexList[i];
                var   serieData = serie.GetSerieData(dataIndex);
                var   numericFormatter = GetItemNumericFormatter(tooltip, serie, serieData);
                float xValue, yValue;
                serie.GetXYData(dataIndex, null, out xValue, out yValue);

                sb.Append("<color=#").Append(themeInfo.GetColorStr(serie.index)).Append(">● </color>");
                if (!string.IsNullOrEmpty(serieData.name))
                {
                    sb.Append(serieData.name).Append(": ");
                }
                sb.AppendFormat("({0},{1})", ChartCached.FloatToStr(xValue, numericFormatter),
                                ChartCached.FloatToStr(yValue, numericFormatter));
                if (i != dataIndexList.Count - 1)
                {
                    sb.Append("\n");
                }
            }
        }
Пример #23
0
        private void DrawPieLabelLine(VertexHelper vh, Serie serie, SerieData serieData, Color color)
        {
            var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);

            if (serieLabel.show &&
                serieLabel.position == SerieLabel.Position.Outside &&
                serieLabel.line)
            {
                var insideRadius  = serieData.runtimePieInsideRadius;
                var outSideRadius = serieData.runtimePieOutsideRadius;
                var center        = serie.runtimeCenterPos;
                var currAngle     = serieData.runtimePieHalfAngle;
                if (!ChartHelper.IsClearColor(serieLabel.lineColor))
                {
                    color = serieLabel.lineColor;
                }
                else if (serieLabel.lineType == SerieLabel.LineType.HorizontalLine)
                {
                    color *= color;
                }
                float currSin = Mathf.Sin(currAngle * Mathf.Deg2Rad);
                float currCos = Mathf.Cos(currAngle * Mathf.Deg2Rad);
                var   radius1 = serieLabel.lineType == SerieLabel.LineType.HorizontalLine ?
                                serie.runtimeOutsideRadius : outSideRadius;
                var radius2 = serie.runtimeOutsideRadius + serieLabel.lineLength1;
                var radius3 = insideRadius + (outSideRadius - insideRadius) / 2;
                if (radius1 < serie.runtimeInsideRadius)
                {
                    radius1 = serie.runtimeInsideRadius;
                }
                radius1 -= 0.1f;
                var pos0 = new Vector3(center.x + radius3 * currSin, center.y + radius3 * currCos);
                var pos1 = new Vector3(center.x + radius1 * currSin, center.y + radius1 * currCos);
                var pos2 = serieData.labelPosition;
                if (pos2.x == 0)
                {
                    pos2 = new Vector3(center.x + radius2 * currSin, center.y + radius2 * currCos);
                }
                Vector3 pos4, pos6;
                var     horizontalLineCircleRadius = serieLabel.lineWidth * 4f;
                var     lineCircleDiff             = horizontalLineCircleRadius - 0.3f;
                if (currAngle < 90)
                {
                    var r4 = Mathf.Sqrt(radius1 * radius1 - Mathf.Pow(currCos * radius3, 2)) - currSin * radius3;
                    r4  += serieLabel.lineLength1 - lineCircleDiff;
                    pos6 = pos0 + Vector3.right * lineCircleDiff;
                    pos4 = pos6 + Vector3.right * r4;
                }
                else if (currAngle < 180)
                {
                    var r4 = Mathf.Sqrt(radius1 * radius1 - Mathf.Pow(currCos * radius3, 2)) - currSin * radius3;
                    r4  += serieLabel.lineLength1 - lineCircleDiff;
                    pos6 = pos0 + Vector3.right * lineCircleDiff;
                    pos4 = pos6 + Vector3.right * r4;
                }
                else if (currAngle < 270)
                {
                    var currSin1 = Mathf.Sin((360 - currAngle) * Mathf.Deg2Rad);
                    var currCos1 = Mathf.Cos((360 - currAngle) * Mathf.Deg2Rad);
                    var r4       = Mathf.Sqrt(radius1 * radius1 - Mathf.Pow(currCos1 * radius3, 2)) - currSin1 * radius3;
                    r4  += serieLabel.lineLength1 - lineCircleDiff;
                    pos6 = pos0 + Vector3.left * lineCircleDiff;
                    pos4 = pos6 + Vector3.left * r4;
                }
                else
                {
                    var currSin1 = Mathf.Sin((360 - currAngle) * Mathf.Deg2Rad);
                    var currCos1 = Mathf.Cos((360 - currAngle) * Mathf.Deg2Rad);
                    var r4       = Mathf.Sqrt(radius1 * radius1 - Mathf.Pow(currCos1 * radius3, 2)) - currSin1 * radius3;
                    r4  += serieLabel.lineLength1 - lineCircleDiff;
                    pos6 = pos0 + Vector3.left * lineCircleDiff;
                    pos4 = pos6 + Vector3.left * r4;
                }
                var pos5X = currAngle > 180 ? pos2.x - serieLabel.lineLength2 : pos2.x + serieLabel.lineLength2;
                var pos5  = new Vector3(pos5X, pos2.y);
                switch (serieLabel.lineType)
                {
                case SerieLabel.LineType.BrokenLine:
                    UGL.DrawLine(vh, pos1, pos2, pos5, serieLabel.lineWidth, color);
                    break;

                case SerieLabel.LineType.Curves:
                    UGL.DrawCurves(vh, pos1, pos5, pos1, pos2, serieLabel.lineWidth, color,
                                   chart.settings.lineSmoothness);
                    break;

                case SerieLabel.LineType.HorizontalLine:
                    UGL.DrawCricle(vh, pos0, horizontalLineCircleRadius, color);
                    UGL.DrawLine(vh, pos6, pos4, serieLabel.lineWidth, color);
                    break;
                }
            }
        }
Пример #24
0
        protected void DrawXBarSerie(VertexHelper vh, Serie serie, int colorIndex, ref List <float> seriesHig)
        {
            if (!IsActive(serie.index))
            {
                return;
            }
            if (serie.animation.HasFadeOut())
            {
                return;
            }
            var showData = serie.GetDataList(m_DataZoom);
            var yAxis    = m_YAxises[serie.axisIndex];
            var xAxis    = m_XAxises[serie.axisIndex];

            if (!xAxis.show)
            {
                xAxis = m_XAxises[(serie.axisIndex + 1) % m_XAxises.Count];
            }

            float categoryWidth = AxisHelper.GetDataWidth(xAxis, m_CoordinateWidth, showData.Count, m_DataZoom);
            float barGap        = GetBarGap();
            float totalBarWidth = GetBarTotalWidth(categoryWidth, barGap);
            float barWidth      = serie.GetBarWidth(categoryWidth);
            float offset        = (categoryWidth - totalBarWidth) / 2;
            float barGapWidth   = barWidth + barWidth * barGap;
            float space         = serie.barGap == -1 ? offset : offset + m_BarLastOffset;
            int   maxCount      = serie.maxShow > 0 ?
                                  (serie.maxShow > showData.Count ? showData.Count : serie.maxShow)
                : showData.Count;

            if (seriesHig.Count < serie.minShow)
            {
                for (int i = 0; i < serie.minShow; i++)
                {
                    seriesHig.Add(0);
                }
            }

            var   isPercentStack     = SeriesHelper.IsPercentStack(m_Series, serie.stack, SerieType.Bar);
            bool  dataChanging       = false;
            float dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
            float yMinValue          = yAxis.GetCurrMinValue(dataChangeDuration);
            float yMaxValue          = yAxis.GetCurrMaxValue(dataChangeDuration);

            for (int i = serie.minShow; i < maxCount; i++)
            {
                if (i >= seriesHig.Count)
                {
                    seriesHig.Add(0);
                }
                var serieData = showData[i];
                if (serie.IsIgnoreValue(serieData.GetData(1)))
                {
                    serie.dataPoints.Add(Vector3.zero);
                    continue;
                }
                var highlight = (m_Tooltip.show && m_Tooltip.IsSelected(i)) ||
                                serie.data[i].highlighted ||
                                serie.highlighted;
                var   itemStyle   = SerieHelper.GetItemStyle(serie, serieData, highlight);
                float value       = serieData.GetCurrData(1, dataChangeDuration, yAxis.inverse);
                float borderWidth = value == 0 ? 0 : itemStyle.runtimeBorderWidth;
                if (serieData.IsDataChanged())
                {
                    dataChanging = true;
                }
                float pX    = m_CoordinateX + i * categoryWidth;
                float zeroY = m_CoordinateY + yAxis.runtimeZeroYOffset;
                if (!xAxis.boundaryGap)
                {
                    pX -= categoryWidth / 2;
                }
                float axisLineWidth = (value < 0 ? -1 : 1) * xAxis.axisLine.width;
                float pY            = seriesHig[i] + zeroY + axisLineWidth;

                var barHig     = 0f;
                var valueTotal = 0f;
                if (isPercentStack)
                {
                    valueTotal    = GetSameStackTotalValue(serie.stack, i);
                    barHig        = valueTotal != 0 ? (value / valueTotal * m_CoordinateHeight) : 0;
                    seriesHig[i] += barHig;
                }
                else
                {
                    valueTotal = yMaxValue - yMinValue;
                    if (valueTotal != 0)
                    {
                        barHig = (yMinValue > 0 ? value - yMinValue : value)
                                 / valueTotal * m_CoordinateHeight;
                    }
                    seriesHig[i] += barHig;
                }
                float   currHig = CheckAnimation(serie, i, barHig);
                Vector3 plb, plt, prt, prb, top;
                if (value < 0)
                {
                    plb = new Vector3(pX + space + borderWidth, pY - borderWidth);
                    plt = new Vector3(pX + space + borderWidth, pY + currHig + borderWidth - axisLineWidth);
                    prt = new Vector3(pX + space + barWidth - borderWidth, pY + currHig + borderWidth - axisLineWidth);
                    prb = new Vector3(pX + space + barWidth - borderWidth, pY - borderWidth);
                }
                else
                {
                    plb = new Vector3(pX + space + borderWidth, pY + borderWidth);
                    plt = new Vector3(pX + space + borderWidth, pY + currHig - borderWidth - axisLineWidth);
                    prt = new Vector3(pX + space + barWidth - borderWidth, pY + currHig - borderWidth - axisLineWidth);
                    prb = new Vector3(pX + space + barWidth - borderWidth, pY + borderWidth);
                }
                top = new Vector3(pX + space + barWidth / 2, pY + currHig - borderWidth);
                if (serie.clip)
                {
                    plb = ClampInCoordinate(plb);
                    plt = ClampInCoordinate(plt);
                    prt = ClampInCoordinate(prt);
                    prb = ClampInCoordinate(prb);
                    top = ClampInCoordinate(top);
                }
                serie.dataPoints.Add(top);
                if (serie.show)
                {
                    switch (serie.barType)
                    {
                    case BarType.Normal:
                        DrawNormalBar(vh, serie, serieData, itemStyle, colorIndex, highlight, space, barWidth,
                                      pX, pY, plb, plt, prt, prb, false);
                        break;

                    case BarType.Zebra:
                        DrawZebraBar(vh, serie, serieData, itemStyle, colorIndex, highlight, space, barWidth,
                                     pX, pY, plb, plt, prt, prb, false);
                        break;

                    case BarType.Capsule:
                        DrawCapsuleBar(vh, serie, serieData, itemStyle, colorIndex, highlight, space, barWidth,
                                       pX, pY, plb, plt, prt, prb, false);
                        break;
                    }
                }
            }
            if (dataChanging)
            {
                RefreshChart();
            }
            if (!SeriesHelper.IsStack(m_Series, serie.stack, SerieType.Bar))
            {
                m_BarLastOffset += barGapWidth;
            }
        }
        private void DrawMarkLine(VertexHelper vh, Serie serie)
        {
            if (!serie.show || !serie.markLine.show)
            {
                return;
            }
            if (serie.markLine.data.Count == 0)
            {
                return;
            }
            var yAxis      = chart.GetSerieYAxisOrDefault(serie);
            var xAxis      = chart.GetSerieXAxisOrDefault(serie);
            var grid       = chart.GetSerieGridOrDefault(serie);
            var dataZoom   = DataZoomHelper.GetAxisRelatedDataZoom(xAxis, chart.dataZooms);
            var animation  = serie.markLine.animation;
            var showData   = serie.GetDataList(dataZoom);
            var sp         = Vector3.zero;
            var ep         = Vector3.zero;
            var colorIndex = chart.GetLegendRealShowNameIndex(serie.name);
            var serieColor = SerieHelper.GetLineColor(serie, chart.theme, colorIndex, false);

            animation.InitProgress(1, 0, 1f);
            ResetTempMarkLineGroupData(serie.markLine);
            if (m_TempGroupData.Count > 0)
            {
                foreach (var kv in m_TempGroupData)
                {
                    if (kv.Value.Count >= 2)
                    {
                        sp = GetSinglePos(xAxis, yAxis, grid, serie, dataZoom, kv.Value[0], showData.Count);
                        ep = GetSinglePos(xAxis, yAxis, grid, serie, dataZoom, kv.Value[1], showData.Count);
                        kv.Value[0].runtimeStartPosition = sp;
                        kv.Value[1].runtimeEndPosition   = ep;
                        DrawMakLineData(vh, kv.Value[0], animation, serie, grid, serieColor, sp, ep);
                    }
                }
            }
            foreach (var data in serie.markLine.data)
            {
                if (data.group != 0)
                {
                    continue;
                }
                switch (data.type)
                {
                case MarkLineType.Min:
                    data.runtimeValue = SerieHelper.GetMinData(serie, data.dimension, dataZoom);
                    GetStartEndPos(xAxis, yAxis, grid, data.runtimeValue, ref sp, ref ep);
                    break;

                case MarkLineType.Max:
                    data.runtimeValue = SerieHelper.GetMaxData(serie, data.dimension, dataZoom);
                    GetStartEndPos(xAxis, yAxis, grid, data.runtimeValue, ref sp, ref ep);
                    break;

                case MarkLineType.Average:
                    data.runtimeValue = SerieHelper.GetAverageData(serie, data.dimension, dataZoom);
                    GetStartEndPos(xAxis, yAxis, grid, data.runtimeValue, ref sp, ref ep);
                    break;

                case MarkLineType.Median:
                    data.runtimeValue = SerieHelper.GetMedianData(serie, data.dimension, dataZoom);
                    GetStartEndPos(xAxis, yAxis, grid, data.runtimeValue, ref sp, ref ep);
                    break;

                case MarkLineType.None:
                    if (data.xPosition != 0)
                    {
                        data.runtimeValue = data.xPosition;
                        var pX = grid.runtimeX + data.xPosition;
                        sp = new Vector3(pX, grid.runtimeY);
                        ep = new Vector3(pX, grid.runtimeY + grid.runtimeHeight);
                    }
                    else if (data.yPosition != 0)
                    {
                        data.runtimeValue = data.yPosition;
                        var pY = grid.runtimeY + data.yPosition;
                        sp = new Vector3(grid.runtimeX, pY);
                        ep = new Vector3(grid.runtimeX + grid.runtimeWidth, pY);
                    }
                    else if (data.yValue != 0)
                    {
                        data.runtimeValue = data.yValue;
                        if (yAxis.IsCategory())
                        {
                            var pY = AxisHelper.GetAxisPosition(grid, yAxis, data.yValue, showData.Count, dataZoom);
                            sp = new Vector3(grid.runtimeX, pY);
                            ep = new Vector3(grid.runtimeX + grid.runtimeWidth, pY);
                        }
                        else
                        {
                            GetStartEndPos(xAxis, yAxis, grid, data.yValue, ref sp, ref ep);
                        }
                    }
                    else
                    {
                        data.runtimeValue = data.xValue;
                        if (xAxis.IsCategory())
                        {
                            var pX = AxisHelper.GetAxisPosition(grid, xAxis, data.xValue, showData.Count, dataZoom);
                            sp = new Vector3(pX, grid.runtimeY);
                            ep = new Vector3(pX, grid.runtimeY + grid.runtimeHeight);
                        }
                        else
                        {
                            GetStartEndPos(xAxis, yAxis, grid, data.xValue, ref sp, ref ep);
                        }
                    }
                    break;

                default:
                    break;
                }
                data.runtimeStartPosition = sp;
                data.runtimeEndPosition   = ep;
                DrawMakLineData(vh, data, animation, serie, grid, serieColor, sp, ep);
            }
            if (!animation.IsFinish())
            {
                animation.CheckProgress(1f);
                chart.RefreshTopPainter();
            }
        }
Пример #26
0
        private void DrawNormalBar(VertexHelper vh, Serie serie, SerieData serieData, ItemStyle itemStyle, int colorIndex,
                                   bool highlight, float space, float barWidth, float pX, float pY, Vector3 plb, Vector3 plt, Vector3 prt,
                                   Vector3 prb, bool isYAxis)
        {
            Color areaColor   = SerieHelper.GetItemColor(serie, serieData, m_ThemeInfo, colorIndex, highlight);
            Color areaToColor = SerieHelper.GetItemToColor(serie, serieData, m_ThemeInfo, colorIndex, highlight);

            DrawBarBackground(vh, serie, serieData, itemStyle, colorIndex, highlight, pX, pY, space, barWidth, isYAxis);
            var borderWidth = itemStyle.runtimeBorderWidth;

            if (isYAxis)
            {
                if (serie.clip)
                {
                    prb = ClampInCoordinate(prb);
                    plb = ClampInCoordinate(plb);
                    plt = ClampInCoordinate(plt);
                    prt = ClampInCoordinate(prt);
                }
                var borderColor = itemStyle.borderColor;
                var itemWidth   = Mathf.Abs(prb.x - plt.x);
                var itemHeight  = Mathf.Abs(prt.y - plb.y);
                var center      = new Vector3((plt.x + prb.x) / 2, (prt.y + plb.y) / 2);
                if (itemWidth > 0 && itemHeight > 0)
                {
                    if (ItemStyleHelper.IsNeedCorner(itemStyle))
                    {
                        ChartDrawer.DrawRoundRectangle(vh, center, itemWidth, itemHeight, areaColor, areaToColor, 0, itemStyle.cornerRadius, isYAxis);
                    }
                    else
                    {
                        CheckClipAndDrawPolygon(vh, plb, plt, prt, prb, areaColor, areaToColor, serie.clip);
                    }
                    ChartDrawer.DrawBorder(vh, center, itemWidth, itemHeight, borderWidth, borderColor, 0, itemStyle.cornerRadius, isYAxis);
                }
            }
            else
            {
                if (serie.clip)
                {
                    prb = ClampInCoordinate(prb);
                    plb = ClampInCoordinate(plb);
                    plt = ClampInCoordinate(plt);
                    prt = ClampInCoordinate(prt);
                }
                var borderColor = itemStyle.borderColor;
                var itemWidth   = Mathf.Abs(prt.x - plb.x);
                var itemHeight  = Mathf.Abs(plt.y - prb.y);
                var center      = new Vector3((plb.x + prt.x) / 2, (plt.y + prb.y) / 2);
                if (itemWidth > 0 && itemHeight > 0)
                {
                    if (ItemStyleHelper.IsNeedCorner(itemStyle))
                    {
                        ChartDrawer.DrawRoundRectangle(vh, center, itemWidth, itemHeight, areaColor, areaToColor, 0, itemStyle.cornerRadius, isYAxis);
                    }
                    else
                    {
                        CheckClipAndDrawPolygon(vh, ref prb, ref plb, ref plt, ref prt, areaColor, areaToColor, serie.clip);
                    }
                    ChartDrawer.DrawBorder(vh, center, itemWidth, itemHeight, borderWidth, borderColor, 0, itemStyle.cornerRadius, isYAxis);
                }
            }
        }
Пример #27
0
 private float GetStartAngle(Serie serie)
 {
     return(serie.clockwise ? serie.startAngle : 360 - serie.startAngle);
 }
Пример #28
0
        private void DrawCapsuleBar(VertexHelper vh, Serie serie, SerieData serieData, ItemStyle itemStyle, int colorIndex,
                                    bool highlight, float space, float barWidth, float pX, float pY, Vector3 plb, Vector3 plt, Vector3 prt,
                                    Vector3 prb, bool isYAxis)
        {
            Color areaColor   = SerieHelper.GetItemColor(serie, serieData, m_ThemeInfo, colorIndex, highlight);
            Color areaToColor = SerieHelper.GetItemToColor(serie, serieData, m_ThemeInfo, colorIndex, highlight);

            DrawBarBackground(vh, serie, serieData, itemStyle, colorIndex, highlight, pX, pY, space, barWidth, isYAxis);
            var borderWidth = itemStyle.runtimeBorderWidth;
            var radius      = barWidth / 2 - borderWidth;
            var isGradient  = !ChartHelper.IsValueEqualsColor(areaColor, areaToColor);

            if (isYAxis)
            {
                var diff = Vector3.right * radius;
                if (plt.x < prt.x)
                {
                    var pcl = (plt + plb) / 2 + diff;
                    var pcr = (prt + prb) / 2 - diff;
                    if (pcr.x > pcl.x)
                    {
                        if (isGradient)
                        {
                            var barLen         = prt.x - plt.x;
                            var rectStartColor = Color.Lerp(areaColor, areaToColor, radius / barLen);
                            var rectEndColor   = Color.Lerp(areaColor, areaToColor, (barLen - radius) / barLen);
                            CheckClipAndDrawPolygon(vh, plb + diff, plt + diff, prt - diff, prb - diff, rectStartColor, rectEndColor, serie.clip);
                            ChartDrawer.DrawSector(vh, pcl, radius, areaColor, rectStartColor, 180, 360, 1, isYAxis);
                            ChartDrawer.DrawSector(vh, pcr, radius, rectEndColor, areaToColor, 0, 180, 1, isYAxis);
                        }
                        else
                        {
                            CheckClipAndDrawPolygon(vh, plb + diff, plt + diff, prt - diff, prb - diff, areaColor, areaToColor, serie.clip);
                            ChartDrawer.DrawSector(vh, pcl, radius, areaColor, 180, 360);
                            ChartDrawer.DrawSector(vh, pcr, radius, areaToColor, 0, 180);
                        }
                    }
                }
                else if (plt.x > prt.x)
                {
                    var pcl = (plt + plb) / 2 - diff;
                    var pcr = (prt + prb) / 2 + diff;
                    if (pcr.x < pcl.x)
                    {
                        if (isGradient)
                        {
                            var barLen         = plt.x - prt.x;
                            var rectStartColor = Color.Lerp(areaColor, areaToColor, radius / barLen);
                            var rectEndColor   = Color.Lerp(areaColor, areaToColor, (barLen - radius) / barLen);
                            CheckClipAndDrawPolygon(vh, plb - diff, plt - diff, prt + diff, prb + diff, rectStartColor, rectEndColor, serie.clip);
                            ChartDrawer.DrawSector(vh, pcl, radius, rectStartColor, areaColor, 0, 180, 1, isYAxis);
                            ChartDrawer.DrawSector(vh, pcr, radius, areaToColor, rectEndColor, 180, 360, 1, isYAxis);
                        }
                        else
                        {
                            CheckClipAndDrawPolygon(vh, plb - diff, plt - diff, prt + diff, prb + diff, areaColor, areaToColor, serie.clip);
                            ChartDrawer.DrawSector(vh, pcl, radius, areaColor, 0, 180);
                            ChartDrawer.DrawSector(vh, pcr, radius, areaToColor, 180, 360);
                        }
                    }
                }
            }
            else
            {
                var diff = Vector3.up * radius;
                if (plt.y > plb.y)
                {
                    var pct = (plt + prt) / 2 - diff;
                    var pcb = (plb + prb) / 2 + diff;
                    if (pct.y > pcb.y)
                    {
                        if (isGradient)
                        {
                            var barLen         = plt.y - plb.y;
                            var rectStartColor = Color.Lerp(areaColor, areaToColor, radius / barLen);
                            var rectEndColor   = Color.Lerp(areaColor, areaToColor, (barLen - radius) / barLen);
                            CheckClipAndDrawPolygon(vh, prb + diff, plb + diff, plt - diff, prt - diff, rectStartColor, rectEndColor, serie.clip);
                            ChartDrawer.DrawSector(vh, pct, radius, rectEndColor, areaToColor, 270, 450, 1, isYAxis);
                            ChartDrawer.DrawSector(vh, pcb, radius, rectStartColor, areaColor, 90, 270, 1, isYAxis);
                        }
                        else
                        {
                            CheckClipAndDrawPolygon(vh, prb + diff, plb + diff, plt - diff, prt - diff, areaColor, areaToColor, serie.clip);
                            ChartDrawer.DrawSector(vh, pct, radius, areaToColor, 270, 450);
                            ChartDrawer.DrawSector(vh, pcb, radius, areaColor, 90, 270);
                        }
                    }
                }
                else if (plt.y < plb.y)
                {
                    var pct = (plt + prt) / 2 + diff;
                    var pcb = (plb + prb) / 2 - diff;
                    if (pct.y < pcb.y)
                    {
                        if (isGradient)
                        {
                            var barLen         = plb.y - plt.y;
                            var rectStartColor = Color.Lerp(areaColor, areaToColor, radius / barLen);
                            var rectEndColor   = Color.Lerp(areaColor, areaToColor, (barLen - radius) / barLen);
                            CheckClipAndDrawPolygon(vh, prb - diff, plb - diff, plt + diff, prt + diff, rectStartColor, rectEndColor, serie.clip);
                            ChartDrawer.DrawSector(vh, pct, radius, rectEndColor, areaToColor, 90, 270, 1, isYAxis);
                            ChartDrawer.DrawSector(vh, pcb, radius, rectStartColor, areaColor, 270, 450, 1, isYAxis);
                        }
                        else
                        {
                            CheckClipAndDrawPolygon(vh, prb - diff, plb - diff, plt + diff, prt + diff, areaColor, areaToColor, serie.clip);
                            ChartDrawer.DrawSector(vh, pct, radius, areaToColor, 90, 270);
                            ChartDrawer.DrawSector(vh, pcb, radius, areaColor, 270, 450);
                        }
                    }
                }
            }
        }
Пример #29
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 = 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);
            }
        }
        protected void DrawScatterSerie(VertexHelper vh, int colorIndex, Serie serie)
        {
            var yAxis = m_YAxises[serie.axisIndex];
            var xAxis = m_XAxises[serie.axisIndex];
            var color = serie.symbol.color != Color.clear ? serie.symbol.color : (Color)m_ThemeInfo.GetColor(colorIndex);

            color.a *= serie.symbol.opacity;
            int maxCount = serie.maxShow > 0 ?
                           (serie.maxShow > serie.dataCount ? serie.dataCount : serie.maxShow)
                : serie.dataCount;

            serie.animation.InitProgress(1, 0, 1);
            var rate           = serie.animation.GetCurrRate();
            var updateDuration = serie.animation.GetUpdateAnimationDuration();
            var dataChanging   = false;

            for (int n = serie.minShow; n < maxCount; n++)
            {
                var   serieData = serie.GetDataList(m_DataZoom)[n];
                float xValue    = serieData.GetCurrData(0, updateDuration);
                float yValue    = serieData.GetCurrData(1, updateDuration);
                if (serieData.IsDataChanged())
                {
                    dataChanging = true;
                }
                float pX       = coordinateX + xAxis.axisLine.width;
                float pY       = coordinateY + yAxis.axisLine.width;
                float xDataHig = (xValue - xAxis.runtimeMinValue) / (xAxis.runtimeMaxValue - xAxis.runtimeMinValue) * coordinateWidth;
                float yDataHig = (yValue - yAxis.runtimeMinValue) / (yAxis.runtimeMaxValue - yAxis.runtimeMinValue) * coordinateHeight;
                var   pos      = new Vector3(pX + xDataHig, pY + yDataHig);

                var   datas      = serie.data[n].data;
                float symbolSize = 0;
                if (serie.highlighted || serieData.highlighted)
                {
                    symbolSize = serie.symbol.GetSelectedSize(datas);
                }
                else
                {
                    symbolSize = serie.symbol.GetSize(datas);
                }
                symbolSize *= rate;
                if (symbolSize > 100)
                {
                    symbolSize = 100;
                }
                if (serie.type == SerieType.EffectScatter)
                {
                    for (int count = 0; count < serie.symbol.animationSize.Count; count++)
                    {
                        var nowSize = serie.symbol.animationSize[count];
                        color.a = (symbolSize - nowSize) / symbolSize;
                        DrawSymbol(vh, serie.symbol.type, nowSize, 3, pos, color);
                    }
                    RefreshChart();
                }
                else
                {
                    DrawSymbol(vh, serie.symbol.type, symbolSize, 3, pos, color);
                }
            }
            if (!serie.animation.IsFinish())
            {
                float duration = serie.animation.duration > 0 ? (float)serie.animation.duration / 1000 : 1;
                float speed    = 1 / duration;
                serie.animation.CheckProgress(Time.deltaTime * speed);
                m_IsPlayingStartAnimation = true;
                RefreshChart();
            }
            if (dataChanging)
            {
                RefreshChart();
            }
        }