Пример #1
0
        private void InitSerieLabel()
        {
            m_SerieLabelRoot = ChartHelper.AddObject(s_SerieLabelObjectName, transform, m_ChartMinAnchor,
                                                     m_ChartMaxAnchor, m_ChartPivot, m_ChartSizeDelta);
            m_SerieLabelRoot.hideFlags = chartHideFlags;
            SerieLabelPool.ReleaseAll(m_SerieLabelRoot.transform);
            int count = 0;

            for (int i = 0; i < m_Series.Count; i++)
            {
                var serie = m_Series.list[i];
                SerieHelper.UpdateCenter(serie, chartPosition, chartWidth, chartHeight);
                for (int j = 0; j < serie.data.Count; j++)
                {
                    var serieData = serie.data[j];
                    serieData.index = j;
                    AddSerieLabel(serie, serieData, count);
                    count++;
                }
            }
            SerieLabelHelper.UpdateLabelText(m_Series, m_ThemeInfo);
        }
        private void InitAxisLabel()
        {
            if (!SeriesHelper.ContainsSerie(chart.series, SerieType.Gauge))
            {
                return;
            }
            var labelObject = ChartHelper.AddObject(s_AxisLabelObjectName, chart.transform, chart.chartMinAnchor,
                                                    chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta);

            labelObject.hideFlags = chart.chartHideFlags;
            SerieLabelPool.ReleaseAll(labelObject.transform);
            for (int i = 0; i < chart.series.Count; i++)
            {
                var serie = chart.series.list[i];
                if (serie.type != SerieType.Gauge)
                {
                    continue;
                }
                var serieLabel = serie.gaugeAxis.axisLabel;
                var count      = serie.splitNumber > 36 ? 36 : (serie.splitNumber + 1);
                var startAngle = serie.startAngle;
                var textColor  = serieLabel.textStyle.GetColor(chart.theme.gauge.textColor);
                serie.gaugeAxis.ClearLabelObject();
                SerieHelper.UpdateCenter(serie, chart.chartPosition, chart.chartWidth, chart.chartHeight);
                for (int j = 0; j < count; j++)
                {
                    var textName   = ChartCached.GetSerieLabelName(s_SerieLabelObjectName, i, j);
                    var labelObj   = SerieLabelPool.Get(textName, labelObject.transform, serieLabel, textColor, 100, 100, chart.theme);
                    var iconImage  = labelObj.transform.Find("Icon").GetComponent <Image>();
                    var isAutoSize = serieLabel.backgroundWidth == 0 || serieLabel.backgroundHeight == 0;
                    var item       = new ChartLabel();
                    item.SetLabel(labelObj, isAutoSize, serieLabel.paddingLeftRight, serieLabel.paddingTopBottom);
                    item.SetIcon(iconImage);
                    item.SetIconActive(false);
                    serie.gaugeAxis.AddLabelObject(item);
                }
                UpdateAxisLabel(serie);
            }
        }
Пример #3
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.runtimePieDataMax   = 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();
                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 = 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.runtimePieDataMax :
                                                        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, serie.clockwise);
                    }
                    else //if(n==0)
                    {
                        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, serie.clockwise);
                        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;
        }
Пример #4
0
        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);
        }
Пример #5
0
        public void DrawSerie(VertexHelper vh, Serie serie)
        {
            if (serie.type != SerieType.Ring)
            {
                return;
            }
            if (!serie.show || serie.animation.HasFadeOut())
            {
                return;
            }
            var data = serie.data;

            serie.animation.InitProgress(data.Count, serie.startAngle, serie.startAngle + 360);
            SerieHelper.UpdateCenter(serie, chart.chartPosition, chart.chartWidth, chart.chartHeight);
            TitleStyleHelper.CheckTitle(serie, ref chart.m_ReinitTitle, ref m_UpdateTitleText);
            SerieLabelHelper.CheckLabel(serie, ref chart.m_ReinitLabel, ref m_UpdateLabelText);
            var dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
            var ringWidth          = serie.runtimeOutsideRadius - serie.runtimeInsideRadius;
            var dataChanging       = false;

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

                serieData.runtimePieStartAngle    = serie.clockwise ? startDegree : toDegree;
                serieData.runtimePieToAngle       = serie.clockwise ? toDegree : startDegree;
                serieData.runtimePieInsideRadius  = insideRadius;
                serieData.runtimePieOutsideRadius = outsideRadius;
                UGL.DrawDoughnut(vh, serie.runtimeCenterPos, 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);
                UpateLabelPosition(serie, serieData, j, startDegree, toDegree, centerRadius);
            }
            if (!serie.animation.IsFinish())
            {
                serie.animation.CheckProgress(360);
                chart.RefreshChart();
            }
            if (dataChanging)
            {
                chart.RefreshChart();
            }
        }