示例#1
0
        protected override void DrawChart(VertexHelper vh)
        {
            base.DrawChart(vh);
            int  serieNameCount  = -1;
            bool isClickOffset   = false;
            bool isDataHighlight = false;

            for (int i = 0; i < m_Series.Count; i++)
            {
                var serie = m_Series.list[i];
                serie.index = i;
                var data = serie.data;
                serie.animation.InitProgress(data.Count, 0, 360);
                if (!serie.show || serie.animation.HasFadeOut())
                {
                    continue;
                }
                bool isFinish = true;
                if (serie.pieClickOffset)
                {
                    isClickOffset = true;
                }
                serie.runtimeDataMax      = serie.yMax;
                serie.runtimePieDataTotal = serie.yTotal;
                SerieHelper.UpdateCenter(serie, chartPosition, chartWidth, chartHeight);

                float totalDegree   = 360;
                float startDegree   = 0;
                int   showdataCount = 0;
                foreach (var sd in serie.data)
                {
                    if (sd.show && serie.pieRoseType == RoseType.Area)
                    {
                        showdataCount++;
                    }
                    sd.canShowLabel = false;
                }
                bool  dataChanging       = false;
                float dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
                bool  isAllZeroValue     = SerieHelper.IsAllZeroValue(serie, 1);
                float zeroReplaceValue   = 360f / data.Count;
                if (isAllZeroValue)
                {
                    serie.runtimeDataMax      = zeroReplaceValue;
                    serie.runtimePieDataTotal = 360f;
                }
                for (int n = 0; n < data.Count; n++)
                {
                    var serieData = data[n];
                    var itemStyle = SerieHelper.GetItemStyle(serie, serieData, serieData.highlighted);
                    serieData.index = n;
                    float value = isAllZeroValue ? zeroReplaceValue : serieData.GetCurrData(1, dataChangeDuration);
                    if (serieData.IsDataChanged())
                    {
                        dataChanging = true;
                    }
                    serieNameCount = m_LegendRealShowName.IndexOf(serieData.legendName);
                    var color       = SerieHelper.GetItemColor(serie, serieData, m_ThemeInfo, serieNameCount, serieData.highlighted);
                    var toColor     = SerieHelper.GetItemToColor(serie, serieData, m_ThemeInfo, serieNameCount, serieData.highlighted);
                    var borderWidth = itemStyle.borderWidth;
                    var borderColor = itemStyle.borderColor;

                    serieData.runtimePieStartAngle = startDegree;
                    serieData.runtimePieToAngle    = startDegree;
                    serieData.runtimePieHalfAngle  = startDegree;
                    serieData.runtimePieCurrAngle  = startDegree;
                    if (!serieData.show)
                    {
                        continue;
                    }
                    float degree = serie.pieRoseType == RoseType.Area ?
                                   (totalDegree / showdataCount) : (totalDegree * value / serie.runtimePieDataTotal);
                    serieData.runtimePieToAngle = startDegree + degree;

                    serieData.runtimePieOutsideRadius = serie.pieRoseType > 0 ?
                                                        serie.runtimeInsideRadius + (serie.runtimeOutsideRadius - serie.runtimeInsideRadius) * value / serie.runtimeDataMax :
                                                        serie.runtimeOutsideRadius;
                    if (serieData.highlighted)
                    {
                        isDataHighlight = true;
                        serieData.runtimePieOutsideRadius += m_Settings.pieTooltipExtraRadius;
                    }
                    var offset = 0f;
                    if (serie.pieClickOffset && serieData.selected)
                    {
                        offset += m_Settings.pieSelectedOffset;
                    }
                    var halfDegree = (serieData.runtimePieToAngle - startDegree) / 2;
                    serieData.runtimePieHalfAngle = startDegree + halfDegree;
                    float currRad = serieData.runtimePieHalfAngle * Mathf.Deg2Rad;
                    float currSin = Mathf.Sin(currRad);
                    float currCos = Mathf.Cos(currRad);
                    var   center  = serie.runtimeCenterPos;

                    serieData.runtimePieCurrAngle    = serieData.runtimePieToAngle;
                    serieData.runtiemPieOffsetCenter = center;
                    serieData.runtimePieInsideRadius = serie.runtimeInsideRadius;
                    if (serie.animation.CheckDetailBreak(serieData.runtimePieToAngle))
                    {
                        isFinish = false;
                        serieData.runtimePieCurrAngle = serie.animation.GetCurrDetail();
                    }
                    if (offset > 0)
                    {
                        serieData.runtimePieOffsetRadius   = 0;
                        serieData.runtimePieInsideRadius  -= serieData.runtimePieOffsetRadius;
                        serieData.runtimePieOutsideRadius -= serieData.runtimePieOffsetRadius;
                        if (serie.pieClickOffset && serieData.selected)
                        {
                            serieData.runtimePieOffsetRadius += m_Settings.pieSelectedOffset;
                            if (serieData.runtimePieInsideRadius > 0)
                            {
                                serieData.runtimePieInsideRadius += m_Settings.pieSelectedOffset;
                            }
                            serieData.runtimePieOutsideRadius += m_Settings.pieSelectedOffset;
                        }

                        serieData.runtiemPieOffsetCenter = new Vector3(center.x + serieData.runtimePieOffsetRadius * currSin,
                                                                       center.y + serieData.runtimePieOffsetRadius * currCos);
                        var drawEndDegree = serieData.runtimePieCurrAngle;
                        var needRoundCap  = serie.roundCap && serieData.runtimePieInsideRadius > 0;

                        ChartDrawer.DrawDoughnut(vh, serieData.runtiemPieOffsetCenter, serieData.runtimePieInsideRadius,
                                                 serieData.runtimePieOutsideRadius, color, toColor, Color.clear, startDegree, drawEndDegree,
                                                 borderWidth, borderColor, serie.pieSpace / 2, m_Settings.cicleSmoothness, needRoundCap, true);
                    }
                    else
                    {
                        var drawEndDegree = serieData.runtimePieCurrAngle;
                        var needRoundCap  = serie.roundCap && serieData.runtimePieInsideRadius > 0;
                        ChartDrawer.DrawDoughnut(vh, center, serieData.runtimePieInsideRadius, serieData.runtimePieOutsideRadius,
                                                 color, toColor, Color.clear, startDegree, drawEndDegree, borderWidth, borderColor, serie.pieSpace / 2,
                                                 m_Settings.cicleSmoothness, needRoundCap, true);
                        DrawCenter(vh, serie, itemStyle, serieData.runtimePieInsideRadius);
                    }
                    serieData.canShowLabel = serieData.runtimePieCurrAngle >= serieData.runtimePieHalfAngle;
                    isDrawPie   = true;
                    startDegree = serieData.runtimePieToAngle;
                    if (isFinish)
                    {
                        serie.animation.SetDataFinish(n);
                    }
                    else
                    {
                        break;
                    }
                }
                if (!serie.animation.IsFinish())
                {
                    serie.animation.CheckProgress(360);
                    serie.animation.CheckSymbol(serie.symbol.size);
                    RefreshChart();
                }
                if (dataChanging)
                {
                    RefreshChart();
                }
            }
            DrawLabelLine(vh);
            DrawLabelBackground(vh);
            raycastTarget = isClickOffset && isDataHighlight;
        }
        private void UpdateRuntimeData(Serie serie)
        {
            var data = serie.data;

            serie.runtimeDataMax      = serie.yMax;
            serie.runtimePieDataTotal = serie.yTotal;

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

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

            if (isAllZeroValue)
            {
                totalDegree               = 360;
                zeroReplaceValue          = totalDegree / data.Count;
                serie.runtimeDataMax      = zeroReplaceValue;
                serie.runtimePieDataTotal = 360;
            }
            else
            {
                dataTotalFilterMinAngle = GetTotalAngle(serie, serie.runtimePieDataTotal, ref totalDegree);
            }
            serie.animation.InitProgress(data.Count, 0, 360);
            for (int n = 0; n < data.Count; n++)
            {
                var serieData = data[n];
                serieData.index = n;
                float value = isAllZeroValue ? zeroReplaceValue : serieData.GetCurrData(1, dataChangeDuration);
                serieData.runtimePieStartAngle = startDegree;
                serieData.runtimePieToAngle    = startDegree;
                serieData.runtimePieHalfAngle  = startDegree;
                serieData.runtimePieCurrAngle  = startDegree;
                if (!serieData.show)
                {
                    continue;
                }
                float degree = serie.pieRoseType == RoseType.Area
                    ? (totalDegree / showdataCount)
                    : (totalDegree * value / dataTotalFilterMinAngle);
                if (serie.minAngle > 0 && degree < serie.minAngle)
                {
                    degree = serie.minAngle;
                }
                serieData.runtimePieToAngle       = startDegree + degree;
                serieData.runtimePieOutsideRadius = serie.pieRoseType > 0 ?
                                                    serie.runtimeInsideRadius +
                                                    (serie.runtimeOutsideRadius - serie.runtimeInsideRadius) * value / serie.runtimeDataMax :
                                                    serie.runtimeOutsideRadius;
                if (serieData.highlighted)
                {
                    serieData.runtimePieOutsideRadius += chart.theme.serie.pieTooltipExtraRadius;
                }
                var offset = 0f;
                if (serie.pieClickOffset && serieData.selected)
                {
                    offset += chart.theme.serie.pieSelectedOffset;
                }
                if (serie.animation.CheckDetailBreak(serieData.runtimePieToAngle))
                {
                    serieData.runtimePieCurrAngle = serie.animation.GetCurrDetail();
                }
                else
                {
                    serieData.runtimePieCurrAngle = serieData.runtimePieToAngle;
                }
                var halfDegree = (serieData.runtimePieToAngle - startDegree) / 2;
                serieData.runtimePieHalfAngle    = startDegree + halfDegree;
                serieData.runtiemPieOffsetCenter = serie.runtimeCenterPos;
                serieData.runtimePieInsideRadius = serie.runtimeInsideRadius;
                if (offset > 0)
                {
                    var currRad = serieData.runtimePieHalfAngle * Mathf.Deg2Rad;
                    var currSin = Mathf.Sin(currRad);
                    var currCos = Mathf.Cos(currRad);
                    serieData.runtimePieOffsetRadius   = 0;
                    serieData.runtimePieInsideRadius  -= serieData.runtimePieOffsetRadius;
                    serieData.runtimePieOutsideRadius -= serieData.runtimePieOffsetRadius;
                    if (serie.pieClickOffset && serieData.selected)
                    {
                        serieData.runtimePieOffsetRadius += chart.theme.serie.pieSelectedOffset;
                        if (serieData.runtimePieInsideRadius > 0)
                        {
                            serieData.runtimePieInsideRadius += chart.theme.serie.pieSelectedOffset;
                        }
                        serieData.runtimePieOutsideRadius += chart.theme.serie.pieSelectedOffset;
                    }
                    serieData.runtiemPieOffsetCenter = new Vector3(
                        serie.runtimeCenterPos.x + serieData.runtimePieOffsetRadius * currSin,
                        serie.runtimeCenterPos.y + serieData.runtimePieOffsetRadius * currCos);
                }
                serieData.canShowLabel = serieData.runtimePieCurrAngle >= serieData.runtimePieHalfAngle;
                startDegree            = serieData.runtimePieToAngle;
                SerieLabelHelper.UpdatePieLabelPosition(serie, serieData);
            }
            SerieLabelHelper.AvoidLabelOverlap(serie);
        }
