Esempio n. 1
0
        private void InitRadiusAxis(RadiusAxis axis)
        {
            PolarHelper.UpdatePolarCenter(m_Polar, m_ChartPosition, m_ChartWidth, m_ChartHeight);
            var radius = m_Polar.runtimeRadius;

            axis.axisLabelTextList.Clear();
            string objName = "axis_radius";
            var    axisObj = ChartHelper.AddObject(objName, transform, chartAnchorMin,
                                                   chartAnchorMax, chartPivot, new Vector2(chartWidth, chartHeight));

            axisObj.transform.localPosition = Vector3.zero;
            axisObj.SetActive(axis.show && axis.axisLabel.show);
            axisObj.hideFlags = chartHideFlags;
            ChartHelper.HideAllObject(axisObj);
            var labelColor = ChartHelper.IsClearColor(axis.axisLabel.color) ?
                             (Color)m_ThemeInfo.axisTextColor :
                             axis.axisLabel.color;
            int   splitNumber = AxisHelper.GetSplitNumber(axis, radius, null);
            float totalWidth  = 0;
            var   startAngle  = m_AngleAxis.runtimeStartAngle;
            var   cenPos      = m_Polar.runtimeCenterPos;
            var   txtHig      = axis.axisLabel.fontSize + 2;
            var   dire        = ChartHelper.GetDire(startAngle, true).normalized;
            var   tickVetor   = ChartHelper.GetVertialDire(dire) * (m_RadiusAxis.axisTick.length + m_RadiusAxis.axisLabel.margin);

            for (int i = 0; i < splitNumber; i++)
            {
                float labelWidth = AxisHelper.GetScaleWidth(axis, radius, i, null);
                bool  inside     = axis.axisLabel.inside;
                Text  txt        = ChartHelper.AddTextObject(objName + i, axisObj.transform,
                                                             m_ThemeInfo.font, labelColor, TextAnchor.MiddleCenter, new Vector2(0.5f, 0.5f),
                                                             new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(labelWidth, txtHig),
                                                             axis.axisLabel.fontSize, axis.axisLabel.rotate, axis.axisLabel.fontStyle);
                if (i == 0)
                {
                    axis.axisLabel.SetRelatedText(txt, labelWidth);
                }
                var isPercentStack = SeriesHelper.IsPercentStack(m_Series, SerieType.Bar);
                txt.text = AxisHelper.GetLabelName(axis, radius, i, axis.runtimeMinValue, axis.runtimeMaxValue, null,
                                                   isPercentStack);
                txt.gameObject.SetActive(axis.show &&
                                         (axis.axisLabel.interval == 0 || i % (axis.axisLabel.interval + 1) == 0));
                var pos = ChartHelper.GetPos(cenPos, totalWidth, startAngle, true) + tickVetor;
                txt.transform.localPosition = pos;
                AxisHelper.AdjustRadiusAxisLabelPos(txt, pos, cenPos, txtHig, Vector3.zero);
                axis.axisLabelTextList.Add(txt);

                totalWidth += labelWidth;
            }
            if (m_Tooltip.runtimeGameObject)
            {
                Vector2    privot      = new Vector2(0.5f, 1);
                var        labelParent = m_Tooltip.runtimeGameObject.transform;
                GameObject labelObj    = ChartHelper.AddTooltipLabel(ChartCached.GetAxisTooltipLabel(objName), labelParent, m_ThemeInfo.font, privot);
                axis.SetTooltipLabel(labelObj);
                axis.SetTooltipLabelColor(m_ThemeInfo.tooltipBackgroundColor, m_ThemeInfo.tooltipTextColor);
                axis.SetTooltipLabelActive(axis.show && m_Tooltip.show && m_Tooltip.type == Tooltip.Type.Corss);
            }
        }
        private void InitRadiusAxis(RadiusAxis axis)
        {
            var m_Polar = GetPolar(axis.index);

            if (m_Polars == null)
            {
                return;
            }
            var m_AngleAxis = GetAngleAxis(m_Polar.index);

            if (m_AngleAxis == null)
            {
                return;
            }
            PolarHelper.UpdatePolarCenter(m_Polar, m_ChartPosition, m_ChartWidth, m_ChartHeight);
            axis.axisLabelTextList.Clear();
            var radius  = m_Polar.runtimeRadius;
            var objName = "axis_radius" + axis.index;
            var axisObj = ChartHelper.AddObject(objName, transform, graphAnchorMin,
                                                graphAnchorMax, chartPivot, new Vector2(chartWidth, chartHeight));

            axisObj.transform.localPosition = Vector3.zero;
            axisObj.SetActive(axis.show && axis.axisLabel.show);
            axisObj.hideFlags = chartHideFlags;
            ChartHelper.HideAllObject(axisObj);
            var textStyle   = axis.axisLabel.textStyle;
            var splitNumber = AxisHelper.GetSplitNumber(axis, radius, null);
            var totalWidth  = 0f;
            var startAngle  = m_AngleAxis.runtimeStartAngle;
            var cenPos      = m_Polar.runtimeCenterPos;
            var txtHig      = textStyle.GetFontSize(m_Theme.axis) + 2;
            var dire        = ChartHelper.GetDire(startAngle, true).normalized;
            var tickWidth   = axis.axisTick.GetLength(m_Theme.radiusAxis.tickWidth);
            var tickVetor   = ChartHelper.GetVertialDire(dire)
                              * (tickWidth + axis.axisLabel.margin);

            for (int i = 0; i < splitNumber; i++)
            {
                float labelWidth = AxisHelper.GetScaleWidth(axis, radius, i, null);
                bool  inside     = axis.axisLabel.inside;
                var   txt        = ChartHelper.AddTextObject(objName + i, axisObj.transform, new Vector2(0.5f, 0.5f),
                                                             new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(labelWidth, txtHig), textStyle,
                                                             m_Theme.axis);
                if (i == 0)
                {
                    axis.axisLabel.SetRelatedText(txt, labelWidth);
                }
                var isPercentStack = SeriesHelper.IsPercentStack(m_Series, SerieType.Bar);
                var labelName      = AxisHelper.GetLabelName(axis, radius, i, axis.runtimeMinValue, axis.runtimeMaxValue,
                                                             null, isPercentStack);
                txt.SetAlignment(TextAnchor.MiddleCenter);
                txt.SetText(labelName);
                txt.SetActive(axis.show &&
                              (axis.axisLabel.interval == 0 || i % (axis.axisLabel.interval + 1) == 0));
                var pos = ChartHelper.GetPos(cenPos, totalWidth, startAngle, true) + tickVetor;
                txt.SetLocalPosition(pos);
                AxisHelper.AdjustRadiusAxisLabelPos(txt, pos, cenPos, txtHig, Vector3.zero);
                axis.axisLabelTextList.Add(txt);

                totalWidth += labelWidth;
            }
            if (tooltip.runtimeGameObject)
            {
                Vector2    privot      = new Vector2(0.5f, 1);
                var        labelParent = tooltip.runtimeGameObject.transform;
                var        labelName   = ChartCached.GetAxisTooltipLabel(objName);
                GameObject labelObj    = ChartHelper.AddTooltipLabel(labelName, labelParent, m_Theme, privot);
                axis.SetTooltipLabel(labelObj);
                axis.SetTooltipLabelColor(m_Theme.tooltip.labelBackgroundColor, m_Theme.tooltip.labelTextColor);
                axis.SetTooltipLabelActive(axis.show && tooltip.show && tooltip.type == Tooltip.Type.Corss);
            }
        }