Пример #1
0
 private void DrawPieLabelLine(VertexHelper vh, Serie serie, bool drawHightlight)
 {
     foreach (var serieData in serie.data)
     {
         var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
         if (drawHightlight && !serieData.context.highlight)
         {
             continue;
         }
         if (!drawHightlight && serieData.context.highlight)
         {
             continue;
         }
         if (SerieLabelHelper.CanShowLabel(serie, serieData, serieLabel, 1))
         {
             int   colorIndex = chart.m_LegendRealShowName.IndexOf(serieData.name);
             Color color      = chart.theme.GetColor(colorIndex);
             DrawPieLabelLine(vh, serie, serieData, color);
         }
     }
 }
        public static string GetFormatterContent(Serie serie, SerieData serieData,
                                                 double dataValue, double dataTotal, LabelStyle serieLabel, Color color)
        {
            if (serieLabel == null)
            {
                serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
            }
            var numericFormatter = serieLabel == null ? "" : serieLabel.numericFormatter;
            var serieName        = serie.serieName;
            var dataName         = serieData != null ? serieData.name : null;

            if (string.IsNullOrEmpty(serieLabel.formatter))
            {
                var currentContent = ChartCached.NumberToStr(dataValue, numericFormatter);
                if (serieLabel.formatterFunction == null)
                {
                    return(currentContent);
                }
                else
                {
                    return(serieLabel.formatterFunction(serieData.index, dataValue, null, currentContent));
                }
            }
            else
            {
                var content = serieLabel.formatter;
                FormatterHelper.ReplaceSerieLabelContent(ref content, numericFormatter, serie.dataCount, dataValue,
                                                         dataTotal, serieName, dataName, dataName, color, serieData);
                if (serieLabel.formatterFunction == null)
                {
                    return(content);
                }
                else
                {
                    return(serieLabel.formatterFunction(serieData.index, dataValue, null, content));
                }
            }
        }
        private static void CheckSerieDataLabel(Serie serie, SerieData serieData, int total, bool isLeft, ComponentTheme theme,
                                                ref Vector3 lastCheckPos, ref float lastX)
        {
            if (!serieData.context.canShowLabel)
            {
                serieData.SetLabelActive(false);
                return;
            }
            if (!serieData.show)
            {
                return;
            }
            var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
            var isOutside  = serieLabel.position == LabelStyle.Position.Outside ||
                             serieLabel.position == LabelStyle.Position.Default;

            if (!serieLabel.show)
            {
                return;
            }
            if (!isOutside)
            {
                return;
            }
            var labelLine = SerieHelper.GetSerieLabelLine(serie, serieData);
            var fontSize  = serieData.labelObject.GetHeight();

            if (lastCheckPos == Vector3.zero)
            {
                lastCheckPos = serieData.context.labelPosition;
            }
            else if (serieData.context.labelPosition.x != 0)
            {
                if (lastCheckPos.y - serieData.context.labelPosition.y < fontSize)
                {
                    var labelRadius = serie.context.outsideRadius + labelLine.lineLength1;
                    var y1          = lastCheckPos.y - fontSize;
                    var cy          = serie.context.center.y;
                    var diff        = Mathf.Abs(y1 - cy);
                    var diffX       = labelRadius * labelRadius - diff * diff;
                    diffX = diffX <= 0 ? 0 : diffX;
                    var x1     = serie.context.center.x + Mathf.Sqrt(diffX) * (isLeft ? -1 : 1);
                    var newPos = new Vector3(x1, y1);
                    serieData.context.labelPosition = newPos;
                    var angle = ChartHelper.GetAngle360(Vector2.up, newPos - serie.context.center);
                    if (angle >= 180 && angle <= 270)
                    {
                        serieData.context.labelPosition = new Vector3(isLeft?(++lastX): (--lastX), y1);
                    }
                    else if (angle < 180 && angle >= 90)
                    {
                        serieData.context.labelPosition = new Vector3(isLeft?(++lastX): (--lastX), y1);
                    }
                    else
                    {
                        lastX = x1;
                    }
                }
                else
                {
                    lastX = serieData.context.labelPosition.x;
                }
                lastCheckPos = serieData.context.labelPosition;
                serieData.labelObject.SetPosition(SerieLabelHelper.GetRealLabelPosition(serie, serieData, serieLabel, labelLine));
            }
        }
