Пример #1
0
        /// <summary>
        /// 给定的线段和Grid边界的交点
        /// </summary>
        /// <param name="sp"></param>
        /// <param name="ep"></param>
        /// <returns></returns>
        public bool BoundaryPoint(Vector3 sp, Vector3 ep, ref Vector3 point)
        {
            if (Contains(sp) && Contains(ep))
            {
                point = ep;
                return(false);
            }
            var lb = new Vector3(context.x, context.y);
            var lt = new Vector3(context.x, context.y + context.height);
            var rt = new Vector3(context.x + context.width, context.y + context.height);
            var rb = new Vector3(context.x + context.width, context.y);

            if (UGLHelper.GetIntersection(sp, ep, rb, rt, ref point))
            {
                return(true);
            }
            if (UGLHelper.GetIntersection(sp, ep, lt, rt, ref point))
            {
                return(true);
            }
            if (UGLHelper.GetIntersection(sp, ep, lb, rb, ref point))
            {
                return(true);
            }
            if (UGLHelper.GetIntersection(sp, ep, lb, lt, ref point))
            {
                return(true);
            }
            return(false);
        }
Пример #2
0
        public static bool GetAnimationPosition(AnimationStyle animation, bool isY, Vector3 lp, Vector3 cp, float progress, ref Vector3 ip)
        {
            if (animation.context.type == AnimationType.AlongPath)
            {
                var dist = Vector3.Distance(lp, cp);
                var rate = (dist - animation.context.currentPathDistance + animation.GetCurrDetail()) / dist;
                ip = Vector3.Lerp(lp, cp, rate);
                return(true);
            }
            else
            {
                var startPos = isY ? new Vector3(-10000, progress) : new Vector3(progress, -10000);
                var endPos   = isY ? new Vector3(10000, progress) : new Vector3(progress, 10000);

                return(UGLHelper.GetIntersection(lp, cp, startPos, endPos, ref ip));
            }
        }
Пример #3
0
        private void DrawParallelSerie(VertexHelper vh, Parallel serie)
        {
            if (!serie.show)
            {
                return;
            }
            if (serie.animation.HasFadeOut())
            {
                return;
            }

            var parallel = chart.GetChartComponent <ParallelCoord>(serie.parallelIndex);

            if (parallel == null)
            {
                return;
            }

            var axisCount = parallel.context.parallelAxes.Count;

            if (axisCount <= 0)
            {
                return;
            }

            var animationIndex = serie.animation.GetCurrIndex();
            var isHorizonal    = parallel.orient == Orient.Horizonal;
            var lineColor      = SerieHelper.GetLineColor(serie, null, chart.theme, serie.context.colorIndex, false);
            var lineWidth      = serie.lineStyle.GetWidth(chart.theme.serie.lineWidth);

            float currDetailProgress = !isHorizonal ?
                                       parallel.context.x :
                                       parallel.context.y;

            float totalDetailProgress = !isHorizonal ?
                                        parallel.context.x + parallel.context.width :
                                        parallel.context.y + parallel.context.height;

            serie.animation.InitProgress(currDetailProgress, totalDetailProgress);

            serie.context.dataPoints.Clear();
            serie.containerIndex       = parallel.index;
            serie.containterInstanceId = parallel.instanceId;

            var currProgress = serie.animation.GetCurrDetail();
            var isSmooth     = serie.lineType == LineType.Smooth;

            foreach (var serieData in serie.data)
            {
                m_Points.Clear();
                var count = Mathf.Min(axisCount, serieData.data.Count);
                var lp    = Vector3.zero;
                for (int i = 0; i < count; i++)
                {
                    if (animationIndex >= 0 && i > animationIndex)
                    {
                        continue;
                    }
                    var pos = GetPos(parallel, i, serieData.data[i], isHorizonal);
                    if (!isHorizonal)
                    {
                        if (isSmooth)
                        {
                            m_Points.Add(pos);
                        }
                        else if (pos.x <= currProgress)
                        {
                            m_Points.Add(pos);
                        }
                        else
                        {
                            var currProgressStart = new Vector3(currProgress, parallel.context.y - 50);
                            var currProgressEnd   = new Vector3(currProgress, parallel.context.y + parallel.context.height + 50);
                            var intersectionPos   = Vector3.zero;

                            if (UGLHelper.GetIntersection(lp, pos, currProgressStart, currProgressEnd, ref intersectionPos))
                            {
                                m_Points.Add(intersectionPos);
                            }
                            else
                            {
                                m_Points.Add(pos);
                            }
                            break;
                        }
                    }
                    else
                    {
                        if (isSmooth)
                        {
                            m_Points.Add(pos);
                        }
                        else if (pos.y <= currProgress)
                        {
                            m_Points.Add(pos);
                        }
                        else
                        {
                            var currProgressStart = new Vector3(parallel.context.x - 50, currProgress);
                            var currProgressEnd   = new Vector3(parallel.context.x + parallel.context.width + 50, currProgress);
                            var intersectionPos   = Vector3.zero;

                            if (UGLHelper.GetIntersection(lp, pos, currProgressStart, currProgressEnd, ref intersectionPos))
                            {
                                m_Points.Add(intersectionPos);
                            }
                            else
                            {
                                m_Points.Add(pos);
                            }
                            break;
                        }
                    }
                    lp = pos;
                }
                if (isSmooth)
                {
                    UGL.DrawCurves(vh, m_Points, lineWidth, lineColor, chart.settings.lineSmoothness, currProgress, isHorizonal);
                }
                else
                {
                    UGL.DrawLine(vh, m_Points, lineWidth, lineColor, isSmooth);
                }
            }
            if (!serie.animation.IsFinish())
            {
                serie.animation.CheckProgress(totalDetailProgress - currDetailProgress);
                chart.RefreshPainter(serie);
            }
        }
