private Vector3 GetLabelPosition(PolarCoord polar, Axis axis, float startAngle, float totalWidth)
        {
            var cenPos     = polar.context.center;
            var dire       = ChartHelper.GetDire(startAngle, true).normalized;
            var tickLength = axis.axisTick.GetLength(chart.theme.axis.tickLength);
            var tickVector = ChartHelper.GetVertialDire(dire) *
                             (tickLength + axis.axisLabel.distance);

            return(ChartHelper.GetPos(cenPos, totalWidth, startAngle, true) + tickVector);
        }
        private void DrawRadiusAxis(VertexHelper vh, RadiusAxis radiusAxis)
        {
            var polar = chart.GetChartComponent <PolarCoord>(radiusAxis.polarIndex);

            if (polar == null)
            {
                return;
            }

            var angleAxis = ComponentHelper.GetAngleAxis(chart.components, polar.index);

            if (angleAxis == null)
            {
                return;
            }

            var startAngle = angleAxis.context.startAngle;
            var radius     = polar.context.radius;
            var cenPos     = polar.context.center;
            var size       = AxisHelper.GetScaleNumber(radiusAxis, radius, null);
            var totalWidth = 0f;
            var dire       = ChartHelper.GetDire(startAngle, true).normalized;
            var tickWidth  = radiusAxis.axisTick.GetWidth(chart.theme.axis.tickWidth);
            var tickLength = radiusAxis.axisTick.GetLength(chart.theme.axis.tickLength);
            var tickVetor  = ChartHelper.GetVertialDire(dire) * tickLength;

            for (int i = 0; i <= size; i++)
            {
                var scaleWidth = AxisHelper.GetScaleWidth(radiusAxis, radius, i);
                var pos        = ChartHelper.GetPos(cenPos, totalWidth + tickWidth, startAngle, true);
                if (radiusAxis.show && radiusAxis.splitLine.show)
                {
                    var outsideRaidus  = totalWidth + radiusAxis.splitLine.GetWidth(chart.theme.axis.splitLineWidth) * 2;
                    var splitLineColor = radiusAxis.splitLine.GetColor(chart.theme.axis.splitLineColor);
                    UGL.DrawDoughnut(vh, cenPos, totalWidth, outsideRaidus, splitLineColor, Color.clear);
                }
                if (radiusAxis.show && radiusAxis.axisTick.show)
                {
                    if ((i == 0 && radiusAxis.axisTick.showStartTick) ||
                        (i == size && radiusAxis.axisTick.showEndTick) ||
                        (i > 0 && i < size))
                    {
                        UGL.DrawLine(vh, pos, pos + tickVetor, tickWidth, chart.theme.axis.lineColor);
                    }
                }
                totalWidth += scaleWidth;
            }
            if (radiusAxis.show && radiusAxis.axisLine.show)
            {
                var lineStartPos = polar.context.center - dire * tickWidth;
                var lineEndPos   = polar.context.center + dire * (radius + tickWidth);
                var lineWidth    = radiusAxis.axisLine.GetWidth(chart.theme.axis.lineWidth);
                UGL.DrawLine(vh, lineStartPos, lineEndPos, lineWidth, chart.theme.axis.lineColor);
            }
        }
Esempio n. 3
0
        private void InitAngleAxis(AngleAxis axis)
        {
            var polar = chart.GetChartComponent <PolarCoord>(axis.polarIndex);

            if (polar == null)
            {
                return;
            }
            PolarHelper.UpdatePolarCenter(polar, chart.chartPosition, chart.chartWidth, chart.chartHeight);
            var radius = polar.context.radius;

            axis.context.labelObjectList.Clear();
            axis.context.startAngle = 90 - axis.startAngle;

            string objName = component.GetType().Name + axis.index;
            var    axisObj = ChartHelper.AddObject(objName, chart.transform, chart.chartMinAnchor,
                                                   chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta);

            axisObj.transform.localPosition = Vector3.zero;
            axisObj.SetActive(axis.show);
            axisObj.hideFlags = chart.chartHideFlags;
            ChartHelper.HideAllObject(axisObj);
            var splitNumber    = AxisHelper.GetSplitNumber(axis, radius, null);
            var totalAngle     = axis.context.startAngle;
            var total          = 360;
            var cenPos         = polar.context.center;
            var txtHig         = axis.axisLabel.textStyle.GetFontSize(chart.theme.axis) + 2;
            var margin         = axis.axisLabel.distance + axis.axisTick.GetLength(chart.theme.axis.tickLength);
            var isCategory     = axis.IsCategory();
            var isPercentStack = SeriesHelper.IsPercentStack <Bar>(chart.series);

            for (int i = 0; i < splitNumber; i++)
            {
                float scaleAngle = AxisHelper.GetScaleWidth(axis, total, i + 1, null);
                bool  inside     = axis.axisLabel.inside;
                var   labelName  = AxisHelper.GetLabelName(axis, total, i, axis.context.minValue, axis.context.maxValue,
                                                           null, isPercentStack);
                var label = ChartHelper.AddAxisLabelObject(splitNumber, i, objName + i, axisObj.transform,
                                                           new Vector2(scaleAngle, txtHig), axis,
                                                           chart.theme.axis, labelName, Color.clear);
                label.text.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.text, scaleAngle);
                }
                axis.context.labelObjectList.Add(label);

                totalAngle += scaleAngle;
            }
        }
