Exemple #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);
            }
        }
Exemple #2
0
        private void DrawCricleRadar(VertexHelper vh)
        {
            float   insideRadius = 0, outsideRadius = 0;
            float   block        = radarInfo.radius / radarInfo.splitNumber;
            int     indicatorNum = radarInfo.indicatorList.Count;
            Vector3 p            = new Vector3(radarCenterX, radarCenterY);
            Vector3 p1;
            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;
                ChartUtils.DrawDoughnut(vh, p, insideRadius, outsideRadius, 0, 360, color);
                ChartUtils.DrawCicleNotFill(vh, p, outsideRadius, radarInfo.lineTickness,
                                            radarInfo.lineColor);
                insideRadius = outsideRadius;
            }
            for (int j = 0; j <= indicatorNum; j++)
            {
                float currAngle = j * angle;
                p1 = new Vector3(p.x + outsideRadius * Mathf.Sin(currAngle),
                                 p.y + outsideRadius * Mathf.Cos(currAngle));
                ChartUtils.DrawLine(vh, p, p1, radarInfo.lineTickness / 2, radarInfo.lineColor);
            }
        }
Exemple #3
0
        protected override void OnPopulateMesh(VertexHelper vh)
        {
            if (dataList == null)
            {
                return;
            }

            base.OnPopulateMesh(vh);
            UpdatePieCenter();

            float totalDegree = 360;
            float startDegree = 0;
            float dataTotal   = GetDataTotal();
            float dataMax     = GetDataMax();

            for (int i = 0; i < dataList.Count; i++)
            {
                if (!legend.IsShowSeries(i))
                {
                    continue;
                }
                float value    = dataList[i].value;
                float degree   = totalDegree * value / dataTotal;
                float toDegree = startDegree + degree;

                float outSideRadius = pieInfo.outsideRadiusDynamic ?
                                      pieInfo.insideRadius + (pieRadius - pieInfo.insideRadius) * value / dataMax :
                                      pieRadius;
                ChartUtils.DrawDoughnut(vh, new Vector3(pieCenterX, pieCenterY), pieInfo.insideRadius,
                                        outSideRadius, startDegree, toDegree, themeInfo.GetColor(i));
                startDegree = toDegree;
            }
        }
Exemple #4
0
        protected override void DrawChart(VertexHelper vh)
        {
            base.DrawChart(vh);
            UpdatePieCenter();
            float totalDegree = 360;
            float startDegree = 0;
            float dataTotal   = GetDataTotal();
            float dataMax     = GetDataMax();

            angleList.Clear();
            for (int i = 0; i < seriesList.Count; i++)
            {
                if (!legend.IsShowSeries(i))
                {
                    angleList.Add(0);
                    continue;
                }
                float value    = seriesList[i].DataList[0];
                float degree   = totalDegree * value / dataTotal;
                float toDegree = startDegree + degree;

                float outSideRadius = pieInfo.outsideRadiusDynamic ?
                                      pieInfo.insideRadius + (pieRadius - pieInfo.insideRadius) * value / dataMax :
                                      pieRadius;
                if (tooltip.show && tooltip.DataIndex == i + 1)
                {
                    outSideRadius += pieInfo.tooltipExtraRadius;
                }
                ChartUtils.DrawDoughnut(vh, pieCenter, pieInfo.insideRadius,
                                        outSideRadius, startDegree, toDegree, themeInfo.GetColor(i));
                angleList.Add(toDegree);
                startDegree = toDegree;
            }
        }
Exemple #5
0
        protected override Vector2 GetMaxAndMinValue()
        {
            float max = 0, min = 0;

            for (int i = 0; i < seriesList.Count; i++)
            {
                if (legend.IsShowSeries(i) && seriesList[i].Max > max)
                {
                    max = seriesList[i].Max;
                }
                if (legend.IsShowSeries(i) && seriesList[i].Min < min)
                {
                    min = seriesList[i].Min;
                }
            }

            if (!float.IsNaN(upper))
            {
                max = upper > max ? upper : max;
            }
            if (!float.IsNaN(lower))
            {
                min = lower < min ? lower : min;
            }

            Vector2 v2 = ChartUtils.MagicNumbers(max, min);

            //if (v2.x < 5) v2.x = 5;
            //if (v2.y < 0 && v2.y > -5) v2.y = -5;
            return(v2);
        }
