예제 #1
0
        protected void DrawLabelBackground(VertexHelper vh, Serie serie, SerieData serieData)
        {
            var labelHalfWid = serieData.GetLabelWidth() / 2;
            var labelHalfHig = serieData.GetLabelHeight() / 2;
            var serieLabel   = serieData.GetSerieLabel(serie.label);
            var invert       = serie.type == SerieType.Line &&
                               SerieHelper.IsDownPoint(serie, serieData.index) &&
                               !serie.areaStyle.show;
            var centerPos = serieData.labelPosition + serieLabel.offset * (invert ? -1 : 1);
            var p1        = new Vector3(centerPos.x - labelHalfWid, centerPos.y + labelHalfHig);
            var p2        = new Vector3(centerPos.x + labelHalfWid, centerPos.y + labelHalfHig);
            var p3        = new Vector3(centerPos.x + labelHalfWid, centerPos.y - labelHalfHig);
            var p4        = new Vector3(centerPos.x - labelHalfWid, centerPos.y - labelHalfHig);

            if (serieLabel.rotate > 0)
            {
                p1 = ChartHelper.RotateRound(p1, centerPos, Vector3.forward, serieLabel.rotate);
                p2 = ChartHelper.RotateRound(p2, centerPos, Vector3.forward, serieLabel.rotate);
                p3 = ChartHelper.RotateRound(p3, centerPos, Vector3.forward, serieLabel.rotate);
                p4 = ChartHelper.RotateRound(p4, centerPos, Vector3.forward, serieLabel.rotate);
            }

            ChartDrawer.DrawPolygon(vh, p1, p2, p3, p4, serieLabel.backgroundColor);

            if (serieLabel.border)
            {
                ChartDrawer.DrawBorder(vh, centerPos, serieData.GetLabelWidth(), serieData.GetLabelHeight(),
                                       serieLabel.borderWidth, serieLabel.borderColor, serieLabel.rotate);
            }
        }
예제 #2
0
        protected void DrawLabelBackground(VertexHelper vh, Serie serie, SerieData serieData)
        {
            var labelHalfWid = serieData.GetLabelWidth() / 2;
            var labelHalfHig = serieData.GetLabelHeight() / 2;
            var serieLabel   = serieData.GetSerieLabel(serie.label);
            var centerPos    = serieData.labelPosition + serieLabel.offset;
            var p1           = new Vector3(centerPos.x - labelHalfWid, centerPos.y + labelHalfHig);
            var p2           = new Vector3(centerPos.x + labelHalfWid, centerPos.y + labelHalfHig);
            var p3           = new Vector3(centerPos.x + labelHalfWid, centerPos.y - labelHalfHig);
            var p4           = new Vector3(centerPos.x - labelHalfWid, centerPos.y - labelHalfHig);

            if (serieLabel.rotate > 0)
            {
                p1 = ChartHelper.RotateRound(p1, centerPos, Vector3.forward, serieLabel.rotate);
                p2 = ChartHelper.RotateRound(p2, centerPos, Vector3.forward, serieLabel.rotate);
                p3 = ChartHelper.RotateRound(p3, centerPos, Vector3.forward, serieLabel.rotate);
                p4 = ChartHelper.RotateRound(p4, centerPos, Vector3.forward, serieLabel.rotate);
            }

            ChartDrawer.DrawPolygon(vh, p1, p2, p3, p4, serieLabel.backgroundColor);

            if (serieLabel.border)
            {
                ChartDrawer.DrawBorder(vh, centerPos, serieData.GetLabelWidth(), serieData.GetLabelHeight(),
                                       serieLabel.borderWidth, serieLabel.borderColor, serieLabel.rotate);
            }
        }
