Exemplo n.º 1
0
        private void UpdateRuntimeData(Serie serie)
        {
            var data = serie.data;

            serie.context.dataMax    = serie.yMax;
            serie.context.startAngle = GetStartAngle(serie);
            var runtimePieDataTotal = serie.yTotal;

            SerieHelper.UpdateCenter(serie, chart.chartPosition, chart.chartWidth, chart.chartHeight);
            float startDegree      = serie.context.startAngle;
            float totalDegree      = 0;
            float zeroReplaceValue = 0;
            int   showdataCount    = 0;

            foreach (var sd in serie.data)
            {
                if (sd.show && serie.pieRoseType == RoseType.Area)
                {
                    showdataCount++;
                }
                sd.context.canShowLabel = false;
            }
            float dataChangeDuration      = serie.animation.GetUpdateAnimationDuration();
            bool  isAllZeroValue          = SerieHelper.IsAllZeroValue(serie, 1);
            var   dataTotalFilterMinAngle = runtimePieDataTotal;

            if (isAllZeroValue)
            {
                totalDegree             = 360;
                zeroReplaceValue        = totalDegree / data.Count;
                serie.context.dataMax   = zeroReplaceValue;
                runtimePieDataTotal     = 360;
                dataTotalFilterMinAngle = 360;
            }
            else
            {
                dataTotalFilterMinAngle = GetTotalAngle(serie, runtimePieDataTotal, ref totalDegree);
            }
            for (int n = 0; n < data.Count; n++)
            {
                var serieData = data[n];
                serieData.index = n;
                var value = isAllZeroValue ? zeroReplaceValue : serieData.GetCurrData(1, dataChangeDuration);
                serieData.context.startAngle   = startDegree;
                serieData.context.toAngle      = startDegree;
                serieData.context.halfAngle    = startDegree;
                serieData.context.currentAngle = startDegree;
                if (!serieData.show)
                {
                    continue;
                }
                float degree = serie.pieRoseType == RoseType.Area ?
                               (totalDegree / showdataCount) :
                               (float)(totalDegree * value / dataTotalFilterMinAngle);
                if (serie.minAngle > 0 && degree < serie.minAngle)
                {
                    degree = serie.minAngle;
                }
                serieData.context.toAngle = startDegree + degree;
                if (serieData.radius > 0)
                {
                    serieData.context.outsideRadius = ChartHelper.GetActualValue(serieData.radius, Mathf.Min(chart.chartWidth, chart.chartHeight));
                }
                else
                {
                    serieData.context.outsideRadius = serie.pieRoseType > 0 ?
                                                      serie.context.insideRadius + (float)((serie.context.outsideRadius - serie.context.insideRadius) * value / serie.context.dataMax) :
                                                      serie.context.outsideRadius;
                }
                if (serieData.context.highlight)
                {
                    serieData.context.outsideRadius += chart.theme.serie.pieTooltipExtraRadius;
                }
                var offset = 0f;
                if (serie.pieClickOffset && serieData.selected)
                {
                    offset += chart.theme.serie.pieSelectedOffset;
                }
                if (serie.animation.CheckDetailBreak(serieData.context.toAngle))
                {
                    serieData.context.currentAngle = serie.animation.GetCurrDetail();
                }
                else
                {
                    serieData.context.currentAngle = serieData.context.toAngle;
                }
                var halfDegree = (serieData.context.toAngle - startDegree) / 2;
                serieData.context.halfAngle    = startDegree + halfDegree;
                serieData.context.offsetCenter = serie.context.center;
                serieData.context.insideRadius = serie.context.insideRadius;
                if (offset > 0)
                {
                    var currRad = serieData.context.halfAngle * Mathf.Deg2Rad;
                    var currSin = Mathf.Sin(currRad);
                    var currCos = Mathf.Cos(currRad);
                    serieData.context.offsetRadius   = 0;
                    serieData.context.insideRadius  -= serieData.context.offsetRadius;
                    serieData.context.outsideRadius -= serieData.context.offsetRadius;
                    if (serie.pieClickOffset && serieData.selected)
                    {
                        serieData.context.offsetRadius += chart.theme.serie.pieSelectedOffset;
                        if (serieData.context.insideRadius > 0)
                        {
                            serieData.context.insideRadius += chart.theme.serie.pieSelectedOffset;
                        }
                        serieData.context.outsideRadius += chart.theme.serie.pieSelectedOffset;
                    }
                    serieData.context.offsetCenter = new Vector3(
                        serie.context.center.x + serieData.context.offsetRadius * currSin,
                        serie.context.center.y + serieData.context.offsetRadius * currCos);
                }
                serieData.context.canShowLabel = serieData.context.currentAngle >= serieData.context.halfAngle;
                startDegree = serieData.context.toAngle;
                SerieLabelHelper.UpdatePieLabelPosition(serie, serieData);
            }
            SerieLabelHelper.AvoidLabelOverlap(serie, chart.theme.common);
        }