Exemple #6
0
 protected virtual void InitLegend()
 {
     for (int i = 0; i < legend.dataList.Count; i++)
     {
         //LegendData data = legend.dataList[i];
         Button btn = ChartUtils.AddButtonObject(LEGEND_TEXT + "_" + i, transform, themeInfo.font,
                                                 themeInfo.textColor, Vector2.zero, Vector2.zero, Vector2.zero,
                                                 new Vector2(legend.itemWidth, legend.itemHeight));
         legend.SetDataButton(i, btn);
         Color bcolor = themeInfo.GetColor(i);
         btn.gameObject.SetActive(legend.show);
         btn.transform.localPosition              = GetLegendPosition(i);
         btn.GetComponent <Image>().color         = bcolor;
         btn.GetComponentInChildren <Text>().text = legend.dataList[i];
         btn.onClick.AddListener(delegate() {
             int index = int.Parse(btn.name.Split('_')[1]);
             legend.SetShowData(index, !legend.IsShowSeries(index));
             btn.GetComponent <Image>().color = legend.IsShowSeries(index) ?
                                                themeInfo.GetColor(index) : themeInfo.unableColor;
             OnYMaxValueChanged();
             OnLegendButtonClicked();
             RefreshChart();
         });
     }
 }
Exemple #7
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);
                }
            }
        }
Exemple #8
0
        private void InitIndicator()
        {
            indicatorTextList.Clear();
            HideChild(INDICATOR_TEXT);
            int   indicatorNum = radarInfo.indicatorList.Count;
            float txtWid       = 150;
            float txtHig       = 35;
            var   txtColor     = themeInfo.GetColor(0);

            for (int i = 0; i < indicatorNum; i++)
            {
                var        pos    = GetIndicatorPosition(i);
                TextAnchor anchor = TextAnchor.MiddleCenter;
                var        diff   = pos.x - radarCenterX;
                if (diff < -1f)
                {
                    var posY = pos.y;
                    if (pos.y > radarCenterY)
                    {
                        posY += 10;
                    }
                    else if (pos.y < radarCenterY)
                    {
                        posY -= 10;
                    }
                    pos    = new Vector3(pos.x - 20, posY);
                    anchor = TextAnchor.MiddleRight;
                }
                else if (diff > 1f)
                {
                    var posY = pos.y;
                    if (pos.y > radarCenterY)
                    {
                        posY += 10;
                    }
                    else if (pos.y < radarCenterY)
                    {
                        posY -= 10;
                    }
                    anchor = TextAnchor.MiddleLeft;
                    pos    = new Vector3(pos.x + txtWid + 20, posY);
                }
                else
                {
                    anchor = pos.y > radarCenterY ? TextAnchor.LowerCenter : TextAnchor.UpperCenter;
                    float y = pos.y > radarCenterY ? pos.y + txtHig / 2 : pos.y - txtHig / 2;
                    pos = new Vector3(pos.x + txtWid / 2, y + (pos.y > radarCenterY ? 20 : -20));
                }

                Text txt = ChartUtils.AddTextObject(INDICATOR_TEXT + i, transform, themeInfo.font,
                                                    themeInfo.textColor, anchor, Vector2.zero, Vector2.zero, new Vector2(1, 0.5f),
                                                    new Vector2(txtWid, txtHig), themeInfo.fontsize);
                txt.transform.localPosition = pos;
                txt.text = radarInfo.indicatorList[i].name;
                txt.gameObject.SetActive(radarInfo.showIndicator);
                txt.color = txtColor;
                indicatorTextList.Add(txt);
            }
        }
Exemple #9
0
        private void InitTooltip()
        {
            GameObject obj = ChartUtils.AddTooltipObject("tooltip", transform, themeInfo.font);

            tooltip.SetObj(obj);
            tooltip.SetBackgroundColor(themeInfo.tooltipBackgroundColor);
            tooltip.SetTextColor(themeInfo.tooltipTextColor);
            tooltip.SetActive(false);
        }