Esempio n. 4
0
        private void DrawAngleAxis(VertexHelper vh, AngleAxis angleAxis)
        {
            var polar          = chart.GetChartComponent <PolarCoord>(angleAxis.polarIndex);
            var radius         = polar.context.radius;
            var cenPos         = polar.context.center;
            var total          = 360;
            var size           = AxisHelper.GetScaleNumber(angleAxis, total, null);
            var currAngle      = angleAxis.context.startAngle;
            var tickWidth      = angleAxis.axisTick.GetWidth(chart.theme.axis.tickWidth);
            var tickLength     = angleAxis.axisTick.GetLength(chart.theme.axis.tickLength);
            var tickColor      = angleAxis.axisTick.GetColor(chart.theme.axis.lineColor);
            var lineColor      = angleAxis.axisLine.GetColor(chart.theme.axis.lineColor);
            var splitLineColor = angleAxis.splitLine.GetColor(chart.theme.axis.splitLineColor);

            for (int i = 1; i < size; i++)
            {
                var scaleWidth = AxisHelper.GetScaleWidth(angleAxis, total, i);
                var pos        = ChartHelper.GetPos(cenPos, radius, currAngle, true);
                if (angleAxis.show && angleAxis.splitLine.show)
                {
                    var lineWidth = angleAxis.splitLine.GetWidth(chart.theme.axis.splitLineWidth);
                    UGL.DrawLine(vh, cenPos, pos, lineWidth, splitLineColor);
                }
                if (angleAxis.show && angleAxis.axisTick.show)
                {
                    if ((i == 1 && angleAxis.axisTick.showStartTick) ||
                        (i == size - 1 && angleAxis.axisTick.showEndTick) ||
                        (i > 1 && i < size - 1))
                    {
                        var tickY   = radius + tickLength;
                        var tickPos = ChartHelper.GetPos(cenPos, tickY, currAngle, true);
                        UGL.DrawLine(vh, pos, tickPos, tickWidth, tickColor);
                    }
                }
                currAngle += scaleWidth;
            }
            if (angleAxis.show && angleAxis.axisLine.show)
            {
                var lineWidth     = angleAxis.axisLine.GetWidth(chart.theme.axis.lineWidth);
                var outsideRaidus = radius + lineWidth * 2;
                UGL.DrawDoughnut(vh, cenPos, radius, outsideRaidus, lineColor, Color.clear);
            }
        }
        private void DrawPolarIndicator(VertexHelper vh, Tooltip tooltip, PolarCoord m_Polar)
        {
            if (tooltip.context.angle < 0)
            {
                return;
            }
            var theme        = chart.theme;
            var m_AngleAxis  = ComponentHelper.GetAngleAxis(chart.components, m_Polar.index);
            var lineColor    = TooltipHelper.GetLineColor(tooltip, theme);
            var lineType     = tooltip.lineStyle.GetType(theme.tooltip.lineType);
            var lineWidth    = tooltip.lineStyle.GetWidth(theme.tooltip.lineWidth);
            var cenPos       = m_Polar.context.center;
            var radius       = m_Polar.context.radius;
            var sp           = m_Polar.context.center;
            var tooltipAngle = m_AngleAxis.GetValueAngle(tooltip.context.angle);

            var ep = ChartHelper.GetPos(sp, radius, tooltipAngle, true);

            switch (tooltip.type)
            {
            case Tooltip.Type.Corss:
                ChartDrawer.DrawLineStyle(vh, lineType, lineWidth, sp, ep, lineColor);
                var dist = Vector2.Distance(chart.pointerPos, cenPos);
                if (dist > radius)
                {
                    dist = radius;
                }
                var outsideRaidus = dist + tooltip.lineStyle.GetWidth(theme.tooltip.lineWidth) * 2;
                UGL.DrawDoughnut(vh, cenPos, dist, outsideRaidus, lineColor, Color.clear);
                break;

            case Tooltip.Type.Line:
                ChartDrawer.DrawLineStyle(vh, lineType, lineWidth, sp, ep, lineColor);
                break;

            case Tooltip.Type.Shadow:
                UGL.DrawSector(vh, cenPos, radius, lineColor, tooltipAngle - 2, tooltipAngle + 2, chart.settings.cicleSmoothness);
                break;
            }
        }
        private Vector3 GetPolarPos(PolarCoord m_Polar, AngleAxis m_AngleAxis, SerieData serieData, double min,
                                    double max, float polarRadius)
        {
            var angle = 0f;

            if (!m_AngleAxis.clockwise)
            {
                angle = m_AngleAxis.GetValueAngle((float)serieData.GetData(1));
            }
            else
            {
                angle = m_AngleAxis.GetValueAngle((float)serieData.GetData(1));
            }

            var value  = serieData.GetData(0);
            var radius = (float)((value - min) / (max - min) * polarRadius);

            angle = (angle + 360) % 360;
            serieData.context.angle    = angle;
            serieData.context.position = ChartHelper.GetPos(m_Polar.context.center, radius, angle, true);

            return(serieData.context.position);
        }