예제 #3
0
        protected void DrawLabelBackground(VertexHelper vh, Serie serie, SerieData serieData)
        {
            var labelHalfWid = serieData.GetLabelWidth() / 2;
            var labelHalfHig = serieData.GetLabelHeight() / 2;
            var serieLabel   = serieData.GetSerieLabel(serie.label);
            var centerPos    = serieData.labelPosition + serieLabel.offset;
            var p1           = new Vector3(centerPos.x - labelHalfWid, centerPos.y + labelHalfHig);
            var p2           = new Vector3(centerPos.x + labelHalfWid, centerPos.y + labelHalfHig);
            var p3           = new Vector3(centerPos.x + labelHalfWid, centerPos.y - labelHalfHig);
            var p4           = new Vector3(centerPos.x - labelHalfWid, centerPos.y - labelHalfHig);

            if (serieLabel.rotate > 0)
            {
                p1 = ChartHelper.RotateRound(p1, centerPos, Vector3.forward, serieLabel.rotate);
                p2 = ChartHelper.RotateRound(p2, centerPos, Vector3.forward, serieLabel.rotate);
                p3 = ChartHelper.RotateRound(p3, centerPos, Vector3.forward, serieLabel.rotate);
                p4 = ChartHelper.RotateRound(p4, centerPos, Vector3.forward, serieLabel.rotate);
            }

            ChartDrawer.DrawPolygon(vh, p1, p2, p3, p4, serieLabel.backgroundColor);

            if (serieLabel.border)
            {
                var borderWid = serieLabel.borderWidth;
                p1 = new Vector3(centerPos.x - labelHalfWid, centerPos.y + labelHalfHig + borderWid);
                p2 = new Vector3(centerPos.x + labelHalfWid + 2 * borderWid, centerPos.y + labelHalfHig + borderWid);
                p3 = new Vector3(centerPos.x + labelHalfWid + borderWid, centerPos.y + labelHalfHig);
                p4 = new Vector3(centerPos.x + labelHalfWid + borderWid, centerPos.y - labelHalfHig - 2 * borderWid);
                var p5 = new Vector3(centerPos.x + labelHalfWid, centerPos.y - labelHalfHig - borderWid);
                var p6 = new Vector3(centerPos.x - labelHalfWid - 2 * borderWid, centerPos.y - labelHalfHig - borderWid);
                var p7 = new Vector3(centerPos.x - labelHalfWid - borderWid, centerPos.y - labelHalfHig);
                var p8 = new Vector3(centerPos.x - labelHalfWid - borderWid, centerPos.y + labelHalfHig + 2 * borderWid);
                if (serieLabel.rotate > 0)
                {
                    p1 = ChartHelper.RotateRound(p1, centerPos, Vector3.forward, serieLabel.rotate);
                    p2 = ChartHelper.RotateRound(p2, centerPos, Vector3.forward, serieLabel.rotate);
                    p3 = ChartHelper.RotateRound(p3, centerPos, Vector3.forward, serieLabel.rotate);
                    p4 = ChartHelper.RotateRound(p4, centerPos, Vector3.forward, serieLabel.rotate);
                    p5 = ChartHelper.RotateRound(p5, centerPos, Vector3.forward, serieLabel.rotate);
                    p6 = ChartHelper.RotateRound(p6, centerPos, Vector3.forward, serieLabel.rotate);
                    p7 = ChartHelper.RotateRound(p7, centerPos, Vector3.forward, serieLabel.rotate);
                    p8 = ChartHelper.RotateRound(p8, centerPos, Vector3.forward, serieLabel.rotate);
                }
                ChartDrawer.DrawLine(vh, p1, p2, borderWid, serieLabel.borderColor);
                ChartDrawer.DrawLine(vh, p3, p4, borderWid, serieLabel.borderColor);
                ChartDrawer.DrawLine(vh, p5, p6, borderWid, serieLabel.borderColor);
                ChartDrawer.DrawLine(vh, p7, p8, borderWid, serieLabel.borderColor);
            }
        }
예제 #4
0
        protected void UpdateLabelPostion(Serie serie, SerieData serieData)
        {
            if (serieData.labelText == 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    = serieData.GetSerieLabel(serie.label);

            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.labelText.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.labelText.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;
            }
        }
예제 #5
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  = serieData.GetSerieLabel(serie.label);
            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();
        }
예제 #6
0
        private void DrawLabelLine(VertexHelper vh, Serie serie, SerieData serieData, Color color)
        {
            var serieLabel = serieData.GetSerieLabel(serie.label);

            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 (serieLabel.lineColor != Color.clear)
                {
                    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 = new Vector3(center.x + radius2 * currSin, center.y + radius2 * currCos);
                float   tx, ty;
                Vector3 pos3, pos4, pos6;
                var     horizontalLineCircleRadius = serieLabel.lineWidth * 4f;
                var     lineCircleDiff             = horizontalLineCircleRadius - 0.3f;
                if (currAngle < 90)
                {
                    ty   = serieLabel.lineWidth * Mathf.Cos((90 - currAngle) * Mathf.Deg2Rad);
                    tx   = serieLabel.lineWidth * Mathf.Sin((90 - currAngle) * Mathf.Deg2Rad);
                    pos3 = new Vector3(pos2.x - tx, pos2.y + ty - serieLabel.lineWidth);
                    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)
                {
                    ty   = serieLabel.lineWidth * Mathf.Sin((180 - currAngle) * Mathf.Deg2Rad);
                    tx   = serieLabel.lineWidth * Mathf.Cos((180 - currAngle) * Mathf.Deg2Rad);
                    pos3 = new Vector3(pos2.x - tx, pos2.y - ty + serieLabel.lineWidth);
                    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)
                {
                    ty = serieLabel.lineWidth * Mathf.Sin((180 + currAngle) * Mathf.Deg2Rad);
                    tx = serieLabel.lineWidth * Mathf.Cos((180 + currAngle) * Mathf.Deg2Rad);
                    var currSin1 = Mathf.Sin((360 - currAngle) * Mathf.Deg2Rad);
                    var currCos1 = Mathf.Cos((360 - currAngle) * Mathf.Deg2Rad);
                    pos3 = new Vector3(pos2.x + tx, pos2.y - ty + serieLabel.lineWidth);
                    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
                {
                    ty   = serieLabel.lineWidth * Mathf.Cos((90 + currAngle) * Mathf.Deg2Rad);
                    tx   = serieLabel.lineWidth * Mathf.Sin((90 + currAngle) * Mathf.Deg2Rad);
                    pos3 = new Vector3(pos2.x + tx, pos2.y + ty - serieLabel.lineWidth);
                    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 pos5 = new Vector3(currAngle > 180 ? pos3.x - serieLabel.lineLength2 : pos3.x + serieLabel.lineLength2, pos3.y);
                switch (serieLabel.lineType)
                {
                case SerieLabel.LineType.BrokenLine:
                    ChartDrawer.DrawLine(vh, pos1, pos2, serieLabel.lineWidth, color);
                    ChartDrawer.DrawLine(vh, pos3, pos5, serieLabel.lineWidth, color);
                    break;

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

                case SerieLabel.LineType.HorizontalLine:
                    ChartDrawer.DrawCricle(vh, pos0, horizontalLineCircleRadius, color);
                    ChartDrawer.DrawLine(vh, pos6, pos4, serieLabel.lineWidth, color);
                    break;
                }
            }
        }