Exemple #10
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);
        }
Exemple #11
0
        public void DrawLine(VertexHelper vh, float value, Color color)
        {
            float   y        = GetPostionY(value);
            float   scaleWid = xAxis.GetDataWidth(coordinateWid);
            float   startX   = zeroX + (xAxis.boundaryGap ? scaleWid / 2 : 0);
            Vector3 start    = new Vector3(startX + 0 * scaleWid, y);
            Vector3 to       = new Vector3(startX + (seriesList[0].DataList.Count - 1) * scaleWid, y);

            ChartUtils.DrawLine(vh, start, to, lineInfo.tickness * 0.5f, color);
        }
        protected override void DrawCoordinate(VertexHelper vh)
        {
            if (!coordinate.show)
            {
                return;
            }
            // draw splitline
            for (int i = 1; i < yAxis.GetScaleNumber(); i++)
            {
                float pX = zeroX - coordinate.splitWidth;
                float pY = zeroY + i * coordinateHig / (yAxis.GetScaleNumber() - 1);
                ChartUtils.DrawLine(vh, new Vector3(pX, pY), new Vector3(zeroX, pY), coordinate.tickness,
                                    themeInfo.axisLineColor);
                if (yAxis.showSplitLine)
                {
                    DrawSplitLine(vh, true, yAxis.splitLineType, new Vector3(zeroX, pY),
                                  new Vector3(zeroX + coordinateWid, pY));
                }
            }
            for (int i = 1; i < xAxis.GetScaleNumber(); i++)
            {
                float pX = zeroX + i * coordinateWid / (xAxis.GetScaleNumber() - 1);
                float pY = zeroY - coordinate.splitWidth - 2;
                ChartUtils.DrawLine(vh, new Vector3(pX, zeroY), new Vector3(pX, pY), coordinate.tickness,
                                    themeInfo.axisLineColor);
                if (xAxis.showSplitLine)
                {
                    DrawSplitLine(vh, false, xAxis.splitLineType, new Vector3(pX, zeroY),
                                  new Vector3(pX, zeroY + coordinateHig));
                }
            }

            for (int i = 1; i < yAxis.GetScaleNumber(); i++)
            {
                float pX = zeroX + coordinateWid;
                float pY = zeroY + i * coordinateHig / (yAxis.GetScaleNumber() - 1);
                ChartUtils.DrawLine(vh, new Vector3(pX, pY), new Vector3(pX + coordinate.splitWidth, pY), coordinate.tickness,
                                    themeInfo.axisLineColor);
            }

            ChartUtils.DrawLine(vh, new Vector3(zeroX, zeroY - coordinate.splitWidth),
                                new Vector3(zeroX, zeroY + coordinateHig + 2), coordinate.tickness,
                                themeInfo.axisLineColor);
            ChartUtils.DrawLine(vh, new Vector3(zeroX - coordinate.splitWidth, zeroY),
                                new Vector3(zeroX + coordinateWid + 5, zeroY), coordinate.tickness,
                                themeInfo.axisLineColor);


            ChartUtils.DrawLine(vh, new Vector3(zeroX + coordinateWid, zeroY - coordinate.splitWidth),
                                new Vector3(zeroX + coordinateWid, zeroY + coordinateHig + 2), coordinate.tickness,
                                themeInfo.axisLineColor);
        }
