Ejemplo n.º 1
0
        private int GetPiePosIndex(Serie serie, Vector2 local)
        {
            if (!(serie is Pie))
            {
                return(-1);
            }

            var dist      = Vector2.Distance(local, serie.context.center);
            var maxRadius = serie.context.outsideRadius + 3 * chart.theme.serie.pieSelectedOffset;

            if (dist < serie.context.insideRadius || dist > maxRadius)
            {
                return(-1);
            }

            var dir   = local - new Vector2(serie.context.center.x, serie.context.center.y);
            var angle = ChartHelper.GetAngle360(Vector2.up, dir);

            for (int i = 0; i < serie.data.Count; i++)
            {
                var serieData = serie.data[i];
                if (angle >= serieData.context.startAngle && angle <= serieData.context.toAngle)
                {
                    var ndist = serieData.selected ?
                                Vector2.Distance(local, serieData.context.offsetCenter) :
                                dist;
                    if (ndist >= serieData.context.insideRadius && ndist <= serieData.context.outsideRadius)
                    {
                        return(i);
                    }
                }
            }
            return(-1);
        }
Ejemplo n.º 2
0
        protected override void UpdatePointerValue(Axis axis)
        {
            var polar = chart.GetChartComponent <PolarCoord>(axis.polarIndex);

            if (polar == null)
            {
                return;
            }

            if (!polar.context.isPointerEnter)
            {
                axis.context.pointerValue = double.PositiveInfinity;
                return;
            }

            var dir   = (chart.pointerPos - new Vector2(polar.context.center.x, polar.context.center.y)).normalized;
            var angle = ChartHelper.GetAngle360(Vector2.up, dir);

            axis.context.pointerValue         = (angle - component.context.startAngle + 360) % 360;
            axis.context.pointerLabelPosition = polar.context.center + new Vector3(dir.x, dir.y) * (polar.context.radius + 25);
        }
        private static void CheckSerieDataLabel(Serie serie, SerieData serieData, int total, bool isLeft, ComponentTheme theme,
                                                ref Vector3 lastCheckPos, ref float lastX)
        {
            if (!serieData.context.canShowLabel)
            {
                serieData.SetLabelActive(false);
                return;
            }
            if (!serieData.show)
            {
                return;
            }
            var serieLabel = SerieHelper.GetSerieLabel(serie, serieData);
            var isOutside  = serieLabel.position == LabelStyle.Position.Outside ||
                             serieLabel.position == LabelStyle.Position.Default;

            if (!serieLabel.show)
            {
                return;
            }
            if (!isOutside)
            {
                return;
            }
            var labelLine = SerieHelper.GetSerieLabelLine(serie, serieData);
            var fontSize  = serieData.labelObject.GetHeight();

            if (lastCheckPos == Vector3.zero)
            {
                lastCheckPos = serieData.context.labelPosition;
            }
            else if (serieData.context.labelPosition.x != 0)
            {
                if (lastCheckPos.y - serieData.context.labelPosition.y < fontSize)
                {
                    var labelRadius = serie.context.outsideRadius + labelLine.lineLength1;
                    var y1          = lastCheckPos.y - fontSize;
                    var cy          = serie.context.center.y;
                    var diff        = Mathf.Abs(y1 - cy);
                    var diffX       = labelRadius * labelRadius - diff * diff;
                    diffX = diffX <= 0 ? 0 : diffX;
                    var x1     = serie.context.center.x + Mathf.Sqrt(diffX) * (isLeft ? -1 : 1);
                    var newPos = new Vector3(x1, y1);
                    serieData.context.labelPosition = newPos;
                    var angle = ChartHelper.GetAngle360(Vector2.up, newPos - serie.context.center);
                    if (angle >= 180 && angle <= 270)
                    {
                        serieData.context.labelPosition = new Vector3(isLeft?(++lastX): (--lastX), y1);
                    }
                    else if (angle < 180 && angle >= 90)
                    {
                        serieData.context.labelPosition = new Vector3(isLeft?(++lastX): (--lastX), y1);
                    }
                    else
                    {
                        lastX = x1;
                    }
                }
                else
                {
                    lastX = serieData.context.labelPosition.x;
                }
                lastCheckPos = serieData.context.labelPosition;
                serieData.labelObject.SetPosition(SerieLabelHelper.GetRealLabelPosition(serie, serieData, serieLabel, labelLine));
            }
        }
        private void UpdateSeriePolarContext()
        {
            if (m_SeriePolar == null)
            {
                return;
            }

            var needCheck = (chart.isPointerInChart && m_SeriePolar.IsPointerEnter()) || m_LegendEnter;
            var lineWidth = 0f;

            if (!needCheck)
            {
                if (m_LastCheckContextFlag != needCheck)
                {
                    var needAnimation1 = false;
                    lineWidth = serie.lineStyle.GetWidth(chart.theme.serie.lineWidth);
                    m_LastCheckContextFlag             = needCheck;
                    serie.context.pointerItemDataIndex = -1;
                    serie.context.pointerEnter         = false;
                    serie.interact.SetValue(ref needAnimation1, lineWidth, false);
                    foreach (var serieData in serie.data)
                    {
                        var symbol     = SerieHelper.GetSerieSymbol(serie, serieData);
                        var symbolSize = symbol.GetSize(serieData.data, chart.theme.serie.lineSymbolSize);
                        serieData.context.highlight = false;
                        serieData.interact.SetValue(ref needAnimation1, symbolSize);
                    }
                    if (needAnimation1)
                    {
                        if (SeriesHelper.IsStack(chart.series))
                        {
                            chart.RefreshTopPainter();
                        }
                        else
                        {
                            chart.RefreshPainter(serie);
                        }
                    }
                }
                return;
            }
            m_LastCheckContextFlag = needCheck;
            var themeSymbolSize         = chart.theme.serie.lineSymbolSize;
            var themeSymbolSelectedSize = chart.theme.serie.lineSymbolSelectedSize;

            lineWidth = serie.lineStyle.GetWidth(chart.theme.serie.lineWidth);

            var needInteract = false;

            if (m_LegendEnter)
            {
                serie.interact.SetValue(ref needInteract, lineWidth, true, chart.theme.serie.selectedRate);
                for (int i = 0; i < serie.dataCount; i++)
                {
                    var serieData          = serie.data[i];
                    var symbol             = SerieHelper.GetSerieSymbol(serie, serieData);
                    var symbolSelectedSize = symbol.GetSelectedSize(serieData.data, themeSymbolSelectedSize);

                    serieData.context.highlight = true;
                    serieData.interact.SetValue(ref needInteract, symbolSelectedSize);
                }
            }
            else
            {
                serie.context.pointerItemDataIndex = -1;
                serie.context.pointerEnter         = false;
                var dir          = chart.pointerPos - new Vector2(m_SeriePolar.context.center.x, m_SeriePolar.context.center.y);
                var pointerAngle = ChartHelper.GetAngle360(Vector2.up, dir);
                for (int i = 0; i < serie.dataCount; i++)
                {
                    var serieData = serie.data[i];
                    var angle0    = serieData.context.angle;
                    var angle1    = i >= serie.dataCount - 1 ? angle0 : serie.data[i + 1].context.angle;

                    if (pointerAngle >= angle0 && pointerAngle < angle1)
                    {
                        serie.context.pointerItemDataIndex = i;
                        serie.context.pointerEnter         = true;
                        serieData.context.highlight        = true;
                    }
                    else
                    {
                        serieData.context.highlight = false;
                    }
                }
            }
            if (needInteract)
            {
                if (SeriesHelper.IsStack(chart.series))
                {
                    chart.RefreshTopPainter();
                }
                else
                {
                    chart.RefreshPainter(serie);
                }
            }
        }