Ejemplo n.º 1
0
        private void DrawRadar(VertexHelper vh)
        {
            float   insideRadius = 0, outsideRadius = 0;
            float   block = radarInfo.radius / radarInfo.splitNumber;
            int     indicatorNum = radarInfo.indicatorList.Count;
            Vector3 p1, p2, p3, p4;
            Vector3 p     = new Vector3(radarCenterX, radarCenterY);
            float   angle = 2 * Mathf.PI / indicatorNum;

            for (int i = 0; i < radarInfo.splitNumber; i++)
            {
                Color color = radarInfo.backgroundColorList[i % radarInfo.backgroundColorList.Count];
                outsideRadius = insideRadius + block;
                p1            = new Vector3(p.x + insideRadius * Mathf.Sin(0), p.y + insideRadius * Mathf.Cos(0));
                p2            = new Vector3(p.x + outsideRadius * Mathf.Sin(0), p.y + outsideRadius * Mathf.Cos(0));
                for (int j = 0; j <= indicatorNum; j++)
                {
                    float currAngle = j * angle;
                    p3 = new Vector3(p.x + outsideRadius * Mathf.Sin(currAngle), p.y + outsideRadius * Mathf.Cos(currAngle));
                    p4 = new Vector3(p.x + insideRadius * Mathf.Sin(currAngle), p.y + insideRadius * Mathf.Cos(currAngle));

                    ChartUtils.DrawPolygon(vh, p1, p2, p3, p4, color);
                    ChartUtils.DrawLine(vh, p2, p3, radarInfo.lineTickness, radarInfo.lineColor);
                    p1 = p4;
                    p2 = p3;
                }
                insideRadius = outsideRadius;
            }
            for (int j = 0; j <= indicatorNum; j++)
            {
                float currAngle = j * angle;
                p3 = new Vector3(p.x + outsideRadius * Mathf.Sin(currAngle), p.y + outsideRadius * Mathf.Cos(currAngle));
                ChartUtils.DrawLine(vh, p, p3, radarInfo.lineTickness / 2, radarInfo.lineColor);
            }
        }
Ejemplo n.º 2
0
        private void DrawBackground(VertexHelper vh)
        {
            // draw bg
            Vector3 p1 = new Vector3(0, chartHig);
            Vector3 p2 = new Vector3(chartWid, chartHig);
            Vector3 p3 = new Vector3(chartWid, 0);
            Vector3 p4 = new Vector3(0, 0);

            ChartUtils.DrawPolygon(vh, p1, p2, p3, p4, themeInfo.backgroundColor);
        }