Exemple #13
0
        private void InitTitle()
        {
            TextAnchor anchor    = TextAnchor.MiddleCenter;
            Vector2    anchorMin = new Vector2(0, 0);
            Vector2    anchorMax = new Vector2(0, 0);
            Vector3    titlePosition;
            float      titleWid = 200;
            float      titleHig = 20;

            switch (title.align)
            {
            case Align.left:
                anchor        = TextAnchor.MiddleLeft;
                titlePosition = new Vector3(title.left, chartHig - title.top, 0);
                break;

            case Align.right:
                anchor        = TextAnchor.MiddleRight;
                titlePosition = new Vector3(chartWid - title.right - titleWid,
                                            chartHig - title.top, 0);
                break;

            case Align.center:
                anchor        = TextAnchor.MiddleCenter;
                titlePosition = new Vector3(chartWid / 2 - titleWid / 2, chartHig - title.top, 0);
                break;

            default:
                anchor        = TextAnchor.MiddleCenter;
                titlePosition = new Vector3(0, -title.top, 0);
                break;
            }
            Text titleText = ChartUtils.AddTextObject(TILTE_TEXT, transform, themeInfo.font,
                                                      themeInfo.textColor, anchor, anchorMin, anchorMax, new Vector2(0, 1),
                                                      new Vector2(titleWid, titleHig), 16);

            titleText.alignment = anchor;
            titleText.gameObject.SetActive(title.show);
            titleText.transform.localPosition = titlePosition;
            titleText.text = title.text;

            Text subText = ChartUtils.AddTextObject(SUB_TILTE_TEXT, transform, themeInfo.font,
                                                    themeInfo.textColor, anchor, anchorMin, anchorMax, new Vector2(0, 1),
                                                    new Vector2(titleWid, titleHig), 14);

            subText.alignment = anchor;
            subText.gameObject.SetActive(title.show && !string.IsNullOrEmpty(title.subText));
            subText.transform.localPosition = titlePosition - new Vector3(0, 15, 0);
            subText.text = title.subText;
        }
 private void InitLineButton()
 {
     for (int i = 0; i < lineList.Count; i++)
     {
         if (lineList[i].button)
         {
             continue;
         }
         Button btn = ChartUtils.AddButtonObject("button" + i, transform, font, Vector2.zero,
                                                 Vector2.zero, Vector2.zero, new Vector2(50, 20));
         btn.transform.localPosition = new Vector3(i * 50, chartHig + 30, 0);
         lineList[i].button          = btn;
     }
 }
        protected override void InitYScale()
        {
            if (seriesList.Count == 0)
            {
                return;
            }
            foreach (var item in yScaleTextList)
            {
                item.text = string.Empty;
            }

            yScaleTextList.Clear();
            float max      = GetMaxValue();
            float scaleWid = yAxis.GetScaleWidth(coordinateHig);

            for (int i = 0; i < yAxis.GetSplitNumber(); i++)
            {
                Text txt = ChartUtils.AddTextObject("yScale" + i, transform, themeInfo.font,
                                                    themeInfo.textColor, TextAnchor.MiddleRight, Vector2.zero, Vector2.zero,
                                                    new Vector2(1, 0.5f),
                                                    new Vector2(coordinate.left, 20));
                txt.transform.localPosition = GetYScalePosition(scaleWid, i);
                txt.text = yAxis.GetScaleName(i, max);
                txt.gameObject.SetActive(coordinate.show);
                yScaleTextList.Add(txt);
            }

            foreach (var item in rightYScaleTextList)
            {
                item.text = string.Empty;
            }

            rightYScaleTextList.Clear();
            Vector2 v2 = GetMaxAndMinValue();

            for (int i = 0; i < yAxis.GetSplitNumber(); i++)
            {
                Text txt = ChartUtils.AddTextObject("rightYScale" + i, transform, themeInfo.font,
                                                    themeInfo.textColor, TextAnchor.MiddleLeft, Vector2.zero, Vector2.zero,
                                                    new Vector2(1, 0.5f),
                                                    new Vector2(coordinate.left, 20));
                txt.transform.localPosition = GetRightYScalePosition(scaleWid, i);
                txt.text = yAxis.GetScaleName(i, v2.x, v2.y);
                txt.gameObject.SetActive(ShowRightScale && coordinate.show);
                rightYScaleTextList.Add(txt);
            }
        }
        protected override float GetMaxValue()
        {
            float max   = 0;
            int   count = ShowRightScale ? 1:seriesList.Count;

            for (int i = 0; i < count; i++)
            {
                if (legend.IsShowSeries(i) && seriesList[i].Max > max)
                {
                    max = seriesList[i].Max;
                }
            }

            Vector2 v2 = ChartUtils.MagicNumbers(max, 0, true);

            return(v2.x);
        }
