Ejemplo n.º 1
0
        private void DrawData(VertexHelper vh)
        {
            int     indicatorNum = radarInfo.indicatorList.Count;
            var     angle        = 2 * Mathf.PI / indicatorNum;
            var     p            = new Vector3(radarCenterX, radarCenterY);
            Vector3 startPoint   = Vector3.zero;
            Vector3 toPoint      = Vector3.zero;
            Vector3 firstPoint   = Vector3.zero;

            for (int i = 0; i < seriesList.Count; i++)
            {
                if (!legend.IsShowSeries(i))
                {
                    continue;
                }
                var dataList  = seriesList[i].dataList;
                var color     = themeInfo.GetColor(i);
                var areaColor = new Color(color.r, color.g, color.b, color.a * 0.7f);
                var max       = radarInfo.indicatorList[i].max > 0 ?
                                radarInfo.indicatorList[i].max :
                                GetMaxValue();
                List <Vector3> pointList = new List <Vector3>();
                for (int j = 0; j < dataList.Count; j++)
                {
                    var radius    = radarInfo.radius * dataList[j].value / max;
                    var currAngle = j * angle;
                    if (j == 0)
                    {
                        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 (radarInfo.area)
                        {
                            ChartUtils.DrawTriangle(vh, p, startPoint, toPoint, areaColor);
                        }
                        ChartUtils.DrawLine(vh, startPoint, toPoint, radarInfo.lineTickness, color);
                        startPoint = toPoint;
                    }
                    pointList.Add(startPoint);
                }
                if (radarInfo.area)
                {
                    ChartUtils.DrawTriangle(vh, p, startPoint, firstPoint, areaColor);
                }
                ChartUtils.DrawLine(vh, startPoint, firstPoint, radarInfo.lineTickness, color);
                foreach (var point in pointList)
                {
                    float radius = radarInfo.linePointSize - radarInfo.lineTickness * 2;

                    ChartUtils.DrawCricle(vh, point, radius, Color.white);
                    ChartUtils.DrawDoughnut(vh, point, radius, radarInfo.linePointSize, 0, 360, color);
                }
            }
        }
Ejemplo n.º 2
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);
        }