Exemple #1
0
        private static DataPoint FindNextNonEmptyPoint(IList <DataPoint> dataPoints, DataPointSegment dataSegment, bool isClosedShape)
        {
            // NOTE: We cannot simply get the first point from the next segment as "segment" is defined at least for two points
            // and it is possible that there are single non-empty points in-between segments.
            if (dataSegment.EndIndex < dataPoints.Count - 1)
            {
                for (int i = dataSegment.EndIndex + 1; i < dataPoints.Count; i++)
                {
                    var point = dataPoints[i];
                    if (!point.isEmpty && !double.IsNaN(point.CenterX()) && !double.IsNaN(point.CenterY()))
                    {
                        return(point);
                    }
                }
            }

            if (isClosedShape)
            {
                for (int i = 0; i < dataPoints.Count; i++)
                {
                    var point = dataPoints[i];
                    if (!point.isEmpty && !double.IsNaN(point.CenterX()) && !double.IsNaN(point.CenterY()))
                    {
                        return(point);
                    }
                }
            }

            return(dataPoints[dataSegment.EndIndex]);
        }
Exemple #2
0
        protected override IEnumerable <Point> GetPoints(DataPointSegment segment)
        {
            AxisPlotDirection plotDirection = this.model.GetTypedValue <AxisPlotDirection>(AxisModel.PlotDirectionPropertyKey, AxisPlotDirection.Vertical);
            ReferenceDictionary <string, Delegate> valueExtractor = plotDirection == AxisPlotDirection.Vertical ? VerticalPlotValueExtractors : HorizontalPlotValueExtractors;

            foreach (Point point in StepSeriesHelper.GetPoints(segment, this.model as StepSeriesModel, this.renderPoints, valueExtractor))
            {
                yield return(point);
            }
        }
Exemple #3
0
        protected override IEnumerable <Point> GetTopPoints(DataPointSegment segment)
        {
            int pointIndex = segment.StartIndex;

            while (pointIndex <= segment.EndIndex)
            {
                yield return(this.renderPoints[pointIndex].Center());

                pointIndex++;
            }
        }
Exemple #4
0
        protected override IEnumerable <Point> GetPoints(DataPointSegment segment)
        {
            // return the first point since spline segmentation skips it
            yield return(this.renderPoints[segment.StartIndex].Center());

            IChartView view        = this.model.GetChartArea().view;
            double     scaleFactor = Math.Abs(view.ZoomWidth - view.ZoomHeight) / 2;

            foreach (Point point in SplineHelper.GetSplinePoints(this.renderPoints, segment, scaleFactor))
            {
                yield return(point);
            }
        }
Exemple #5
0
        protected override IEnumerable <Windows.Foundation.Point> GetTopPoints(DataPointSegment segment)
        {
            AxisPlotDirection plotDirection = this.model.GetTypedValue <AxisPlotDirection>(AxisModel.PlotDirectionPropertyKey, AxisPlotDirection.Vertical);
            ReferenceDictionary <string, Delegate> valueExtractor = plotDirection == AxisPlotDirection.Vertical ? VerticalRangePlotValueExtractors : HorizontalRangePlotValueExtractors;
            Func <DataPoint, Point> topPointGetter = (Func <DataPoint, Point>)valueExtractor[TopPointGetter];

            int pointIndex = segment.StartIndex;

            while (pointIndex <= segment.EndIndex)
            {
                var currentPoint = this.renderPoints[pointIndex];
                yield return(topPointGetter(currentPoint));

                pointIndex++;
            }
        }
Exemple #6
0
        protected static IEnumerable <DataPointSegment> GetDataSegments(IList <DataPoint> dataPoints)
        {
            DataPointSegment dataSegment = null;

            int pointIndex = 0;

            foreach (DataPoint point in dataPoints)
            {
                if (point.isEmpty || double.IsNaN(point.CenterX()) || double.IsNaN(point.CenterY()))
                {
                    if (dataSegment != null)
                    {
                        dataSegment.EndIndex = pointIndex - 1;

                        // segment is defined for at least two points
                        if (dataSegment.StartIndex != dataSegment.EndIndex)
                        {
                            yield return(dataSegment);
                        }

                        dataSegment = null;
                    }
                }
                else
                {
                    if (dataSegment == null)
                    {
                        dataSegment            = new DataPointSegment();
                        dataSegment.StartIndex = pointIndex;
                    }
                }

                pointIndex++;
            }

            if (dataSegment != null)
            {
                dataSegment.EndIndex = dataPoints.Count - 1;

                // segment is defined for at least two points
                if (dataSegment.StartIndex != dataSegment.EndIndex)
                {
                    yield return(dataSegment);
                }
            }
        }