Exemple #17
0
        protected override void OnPopulateMesh(VertexHelper vh)
        {
            base.OnPopulateMesh(vh);
            UpdatePieCenter();
            float totalDegree = 360;
            float startDegree = 0;

            float degree   = totalDegree * progressInfo.progress / 100;
            float toDegree = startDegree + degree;

            ChartUtils.DrawDoughnut(vh, new Vector3(pieCenterX, pieCenterY), progressInfo.insideRadius,
                                    progressInfo.outsideRadius, startDegree, toDegree, progressInfo.progressColor);
            startDegree = toDegree;

            ChartUtils.DrawDoughnut(vh, new Vector3(pieCenterX, pieCenterY), progressInfo.insideRadius,
                                    progressInfo.outsideRadius, startDegree, totalDegree, progressInfo.backgroundColor);
        }
        private void InitYScale()
        {
            yScaleTextList.Clear();
            float max      = GetMaxValue();
            float scaleWid = yAxis.GetScaleWidth(coordinateHig);

            for (int i = 0; i < yAxis.GetSplitNumber(); i++)
            {
                Text txt = ChartUtils.AddTextObject(YSCALE_TEXT_PREFIX + i, transform, themeInfo.font,
                                                    themeInfo.textColor, TextAnchor.MiddleRight, Vector2.zero, Vector2.zero,
                                                    new Vector2(1, 0.5f),
                                                    new Vector2(coordinate.left, 20));
                txt.transform.localPosition = GetYScalePosition(scaleWid, i);
                txt.text = yAxis.GetScaleName(i, max);
                txt.gameObject.SetActive(coordinate.show);
                yScaleTextList.Add(txt);
            }
        }
        public void InitXScale()
        {
            xScaleTextList.Clear();
            float max      = GetMaxValue();
            float scaleWid = xAxis.GetScaleWidth(coordinateWid);

            for (int i = 0; i < xAxis.GetSplitNumber(); i++)
            {
                Text txt = ChartUtils.AddTextObject(XSCALE_TEXT_PREFIX + i, transform, themeInfo.font,
                                                    themeInfo.textColor, TextAnchor.MiddleCenter, Vector2.zero, Vector2.zero,
                                                    new Vector2(1, 0.5f),
                                                    new Vector2(scaleWid, 20));
                txt.transform.localPosition = GetXScalePosition(scaleWid, i);

                txt.text = xAxis.GetScaleName(i, max);
                txt.gameObject.SetActive(coordinate.show);
                xScaleTextList.Add(txt);
            }
        }
        protected override void InitXScale()
        {
            foreach (var item in xScaleTextList)
            {
                item.text = string.Empty;
            }

            xScaleTextList.Clear();
            //float max = GetMaxValue();
            Vector2            v2       = GetMaxAndMinValue();
            float              scaleWid = xAxis.GetScaleWidth(coordinateWid);
            Vector2            sizeDelta;
            HorizontalWrapMode horizontalWrap;
            VerticalWrapMode   verticalWrap;
            int fontSize = 14;

            if (xAxis.horizontal)
            {
                sizeDelta      = new Vector2(scaleWid, 20);
                horizontalWrap = HorizontalWrapMode.Overflow;
                verticalWrap   = VerticalWrapMode.Overflow;
            }
            else
            {
                sizeDelta      = new Vector2(fontSize * 1.5f, coordinate.xScaleRectHeight);
                horizontalWrap = HorizontalWrapMode.Wrap;
                verticalWrap   = VerticalWrapMode.Truncate;
            }

            for (int i = 0; i < xAxis.GetSplitNumber(); i++)
            {
                Text txt = ChartUtils.AddTextObject("xScale" + i, transform, themeInfo.font,
                                                    themeInfo.textColor, TextAnchor.UpperCenter, Vector2.zero, Vector2.zero,
                                                    xAxis.horizontal ? new Vector2(1, 0.5f) : new Vector2(0.5f, 1),
                                                    sizeDelta, 14, horizontalWrap, verticalWrap);
                txt.transform.localPosition = GetXScalePosition(scaleWid, i, xAxis.horizontal, fontSize);

                txt.text = xAxis.GetScaleName(i, v2.x, v2.y);
                txt.gameObject.SetActive(coordinate.show);
                xScaleTextList.Add(txt);
            }
        }