Ejemplo n.º 3
0
        protected override void DrawChart(VertexHelper vh)
        {
            base.DrawChart(vh);
            int seriesCount = seriesList.Count;

            Vector2 v2  = GetMaxAndMinValue();
            float   max = v2.x - v2.y;
            //float max = GetMaxValue();

            float minValue = v2.y;

            //draw tooltip line
            if (tooltip.show && tooltip.DataIndex > 0)
            {
                float   splitWid = coordinateWid / (xAxis.GetDataNumber() - 1);
                float   px       = zeroX + (tooltip.DataIndex - 1) * splitWid + (xAxis.boundaryGap ? splitWid / 2 : 0);
                Vector2 sp       = new Vector2(px, zeroY);
                Vector2 ep       = new Vector2(px, zeroY + coordinateHig);
                ChartUtils.DrawLine(vh, sp, ep, coordinate.tickness, themeInfo.tooltipFlagAreaColor);
            }

            DrawLine(vh, upper, new Color32(13, 217, 157, 255));
            DrawLine(vh, lower, new Color32(246, 72, 82, 255));

            float scaleWid = xAxis.GetDataWidth(coordinateWid);

            for (int j = 0; j < seriesCount; j++)
            {
                if (!legend.IsShowSeries(j))
                {
                    continue;
                }
                Series  series         = seriesList[j];
                Color32 color          = themeInfo.GetColor(j);
                Vector3 lp             = Vector3.zero;
                Vector3 np             = Vector3.zero;
                float   startX         = zeroX + (xAxis.boundaryGap ? scaleWid / 2 : 0);
                int     showDataNumber = series.showDataNumber;
                int     startIndex     = 0;
                if (series.showDataNumber > 0 && series.DataList.Count > series.showDataNumber)
                {
                    startIndex = series.DataList.Count - series.showDataNumber;
                }
                for (int i = startIndex; i < series.DataList.Count; i++)
                {
                    float value = series.DataList[i];

                    np = new Vector3(startX + i * scaleWid, zeroY + (value - minValue) * coordinateHig / max);
                    if (i > 0)
                    {
                        if (lineInfo.smooth)
                        {
                            var     list = ChartUtils.GetBezierList(lp, np, lineInfo.smoothStyle);
                            Vector3 start, to;
                            start = list[0];
                            for (int k = 1; k < list.Length; k++)
                            {
                                to = list[k];
                                ChartUtils.DrawLine(vh, start, to, lineInfo.tickness, color);
                                start = to;
                            }
                        }
                        else
                        {
                            ChartUtils.DrawLine(vh, lp, np, lineInfo.tickness, color);
                            if (lineInfo.area)
                            {
                                ChartUtils.DrawPolygon(vh, lp, np, new Vector3(np.x, zeroY),
                                                       new Vector3(lp.x, zeroY), color);
                            }
                        }
                    }
                    lp = np;
                }
                // draw point
                if (lineInfo.showPoint)
                {
                    for (int i = 0; i < series.DataList.Count; i++)
                    {
                        float value = series.DataList[i];

                        Vector3 p = new Vector3(startX + i * scaleWid,
                                                zeroY + (value - minValue) * coordinateHig / max);
                        float pointWid = lineInfo.pointWid;
                        if (tooltip.show && i == tooltip.DataIndex - 1)
                        {
                            pointWid = pointWid * 5f;
                        }
                        if (theme == Theme.Dark)
                        {
                            ChartUtils.DrawCricle(vh, p, pointWid, color,
                                                  (int)lineInfo.pointWid * 5);
                        }
                        else
                        {
                            ChartUtils.DrawCricle(vh, p, pointWid, color);
                            //ChartUtils.DrawDoughnut(vh, p, pointWid - lineInfo.tickness,
                            //pointWid, 0, 360, color);
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
 protected override void DrawChart(VertexHelper vh)
 {
     base.DrawChart(vh);
     if (yAxis.type == AxisType.category)
     {
         int   seriesCount = seriesList.Count;
         float scaleWid    = yAxis.GetDataWidth(coordinateHig);
         float barWid      = barInfo.barWid > 1 ? barInfo.barWid : scaleWid * barInfo.barWid;
         float offset      = (scaleWid - barWid * seriesCount - barInfo.space * (seriesCount - 1)) / 2;
         float max         = GetMaxValue();
         if (tooltip.show && tooltip.DataIndex > 0)
         {
             float   pX = zeroX + coordinateWid;
             float   pY = zeroY + scaleWid * (tooltip.DataIndex - 1);
             Vector3 p1 = new Vector3(zeroX, pY);
             Vector3 p2 = new Vector3(zeroX, pY + scaleWid);
             Vector3 p3 = new Vector3(pX, pY + scaleWid);
             Vector3 p4 = new Vector3(pX, pY);
             ChartUtils.DrawPolygon(vh, p1, p2, p3, p4, themeInfo.tooltipFlagAreaColor);
         }
         for (int j = 0; j < seriesCount; j++)
         {
             if (!legend.IsShowSeries(j))
             {
                 continue;
             }
             Series series     = seriesList[j];
             Color  color      = themeInfo.GetColor(j);
             int    startIndex = 0;
             if (series.showDataNumber > 0 && series.DataList.Count > series.showDataNumber)
             {
                 startIndex = series.DataList.Count - series.showDataNumber;
             }
             for (int i = startIndex; i < series.DataList.Count; i++)
             {
                 float data = series.DataList[i];
                 float pX   = zeroX + coordinate.tickness;
                 float pY   = zeroY + i * scaleWid;
                 if (!yAxis.boundaryGap)
                 {
                     pY -= scaleWid / 2;
                 }
                 float   barHig = data / max * coordinateWid;
                 float   space  = offset + j * (barWid + barInfo.space);
                 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);
                 ChartUtils.DrawPolygon(vh, p1, p2, p3, p4, color);
             }
         }
     }
     else
     {
         int   seriesCount = seriesList.Count;
         float scaleWid    = xAxis.GetDataWidth(coordinateWid);
         float barWid      = barInfo.barWid > 1 ? barInfo.barWid : scaleWid * barInfo.barWid;
         float offset      = (scaleWid - barWid * seriesCount - barInfo.space * (seriesCount - 1)) / 2;
         float max         = GetMaxValue();
         if (tooltip.show && tooltip.DataIndex > 0)
         {
             float   tooltipSplitWid = scaleWid < 1 ? 1 : scaleWid;
             float   pX = zeroX + scaleWid * (tooltip.DataIndex - 1);
             float   pY = zeroY + coordinateHig;
             Vector3 p1 = new Vector3(pX, zeroY);
             Vector3 p2 = new Vector3(pX, pY);
             Vector3 p3 = new Vector3(pX + tooltipSplitWid, pY);
             Vector3 p4 = new Vector3(pX + tooltipSplitWid, zeroY);
             ChartUtils.DrawPolygon(vh, p1, p2, p3, p4, themeInfo.tooltipFlagAreaColor);
         }
         for (int j = 0; j < seriesCount; j++)
         {
             if (!legend.IsShowSeries(j))
             {
                 continue;
             }
             Series series     = seriesList[j];
             Color  color      = themeInfo.GetColor(j);
             int    startIndex = 0;
             if (series.showDataNumber > 0 && series.DataList.Count > series.showDataNumber)
             {
                 startIndex = series.DataList.Count - series.showDataNumber;
             }
             for (int i = startIndex; i < series.DataList.Count; i++)
             {
                 float data = series.DataList[i];
                 float pX   = zeroX + i * scaleWid;
                 if (!xAxis.boundaryGap)
                 {
                     pX -= scaleWid / 2;
                 }
                 float   pY     = zeroY + coordinate.tickness;
                 float   barHig = data / max * coordinateHig;
                 float   space  = offset + j * (barWid + barInfo.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);
                 ChartUtils.DrawPolygon(vh, p1, p2, p3, p4, color);
             }
         }
     }
 }
Ejemplo n.º 5
0
        protected override void OnPopulateMesh(VertexHelper vh)
        {
            vh.Clear();
            int   dataRectWid = (int)(chartWid / pointWidth) * pointWidth;
            float dataMax     = GetAllLineMax();
            // draw bg
            Vector3 p1 = new Vector3(-graduationWidth, chartHig + 30);
            Vector3 p2 = new Vector3(dataRectWid + 50, chartHig + 30);
            Vector3 p3 = new Vector3(dataRectWid + 50, -20);
            Vector3 p4 = new Vector3(-graduationWidth, -20);

            ChartUtils.DrawPolygon(vh, p1, p2, p3, p4, backgroundColor);
            // draw coordinate
            Vector3 coordZero = Vector3.zero;

            ChartUtils.DrawLine(vh, new Vector3(dataRectWid + 5, -5),
                                new Vector3(dataRectWid + 5, chartHig + 0.5f), 1, Color.grey);
            // draw graduation
            for (int i = 0; i < graduationList.Count; i++)
            {
                Vector3 sp = new Vector3(-5, chartHig * i / (graduationList.Count - 1));
                Vector3 ep = new Vector3(dataRectWid + 5, chartHig * i / (graduationList.Count - 1));
                ChartUtils.DrawLine(vh, sp, ep, 0.5f, Color.grey);
            }

            // draw line
            for (int index = 0; index < lineList.Count; index++)
            {
                LineData_old line = lineList[index];
                if (!line.visible)
                {
                    continue;
                }
                Vector3 lp = Vector3.zero;
                Vector3 np = Vector3.zero;

                for (int i = 0; i < line.dataList.Count; i++)
                {
                    float data = line.dataList[i] * chartHig / dataMax;
                    np = new Vector3(i * pointWidth, data);
                    if (i > 0)
                    {
                        ChartUtils.DrawLine(vh, lp, np, lineSize, line.lineColor);
                    }
                    lp = np;
                }

                // draw point
                for (int i = 0; i < line.dataList.Count; i++)
                {
                    UIVertex[] quadverts = new UIVertex[4];
                    float      data      = line.dataList[i] * chartHig / dataMax;
                    Vector3    p         = new Vector3(i * pointWidth, data);
                    ChartUtils.DrawPolygon(vh, p, pointSize, line.pointColor);
                }
            }

            //draw x,y axis
            float xLen = dataRectWid + 25;
            float yLen = chartHig + 15;
            float xPos = 0;
            float yPos = -5;

            ChartUtils.DrawLine(vh, new Vector3(xPos, yPos - 1.5f), new Vector3(xPos, yLen), 1.5f, Color.white);
            ChartUtils.DrawLine(vh, new Vector3(xPos, yPos), new Vector3(xLen, yPos), 1.5f, Color.white);
            //draw arrows
            ChartUtils.DrawTriangle(vh, new Vector3(xPos - arrowSize, yLen - arrowLen), new Vector3(xPos, yLen + 4),
                                    new Vector3(xPos + arrowSize, yLen - arrowLen), Color.white);
            ChartUtils.DrawTriangle(vh, new Vector3(xLen - arrowLen, yPos + arrowSize), new Vector3(xLen + 4, yPos),
                                    new Vector3(xLen - arrowLen, yPos - arrowSize), Color.white);
        }
Ejemplo n.º 6
0
        void DrawLineChart(VertexHelper vh)
        {
            if (Mode == ChartMode.Bar)
            {
                return;
            }
            int seriesCount = seriesList.Count;

            Vector2 v2  = GetMaxAndMinValue();
            float   max = v2.x - v2.y;
            //float max = GetMaxValue();

            float minValue = v2.y;

            float scaleWid = xAxis.GetDataWidth(coordinateWid);
            int   num      = Mode == ChartMode.Mixed?1:0;

            for (int j = num; j < seriesCount; j++)
            {
                if (!legend.IsShowSeries(j))
                {
                    continue;
                }
                Series  series         = seriesList[j];
                Color32 color          = themeInfo.GetColor(j);
                Vector3 lp             = Vector3.zero;
                Vector3 np             = Vector3.zero;
                float   startX         = zeroX + (xAxis.boundaryGap ? scaleWid / 2 : 0);
                int     showDataNumber = series.showDataNumber;
                int     startIndex     = 0;
                if (series.showDataNumber > 0 && series.DataList.Count > series.showDataNumber)
                {
                    startIndex = series.DataList.Count - series.showDataNumber;
                }
                for (int i = startIndex; i < series.DataList.Count; i++)
                {
                    float value = series.DataList[i];

                    np = new Vector3(startX + i * scaleWid, zeroY + (value - minValue) * coordinateHig / max);
                    if (i > 0)
                    {
                        if (lineInfo.smooth)
                        {
                            var     list = ChartUtils.GetBezierList(lp, np, lineInfo.smoothStyle);
                            Vector3 start, to;
                            start = list[0];
                            for (int k = 1; k < list.Length; k++)
                            {
                                to = list[k];
                                ChartUtils.DrawLine(vh, start, to, lineInfo.tickness, color);
                                start = to;
                            }
                        }
                        else
                        {
                            ChartUtils.DrawLine(vh, lp, np, lineInfo.tickness, color);
                            if (lineInfo.area)
                            {
                                ChartUtils.DrawPolygon(vh, lp, np, new Vector3(np.x, zeroY),
                                                       new Vector3(lp.x, zeroY), color);
                            }
                        }
                    }
                    lp = np;
                }
                // draw point
                if (lineInfo.showPoint)
                {
                    for (int i = num; i < series.DataList.Count; i++)
                    {
                        float value = series.DataList[i];

                        Vector3 p = new Vector3(startX + i * scaleWid,
                                                zeroY + (value - minValue) * coordinateHig / max);
                        float pointWid = lineInfo.pointWid;
                        if (tooltip.show && i == tooltip.DataIndex - 1)
                        {
                            pointWid = pointWid * 1.8f;
                        }
                        if (theme == Theme.Dark)
                        {
                            ChartUtils.DrawCricle(vh, p, pointWid, color,
                                                  (int)lineInfo.pointWid * 5);
                        }
                        else
                        {
                            ChartUtils.DrawCricle(vh, p, pointWid, Color.white);
                            ChartUtils.DrawDoughnut(vh, p, pointWid - lineInfo.tickness,
                                                    pointWid, 0, 360, color);
                        }
                    }
                }
            }
        }
Ejemplo n.º 7
0
        protected override void OnPopulateMesh(VertexHelper vh)
        {
            base.OnPopulateMesh(vh);

            if (yAxis.type == AxisType.category)
            {
                int   seriesCount = seriesList.Count;
                float scaleWid    = coordinateHig / (yAxis.splitNumber - 1);
                float barWid      = barInfo.barWid > 1 ? barInfo.barWid : scaleWid * barInfo.barWid;
                float offset      = (scaleWid - barWid * seriesCount - barInfo.space * (seriesCount - 1)) / 2;
                float max         = GetMaxValue();
                for (int j = 0; j < seriesCount; j++)
                {
                    if (!legend.IsShowSeries(j))
                    {
                        continue;
                    }
                    Series series     = seriesList[j];
                    Color  color      = themeInfo.GetColor(j);
                    int    startIndex = 0;
                    if (series.showDataNumber > 0 && series.dataList.Count > series.showDataNumber)
                    {
                        startIndex = series.dataList.Count - series.showDataNumber;
                    }
                    for (int i = startIndex; i < series.dataList.Count; i++)
                    {
                        SeriesData data = series.dataList[i];
                        float      pX   = zeroX + coordinate.tickness;
                        float      pY   = zeroY + i * coordinateHig / (yAxis.splitNumber - 1);
                        if (!yAxis.boundaryGap)
                        {
                            pY -= scaleWid / 2;
                        }
                        float   barHig = data.value / max * coordinateWid;
                        float   space  = offset + j * (barWid + barInfo.space);
                        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);
                        ChartUtils.DrawPolygon(vh, p1, p2, p3, p4, color);
                    }
                }
            }
            else
            {
                int   seriesCount = seriesList.Count;
                float scaleWid    = coordinateWid / (xAxis.splitNumber - 1);
                float barWid      = barInfo.barWid > 1 ? barInfo.barWid : scaleWid * barInfo.barWid;
                float offset      = (scaleWid - barWid * seriesCount - barInfo.space * (seriesCount - 1)) / 2;
                float max         = GetMaxValue();
                for (int j = 0; j < seriesCount; j++)
                {
                    if (!legend.IsShowSeries(j))
                    {
                        continue;
                    }
                    Series series     = seriesList[j];
                    Color  color      = themeInfo.GetColor(j);
                    int    startIndex = 0;
                    if (series.showDataNumber > 0 && series.dataList.Count > series.showDataNumber)
                    {
                        startIndex = series.dataList.Count - series.showDataNumber;
                    }
                    for (int i = startIndex; i < series.dataList.Count; i++)
                    {
                        SeriesData data = series.dataList[i];
                        float      pX   = zeroX + i * coordinateWid / (xAxis.splitNumber - 1);
                        if (!xAxis.boundaryGap)
                        {
                            pX -= scaleWid / 2;
                        }
                        float   pY     = zeroY + coordinate.tickness;
                        float   barHig = data.value / max * coordinateHig;
                        float   space  = offset + j * (barWid + barInfo.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);
                        ChartUtils.DrawPolygon(vh, p1, p2, p3, p4, color);
                    }
                }
            }
        }
Ejemplo n.º 8
0
        protected override void OnPopulateMesh(VertexHelper vh)
        {
            base.OnPopulateMesh(vh);
            int   seriesCount = seriesList.Count;
            float max         = GetMaxValue();
            float scaleWid    = coordinateWid / (xAxis.splitNumber - 1);

            for (int j = 0; j < seriesCount; j++)
            {
                if (!legend.IsShowSeries(j))
                {
                    continue;
                }
                Series  series         = seriesList[j];
                Color   color          = themeInfo.GetColor(j);
                Vector3 lp             = Vector3.zero;
                Vector3 np             = Vector3.zero;
                float   startX         = zeroX + (xAxis.boundaryGap ? scaleWid / 2 : 0);
                int     showDataNumber = series.showDataNumber;
                int     startIndex     = 0;
                if (series.showDataNumber > 0 && series.dataList.Count > series.showDataNumber)
                {
                    startIndex = series.dataList.Count - series.showDataNumber;
                }
                for (int i = startIndex; i < series.dataList.Count; i++)
                {
                    SeriesData data = series.dataList[i];

                    np = new Vector3(startX + i * scaleWid, zeroY + data.value * coordinateHig / max);
                    if (i > 0)
                    {
                        if (lineInfo.smooth)
                        {
                            var     list = ChartUtils.GetBezierList(lp, np, lineInfo.smoothStyle);
                            Vector3 start, to;
                            start = list[0];
                            for (int k = 1; k < list.Count; k++)
                            {
                                to = list[k];
                                ChartUtils.DrawLine(vh, start, to, lineInfo.tickness, color);
                                start = to;
                            }
                        }
                        else
                        {
                            ChartUtils.DrawLine(vh, lp, np, lineInfo.tickness, color);
                            if (lineInfo.area)
                            {
                                ChartUtils.DrawPolygon(vh, lp, np, new Vector3(np.x, zeroY),
                                                       new Vector3(lp.x, zeroY), color);
                            }
                        }
                    }
                    lp = np;
                }
                // draw point
                if (lineInfo.showPoint)
                {
                    for (int i = 0; i < series.dataList.Count; i++)
                    {
                        SeriesData data = series.dataList[i];

                        Vector3 p = new Vector3(startX + i * scaleWid,
                                                zeroY + data.value * coordinateHig / max);
                        if (theme == Theme.Dark)
                        {
                            ChartUtils.DrawCricle(vh, p, lineInfo.pointWid, color,
                                                  (int)lineInfo.pointWid * 5);
                        }
                        else
                        {
                            ChartUtils.DrawCricle(vh, p, lineInfo.pointWid, Color.white);
                            ChartUtils.DrawDoughnut(vh, p, lineInfo.pointWid - lineInfo.tickness,
                                                    lineInfo.pointWid, 0, 360, color);
                        }
                    }
                }
            }
        }