Пример #4
0
        private static void DrawSerieLineNormalArea(VertexHelper vh, Serie serie, bool isY,
                                                    float zero, float min, float max, Color32 areaColor, Color32 areaToColor,
                                                    VisualMap visualMap, Axis axis, Axis relativedAxis, GridCoord grid)
        {
            var points = serie.context.drawPoints;
            var count  = points.Count;

            if (count < 2)
            {
                return;
            }

            var isBreak             = false;
            var lp                  = Vector3.zero;
            var isVisualMapGradient = VisualMapHelper.IsNeedAreaGradient(visualMap);
            var areaLerp            = !ChartHelper.IsValueEqualsColor(areaColor, areaToColor);
            var zsp                 = isY ?
                                      new Vector3(zero, points[0].position.y) :
                                      new Vector3(points[0].position.x, zero);
            var zep = isY ?
                      new Vector3(zero, points[count - 1].position.y) :
                      new Vector3(points[count - 1].position.x, zero);

            var lastDataIsIgnore = false;

            for (int i = 0; i < points.Count; i++)
            {
                var tp       = points[i].position;
                var isIgnore = points[i].isIgnoreBreak;
                var color    = areaColor;
                var toColor  = areaToColor;
                var lerp     = areaLerp;

                if (serie.animation.CheckDetailBreak(tp, isY))
                {
                    isBreak = true;

                    var progress     = serie.animation.GetCurrDetail();
                    var ip           = Vector3.zero;
                    var axisStartPos = isY ? new Vector3(-10000, progress) : new Vector3(progress, -10000);
                    var axisEndPos   = isY ? new Vector3(10000, progress) : new Vector3(progress, 10000);

                    if (UGLHelper.GetIntersection(lp, tp, axisStartPos, axisEndPos, ref ip))
                    {
                        tp = ip;
                    }
                }
                var zp = isY ? new Vector3(zero, tp.y) : new Vector3(tp.x, zero);
                if (isVisualMapGradient)
                {
                    color   = VisualMapHelper.GetLineGradientColor(visualMap, zp, grid, axis, relativedAxis, areaColor);
                    toColor = VisualMapHelper.GetLineGradientColor(visualMap, tp, grid, axis, relativedAxis, areaToColor);
                    lerp    = true;
                }
                if (i > 0)
                {
                    if ((lp.y - zero > 0 && tp.y - zero < 0) || (lp.y - zero < 0 && tp.y - zero > 0))
                    {
                        var ip = Vector3.zero;
                        if (UGLHelper.GetIntersection(lp, tp, zsp, zep, ref ip))
                        {
                            if (lerp)
                            {
                                AddVertToVertexHelperWithLerpColor(vh, ip, ip, color, toColor, isY, min, max, i > 0);
                            }
                            else
                            {
                                if (lastDataIsIgnore)
                                {
                                    UGL.AddVertToVertexHelper(vh, ip, ip, ColorUtil.clearColor32, true);
                                }

                                UGL.AddVertToVertexHelper(vh, ip, ip, toColor, color, i > 0);

                                if (isIgnore)
                                {
                                    UGL.AddVertToVertexHelper(vh, ip, ip, ColorUtil.clearColor32, true);
                                }
                            }
                        }
                    }
                }

                if (lerp)
                {
                    AddVertToVertexHelperWithLerpColor(vh, tp, zp, color, toColor, isY, min, max, i > 0);
                }
                else
                {
                    if (lastDataIsIgnore)
                    {
                        UGL.AddVertToVertexHelper(vh, tp, zp, ColorUtil.clearColor32, true);
                    }

                    UGL.AddVertToVertexHelper(vh, tp, zp, toColor, color, i > 0);

                    if (isIgnore)
                    {
                        UGL.AddVertToVertexHelper(vh, tp, zp, ColorUtil.clearColor32, true);
                    }
                }
                lp = tp;
                lastDataIsIgnore = isIgnore;
                if (isBreak)
                {
                    break;
                }
            }
        }