Exemple #7
0
        internal static IEnumerable <Point> GetPoints(DataPointSegment segment, StepSeriesModel seriesModel, IList <DataPoint> renderPoints, ReferenceDictionary <string, Delegate> valueExtractor)
        {
            AxisPlotDirection plotDirection = seriesModel.GetTypedValue <AxisPlotDirection>(AxisModel.PlotDirectionPropertyKey, AxisPlotDirection.Vertical);
            AxisModel         axisModel     = plotDirection == AxisPlotDirection.Vertical ? seriesModel.firstAxis : seriesModel.secondAxis;

            var risersActualPosition            = StepSeriesHelper.GetActualRisersPosition(seriesModel.RisersPosition, axisModel.ActualPlotMode);
            var isRisersPositionEqualToPlotMode = StepSeriesHelper.IsRisersPositionEqualToPlotMode(axisModel.ActualPlotMode, risersActualPosition);

            var    view           = seriesModel.GetChartArea().view;
            Size   chartScale     = new Size(view.ZoomWidth, view.ZoomHeight);
            double slotLength     = StepSeriesHelper.GetSlotLength(seriesModel, plotDirection, chartScale);
            double halfSlotLength = slotLength / 2;

            Func <Point, Point, Point>         riserPointGetter       = (Func <Point, Point, Point>)valueExtractor[RiserPointGetter];
            Func <Point, Point, double, Point> firstRiserPointGetter  = (Func <Point, Point, double, Point>)valueExtractor[FirstRiserPointGetter];
            Func <Point, Point, double, Point> secondRiserPointGetter = (Func <Point, Point, double, Point>)valueExtractor[SecondRiserPointGetter];

            int pointIndex = segment.StartIndex;

            while (pointIndex <= segment.EndIndex)
            {
                var currentPoint = renderPoints[pointIndex].Center();
                yield return(currentPoint);

                if (pointIndex == segment.EndIndex)
                {
                    yield break;
                }

                var nextPoint = renderPoints[pointIndex + 1].Center();
                if (isRisersPositionEqualToPlotMode || axisModel is DateTimeContinuousAxisModel)
                {
                    yield return(riserPointGetter(currentPoint, nextPoint));
                }
                else
                {
                    yield return(firstRiserPointGetter(currentPoint, nextPoint, halfSlotLength));

                    yield return(secondRiserPointGetter(currentPoint, nextPoint, halfSlotLength));
                }

                pointIndex++;
            }
        }
Exemple #8
0
        protected override IList <Point> GetBottomPoints(AreaRenderContext context)
        {
            AxisPlotDirection plotDirection = this.model.GetTypedValue <AxisPlotDirection>(AxisModel.PlotDirectionPropertyKey, AxisPlotDirection.Vertical);
            ReferenceDictionary <string, Delegate> valueExtractor = plotDirection == AxisPlotDirection.Vertical ? VerticalRangePlotValueExtractors : HorizontalRangePlotValueExtractors;
            Func <DataPoint, Point> bottomPointGetter             = (Func <DataPoint, Point>)valueExtractor[BottomPointGetter];

            DataPointSegment currentSegment = context.CurrentSegment;
            List <Point>     points         = new List <Point>();
            int pointIndex = currentSegment.StartIndex;

            while (pointIndex <= currentSegment.EndIndex)
            {
                var currentPoint = this.renderPoints[pointIndex];
                points.Add(bottomPointGetter(currentPoint));
                pointIndex++;
            }

            return(points);
        }