Exemple #21
0
        protected virtual Vector2 GetMaxAndMinValue()
        {
            float max = 0, min = 0;

            for (int i = 0; i < seriesList.Count; i++)
            {
                if (legend.IsShowSeries(i) && seriesList[i].Max > max)
                {
                    max = seriesList[i].Max;
                }
                if (legend.IsShowSeries(i) && seriesList[i].Min < min)
                {
                    min = seriesList[i].Min;
                }
            }

            Vector2 v2 = ChartUtils.MagicNumbers(max, min);

            return(v2);
        }
Exemple #22
0
 private void InitXScale()
 {
     xScaleTextList.Clear();
     if (xAxis.type == AxisType.value)
     {
         float max = GetMaxValue();
         if (max <= 0)
         {
             max = 400;
         }
         xAxis.splitNumber = DEFAULT_YSACLE_NUM;
         float scaleWid = coordinateWid / (xAxis.splitNumber - 1);
         for (int i = 0; i < xAxis.splitNumber; i++)
         {
             Text txt = ChartUtils.AddTextObject(XSCALE_TEXT_PREFIX + i, transform, themeInfo.font,
                                                 themeInfo.textColor, TextAnchor.MiddleCenter, Vector2.zero, Vector2.zero,
                                                 new Vector2(1, 0.5f),
                                                 new Vector2(scaleWid, 20));
             txt.transform.localPosition = GetXScalePosition(i);
             txt.text = ((int)(max * i / xAxis.splitNumber)).ToString();
             txt.gameObject.SetActive(coordinate.show);
             xScaleTextList.Add(txt);
         }
     }
     else
     {
         xAxis.splitNumber = xAxis.boundaryGap ? xAxis.data.Count + 1 : xAxis.data.Count;
         float scaleWid = coordinateWid / (xAxis.data.Count - 1);
         for (int i = 0; i < xAxis.data.Count; i++)
         {
             Text txt = ChartUtils.AddTextObject(XSCALE_TEXT_PREFIX + i, transform, themeInfo.font,
                                                 themeInfo.textColor, TextAnchor.MiddleCenter, Vector2.zero, Vector2.zero,
                                                 new Vector2(1, 0.5f),
                                                 new Vector2(scaleWid, 20));
             txt.transform.localPosition = GetXScalePosition(i);
             txt.text = xAxis.data[i];
             txt.gameObject.SetActive(coordinate.show);
             xScaleTextList.Add(txt);
         }
     }
 }
        protected override Vector2 GetMaxAndMinValue()
        {
            float max = 0, min = 0;
            int   ori = ShowRightScale ? 1 : 0;

            for (int i = ori; i < seriesList.Count; i++)
            {
                if (legend.IsShowSeries(i) && seriesList[i].Max > max)
                {
                    max = seriesList[i].Max;
                }
                if (legend.IsShowSeries(i) && seriesList[i].Min < min)
                {
                    min = seriesList[i].Min;
                }
            }

            Vector2 v2 = ChartUtils.MagicNumbers(max, min, true);

            return(v2);
        }
 private void InitHideAndShowButton()
 {
     if (lineList.Count <= 0)
     {
         return;
     }
     btnAll = ChartUtils.AddButtonObject("buttonall", transform, font, Vector2.zero,
                                         Vector2.zero, Vector2.zero, new Vector2(graduationWidth, 20));
     btnAll.transform.localPosition = new Vector3(-graduationWidth, chartHig + 30, 0);
     btnAll.GetComponentInChildren <Text>().text = isShowAll ? "HIDE" : "SHOW";
     btnAll.GetComponent <Image>().color         = backgroundColor;
     btnAll.onClick.AddListener(delegate()
     {
         isShowAll = !isShowAll;
         btnAll.GetComponentInChildren <Text>().text = isShowAll ? "HIDE" : "SHOW";
         foreach (var line in lineList)
         {
             line.visible = isShowAll;
         }
     });
 }