示例#3
0
        private void DrawPie(VertexHelper vh)
        {
            bool isClickOffset   = false;
            bool isDataHighlight = false;

            for (int i = 0; i < m_Series.Count; i++)
            {
                var serie = m_Series.list[i];
                serie.index = i;
                var data = serie.data;
                serie.animation.InitProgress(data.Count, 0, 360);
                if (!serie.show || serie.animation.HasFadeOut())
                {
                    continue;
                }
                if (serie.pieClickOffset)
                {
                    isClickOffset = true;
                }
                bool  dataChanging       = false;
                float dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
                bool  isAllZeroValue     = SerieHelper.IsAllZeroValue(serie, 1);
                for (int n = 0; n < data.Count; n++)
                {
                    var serieData = data[n];
                    if (!serieData.show)
                    {
                        continue;
                    }
                    var itemStyle = SerieHelper.GetItemStyle(serie, serieData, serieData.highlighted);
                    if (serieData.IsDataChanged())
                    {
                        dataChanging = true;
                    }
                    var serieNameCount = m_LegendRealShowName.IndexOf(serieData.legendName);
                    var color          = SerieHelper.GetItemColor(serie, serieData, m_ThemeInfo, serieNameCount, serieData.highlighted);
                    var toColor        = SerieHelper.GetItemToColor(serie, serieData, m_ThemeInfo, serieNameCount, serieData.highlighted);
                    var borderWidth    = itemStyle.borderWidth;
                    var borderColor    = itemStyle.borderColor;

                    if (serieData.highlighted)
                    {
                        isDataHighlight = true;
                    }
                    if (serie.pieClickOffset && serieData.selected)
                    {
                        var drawEndDegree = serieData.runtimePieCurrAngle;
                        var needRoundCap  = serie.roundCap && serieData.runtimePieInsideRadius > 0;
                        ChartDrawer.DrawDoughnut(vh, serieData.runtiemPieOffsetCenter, serieData.runtimePieInsideRadius,
                                                 serieData.runtimePieOutsideRadius, color, toColor, Color.clear, serieData.runtimePieStartAngle, drawEndDegree,
                                                 borderWidth, borderColor, serie.pieSpace / 2, m_Settings.cicleSmoothness, needRoundCap, true);
                    }
                    else
                    {
                        var drawEndDegree = serieData.runtimePieCurrAngle;
                        var needRoundCap  = serie.roundCap && serieData.runtimePieInsideRadius > 0;
                        ChartDrawer.DrawDoughnut(vh, serie.runtimeCenterPos, serieData.runtimePieInsideRadius, serieData.runtimePieOutsideRadius,
                                                 color, toColor, Color.clear, serieData.runtimePieStartAngle, drawEndDegree, borderWidth, borderColor, serie.pieSpace / 2,
                                                 m_Settings.cicleSmoothness, needRoundCap, true);
                        DrawCenter(vh, serie, itemStyle, serieData.runtimePieInsideRadius);
                    }
                    isDrawPie = true;
                    if (!serie.animation.CheckDetailBreak(serieData.runtimePieToAngle))
                    {
                        serie.animation.SetDataFinish(n);
                    }
                    else
                    {
                        break;
                    }
                }
                if (!serie.animation.IsFinish())
                {
                    serie.animation.CheckProgress(360);
                    serie.animation.CheckSymbol(serie.symbol.size);
                    RefreshChart();
                }
                if (dataChanging)
                {
                    RefreshChart();
                }
            }
            raycastTarget = isClickOffset && isDataHighlight;
        }