Exemple #9
0
        public static IEnumerable <Point> GetSplinePoints(IList <DataPoint> dataPoints, DataPointSegment dataSegment, double scaleFactor, bool isClosedShape = false)
        {
            double tolerance = DefaultTolerance;

            if (scaleFactor > 2)
            {
                tolerance *= (int)scaleFactor / 2;
            }

            Point startPoint = FindPreviousNonEmptyPoint(dataPoints, dataSegment, isClosedShape).Center();
            Point endPoint   = FindNextNonEmptyPoint(dataPoints, dataSegment, isClosedShape).Center();

            // NOTE: data segment is defined for at least two points so we do not need the check conditions for zero or one count.
            int segmentPointCount = dataSegment.EndIndex - dataSegment.StartIndex + 1;

            if (segmentPointCount == 2)
            {
                Point firstPoint  = dataPoints[dataSegment.StartIndex].Center();
                Point secondPoint = dataPoints[dataSegment.EndIndex].Center();

                foreach (Point segmentedPoint in Segment(startPoint, firstPoint, secondPoint, endPoint, tolerance))
                {
                    yield return(segmentedPoint);
                }

                yield break;
            }

            IEnumerable <Point> segmentedPoints;

            for (int i = dataSegment.StartIndex; i < dataSegment.EndIndex; i++)
            {
                if (i == dataSegment.StartIndex)
                {
                    segmentedPoints = Segment(
                        startPoint,
                        dataPoints[i].Center(),
                        dataPoints[i + 1].Center(),
                        dataPoints[i + 2].Center(),
                        tolerance);
                }
                else if (i == dataSegment.EndIndex - 1)
                {
                    segmentedPoints = Segment(
                        dataPoints[i - 1].Center(),
                        dataPoints[i].Center(),
                        dataPoints[i + 1].Center(),
                        endPoint,
                        tolerance);
                }
                else
                {
                    segmentedPoints = Segment(
                        dataPoints[i - 1].Center(),
                        dataPoints[i].Center(),
                        dataPoints[i + 1].Center(),
                        dataPoints[i + 2].Center(),
                        tolerance);
                }

                foreach (Point point in segmentedPoints)
                {
                    yield return(point);
                }
            }
        }
 protected abstract IEnumerable <Point> GetTopPoints(DataPointSegment segment);
Exemple #11
0
        protected override IList <Windows.Foundation.Point> GetBottomPoints(AreaRenderContext context)
        {
            List <Point>     points         = new List <Point>();
            DataPointSegment currentSegment = context.CurrentSegment;

            ReferenceDictionary <string, Delegate> valueExtractor;

            if (context.PlotDirection == AxisPlotDirection.Vertical)
            {
                valueExtractor = AreaRendererBase.VerticalPlotValueExtractors;
            }
            else
            {
                valueExtractor = AreaRendererBase.HorizontalPlotValueExtractors;
            }

            if (!context.IsStacked)
            {
                Func <DataPoint, double, Point> pointGetter = (Func <DataPoint, double, Point>)valueExtractor[PointGetter];

                points.Add(pointGetter(this.renderPoints[currentSegment.StartIndex], context.PlotLine));
                points.Add(pointGetter(this.renderPoints[currentSegment.EndIndex], context.PlotLine));
            }
            else
            {
                Func <Point, int>           pointBoundsGetter        = (Func <Point, int>)valueExtractor[PointBoundsGetter];
                Func <DataPoint, bool, int> dataPointBoundsGetter    = (Func <DataPoint, bool, int>)valueExtractor[DataPointBoundsGetter];
                Func <int, int, bool, bool> shouldSkipPreviousPoints = (Func <int, int, bool, bool>)valueExtractor[ShouldSkipPreviousPoints];
                Func <int, int, bool, bool> segmentEndNotReached     = (Func <int, int, bool, bool>)valueExtractor[SegmentEndNotReached];
                Func <Point, Point, bool>   shouldRemoveDuplicate    = (Func <Point, Point, bool>)valueExtractor[ShouldRemoveDuplicate];

                int           segmentStart  = dataPointBoundsGetter(this.renderPoints[currentSegment.StartIndex], context.IsPlotInverse);
                int           segmentEnd    = dataPointBoundsGetter(this.renderPoints[currentSegment.EndIndex], context.IsPlotInverse);
                IList <Point> stackedPoints = context.PreviousStackedPoints;
                Point         currentPoint;
                int           currentPointBounds;

                do
                {
                    currentPoint       = stackedPoints[context.PreviousStackedPointsCurrentIndex];
                    currentPointBounds = pointBoundsGetter(currentPoint);

                    context.PreviousStackedPointsCurrentIndex++;
                    if (shouldSkipPreviousPoints(currentPointBounds, segmentStart, context.IsPlotInverse))
                    {
                        continue;
                    }

                    points.Add(currentPoint);
                }while (segmentEndNotReached(currentPointBounds, segmentEnd, context.IsPlotInverse) && context.PreviousStackedPointsCurrentIndex < stackedPoints.Count);

                context.PreviousStackedPointsCurrentIndex--;

                if (shouldRemoveDuplicate(points[0], points[1]))
                {
                    points.RemoveAt(0);
                }
            }

            return(points);
        }