Exemple #25
0
        private void InitLegend()
        {
            for (int i = 0; i < legend.dataList.Count; i++)
            {
                LegendData data = legend.dataList[i];
                Button     btn  = ChartUtils.AddButtonObject(LEGEND_TEXT + i, transform, themeInfo.font,
                                                             themeInfo.textColor, Vector2.zero, Vector2.zero, Vector2.zero,
                                                             new Vector2(legend.itemWidth, legend.itemHeight));
                btn.name = data.key;
                legend.dataList[i].button = btn;
                Color bcolor = data.show ? themeInfo.GetColor(i) : themeInfo.unableColor;
                btn.gameObject.SetActive(legend.show);
                btn.transform.localPosition              = GetLegendPosition(i);
                btn.GetComponent <Image>().color         = bcolor;
                btn.GetComponentInChildren <Text>().text = data.text;
                //btn.onClick.AddListener(delegate ()
                //{
                //    Debug.Log(btn.name + "Clicked!");
                //    //data.show = !data.show;
                //    //btn.GetComponent<Image>().color = data.show ? themeInfo.GetColor(i) : themeInfo.unableColor;
                //    //OnYMaxValueChanged();
                //    //OnLegendButtonClicked();
                //    //RefreshChart();
                //});
            }

            checkTheme = theme;

            checkLegend.checkDataListCount = legend.dataList.Count;
            checkLegend.itemWidth          = legend.itemWidth;
            checkLegend.itemHeight         = legend.itemHeight;
            checkLegend.itemGap            = legend.itemGap;
            checkLegend.left     = legend.left;
            checkLegend.right    = legend.right;
            checkLegend.bottom   = legend.bottom;
            checkLegend.top      = legend.top;
            checkLegend.location = legend.location;
            checkLegend.show     = legend.show;
        }
Exemple #26
0
        protected virtual float GetMaxValue()
        {
            float max = 0;

            for (int i = 0; i < seriesList.Count; i++)
            {
                if (legend.IsShowSeries(i) && seriesList[i].Max > max)
                {
                    max = seriesList[i].Max;
                }
            }
            //int bigger = (int)(max * 1.3f);
            //return bigger < 10 ? bigger : bigger - bigger % 10;

            Vector2 v2 = ChartUtils.MagicNumbers(max, 0);

            if (v2.x < 5)
            {
                v2.x = 5;
            }
            return(v2.x);
        }
Exemple #27
0
 private void InitYScale()
 {
     yScaleTextList.Clear();
     if (yAxis.type == AxisType.value)
     {
         float max = GetMaxValue();
         if (max <= 0)
         {
             max = 400;
         }
         yAxis.splitNumber = DEFAULT_YSACLE_NUM;
         for (int i = 0; i < yAxis.splitNumber; i++)
         {
             Text txt = ChartUtils.AddTextObject(YSCALE_TEXT_PREFIX + i, transform, themeInfo.font,
                                                 themeInfo.textColor, TextAnchor.MiddleRight, Vector2.zero, Vector2.zero,
                                                 new Vector2(1, 0.5f),
                                                 new Vector2(coordinate.left, 20));
             txt.transform.localPosition = GetYScalePosition(i);
             txt.text = ((int)(max * i / yAxis.splitNumber)).ToString();
             txt.gameObject.SetActive(coordinate.show);
             yScaleTextList.Add(txt);
         }
     }
     else
     {
         yAxis.splitNumber = yAxis.boundaryGap ? yAxis.data.Count + 1 : yAxis.data.Count;
         for (int i = 0; i < yAxis.data.Count; i++)
         {
             Text txt = ChartUtils.AddTextObject(YSCALE_TEXT_PREFIX + i, transform, themeInfo.font,
                                                 themeInfo.textColor, TextAnchor.MiddleRight, Vector2.zero, Vector2.zero,
                                                 new Vector2(1, 0.5f),
                                                 new Vector2(coordinate.left, 20));
             txt.transform.localPosition = GetYScalePosition(i);
             txt.text = yAxis.data[i];
             txt.gameObject.SetActive(coordinate.show);
             yScaleTextList.Add(txt);
         }
     }
 }