Exemplo n.º 2
0
        public override void DrawSerie(VertexHelper vh)
        {
            if (!serie.show || serie.animation.HasFadeOut())
            {
                return;
            }
            var data = serie.data;

            serie.animation.InitProgress(serie.startAngle, serie.startAngle + 360);
            SerieHelper.UpdateCenter(serie, chart.chartPosition, chart.chartWidth, chart.chartHeight);
            var dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
            var ringWidth          = serie.context.outsideRadius - serie.context.insideRadius;
            var dataChanging       = false;

            for (int j = 0; j < data.Count; j++)
            {
                var serieData = data[j];
                serieData.index = j;
                if (!serieData.show)
                {
                    continue;
                }
                if (serieData.IsDataChanged())
                {
                    dataChanging = true;
                }
                var value         = serieData.GetFirstData(dataChangeDuration);
                var max           = serieData.GetLastData();
                var degree        = (float)(360 * value / max);
                var startDegree   = GetStartAngle(serie);
                var toDegree      = GetToAngle(serie, degree);
                var itemStyle     = SerieHelper.GetItemStyle(serie, serieData, serieData.context.highlight);
                var colorIndex    = chart.GetLegendRealShowNameIndex(serieData.legendName);
                var itemColor     = SerieHelper.GetItemColor(serie, serieData, chart.theme, colorIndex, serieData.context.highlight);
                var itemToColor   = SerieHelper.GetItemToColor(serie, serieData, chart.theme, colorIndex, serieData.context.highlight);
                var outsideRadius = serie.context.outsideRadius - j * (ringWidth + serie.gap);
                var insideRadius  = outsideRadius - ringWidth;
                var borderWidth   = itemStyle.borderWidth;
                var borderColor   = itemStyle.borderColor;
                var roundCap      = serie.roundCap && insideRadius > 0;

                serieData.context.startAngle    = serie.clockwise ? startDegree : toDegree;
                serieData.context.toAngle       = serie.clockwise ? toDegree : startDegree;
                serieData.context.insideRadius  = insideRadius;
                serieData.context.outsideRadius = serieData.radius > 0 ? serieData.radius : outsideRadius;
                DrawBackground(vh, serie, serieData, j, insideRadius, outsideRadius);
                UGL.DrawDoughnut(vh, serie.context.center, insideRadius, outsideRadius, itemColor, itemToColor,
                                 Color.clear, startDegree, toDegree, borderWidth, borderColor, 0, chart.settings.cicleSmoothness,
                                 roundCap, serie.clockwise);
                DrawCenter(vh, serie, serieData, insideRadius, j == data.Count - 1);
            }
            if (!serie.animation.IsFinish())
            {
                serie.animation.CheckProgress(360);
                chart.RefreshChart();
            }
            if (dataChanging)
            {
                chart.RefreshChart();
            }
        }