core-plot Mixing CPTScatterPlotInterpolationCurved and CPTScatterPlotInterpolationLinear

254 Views Asked by At

I need to be able to draw sequential line segments that have the same Y Coordinate with CPTScatterPlotInterpolationLinear and ones that do not with CPTScatterPlotInterpolationCurved. As CPTScatterPlotInterpolationCurved draws all lines curved. I am currently doing this by adding multiple plots.

public List<CorrectedGraphPoints> GetCorrectDataPoints(List<PointF> dataSource)
        {
            int lastIndex = 0;
            bool shouldLoop = true;
            CPTScatterPlotInterpolation interpolation = CPTScatterPlotInterpolation.Curved;
            List<CorrectedGraphPoints> OuterList = new List<CorrectedGraphPoints> ();

            if (dataSource [0].Y == dataSource [1].Y)
                interpolation = CPTScatterPlotInterpolation.Linear;

            while (lastIndex+1 != dataSource.Count) {
                OuterList.Add (new CorrectedGraphPoints (interpolation));

                while (shouldLoop) 
                {

                    OuterList[OuterList.Count -1].Add(dataSource[lastIndex]);
                    if ((lastIndex + 1) < dataSource.Count) {
                        if (interpolation == CPTScatterPlotInterpolation.Linear) {
                            if (dataSource [lastIndex].Y != dataSource [lastIndex + 1].Y) {
                                interpolation = CPTScatterPlotInterpolation.Curved;
                                shouldLoop = false;
                                break;
                            }
                        }

                        if (interpolation == CPTScatterPlotInterpolation.Curved) {
                            if (dataSource [lastIndex].Y == dataSource [lastIndex + 1].Y) {
                                interpolation = CPTScatterPlotInterpolation.Linear;
                                shouldLoop = false;
                                break;
                            }
                        }
                    } 
                    else {
                        shouldLoop = false;
                        break;
                    }

                    if (shouldLoop)
                        lastIndex++;
                }

                shouldLoop = true;
            }

            return OuterList;


        }



public class CorrectedGraphPoints
    {
        private List<PointF> points;
        public List<PointF> Points { get { return points; } }

        private CPTScatterPlotInterpolation interpolation;
        public CPTScatterPlotInterpolation Interpolation { get { return interpolation; } }


        public CorrectedGraphPoints(CPTScatterPlotInterpolation interpolation)
        {
            this.interpolation = interpolation;
            points = new List<PointF> ();
        }

        public void Add(PointF point)
        {
            points.Add (point);
        }
    }

However creating multiple plots that use fill slows the app down tremendously. I was wondering if I could limit how much I do this? I haven't been able to find a way to change the interpolation for a section?? IS this an just an issue with core plot or is it something wrong with my logic or code?

1

There are 1 best solutions below

1
On

Another possible solution would be to add additional points to your data to draw the curved sections. This would allow you to use only one plot. The number of additional points needed will depend on several factors including the size of the plot and the line style used to draw the line.