Пример #4
0
        private void DrawPieLabelLine(VertexHelper vh, Serie serie, SerieData serieData, Color color)
        {
            var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
            var labelLine  = SerieHelper.GetSerieLabelLine(serie, serieData);

            if (serieLabel != null && serieLabel.show &&
                labelLine != null && labelLine.show &&
                (serieLabel.IsDefaultPosition(LabelStyle.Position.Outside)))
            {
                var insideRadius  = serieData.context.insideRadius;
                var outSideRadius = serieData.context.outsideRadius;
                var center        = serie.context.center;
                var currAngle     = serieData.context.halfAngle;

                if (!ChartHelper.IsClearColor(labelLine.lineColor))
                {
                    color = labelLine.lineColor;
                }
                else if (labelLine.lineType == LabelLine.LineType.HorizontalLine)
                {
                    color *= color;
                }

                float currSin = Mathf.Sin(currAngle * Mathf.Deg2Rad);
                float currCos = Mathf.Cos(currAngle * Mathf.Deg2Rad);
                var   radius1 = labelLine.lineType == LabelLine.LineType.HorizontalLine ?
                                serie.context.outsideRadius : outSideRadius;
                var radius3 = insideRadius + (outSideRadius - insideRadius) / 2;
                if (radius1 < serie.context.insideRadius)
                {
                    radius1 = serie.context.insideRadius;
                }
                radius1 -= 0.1f;
                var     pos0 = new Vector3(center.x + radius3 * currSin, center.y + radius3 * currCos);
                var     pos1 = new Vector3(center.x + radius1 * currSin, center.y + radius1 * currCos);
                var     pos2 = serieData.context.labelPosition;
                Vector3 pos4, pos6;
                var     horizontalLineCircleRadius = labelLine.lineWidth * 4f;
                var     lineCircleDiff             = horizontalLineCircleRadius - 0.3f;
                var     startAngle                 = serie.context.startAngle;
                if (currAngle < 90)
                {
                    var r4 = Mathf.Sqrt(radius1 * radius1 - Mathf.Pow(currCos * radius3, 2)) - currSin * radius3;
                    r4  += labelLine.lineLength1 - lineCircleDiff;
                    pos6 = pos0 + Vector3.right * lineCircleDiff;
                    pos4 = pos6 + Vector3.right * r4;
                }
                else if (currAngle < 180)
                {
                    var r4 = Mathf.Sqrt(radius1 * radius1 - Mathf.Pow(currCos * radius3, 2)) - currSin * radius3;
                    r4  += labelLine.lineLength1 - lineCircleDiff;
                    pos6 = pos0 + Vector3.right * lineCircleDiff;
                    pos4 = pos6 + Vector3.right * r4;
                }
                else if (currAngle < 270)
                {
                    var currSin1 = Mathf.Sin((360 - currAngle) * Mathf.Deg2Rad);
                    var currCos1 = Mathf.Cos((360 - currAngle) * Mathf.Deg2Rad);
                    var r4       = Mathf.Sqrt(radius1 * radius1 - Mathf.Pow(currCos1 * radius3, 2)) - currSin1 * radius3;
                    r4  += labelLine.lineLength1 - lineCircleDiff;
                    pos6 = pos0 + Vector3.left * lineCircleDiff;
                    pos4 = pos6 + Vector3.left * r4;
                }
                else
                {
                    var currSin1 = Mathf.Sin((360 - currAngle) * Mathf.Deg2Rad);
                    var currCos1 = Mathf.Cos((360 - currAngle) * Mathf.Deg2Rad);
                    var r4       = Mathf.Sqrt(radius1 * radius1 - Mathf.Pow(currCos1 * radius3, 2)) - currSin1 * radius3;
                    r4  += labelLine.lineLength1 - lineCircleDiff;
                    pos6 = pos0 + Vector3.left * lineCircleDiff;
                    pos4 = pos6 + Vector3.left * r4;
                }
                var pos5X = (currAngle - startAngle) % 360 > 180 ?
                            pos2.x - labelLine.lineLength2 : pos2.x + labelLine.lineLength2;
                var pos5  = new Vector3(pos5X, pos2.y);
                var angle = Vector3.Angle(pos1 - center, pos2 - pos1);
                if (angle > 15)
                {
                    UGL.DrawLine(vh, pos1, pos5, labelLine.lineWidth, color);
                }
                else
                {
                    switch (labelLine.lineType)
                    {
                    case LabelLine.LineType.BrokenLine:
                        UGL.DrawLine(vh, pos1, pos2, pos5, labelLine.lineWidth, color);
                        break;

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

                    case LabelLine.LineType.HorizontalLine:
                        UGL.DrawCricle(vh, pos0, horizontalLineCircleRadius, color);
                        UGL.DrawLine(vh, pos6, pos4, labelLine.lineWidth, color);
                        break;
                    }
                }
            }
        }