示例#1
0
        private void InitAngleAxis(AngleAxis axis)
        {
            PolarHelper.UpdatePolarCenter(m_Polar, m_ChartPosition, m_ChartWidth, m_ChartHeight);
            var radius = m_Polar.runtimeRadius;

            axis.axisLabelTextList.Clear();

            string objName = "axis_angle";
            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 totalAngle  = m_AngleAxis.runtimeStartAngle;
            var   total       = 360;
            var   cenPos      = m_Polar.runtimeCenterPos;
            var   txtHig      = m_AngleAxis.axisLabel.fontSize + 2;
            var   margin      = m_AngleAxis.axisLabel.margin;
            var   isCategory  = m_AngleAxis.IsCategory();

            for (int i = 0; i < splitNumber - 1; i++)
            {
                float scaleAngle = AxisHelper.GetScaleWidth(axis, total, 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(scaleAngle, txtHig),
                                                             axis.axisLabel.fontSize, axis.axisLabel.rotate, axis.axisLabel.fontStyle);
                if (i == 0)
                {
                    axis.axisLabel.SetRelatedText(txt, scaleAngle);
                }
                var isPercentStack = SeriesHelper.IsPercentStack(m_Series, SerieType.Bar);
                txt.text = AxisHelper.GetLabelName(axis, total, 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, radius + margin, isCategory ? (totalAngle + scaleAngle / 2) : totalAngle, true);
                AxisHelper.AdjustCircleLabelPos(txt, pos, cenPos, txtHig, Vector3.zero);
                axis.axisLabelTextList.Add(txt);

                totalAngle += scaleAngle;
            }
            if (m_Tooltip.runtimeGameObject)
            {
                Vector2    privot      = new Vector2(0.5f, 0.5f);
                var        labelParent = m_Tooltip.runtimeGameObject.transform;
                GameObject labelObj    = ChartHelper.AddTooltipLabel(ChartCached.GetAxisTooltipLabel(objName), labelParent,
                                                                     m_ThemeInfo.font, privot, privot, privot, new Vector2(10, txtHig));
                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 Vector3 GetPolarPos(Polar m_Polar, AngleAxis m_AngleAxis, SerieData serieData, float min, float max, float polarRadius)
        {
            var angle = 0f;

            if (!m_AngleAxis.clockwise)
            {
                angle = m_AngleAxis.runtimeStartAngle - serieData.GetData(1);
            }
            else
            {
                angle = m_AngleAxis.runtimeStartAngle + serieData.GetData(1);
            }
            angle = (angle + 360) % 360;
            var value  = serieData.GetData(0);
            var radius = (value - min) / (max - min) * polarRadius;

            serieData.runtimeAngle    = angle;
            serieData.runtimePosition = ChartHelper.GetPos(m_Polar.runtimeCenterPos, radius, angle, true);
            return(serieData.runtimePosition);
        }
        public static string GetPolarFormatterContent(Tooltip tooltip, Series series, ThemeInfo themeInfo, AngleAxis angleAxis)
        {
            if (string.IsNullOrEmpty(tooltip.formatter))
            {
                var sb = ChartHelper.sb;
                sb.Length = 0;
                var title       = tooltip.titleFormatter;
                var formatTitle = !string.IsNullOrEmpty(title);
                if ("{i}".Equals(tooltip.titleFormatter))
                {
                    title       = string.Empty;
                    formatTitle = false;
                }
                else if (string.IsNullOrEmpty(title))
                {
                    var angle = angleAxis.clockwise ? tooltip.runtimeAngle : 360 - tooltip.runtimeAngle;
                    title = ChartCached.FloatToStr(angle);
                }
                foreach (var serie in series.list)
                {
                    if (serie.show && IsSelectedSerie(tooltip, serie.index))
                    {
                        if (formatTitle)
                        {
                            FormatterHelper.ReplaceContent(ref title, 0, tooltip.numericFormatter, serie, series, themeInfo, null, null);
                        }
                        var dataIndexList = tooltip.runtimeSerieIndex[serie.index];

                        for (int i = 0; i < dataIndexList.Count; i++)
                        {
                            var   dataIndex = dataIndexList[i];
                            var   serieData = serie.GetSerieData(dataIndex);
                            var   itemFormatter = GetItemFormatter(tooltip, serie, serieData);
                            var   numericFormatter = GetItemNumericFormatter(tooltip, serie, serieData);
                            float xValue, yValue;
                            serie.GetXYData(dataIndex, null, out xValue, out yValue);
                            if (string.IsNullOrEmpty(itemFormatter))
                            {
                                sb.Append("<color=#").Append(themeInfo.GetColorStr(serie.index)).Append(">● </color>");
                                if (!string.IsNullOrEmpty(serie.name))
                                {
                                    sb.Append(serie.name).Append(": ");
                                }
                                sb.AppendFormat("{0}", ChartCached.FloatToStr(xValue, numericFormatter));
                                if (i != dataIndexList.Count - 1)
                                {
                                    sb.Append(FormatterHelper.PH_NN);
                                }
                            }
                            else
                            {
                                string content = itemFormatter;
                                FormatterHelper.ReplaceContent(ref content, dataIndex, tooltip.numericFormatter, serie, series, themeInfo, null, null);
                                var dotColorIndex = serie.type == SerieType.Pie || serie.type == SerieType.Radar || serie.type == SerieType.Ring ? dataIndex : serie.index;
                                sb.Append(ChartCached.ColorToDotStr(themeInfo.GetColor(dotColorIndex)));
                                sb.Append(content);
                            }
                        }
                        sb.Append(FormatterHelper.PH_NN);
                    }
                }
                if (string.IsNullOrEmpty(title))
                {
                    return(FormatterHelper.TrimAndReplaceLine(sb));
                }
                else
                {
                    title = FormatterHelper.TrimAndReplaceLine(title);
                    return(title + FormatterHelper.PH_NN + FormatterHelper.TrimAndReplaceLine(sb));
                }
            }
            else
            {
                string content = tooltip.formatter;
                FormatterHelper.ReplaceContent(ref content, 0, tooltip.numericFormatter, null, series, themeInfo, null, null);
                return(content);
            }
        }
示例#4
0
        private void InitAngleAxis(AngleAxis axis)
        {
            var m_Polar = GetPolar(axis.polarIndex);

            if (m_Polars == null)
            {
                return;
            }
            PolarHelper.UpdatePolarCenter(m_Polar, m_ChartPosition, m_ChartWidth, m_ChartHeight);
            var radius = m_Polar.runtimeRadius;

            axis.runtimeAxisLabelList.Clear();

            string objName = "axis_angle" + axis.index;
            var    axisObj = ChartHelper.AddObject(objName, transform, graphAnchorMin,
                                                   graphAnchorMax, chartPivot, new Vector2(chartWidth, chartHeight));

            axisObj.transform.localPosition = Vector3.zero;
            axisObj.SetActive(axis.show);
            axisObj.hideFlags = chartHideFlags;
            ChartHelper.HideAllObject(axisObj);
            var splitNumber    = AxisHelper.GetSplitNumber(axis, radius, null);
            var totalAngle     = axis.runtimeStartAngle;
            var total          = 360;
            var cenPos         = m_Polar.runtimeCenterPos;
            var txtHig         = axis.axisLabel.textStyle.GetFontSize(m_Theme.axis) + 2;
            var margin         = axis.axisLabel.margin;
            var isCategory     = axis.IsCategory();
            var isPercentStack = SeriesHelper.IsPercentStack(m_Series, SerieType.Bar);

            for (int i = 0; i < splitNumber; i++)
            {
                float scaleAngle = AxisHelper.GetScaleWidth(axis, total, i, null);
                bool  inside     = axis.axisLabel.inside;
                var   labelName  = AxisHelper.GetLabelName(axis, total, i, axis.runtimeMinValue, axis.runtimeMaxValue,
                                                           null, isPercentStack);
                var label = ChartHelper.AddAxisLabelObject(splitNumber, i, objName + i, axisObj.transform, new Vector2(0.5f, 0.5f),
                                                           new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(scaleAngle, txtHig), axis,
                                                           theme.axis, labelName);
                label.label.SetAlignment(axis.axisLabel.textStyle.GetAlignment(TextAnchor.MiddleCenter));
                var pos = ChartHelper.GetPos(cenPos, radius + margin,
                                             isCategory ? (totalAngle + scaleAngle / 2) : totalAngle, true);
                AxisHelper.AdjustCircleLabelPos(label, pos, cenPos, txtHig, Vector3.zero);
                if (i == 0)
                {
                    axis.axisLabel.SetRelatedText(label.label, scaleAngle);
                }
                axis.runtimeAxisLabelList.Add(label);

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