Exemple #28
0
        private void InitIndicator()
        {
            indicatorTextList.Clear();
            HideChild(INDICATOR_TEXT);
            int   indicatorNum = radarInfo.indicatorList.Count;
            float txtWid       = 100;
            float txtHig       = 20;

            for (int i = 0; i < indicatorNum; i++)
            {
                var        pos    = GetIndicatorPosition(i);
                TextAnchor anchor = TextAnchor.MiddleCenter;
                var        diff   = pos.x - radarCenterX;
                if (diff < -1f)
                {
                    pos    = new Vector3(pos.x - 5, pos.y);
                    anchor = TextAnchor.MiddleRight;
                }
                else if (diff > 1f)
                {
                    anchor = TextAnchor.MiddleLeft;
                    pos    = new Vector3(pos.x + txtWid + 5, pos.y);
                }
                else
                {
                    anchor = TextAnchor.MiddleCenter;
                    float y = pos.y > radarCenterY ? pos.y + txtHig / 2 : pos.y - txtHig / 2;
                    pos = new Vector3(pos.x + txtWid / 2, y);
                }
                Text txt = ChartUtils.AddTextObject(INDICATOR_TEXT + i, transform, font,
                                                    anchor, Vector2.zero, Vector2.zero, new Vector2(1, 0.5f),
                                                    new Vector2(txtWid, txtHig));
                txt.transform.localPosition = pos;
                txt.text = radarInfo.indicatorList[i].name;
                txt.gameObject.SetActive(radarInfo.showIndicator);
                indicatorTextList.Add(txt);
            }
        }
Exemple #29
0
 private void InitLegend()
 {
     for (int i = 0; i < legend.dataList.Count; i++)
     {
         LegendData data = legend.dataList[i];
         Button     btn  = ChartUtils.AddButtonObject(LEGEND_TEXT + i, transform, font, Vector2.zero,
                                                      Vector2.zero, Vector2.zero, new Vector2(legend.dataWid, legend.dataHig));
         legend.dataList[i].button = btn;
         Color bcolor = data.show ? data.color : Color.grey;
         btn.gameObject.SetActive(legend.show);
         btn.transform.localPosition              = GetLegendPosition(i);
         btn.GetComponent <Image>().color         = bcolor;
         btn.GetComponentInChildren <Text>().text = data.text;
         btn.onClick.AddListener(delegate()
         {
             data.show = !data.show;
             btn.GetComponent <Image>().color = data.show ? data.color : Color.grey;
             OnYMaxValueChanged();
             OnLegendButtonClicked();
             RefreshChart();
         });
     }
 }
        private void DrawSplitLine(VertexHelper vh, bool isYAxis, SplitLineType type, Vector3 startPos,
                                   Vector3 endPos)
        {
            switch (type)
            {
            case SplitLineType.dashed:
            case SplitLineType.dotted:
                var startX  = startPos.x;
                var startY  = startPos.y;
                var dashLen = type == SplitLineType.dashed ? 6 : 2.5f;
                var count   = isYAxis ? (endPos.x - startPos.x) / (dashLen * 2) :
                              (endPos.y - startPos.y) / (dashLen * 2);
                for (int i = 0; i < count; i++)
                {
                    if (isYAxis)
                    {
                        var toX = startX + dashLen;
                        ChartUtils.DrawLine(vh, new Vector3(startX, startY), new Vector3(toX, startY),
                                            coordinate.tickness, themeInfo.axisSplitLineColor);
                        startX += dashLen * 2;
                    }
                    else
                    {
                        var toY = startY + dashLen;
                        ChartUtils.DrawLine(vh, new Vector3(startX, startY), new Vector3(startX, toY),
                                            coordinate.tickness, themeInfo.axisSplitLineColor);
                        startY += dashLen * 2;
                    }
                }
                break;

            case SplitLineType.solid:
                ChartUtils.DrawLine(vh, startPos, endPos, coordinate.tickness,
                                    themeInfo.axisSplitLineColor);
                break;
            }
        }