Пример #5
0
        private static void DrawSerieLineStackArea(VertexHelper vh, Serie serie, Serie lastStackSerie, bool isY,
                                                   float zero, float min, float max, Color32 color, Color32 toColor, VisualMap visualMap)
        {
            if (lastStackSerie == null)
            {
                return;
            }

            var upPoints   = serie.context.drawPoints;
            var downPoints = lastStackSerie.context.drawPoints;
            var upCount    = upPoints.Count;
            var downCount  = downPoints.Count;

            if (upCount <= 0 || downCount <= 0)
            {
                return;
            }

            var lerp = !ChartHelper.IsValueEqualsColor(color, toColor);
            var ltp  = upPoints[0].position;
            var lbp  = downPoints[0].position;

            if (lerp)
            {
                AddVertToVertexHelperWithLerpColor(vh, ltp, lbp, color, toColor, isY, min, max, false);
            }
            else
            {
                UGL.AddVertToVertexHelper(vh, ltp, lbp, color, false);
            }

            int u = 1, d = 1;
            var isBreakTop    = false;
            var isBreakBottom = false;

            while ((u < upCount || d < downCount))
            {
                var tp = u < upCount ? upPoints[u].position : upPoints[upCount - 1].position;
                var bp = d < downCount ? downPoints[d].position : downPoints[downCount - 1].position;

                var tnp = (u + 1) < upCount ? upPoints[u + 1].position : upPoints[upCount - 1].position;
                var bnp = (d + 1) < downCount ? downPoints[d + 1].position : downPoints[downCount - 1].position;

                if (serie.animation.CheckDetailBreak(tp, isY))
                {
                    isBreakTop = true;

                    var progress = serie.animation.GetCurrDetail();
                    var ip       = Vector3.zero;

                    if (UGLHelper.GetIntersection(ltp, tp,
                                                  new Vector3(progress, -10000),
                                                  new Vector3(progress, 10000), ref ip))
                    {
                        tp = ip;
                    }
                    else
                    {
                        tp = new Vector3(progress, tp.y);
                    }
                }
                if (serie.animation.CheckDetailBreak(bp, isY))
                {
                    isBreakBottom = true;

                    var progress = serie.animation.GetCurrDetail();
                    var ip       = Vector3.zero;

                    if (UGLHelper.GetIntersection(lbp, bp,
                                                  new Vector3(progress, -10000),
                                                  new Vector3(progress, 10000), ref ip))
                    {
                        bp = ip;
                    }
                    else
                    {
                        bp = new Vector3(progress, bp.y);
                    }
                }

                if (lerp)
                {
                    AddVertToVertexHelperWithLerpColor(vh, tp, bp, color, toColor, isY, min, max, true);
                }
                else
                {
                    UGL.AddVertToVertexHelper(vh, tp, bp, color, true);
                }
                u++;
                d++;
                if (bp.x < tp.x && bnp.x < tp.x)
                {
                    u--;
                }
                if (tp.x < bp.x && tnp.x < bp.x)
                {
                    d--;
                }

                ltp = tp;
                lbp = bp;
                if (isBreakTop && isBreakBottom)
                {
                    break;
                }
            }
        }