Inheritance: PathSegment, ILineSegment
コード例 #1
0
        /// <summary>
        /// Updates the segments based on its data point value. This method is not
        /// intended to be called explicitly outside the Chart but it can be overridden by
        /// any derived class.
        /// </summary>
        /// <param name="transformer">Represents the view port of chart control.(refer <see cref="IChartTransformer"/>)</param>
        public override void Update(IChartTransformer transformer)
        {
            PathFigure figure = new PathFigure();

            int startIndex = 0;
            int endIndex   = AreaPoints.Count - 1;

            if (AreaPoints.Count > 0)
            {
                figure.StartPoint = transformer.TransformToVisible(AreaPoints[0].X, AreaPoints[0].Y);

                for (int i = startIndex; i < AreaPoints.Count; i += 2)
                {
                    WindowsLinesegment lineSeg = new WindowsLinesegment();
                    lineSeg.Point = transformer.TransformToVisible(AreaPoints[i].X, AreaPoints[i].Y);
                    figure.Segments.Add(lineSeg);
                }

                for (int i = endIndex; i >= 1; i -= 2)
                {
                    WindowsLinesegment lineSeg = new WindowsLinesegment();
                    lineSeg.Point = transformer.TransformToVisible(AreaPoints[i].X, AreaPoints[i].Y);
                    figure.Segments.Add(lineSeg);
                }
                figure.IsClosed             = true;
                Series.SeriesRootPanel.Clip = null;
            }
            PathGeometry segmentGeometry = new PathGeometry();

            segmentGeometry.Figures.Add(figure);
            segPath.Data = segmentGeometry;
        }
コード例 #2
0
        public void PlotGrid()
        {
            GridLines.Children.Clear();
            double xStart = 5;
            double xEnd = this.ActualWidth - 5;

            double y = 0;
            double step = GridLines.ActualHeight / (_numberogGridLines + 1);

            for (int i = 0; i < _numberogGridLines; i++)
            {
                y += step;
                PathFigure path = new PathFigure();
                path.StartPoint = new Point(xStart, y);
                path.IsClosed = false;
                LineSegment Line = new LineSegment();
                Line.Point = new Point(xEnd, y);
                path.Segments.Add(Line);
                PathGeometry myPath = new PathGeometry();
                myPath.Figures.Add(path);
                Path output = new Path();
                output.Data = myPath;
                output.StrokeThickness = 1;
                output.Stroke = new SolidColorBrush(Windows.UI.Color.FromArgb(100, 150, 150, 150));
                GridLines.Children.Add(output);
            }

            
        }
コード例 #3
0
        private void DrawPathGeometry()
        {
            //When the segment is resized the size is maintained.

            PathFigure pathFigure = new PathFigure();

            pathFigure.StartPoint = new Point(0, 0);

            WindowsLineSegment lineSegment1 = new WindowsLineSegment();
            WindowsLineSegment lineSegment2 = new WindowsLineSegment();

            lineSegment1.Point = new Point(averagePathSize, averagePathSize);
            pathFigure.Segments.Add(lineSegment1);

            PathFigure pathFigure2 = new PathFigure();

            pathFigure2.StartPoint = new Point(averagePathSize, 0);

            lineSegment2.Point = new Point(0, averagePathSize);
            pathFigure2.Segments.Add(lineSegment2);

            PathGeometry geometry = new PathGeometry();

            geometry.Figures.Add(pathFigure);
            geometry.Figures.Add(pathFigure2);

            averagePath.Data = geometry;
        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            // Create the AppBarButton for the 'Triangle' command
            AppBarButton triangle = new AppBarButton();
            triangle.Label = "Triangle";

            // This button will use the PathIcon class for its icon which allows us to 
            // use vector data to represent the icon
            PathIcon trianglePathIcon = new PathIcon();
            PathGeometry g = new PathGeometry();
            g.FillRule = FillRule.Nonzero;

            // Just create a simple triange shape
            PathFigure f = new PathFigure();
            f.IsFilled = true;
            f.IsClosed = true;
            f.StartPoint = new Windows.Foundation.Point(20.0, 5.0);
            LineSegment s1 = new LineSegment();
            s1.Point = new Windows.Foundation.Point(30.0, 30.0);
            LineSegment s2 = new LineSegment();
            s2.Point = new Windows.Foundation.Point(10.0, 30.0);
            LineSegment s3 = new LineSegment();
            s3.Point = new Windows.Foundation.Point(20.0, 5.0);
            f.Segments.Add(s1);
            f.Segments.Add(s2);
            f.Segments.Add(s3);
            g.Figures.Add(f);

            trianglePathIcon.Data = g;

            triangle.Icon = trianglePathIcon;

            ((CommandBar)BottomAppBar).PrimaryCommands.Insert(2, triangle);
        }
        public void Draw(EasingFunctionBase easingFunction)
        {
            canvas1.Children.Clear();


            var pathSegments = new PathSegmentCollection();

            for (double i = 0; i < 1; i += SamplingInterval)
            {
                double x = i * canvas1.Width;
                double y = easingFunction.Ease(i) * canvas1.Height;

                var segment = new LineSegment();
                segment.Point = new Point(x, y);

                pathSegments.Add(segment);

            }
            var p = new Path();
            p.Stroke = new SolidColorBrush(Colors.Black);
            p.StrokeThickness = 3;
            var figures = new PathFigureCollection();
            figures.Add(new PathFigure() { Segments = pathSegments });
            p.Data = new PathGeometry() { Figures = figures };
            canvas1.Children.Add(p);
        }
コード例 #6
0
ファイル: ArrowLine.cs プロジェクト: Mohsens22/OpenPasat
        /// <summary>
        /// Initializes a new instance of the <see cref="ArrowLine"/> class.
        /// </summary>
        public ArrowLine()
        {
            pathGeometry = new PathGeometry();

            pathFigureLine = new PathFigure();
            segmentLine    = new Windows.UI.Xaml.Media.LineSegment();
            pathFigureLine.Segments.Add(segmentLine);

            pathFigureHead  = new PathFigure();
            polySegmentHead = new PolyLineSegment();
            pathFigureHead.Segments.Add(polySegmentHead);
        }
コード例 #7
0
ファイル: PiePath.cs プロジェクト: HppZ/UniversalTest
        public PiePath()
        {
            pathFigure = new PathFigure { IsClosed = true };
            lineSegment = new LineSegment();
            arcSegment = new ArcSegment { SweepDirection = SweepDirection.Clockwise };
            pathFigure.Segments.Add(lineSegment);
            pathFigure.Segments.Add(arcSegment);

            PathGeometry pathGeometry = new PathGeometry();
            pathGeometry.Figures.Add(pathFigure);

            this.Data = pathGeometry;
            UpdateValues();
        }
コード例 #8
0
ファイル: PyramidSegment.cs プロジェクト: Mohsens22/OpenPasat
        /// <summary>
        /// Updates the segments based on its data point value. This method is not
        /// intended to be called explicitly outside the Chart but it can be overriden by
        /// any derived class.
        /// </summary>
        /// <param name="transformer">Reresents the view port of chart control.(refer <see cref="IChartTransformer"/>)</param>
        public override void Update(IChartTransformer transformer)
        {
            if (!this.IsSegmentVisible)
            {
                segmentPath.Visibility = Visibility.Collapsed;
            }
            else
            {
                segmentPath.Visibility = Visibility.Visible;
            }

            Rect          rect   = new Rect(0, 0, transformer.Viewport.Width, transformer.Viewport.Height);
            PyramidSeries series = Series as PyramidSeries;

            if (rect.IsEmpty)
            {
                this.segmentPath.Data = null;
            }
            else
            {
                if (this.isExploded)
                {
                    rect.X += explodedOffset;
                }
                double     top          = y;
                double     bottom       = y + height;
                double     topRadius    = 0.5d * (1d - y);
                double     bottomRadius = 0.5d * (1d - bottom);
                PathFigure figure       = new PathFigure();
                figure.StartPoint = new Point(rect.X + topRadius * rect.Width, rect.Y + top * rect.Height);
                Linesegment lineSeg1 = new Linesegment();
                lineSeg1.Point = new Point(rect.X + (1 - topRadius) * rect.Width, rect.Y + top * rect.Height);
                figure.Segments.Add(lineSeg1);
                Linesegment lineSeg3 = new Linesegment();
                lineSeg3.Point = new Point(rect.X + (1 - bottomRadius) * rect.Width, rect.Y + bottom * rect.Height - series.StrokeThickness / 2);
                figure.Segments.Add(lineSeg3);
                Linesegment lineSeg4 = new Linesegment();
                lineSeg4.Point = new Point(rect.X + bottomRadius * rect.Width, rect.Y + bottom * rect.Height - series.StrokeThickness / 2);
                figure.Segments.Add(lineSeg4);
                figure.IsClosed              = true;
                this.segmentGeometry         = new PathGeometry();
                this.segmentGeometry.Figures = new PathFigureCollection()
                {
                    figure
                };
                segmentPath.Data = segmentGeometry;

                height = ((bottom - top) * rect.Height) / 2;
            }
        }
コード例 #9
0
ファイル: PiePiece.cs プロジェクト: crazycreak/Template10
        public void UpdatePath()
        {
            // ensure variables
            if (GetValue(StartAngleProperty) == DependencyProperty.UnsetValue)
                throw new ArgumentNullException("Start Angle is required");
            if (GetValue(RadiusProperty) == DependencyProperty.UnsetValue)
                throw new ArgumentNullException("Radius is required");
            if (GetValue(AngleProperty) == DependencyProperty.UnsetValue)
                throw new ArgumentNullException("Angle is required");

            Width = Height = 2 * (Radius + StrokeThickness);
            var endAngle = StartAngle + Angle;

            // path container
            var figureP = new Point(Radius, Radius);
            var figure = new PathFigure
            {
                StartPoint = figureP,
                IsClosed = true,
            };

            //  start angle line
            var lineX = Radius + Math.Sin(StartAngle * Math.PI / 180) * Radius;
            var lineY = Radius - Math.Cos(StartAngle * Math.PI / 180) * Radius;
            var lineP = new Point(lineX, lineY);
            var line = new LineSegment { Point = lineP };
            figure.Segments.Add(line);

            // outer arc
            var arcX = Radius + Math.Sin(endAngle * Math.PI / 180) * Radius;
            var arcY = Radius - Math.Cos(endAngle * Math.PI / 180) * Radius;
            var arcS = new Size(Radius, Radius);
            var arcP = new Point(arcX, arcY);
            var arc = new ArcSegment
            {
                IsLargeArc = Angle >= 180.0,
                Point = arcP,
                Size = arcS,
                SweepDirection = SweepDirection.Clockwise,
            };
            figure.Segments.Add(arc);

            // finalé
            Data = new PathGeometry { Figures = { figure } };
            InvalidateArrange();
        }
コード例 #10
0
        private static PathGeometry CloneDeep(PathGeometry pathGeometry)
        {
            var newPathGeometry = new PathGeometry();
            foreach (var figure in pathGeometry.Figures)
            {
                var newFigure = new PathFigure();
                newFigure.StartPoint = figure.StartPoint;
                foreach (var segment in figure.Segments)
                {
                    var segmentAsPolyLineSegment = segment as PolyLineSegment;
                    if (segmentAsPolyLineSegment != null)
                    {
                        var newSegment = new PolyLineSegment();
                        foreach (var point in segmentAsPolyLineSegment.Points)
                        {
                            newSegment.Points.Add(point);
                        }
                        newFigure.Segments.Add(newSegment);
                    }

                    var segmentLineSegment = segment as LineSegment;
                    if (segmentLineSegment != null)
                    {
                        var newSegment = new LineSegment();
                        newSegment.Point = new Point(segmentLineSegment.Point.X, segmentLineSegment.Point.Y);
                        newFigure.Segments.Add(newSegment);
                    }

                    var segmentBezierSegment = segment as BezierSegment;
                    if (segmentBezierSegment != null)
                    {
                        var newSegment = new BezierSegment();
                        newSegment.Point1 = new Point(segmentBezierSegment.Point1.X, segmentBezierSegment.Point1.Y);
                        newSegment.Point2 = new Point(segmentBezierSegment.Point2.X, segmentBezierSegment.Point2.Y);
                        newSegment.Point3 = new Point(segmentBezierSegment.Point3.X, segmentBezierSegment.Point3.Y);
                        newFigure.Segments.Add(newSegment);
                    }
                }

                newPathGeometry.Figures.Add(newFigure);
            }
            return newPathGeometry;
        }
コード例 #11
0
        /// <summary>
        /// Updates the segments based on its data point value. This method is not
        /// intended to be called explicitly outside the Chart but it can be overridden by
        /// any derived class.
        /// </summary>
        /// <param name="transformer">Represents the view port of chart control.(refer <see cref="IChartTransformer"/>)</param>
        public override void Update(IChartTransformer transformer)
        {
            PathFigure figure = new PathFigure();

            if (AreaPoints.Count > 1)
            {
                int endIndex = AreaPoints.Count - 1;
                WindowsLineSegment lineSegment = new WindowsLineSegment();
                figure.StartPoint = transformer.TransformToVisible(AreaPoints[0].X, AreaPoints[0].Y);
                lineSegment.Point = transformer.TransformToVisible(AreaPoints[1].X, AreaPoints[1].Y);
                figure.Segments.Add(lineSegment);

                for (int i = 2; i < AreaPoints.Count - 1; i += 6)
                {
                    BezierSegment segment = new BezierSegment();
                    segment.Point1 = transformer.TransformToVisible(AreaPoints[i].X, AreaPoints[i].Y);
                    segment.Point2 = transformer.TransformToVisible(AreaPoints[i + 1].X, AreaPoints[i + 1].Y);
                    segment.Point3 = transformer.TransformToVisible(AreaPoints[i + 2].X, AreaPoints[i + 2].Y);
                    figure.Segments.Add(segment);
                }

                lineSegment       = new WindowsLineSegment();
                lineSegment.Point = transformer.TransformToVisible(AreaPoints[endIndex].X, AreaPoints[endIndex].Y);
                figure.Segments.Add(lineSegment);

                for (int i = endIndex - 1; i > 1; i -= 6)
                {
                    BezierSegment segment = new BezierSegment();
                    segment.Point1 = transformer.TransformToVisible(AreaPoints[i].X, AreaPoints[i].Y);
                    segment.Point2 = transformer.TransformToVisible(AreaPoints[i - 1].X, AreaPoints[i - 1].Y);
                    segment.Point3 = transformer.TransformToVisible(AreaPoints[i - 2].X, AreaPoints[i - 2].Y);
                    figure.Segments.Add(segment);
                }
            }

            PathGeometry segmentGeometry = new PathGeometry();

            segmentGeometry.Figures.Add(figure);
            this.segPath.Data = segmentGeometry;
        }
コード例 #12
0
    /// <summary>
    /// Override for the path's redraw mehtod, controlling how the path is drawns
    /// </summary>
    protected override void Redraw()
    {
        Debug.Assert(GetValue(StartAngleProperty) != DependencyProperty.UnsetValue);
            Debug.Assert(GetValue(RadiusProperty) != DependencyProperty.UnsetValue);
            Debug.Assert(GetValue(AngleProperty) != DependencyProperty.UnsetValue);

            Width = Height = 2 * (Radius);
            var endAngle = StartAngle + Angle;

            // path container
            var figure = new PathFigure
            {
                StartPoint = new Point(Radius, Radius),
                IsClosed = true,
                IsFilled = true
            };

            //  start angle line
            var lineX = Radius + Math.Sin(StartAngle * Math.PI / 180) * Radius;
            var lineY = Radius - Math.Cos(StartAngle * Math.PI / 180) * Radius;
            var line = new LineSegment { Point = new Point(lineX, lineY) };
            figure.Segments.Add(line);

            // outer arc
            var arcX = Radius + Math.Sin(endAngle * Math.PI / 180) * Radius;
            var arcY = Radius - Math.Cos(endAngle * Math.PI / 180) * Radius;
            var arc = new ArcSegment
            {
                IsLargeArc = Angle >= 180.0,
                Point = new Point(arcX, arcY),
                Size = new Size(Radius, Radius),
                SweepDirection = SweepDirection.Clockwise,
            };

            figure.Segments.Add(arc);

            Data = new PathGeometry { Figures = { figure } };
            InvalidateArrange();
    }
コード例 #13
0
ファイル: RadialScaleHelper.cs プロジェクト: jm991/HeliosApp
        public static Geometry CreateArcGeometry(double minAngle, double maxAngle, double radius, int thickness, SweepDirection sweepDirection)
        {
            //the range will have 4 segments (arc, line, arc, line)
            //if the sweep angle is bigger than 180 use the large arc
            //first use the same sweep direction as the control. invert for the second arc.
            PathFigure figure = new PathFigure();
            figure.IsClosed = true;
            figure.StartPoint = new Point((radius - thickness) * Math.Sin(minAngle * Math.PI / 180),
                -(radius - thickness) * Math.Cos(minAngle * Math.PI / 180));

            //first arc segment
            ArcSegment arc = new ArcSegment();
            arc.Point = new Point((radius - thickness) * Math.Sin(maxAngle * Math.PI / 180),
                -(radius - thickness) * Math.Cos(maxAngle * Math.PI / 180));
            arc.Size = new Size(radius - thickness, radius - thickness);
            arc.SweepDirection = sweepDirection;
            if (Math.Abs(maxAngle - minAngle) > 180) arc.IsLargeArc = true;
            figure.Segments.Add(arc);
            //first line segment
            LineSegment line = new LineSegment();
            line.Point = new Point(radius * Math.Sin(maxAngle * Math.PI / 180),
                -radius * Math.Cos(maxAngle * Math.PI / 180));
            figure.Segments.Add(line);
            //second arc segment
            arc = new ArcSegment();
            arc.Point = new Point(radius * Math.Sin(minAngle * Math.PI / 180),
                -radius * Math.Cos(minAngle * Math.PI / 180));
            arc.Size = new Size(radius, radius);
            arc.SweepDirection = SweepDirection.Counterclockwise;
            if (sweepDirection == SweepDirection.Counterclockwise)
                arc.SweepDirection = SweepDirection.Clockwise;
            if (Math.Abs(maxAngle - minAngle) > 180) arc.IsLargeArc = true;
            figure.Segments.Add(arc);

            PathGeometry path = new PathGeometry();
            path.Figures.Add(figure);
            return path;
        }
コード例 #14
0
ファイル: AreaSegment.cs プロジェクト: Mohsens22/OpenPasat
        /// <summary>
        /// Updates the segments based on its data point value. This method is not
        /// intended to be called explicitly outside the Chart but it can be overridden by
        /// any derived class.
        /// </summary>
        /// <param name="transformer">Represents the view port of chart control.(refer <see cref="IChartTransformer"/>)</param>
        public override void Update(IChartTransformer transformer)
        {
            ChartAxis xAxis     = this.Series.ActualXAxis;
            double    xValue    = 0;
            int       lastIndex = 0;


            if (transformer != null)
            {
                if (segmentUpdated)
                {
                    Series.SeriesRootPanel.Clip = null;
                }

                PathGeometry segmentGeometry = new PathGeometry();

                PathFigure figure = new PathFigure();

                WindowsLinesegment lineSegment;
                double             start  = containerSeries.ActualYAxis.ActualRange.Start;
                double             origin = containerSeries.ActualXAxis.Origin;
                if (containerSeries.ActualXAxis != null && containerSeries.ActualXAxis.Origin == 0 &&
                    containerSeries.ActualYAxis is LogarithmicAxis && (containerSeries.ActualYAxis as LogarithmicAxis).Minimum != null)
                {
                    origin = (double)(containerSeries.ActualYAxis as LogarithmicAxis).Minimum;
                }
                origin            = origin == 0d ? start < 0d ? 0d : start : origin;
                figure.StartPoint = transformer.TransformToVisible(XValues[0], origin);

                ResetStrokeShapes();

                if (Series is PolarRadarSeriesBase && !double.IsNaN(YValues[0]))
                {
                    figure.StartPoint = transformer.TransformToVisible(XValues[0], YValues[0]);
                }

                if ((Series is AreaSeries) && !(Series as AreaSeries).IsClosed && !double.IsNaN(YValues[0]))
                {
                    this.AddStroke(transformer.TransformToVisible(XValues[0], YValues[0]));
                }
                else if (isEmpty)
                {
                    this.AddStroke(figure.StartPoint);
                }

                var    logarithmicXAxis = xAxis as LogarithmicAxis;
                double rangeStart       = logarithmicXAxis != null?Math.Pow(logarithmicXAxis.LogarithmicBase, xAxis.VisibleRange.Start) : xAxis.VisibleRange.Start;

                double rangeEnd = logarithmicXAxis != null?Math.Pow(logarithmicXAxis.LogarithmicBase, xAxis.VisibleRange.End) : xAxis.VisibleRange.End;

                for (int index = 0; index < XValues.Count; index++)
                {
                    // UWP - 256 Aea series is fuzzy on chart if it is in zoomed state
                    xValue = XValues[index];
                    if (!(rangeStart <= xValue && rangeEnd >= xValue))
                    {
                        if (rangeStart >= xValue && index + 1 < XValues.Count &&
                            rangeStart <= XValues[index + 1])
                        {
                            figure.StartPoint = transformer.TransformToVisible(xValue, origin);
                            //To avoid stroke blur when IsClosed & Empty point stroke is false.
                            if ((Series is AreaSeries) && !(Series as AreaSeries).IsClosed && !double.IsNaN(YValues[0]))
                            {
                                ResetStrokeShapes();
                                this.AddStroke(transformer.TransformToVisible(xValue, YValues[index]));
                            }
                            else if (isEmpty)
                            {
                                ResetStrokeShapes();
                                this.AddStroke(figure.StartPoint);
                            }
                        }
                        else if (!(rangeEnd <= xValue && index - 1 > -1 &&
                                   rangeEnd >= XValues[index - 1]))
                        {
                            continue;
                        }
                    }

                    if (!double.IsNaN(YValues[index]))
                    {
                        Point point = transformer.TransformToVisible(xValue, YValues[index]);
                        lineSegment       = new WindowsLinesegment();
                        lineSegment.Point = point;
                        figure.Segments.Add(lineSegment);

                        if ((isEmpty && !Series.ShowEmptyPoints) || (Series is AreaSeries && !(Series as AreaSeries).IsClosed))
                        {
                            if (index > 0 && double.IsNaN(YValues[index - 1]))
                            {
                                strokeFigure            = new PathFigure();
                                strokePolyLine          = new PolyLineSegment();
                                strokeFigure.StartPoint = point;
                                strokeGeometry.Figures.Add(strokeFigure);
                                strokeFigure.Segments.Add(strokePolyLine);
                            }
                            strokePolyLine.Points.Add(point);
                        }
                    }
                    else if (XValues.Count > 1)
                    {
                        if (index > 0 && index < XValues.Count - 1)
                        {
                            lineSegment       = new WindowsLinesegment();
                            lineSegment.Point = transformer.TransformToVisible(XValues[index - 1], origin);
                            figure.Segments.Add(lineSegment);

                            lineSegment       = new WindowsLinesegment();
                            lineSegment.Point = transformer.TransformToVisible(xValue, origin);
                            figure.Segments.Add(lineSegment);

                            lineSegment       = new WindowsLinesegment();
                            lineSegment.Point = transformer.TransformToVisible(XValues[index + 1], origin);
                            figure.Segments.Add(lineSegment);
                        }
                        else if (index == 0)
                        {
                            lineSegment       = new WindowsLinesegment();
                            lineSegment.Point = transformer.TransformToVisible(xValue, origin);
                            figure.Segments.Add(lineSegment);
                            lineSegment       = new WindowsLinesegment();
                            lineSegment.Point = transformer.TransformToVisible(XValues[index + 1], origin);

                            figure.Segments.Add(lineSegment);
                        }
                        else
                        {
                            lineSegment       = new WindowsLinesegment();
                            lineSegment.Point = transformer.TransformToVisible(XValues[index - 1], origin);
                            figure.Segments.Add(lineSegment);
                        }
                    }
                    lastIndex = index;
                }
                if (!(Series is PolarRadarSeriesBase))
                {
                    lineSegment       = new WindowsLinesegment();
                    lineSegment.Point = transformer.TransformToVisible(XValues[lastIndex], origin);
                    figure.Segments.Add(lineSegment);

                    if ((Series is AreaSeries && (Series as AreaSeries).IsClosed) && isEmpty && !double.IsNaN(YValues[lastIndex]))
                    {
                        strokePolyLine.Points.Add(lineSegment.Point);
                    }
                }

                segmentGeometry.Figures.Add(figure);
                this.segPath.Data = segmentGeometry;
                segmentUpdated    = true;
            }
        }
コード例 #15
0
        /// <summary>
        /// Updates the segments based on its data point value. This method is not
        /// intended to be called explicitly outside the Chart but it can be overriden by
        /// any derived class.
        /// </summary>
        /// <param name="transformer">Represents the view port of chart control.(refer <see cref="IChartTransformer"/>)</param>
        public override void Update(IChartTransformer transformer)
        {
            if (transformer != null)
            {
                if (segmentUpdated)
                {
                    Series.SeriesRootPanel.Clip = null;
                }
                PathFigure         figure          = new PathFigure();
                PathGeometry       segmentGeometry = new PathGeometry();
                WindowsLinesegment lineSegment;
                double             origin = containerSeries.ActualXAxis.Origin;
                if (containerSeries.ActualXAxis != null && containerSeries.ActualXAxis.Origin == 0 &&
                    containerSeries.ActualYAxis is LogarithmicAxis && (containerSeries.ActualYAxis as LogarithmicAxis).Minimum != null)
                {
                    origin = (double)(containerSeries.ActualYAxis as LogarithmicAxis).Minimum;
                }
                figure.StartPoint = transformer.TransformToVisible(XValues[0], origin);

                strokeGeometry = new PathGeometry();
                strokeFigure   = new PathFigure();
                strokePolyLine = new PolyLineSegment();
                strokePath     = new Path();


                if (!containerSeries.IsClosed && !double.IsNaN(YValues[YValues.Count / 2]))
                {
                    AddStroke(transformer.TransformToVisible(XValues[YValues.Count / 2], YValues[YValues.Count / 2]));
                }
                else if (isEmpty)
                {
                    AddStroke(transformer.TransformToVisible(XValues[YValues.Count / 2 - 1], YValues[YValues.Count / 2 - 1]));
                }


                for (int index = 0; index < XValues.Count; index++)
                {
                    if (!double.IsNaN(YValues[index]))
                    {
                        Point point = transformer.TransformToVisible(XValues[index], YValues[index]);
                        lineSegment       = new WindowsLinesegment();
                        lineSegment.Point = point;
                        figure.Segments.Add(lineSegment);
                        if ((isEmpty && !Series.ShowEmptyPoints) || !containerSeries.IsClosed)
                        {
                            if (index > (int)(YValues.Count / 2 - 1))
                            {
                                if (double.IsNaN(YValues[index - 1]))
                                {
                                    strokeFigure            = new PathFigure();
                                    strokePolyLine          = new PolyLineSegment();
                                    strokeFigure.StartPoint = point;
                                    strokeGeometry.Figures.Add(strokeFigure);
                                    strokeFigure.Segments.Add(strokePolyLine);
                                }
                                strokePolyLine.Points.Add(point);
                            }
                        }
                    }
                    else if (XValues.Count > 1)
                    {
                        if (index > 0 && index < XValues.Count - 1)
                        {
                            lineSegment       = new WindowsLinesegment();
                            lineSegment.Point = transformer.TransformToVisible(XValues[index - 1], origin);
                            figure.Segments.Add(lineSegment);

                            lineSegment       = new WindowsLinesegment();
                            lineSegment.Point = transformer.TransformToVisible(XValues[index], origin);
                            figure.Segments.Add(lineSegment);

                            lineSegment       = new WindowsLinesegment();
                            lineSegment.Point = transformer.TransformToVisible(XValues[index + 1], origin);
                            figure.Segments.Add(lineSegment);
                        }
                        else if (index == YValues.Count - 1)
                        {
                            lineSegment       = new WindowsLinesegment();
                            lineSegment.Point = transformer.TransformToVisible(XValues[index - 1], origin);

                            figure.Segments.Add(lineSegment);
                            lineSegment       = new WindowsLinesegment();
                            lineSegment.Point = transformer.TransformToVisible(XValues[index], origin);
                            figure.Segments.Add(lineSegment);
                        }
                        else
                        {
                            lineSegment       = new WindowsLinesegment();
                            lineSegment.Point = transformer.TransformToVisible(XValues[index], origin);
                            figure.Segments.Add(lineSegment);
                            lineSegment       = new WindowsLinesegment();
                            lineSegment.Point = transformer.TransformToVisible(XValues[index + 1], origin);

                            figure.Segments.Add(lineSegment);
                        }
                    }
                }

                lineSegment       = new WindowsLinesegment();
                lineSegment.Point = transformer.TransformToVisible(XValues[XValues.Count - 1], origin);
                figure.Segments.Add(lineSegment);

                if (containerSeries.IsClosed && isEmpty && !double.IsNaN(YValues[YValues.Count - 1]))
                {
                    strokePolyLine.Points.Add(lineSegment.Point);
                }
                segmentGeometry.Figures.Add(figure);
                this.segPath.Data = segmentGeometry;
                segmentUpdated    = true;
            }
        }
コード例 #16
0
        public static WMedia.Geometry ToWindows(this Geometry geometry)
        {
            WMedia.Geometry wGeometry = null;

            if (geometry is LineGeometry)
            {
                LineGeometry lineGeometry = geometry as LineGeometry;
                wGeometry = new WMedia.LineGeometry
                {
                    StartPoint = lineGeometry.StartPoint.ToWindows(),
                    EndPoint   = lineGeometry.EndPoint.ToWindows()
                };
            }
            else if (geometry is RectangleGeometry)
            {
                var rect = (geometry as RectangleGeometry).Rect;
                wGeometry = new WMedia.RectangleGeometry
                {
                    Rect = new WFoundation.Rect(rect.X, rect.Y, rect.Width, rect.Height)
                };
            }
            else if (geometry is EllipseGeometry)
            {
                EllipseGeometry ellipseGeometry = geometry as EllipseGeometry;
                wGeometry = new WMedia.EllipseGeometry
                {
                    Center  = ellipseGeometry.Center.ToWindows(),
                    RadiusX = ellipseGeometry.RadiusX,
                    RadiusY = ellipseGeometry.RadiusY
                };
            }
            else if (geometry is GeometryGroup)
            {
                GeometryGroup geometryGroup = geometry as GeometryGroup;
                wGeometry = new WMedia.GeometryGroup
                {
                    FillRule = ConvertFillRule(geometryGroup.FillRule)
                };

                foreach (Geometry children in geometryGroup.Children)
                {
                    WMedia.Geometry winChild = children.ToWindows();
                    (wGeometry as WMedia.GeometryGroup).Children.Add(winChild);
                }
            }
            else if (geometry is PathGeometry)
            {
                PathGeometry pathGeometry = geometry as PathGeometry;

                WMedia.PathGeometry wPathGeometry = new WMedia.PathGeometry
                {
                    FillRule = ConvertFillRule(pathGeometry.FillRule)
                };

                foreach (PathFigure xamPathFigure in pathGeometry.Figures)
                {
                    WMedia.PathFigure wPathFigure = new WMedia.PathFigure
                    {
                        StartPoint = xamPathFigure.StartPoint.ToWindows(),
                        IsFilled   = xamPathFigure.IsFilled,
                        IsClosed   = xamPathFigure.IsClosed
                    };
                    wPathGeometry.Figures.Add(wPathFigure);

                    foreach (PathSegment pathSegment in xamPathFigure.Segments)
                    {
                        // LineSegment
                        if (pathSegment is LineSegment)
                        {
                            LineSegment lineSegment = pathSegment as LineSegment;

                            WMedia.LineSegment winSegment = new WMedia.LineSegment
                            {
                                Point = lineSegment.Point.ToWindows()
                            };

                            wPathFigure.Segments.Add(winSegment);
                        }

                        // PolylineSegment
                        if (pathSegment is PolyLineSegment)
                        {
                            PolyLineSegment        polyLineSegment = pathSegment as PolyLineSegment;
                            WMedia.PolyLineSegment wSegment        = new WMedia.PolyLineSegment();

                            foreach (var point in polyLineSegment.Points)
                            {
                                wSegment.Points.Add(point.ToWindows());
                            }

                            wPathFigure.Segments.Add(wSegment);
                        }

                        // BezierSegment
                        if (pathSegment is BezierSegment)
                        {
                            BezierSegment bezierSegment = pathSegment as BezierSegment;

                            WMedia.BezierSegment wSegment = new WMedia.BezierSegment
                            {
                                Point1 = bezierSegment.Point1.ToWindows(),
                                Point2 = bezierSegment.Point2.ToWindows(),
                                Point3 = bezierSegment.Point3.ToWindows()
                            };

                            wPathFigure.Segments.Add(wSegment);
                        }
                        // PolyBezierSegment
                        else if (pathSegment is PolyBezierSegment)
                        {
                            PolyBezierSegment        polyBezierSegment = pathSegment as PolyBezierSegment;
                            WMedia.PolyBezierSegment wSegment          = new WMedia.PolyBezierSegment();

                            foreach (var point in polyBezierSegment.Points)
                            {
                                wSegment.Points.Add(point.ToWindows());
                            }

                            wPathFigure.Segments.Add(wSegment);
                        }

                        // QuadraticBezierSegment
                        if (pathSegment is QuadraticBezierSegment)
                        {
                            QuadraticBezierSegment quadraticBezierSegment = pathSegment as QuadraticBezierSegment;

                            WMedia.QuadraticBezierSegment wSegment = new WMedia.QuadraticBezierSegment
                            {
                                Point1 = quadraticBezierSegment.Point1.ToWindows(),
                                Point2 = quadraticBezierSegment.Point2.ToWindows()
                            };

                            wPathFigure.Segments.Add(wSegment);
                        }
                        // PolyQuadraticBezierSegment
                        else if (pathSegment is PolyQuadraticBezierSegment)
                        {
                            PolyQuadraticBezierSegment        polyQuadraticBezierSegment = pathSegment as PolyQuadraticBezierSegment;
                            WMedia.PolyQuadraticBezierSegment wSegment = new WMedia.PolyQuadraticBezierSegment();

                            foreach (var point in polyQuadraticBezierSegment.Points)
                            {
                                wSegment.Points.Add(point.ToWindows());
                            }

                            wPathFigure.Segments.Add(wSegment);
                        }
                        // ArcSegment
                        else if (pathSegment is ArcSegment)
                        {
                            ArcSegment arcSegment = pathSegment as ArcSegment;

                            WMedia.ArcSegment wSegment = new WMedia.ArcSegment
                            {
                                Size           = new WFoundation.Size(arcSegment.Size.Width, arcSegment.Size.Height),
                                RotationAngle  = arcSegment.RotationAngle,
                                IsLargeArc     = arcSegment.IsLargeArc,
                                SweepDirection = arcSegment.SweepDirection == SweepDirection.Clockwise ? WMedia.SweepDirection.Clockwise : WMedia.SweepDirection.Counterclockwise,
                                Point          = arcSegment.Point.ToWindows()
                            };

                            wPathFigure.Segments.Add(wSegment);
                        }
                    }
                }

                wGeometry = wPathGeometry;
            }

            return(wGeometry);
        }
コード例 #17
0
ファイル: LatticeRimEngine.cs プロジェクト: dolkensp/OTWB
        private Windows.UI.Xaml.Shapes.Shape MkPath(int indx, int indy, double inc)
        {
            double rad = BasicLib.ToRadians;
            double deg = BasicLib.ToDegrees;

            Path path = new Path();
            path.Stroke = new SolidColorBrush(Colors.Red);
            path.Name = string.Format("Lattice{0}_{1}", indx, indy);
            GeometryGroup g = new GeometryGroup();
            path.Data = g;
            PathGeometry pg = new PathGeometry();
            g.Children.Add(pg);
            double startAngle = indx * repeatAngle;

            foreach (Line2D ll in ld.Lines)
            { 
                PathFigure pf = new PathFigure();
                double angle1 = startAngle + ll.X1 * colAngle;
                double angl1 = angle1 * rad;
                double angle2 = startAngle + ll.X2 * colAngle;
                double angl2 = angle2 * rad;
                double rowstart = indy * ld.Layout.Height;
                double y1 = ld.Layout.ToolPosition - rowstart  - ll.Y1 * rowHeight;
                double y2 = ld.Layout.ToolPosition - rowstart - ll.Y2 * rowHeight;
                
                pf.StartPoint = new Point(y1 * Math.Cos(angl1),
                                          y1 * Math.Sin(angl1));
                if (ll.IsVertical)
                {      
                    LineSegment ls = new LineSegment();
                    ls.Point = new Point(y2 * Math.Cos(angl1),
                                          y2 * Math.Sin(angl1));
                    pf.Segments.Add(ls);
                   
                }
                else if (ll.IsHorizontal)
                {
                    PolyLineSegment pls = new PolyLineSegment();
                    double a = angl1;
                    Point pnt;
                    do
                    {
                        pnt = new Point(y2 * Math.Cos(a), y2 * Math.Sin(a));
                        pls.Points.Add(pnt);
                        a += (angl1 < angl2) ? inc : -inc;
                    }
                    while ((angl1 < angl2) ? (a < angl2) : ( a > angl2));
                    if ((angl1 < angl2) ? (a != angl2) : (a != angl1))
                    {
                        a = (angl1 < angl2) ? angl2 : angl1;
                        pnt = new Point(y2 * Math.Cos(a), y2 * Math.Sin(a));
                        pls.Points.Add(pnt);
                    }
                    pf.Segments.Add(pls);
                }
                else // is diagonal
                {
                    double i = 0;
                    PolyLineSegment pls = new PolyLineSegment();
                    for (i = 0; i <= 1.0; i += inc)
                    {                  
                        pls.Points.Add(Interp(ll.X1,y1,i,ll.X2,y2,startAngle));
                    }        
                    pls.Points.Add(Interp(ll.X1, y1, 1.0, ll.X2, y2,startAngle));
                  
                    pf.Segments.Add(pls);
                } 
                pg.Figures.Add(pf);
            }
            return path;
        }
コード例 #18
0
ファイル: RingSegment.cs プロジェクト: GFlisch/Template10
        private void UpdatePath()
        {
            var innerRadius = this.InnerRadius + this.StrokeThickness / 2;
            var outerRadius = this.Radius - this.StrokeThickness / 2;

            if (_isUpdating ||
                this.ActualWidth == 0 ||
                innerRadius <= 0 ||
                outerRadius < innerRadius)
            {
                return;
            }

            var pathGeometry = new PathGeometry();
            var pathFigure = new PathFigure();
            pathFigure.IsClosed = true;

            var center =
                this.Center ??
                new Point(
                    outerRadius + this.StrokeThickness / 2,
                    outerRadius + this.StrokeThickness / 2);

            // Starting Point
            pathFigure.StartPoint =
                new Point(
                    center.X + Math.Sin(StartAngle * Math.PI / 180) * innerRadius,
                    center.Y - Math.Cos(StartAngle * Math.PI / 180) * innerRadius);

            // Inner Arc
            var innerArcSegment = new ArcSegment();
            innerArcSegment.IsLargeArc = (EndAngle - StartAngle) >= 180.0;
            innerArcSegment.Point =
                new Point(
                    center.X + Math.Sin(EndAngle * Math.PI / 180) * innerRadius,
                    center.Y - Math.Cos(EndAngle * Math.PI / 180) * innerRadius);
            innerArcSegment.Size = new Size(innerRadius, innerRadius);
            innerArcSegment.SweepDirection = SweepDirection.Clockwise;

            var lineSegment =
                new LineSegment
                {
                    Point = new Point(
                        center.X + Math.Sin(EndAngle * Math.PI / 180) * outerRadius,
                        center.Y - Math.Cos(EndAngle * Math.PI / 180) * outerRadius)
                };

            // Outer Arc
            var outerArcSegment = new ArcSegment();
            outerArcSegment.IsLargeArc = (EndAngle - StartAngle) >= 180.0;
            outerArcSegment.Point =
                new Point(
                        center.X + Math.Sin(StartAngle * Math.PI / 180) * outerRadius,
                        center.Y - Math.Cos(StartAngle * Math.PI / 180) * outerRadius);
            outerArcSegment.Size = new Size(outerRadius, outerRadius);
            outerArcSegment.SweepDirection = SweepDirection.Counterclockwise;

            pathFigure.Segments.Add(innerArcSegment);
            pathFigure.Segments.Add(lineSegment);
            pathFigure.Segments.Add(outerArcSegment);
            pathGeometry.Figures.Add(pathFigure);
            this.InvalidateArrange();
            this.Data = pathGeometry;
        }
コード例 #19
0
 private LineSegment[] CreateSegments(float[] ews, float[] nss)
 {
     List<LineSegment> segments = new List<LineSegment>();
     for (int i = 0; i < ews.Length; i++)
     {
         LineSegment seg = new LineSegment()
         {
             Point = new Point()
             {
                 X = ews[i],
                 Y = nss[i]
             }
         };
         segments.Add(seg);
     }
     return segments.ToArray();
 }
コード例 #20
0
ファイル: PieSegment.cs プロジェクト: simonob/chartory
        private void buildPath()
        {
            Point centerPoint;
            if (IsExploaded)
                centerPoint = calculateExplodedCenterPoint();
            else
                centerPoint = calculateStartingCenterPoint();

            if (RenderAsCircle)
               this.Data = buildSingleItemPath(centerPoint);
            else
            {
                var pf = new PathFigure();
                if (InnerRadius == 0)
                    pf.StartPoint = centerPoint;
                else
                    pf.StartPoint = Utils.ComputeCartesianCoordinate(StartAngle, InnerRadius).Offset(centerPoint.X, centerPoint.Y);

                pf.Segments = new PathSegmentCollection();

                //add start line
                var startLine = new LineSegment();
                startLine.Point = Utils.ComputeCartesianCoordinate(StartAngle, Radius).Offset(centerPoint.X, centerPoint.Y);
                pf.Segments.Add(startLine);

                //add arc segment
                var arc = new ArcSegment()
                {
                    Point = Utils.ComputeCartesianCoordinate(EndAngle, Radius).Offset(centerPoint.X, centerPoint.Y),
                    Size = new Windows.Foundation.Size(Radius, Radius),
                    SweepDirection = SweepDirection.Clockwise,
                    IsLargeArc = (EndAngle - StartAngle > 180),
                };
                pf.Segments.Add(arc);

                //add closing line
                var endLine = new LineSegment();
                if (InnerRadius == 0)
                    endLine.Point = centerPoint;
                else
                    endLine.Point = Utils.ComputeCartesianCoordinate(EndAngle, InnerRadius).Offset(centerPoint.X, centerPoint.Y);

                pf.Segments.Add(endLine);

                if (InnerRadius != 0)
                {
                    //add inner arc segment
                    var innerArc = new ArcSegment()
                    {
                        Point = Utils.ComputeCartesianCoordinate(StartAngle, InnerRadius).Offset(centerPoint.X, centerPoint.Y),
                        Size = new Windows.Foundation.Size(InnerRadius, InnerRadius),
                        SweepDirection = SweepDirection.Counterclockwise,
                        IsLargeArc = (EndAngle - StartAngle > 180)
                    };
                    pf.Segments.Add(innerArc);

                }

                this.Data = new PathGeometry()
                {
                    Figures = new PathFigureCollection()
                    {
                        pf
                    }
                };
            }

        }
コード例 #21
0
 private void AddLine(Point point)       //在图形中添加一条线段
 {
     LineSegment segment = new LineSegment();
     segment.Point = point;
     figure.Segments.Add(segment);
 }
コード例 #22
0
 private void AddPoint(double x, double y)        //在图形中添加一个点
 {
     LineSegment segment = new LineSegment();
     segment.Point = new Point(x + 0.5 * StrokeThickness, y + 0.5 * StrokeThickness);
     figure.Segments.Add(segment);
 }
コード例 #23
0
        /// <summary>
        /// Draws an interval for the meter
        /// </summary>
        /// <param name="interval">The MeterRangeInteraval which represents this range of the meter</param>
        /// <param name="tickLength">The length of the ticks for this range</param>
        /// <param name="group">The geometry group to add this to add this to</param>
        /// <param name="startAngle"></param>
        private void DrawInterval(MeterRangeInterval interval, double tickLength, GeometryGroup group, double startAngle = 0.0)
        {
            double startRad = interval.StartDegree*(Math.PI/180), endRad = interval.EndDegree*(Math.PI/180);
            double radianInterval = (endRad - startRad) * (interval.TickInterval / (interval.EndValue - interval.StartValue));
            var tickCount = (uint)((endRad - startRad)/ radianInterval);

            for (var i = 0; i <= tickCount; i++)
            {
                var pathGeometry = new PathGeometry();
                var figure = new PathFigure();

                // draw tick line
                double x1 = MeterRadius * Math.Sin(startAngle),
                       y1 = MeterRadius * Math.Cos(startAngle),
                       x2 = (MeterRadius + tickLength) * Math.Sin(startAngle),
                       y2 = (MeterRadius + tickLength) * Math.Cos(startAngle),
                       labelX = (MeterRadius + LabelOffset + (tickLength / 2)) * Math.Sin(startAngle),
                       labelY = (MeterRadius + LabelOffset + (tickLength / 2)) * Math.Cos(startAngle);

                figure.StartPoint = new Point(Radius + x1, Radius - y1);

                var line = new LineSegment
                {
                    Point = new Point(Radius + x2, Radius - y2)
                };

                MeterTickPoints?.Add(new TickPoint() {
                    // midway point in the tick - the point the tick crosses the meter circle
                    Point = new Point(Radius + (MeterRadius * Math.Sin(startAngle)), Radius - (MeterRadius * Math.Cos(startAngle))),
                    LabelPoint = new Point(Radius + labelX, Radius - labelY),
                    Value = i * interval.TickInterval + interval.StartValue
                });

                figure.Segments.Add(line);
                pathGeometry.Figures.Add(figure);
                group.Children.Add(pathGeometry);
                startAngle += radianInterval;
            }
        }
コード例 #24
0
ファイル: LineGraph.cs プロジェクト: jayharry28/Audiotica
        private void DrawLine(Serie serie)
        {
            //this.InvalidateMeasure(); not sure why anymore...

            RemoveLine(serie);

            var height = ActualHeight - (2*DrawAreaVerticalOffset);
            var width = ActualWidth - (2*DrawAreaHorizontalOffset);

            _drawAreaBottom = 0 + height + DrawAreaVerticalOffset;
                // bottom left of drawing area, add 1 so the offset gets added below
            _drawAreaLeft = 0 + DrawAreaHorizontalOffset; // left of drawing area, add 1 so the offset gets added left

            _divisionX = (width/(_seriesMaxX - _seriesMinX));
            Debug.WriteLine("{0} : {1} / ({2} - {3}) = {4}", Name, width, _seriesMaxX, _seriesMinX, _divisionX);
            _divisionY = (height/(_seriesMaxY - _seriesMinY));

            var myPath = new Path();
            var myPathFigure = new PathFigure();
            var myPathSegmentCollection = new PathSegmentCollection();
            var myPathFigureCollection = new PathFigureCollection();
            var myPathGeometry = new PathGeometry();

            Point p;
            // prepare for drawing by modifying y value
            for (var i = 0; i < serie.Data.Count; i++) // for every datapoint in the serie
            {
                p = serie.Data[i];
                p.X = _drawAreaLeft + (_divisionX*i);
                p.Y = _drawAreaBottom - ((p.Y - _seriesMinY)*_divisionY);
                // data[i] = p; NO - Keep serie data unchanged

                Debug.WriteLine("{0} : ({1}) * {2} = {3}", Name, serie.Data[i], i, p.X);

                if (i == 0)
                {
                    myPathFigure.StartPoint = p;
                }
                else
                {
                    var segment = new LineSegment {Point = p};

                    myPathSegmentCollection.Add(segment);
                }
            }

            if (Fill) // not fully tested
            {
                p.Y = _drawAreaBottom - 0;
                var endsegment = new LineSegment {Point = p};
                myPathSegmentCollection.Add(endsegment);
            }

            myPathFigure.Segments = myPathSegmentCollection;
            myPathFigureCollection.Add(myPathFigure);
            myPathGeometry.Figures = myPathFigureCollection;

            myPath.Stroke = serie.Color;
            myPath.StrokeThickness = 2;
            if (Fill)
            {
                myPath.Fill = serie.Color;
            }

            myPath.Data = myPathGeometry;
            SetZIndex(myPath, 10);

            Children.Add(myPath);
            serie.UiElement = myPath;
        }
コード例 #25
0
ファイル: Grid.cs プロジェクト: dolkensp/OTWB
        public override Path CreateGrid()
        {
            Path _outline = base.CreateGrid();
            _outline.Name = "CARTESIAN_GRID";
            PathGeometry pg = new PathGeometry();
            double startx = Math.Floor(_dim1.Start / _dim1.Inc) * _dim1.Inc;
            double starty = Math.Floor(_dim2.Start / _dim2.Inc) * _dim2.Inc;
            double endx = Math.Ceiling(_dim1.End / _dim1.Inc) * _dim1.Inc;
            double endy = Math.Ceiling(_dim2.End / _dim2.Inc) * _dim2.Inc;

            pg.Figures = new PathFigureCollection();
            // Here we start to create the rows which are horizontal
            // and range over Y which is dim2 
            // from (dim1.Start,y) -> (dim1.end,y)
            // where y ranges from dim2.start to dim2.end
            #region Create rows
            if (_dim2.Start >= 0)
            {
                for (double y = starty; y <= endy; y += _dim2.Inc)
                {
                    PathFigure pf = new PathFigure();
                    pf.StartPoint = new Point(startx, y);
                    pf.Segments = new PathSegmentCollection();
                    LineSegment l = new LineSegment();
                    l.Point = new Point(endx, y);
                    pf.Segments.Add(l);
                    pg.Figures.Add(pf);
                }
            }
            else
            {
                for (double y = 0; y >= starty; y -= _dim2.Inc)
                {
                    PathFigure pf = new PathFigure();
                    pf.StartPoint = new Point(startx, y);
                    pf.Segments = new PathSegmentCollection();
                    LineSegment l = new LineSegment();
                    l.Point = new Point(endx, y);
                    pf.Segments.Add(l);
                    pg.Figures.Add(pf);
                }

                if (_dim2.End > 0)
                {
                    for (double y = 0; y <= endy; y += _dim2.Inc)
                    {
                        PathFigure pf = new PathFigure();
                        pf.StartPoint = new Point(startx, y);
                        pf.Segments = new PathSegmentCollection();
                        LineSegment l = new LineSegment();
                        l.Point = new Point(endx, y);
                        pf.Segments.Add(l);
                        pg.Figures.Add(pf);
                    }
                }
            } 
            #endregion

            // Here we create the columns which are vertical
            // and range over X which is dim1
            // from (x,dim2.start) -> (x,dim2.End)
            // where x ranges from dim1.start to dim1.end
            #region Create Columns
            if (_dim1.Start >= 0)
            {  // both are positive so start at 0

                for (double x = startx; x <= endx; x += _dim1.Inc)
                {
                    PathFigure pf = new PathFigure();
                    pf.StartPoint = new Point(x, starty);
                    pf.Segments = new PathSegmentCollection();
                    LineSegment l = new LineSegment();
                    l.Point = new Point(x, endy);
                    pf.Segments.Add(l);
                    pg.Figures.Add(pf);
                }
            }
            else  // starting value is negative
            {   // here go from 0 down to negative starting value

                for (double x = 0; x >= startx; x -= _dim1.Inc)
                {
                    PathFigure pf = new PathFigure();
                    pf.StartPoint = new Point(x, starty);
                    pf.Segments = new PathSegmentCollection();
                    LineSegment l = new LineSegment();
                    l.Point = new Point(x, endy);
                    pf.Segments.Add(l);
                    pg.Figures.Add(pf);
                }

                if (_dim1.End > 0)
                {
                    //go from 0 to End
                    for (double x = 0; x <= endx; x += _dim1.Inc)
                    {
                        PathFigure pf = new PathFigure();
                        pf.StartPoint = new Point(x, starty);
                        pf.Segments = new PathSegmentCollection();
                        LineSegment l = new LineSegment();
                        l.Point = new Point(x, endy);
                        pf.Segments.Add(l);
                        pg.Figures.Add(pf);
                    }
                }
            } 
            #endregion

            _outline.Data = pg;
            return _outline;
        }
コード例 #26
0
ファイル: PageLayout.xaml.cs プロジェクト: liquidboy/X
        private void DrawGridLines(double width, double height, double overhangX, double overhangY, double spacingX = 10, double spacingY = 10) {
            if (width == 0 || height == 0) return;
            
            PathFigureCollection myPathFigureCollection = new PathFigureCollection();

            //horizontal
            var max = ((height + overhangY) / spacingY);
            for (int y = 0; y < max; y++) {
                
                var yPos = y * spacingY;
                LineSegment myLineSegment = new LineSegment();
                PathFigure myPathFigure = new PathFigure();
                PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection();
                myPathFigure.StartPoint = new Point(0, yPos);
                myLineSegment.Point = new Point(width + overhangX, yPos);
                myPathSegmentCollection.Add(myLineSegment);
                myPathFigure.Segments = myPathSegmentCollection;
                
                if (y > 0 && y < max-1) myPathFigureCollection.Add(myPathFigure);
                
            }

            //vertical
            max = ((width + overhangX) / spacingX);
            for (int x = 0; x < max; x++)
            {
                var xPos = x * spacingX;
                LineSegment myLineSegment = new LineSegment();
                PathFigure myPathFigure = new PathFigure();
                PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection();
                myPathFigure.StartPoint = new Point(xPos, 0);
                myLineSegment.Point = new Point(xPos, height + overhangY);
                myPathSegmentCollection.Add(myLineSegment);
                myPathFigure.Segments = myPathSegmentCollection;
                
                if (x > 0 && x < max-1) myPathFigureCollection.Add(myPathFigure);
            }



            PathGeometry myPathGeometry = new PathGeometry();
            myPathGeometry.Figures = myPathFigureCollection;
            
            pthGridLines.Stroke = new SolidColorBrush(Colors.CornflowerBlue);
            pthGridLines.StrokeThickness = 1;
            pthGridLines.Data = myPathGeometry;
        }
コード例 #27
0
        private void Draw()
        {
            if (ActualHeight > 0)
            {
                FreeLabel.FontSize = ActualHeight*0.25;
            }
            var value = double.NaN;
            var lot = ParkingLot;
            if (lot != null && lot.TotalLots != 0)
            {
                value = ((double)lot.FreeLots) / ((double)lot.TotalLots);
            }
            if (double.IsNaN(value) || double.IsInfinity(value))
            {
                ValueInvertedCircle.Visibility = ValuePath.Visibility = Visibility.Collapsed;
                FreeLabel.Text = "?";
                if (lot != null)
                {
                    PlayAnimation();
                }
                return;
            }
            if (value < 0)
            {
                value = 0;
            }else if (value > 1)
            {
                value = 1;
            }
            ValueInvertedCircle.Visibility = ValuePath.Visibility = Visibility.Visible;
            FreeLabel.Text = Math.Round(value * 100) + "%";

            ValuePath.SetValue(Path.DataProperty, null);
            var pg = new PathGeometry();
            var fig = new PathFigure();

            var height = ActualHeight;
            var width = ActualWidth;
            var radius = height / 2;
            var theta = (360 * value) - 90;
            var xC = radius;
            var yC = radius;

            if (value == 1) theta += 1;

            var finalPointX = xC + (radius * Math.Cos(theta * 0.0174));
            var finalPointY = yC + (radius * Math.Sin(theta * 0.0174));

            fig.StartPoint = new Point(radius, radius);
            var firstLine = new LineSegment {Point = new Point(radius, 0)};
            fig.Segments.Add(firstLine);

            if (value > 0.25)
            {
                var firstQuart = new ArcSegment
                {
                    Point = new Point(width, radius),
                    SweepDirection = SweepDirection.Clockwise,
                    Size = new Size(radius, radius)
                };
                fig.Segments.Add(firstQuart);
            }

            if (value > 0.5)
            {
                var secondQuart = new ArcSegment
                {
                    Point = new Point(radius, height),
                    SweepDirection = SweepDirection.Clockwise,
                    Size = new Size(radius, radius)
                };
                fig.Segments.Add(secondQuart);
            }

            if (value > 0.75)
            {
                var thirdQuart = new ArcSegment
                {
                    Point = new Point(0, radius),
                    SweepDirection = SweepDirection.Clockwise,
                    Size = new Size(radius, radius)
                };
                fig.Segments.Add(thirdQuart);
            }

            var finalQuart = new ArcSegment
            {
                Point = new Point(finalPointX, finalPointY),
                SweepDirection = SweepDirection.Clockwise,
                Size = new Size(radius, radius)
            };
            fig.Segments.Add(finalQuart);

            var lastLine = new LineSegment {Point = new Point(radius, radius)};
            fig.Segments.Add(lastLine);
            pg.Figures.Add(fig);
            ValuePath.SetValue(Path.DataProperty, pg);
            PlayAnimation();
        }
コード例 #28
0
        /// <summary>
        /// Main parser routine, which loops over each char in received string, and performs actions according to command/parameter being passed
        /// </summary>
        /// <param name="path">String with path data definition</param>
        /// <returns>PathGeometry object created from string definition</returns>
        private PathGeometry Parse(string path)
        {
            PathGeometry pathGeometry = null;

            _formatProvider = CultureInfo.InvariantCulture;
            _pathString = path;
            _pathLength = path.Length;
            _curIndex = 0;

            _secondLastPoint = new Point(0, 0);
            _lastPoint = new Point(0, 0);
            _lastStart = new Point(0, 0);

            _figureStarted = false;

            var first = true;

            var lastCmd = ' ';

            while (ReadToken()) // Empty path is allowed in XAML
            {
                char cmd = _token;

                if (first)
                {
                    if ((cmd != 'M') && (cmd != 'm') && (cmd != 'f') && (cmd != 'F'))  // Path starts with M|m
                    {
                        ThrowBadToken();
                    }

                    first = false;
                }

                switch (cmd)
                {
                    case 'f':
                    case 'F':
                        pathGeometry = new PathGeometry();
                        var num = ReadNumber(!AllowComma);
                        // ReSharper disable once CompareOfFloatsByEqualityOperator
                        pathGeometry.FillRule = num == 0 ? FillRule.EvenOdd : FillRule.Nonzero;
                        break;

                    case 'm':
                    case 'M':
                        // XAML allows multiple points after M/m
                        _lastPoint = ReadPoint(cmd, !AllowComma);

                        _figure = new PathFigure
                        {
                            StartPoint = _lastPoint,
                            IsFilled = IsFilled,
                            IsClosed = !IsClosed
                        };
                        //context.BeginFigure(_lastPoint, IsFilled, !IsClosed);
                        _figureStarted = true;
                        _lastStart = _lastPoint;
                        lastCmd = 'M';

                        while (IsNumber(AllowComma))
                        {
                            _lastPoint = ReadPoint(cmd, !AllowComma);

                            var lineSegment = new LineSegment {Point = _lastPoint};
                            _figure.Segments.Add(lineSegment);
                            //context.LineTo(_lastPoint, IsStroked, !IsSmoothJoin);
                            lastCmd = 'L';
                        }
                        break;

                    case 'l':
                    case 'L':
                    case 'h':
                    case 'H':
                    case 'v':
                    case 'V':
                        EnsureFigure();

                        do
                        {
                            switch (cmd)
                            {
                                case 'l': _lastPoint = ReadPoint(cmd, !AllowComma); break;
                                case 'L': _lastPoint = ReadPoint(cmd, !AllowComma); break;
                                case 'h': _lastPoint.X += ReadNumber(!AllowComma); break;
                                case 'H': _lastPoint.X = ReadNumber(!AllowComma); break;
                                case 'v': _lastPoint.Y += ReadNumber(!AllowComma); break;
                                case 'V': _lastPoint.Y = ReadNumber(!AllowComma); break;
                            }

                            var lineSegment = new LineSegment {Point = _lastPoint};
                            _figure.Segments.Add(lineSegment);
                            //context.LineTo(_lastPoint, IsStroked, !IsSmoothJoin);
                        }
                        while (IsNumber(AllowComma));

                        lastCmd = 'L';
                        break;

                    case 'c':
                    case 'C': // cubic Bezier
                    case 's':
                    case 'S': // smooth cublic Bezier
                        EnsureFigure();

                        do
                        {
                            Point p;

                            if ((cmd == 's') || (cmd == 'S'))
                            {
                                p = lastCmd == 'C' ? Reflect() : _lastPoint;

                                _secondLastPoint = ReadPoint(cmd, !AllowComma);
                            }
                            else
                            {
                                p = ReadPoint(cmd, !AllowComma);

                                _secondLastPoint = ReadPoint(cmd, AllowComma);
                            }

                            _lastPoint = ReadPoint(cmd, AllowComma);

                            var bizierSegment = new BezierSegment
                            {
                                Point1 = p,
                                Point2 = _secondLastPoint,
                                Point3 = _lastPoint
                            };
                            _figure.Segments.Add(bizierSegment);
                            //context.BezierTo(p, _secondLastPoint, _lastPoint, IsStroked, !IsSmoothJoin);

                            lastCmd = 'C';
                        }
                        while (IsNumber(AllowComma));

                        break;

                    case 'q':
                    case 'Q': // quadratic Bezier
                    case 't':
                    case 'T': // smooth quadratic Bezier
                        EnsureFigure();

                        do
                        {
                            if ((cmd == 't') || (cmd == 'T'))
                            {
                                _secondLastPoint = lastCmd == 'Q' ? Reflect() : _lastPoint;

                                _lastPoint = ReadPoint(cmd, !AllowComma);
                            }
                            else
                            {
                                _secondLastPoint = ReadPoint(cmd, !AllowComma);
                                _lastPoint = ReadPoint(cmd, AllowComma);
                            }

                            var quadraticBezierSegment = new QuadraticBezierSegment
                            {
                                Point1 = _secondLastPoint,
                                Point2 = _lastPoint
                            };
                            _figure.Segments.Add(quadraticBezierSegment);
                            //context.QuadraticBezierTo(_secondLastPoint, _lastPoint, IsStroked, !IsSmoothJoin);

                            lastCmd = 'Q';
                        }
                        while (IsNumber(AllowComma));

                        break;

                    case 'a':
                    case 'A':
                        EnsureFigure();

                        do
                        {
                            // A 3,4 5, 0, 0, 6,7
                            var w = ReadNumber(!AllowComma);
                            var h = ReadNumber(AllowComma);
                            var rotation = ReadNumber(AllowComma);
                            var large = ReadBool();
                            var sweep = ReadBool();

                            _lastPoint = ReadPoint(cmd, AllowComma);

                            var arcSegment = new ArcSegment
                            {
                                Point = _lastPoint,
                                Size = new Size(w, h),
                                RotationAngle = rotation,
                                IsLargeArc = large,
                                SweepDirection = sweep ? SweepDirection.Clockwise : SweepDirection.Counterclockwise
                            };
                            _figure.Segments.Add(arcSegment);
                            //context.ArcTo(
                            //    _lastPoint,
                            //    new Size(w, h),
                            //    rotation,
                            //    large,
                            //    sweep ? SweepDirection.Clockwise : SweepDirection.Counterclockwise,
                            //    IsStroked,
                            //    !IsSmoothJoin
                            //    );
                        }
                        while (IsNumber(AllowComma));

                        lastCmd = 'A';
                        break;

                    case 'z':
                    case 'Z':
                        EnsureFigure();
                        _figure.IsClosed = IsClosed;
                        //context.SetClosedState(IsClosed);

                        _figureStarted = false;
                        lastCmd = 'Z';

                        _lastPoint = _lastStart; // Set reference point to be first point of current figure
                        break;

                    default:
                        ThrowBadToken();
                        break;
                }

                if (null != _figure)
                {
                    if (_figure.IsClosed)
                    {
                        if (null == pathGeometry)
                            pathGeometry = new PathGeometry();

                        pathGeometry.Figures.Add(_figure);

                        _figure = null;
                        first = true;
                    }
                }

            }

            if (null != _figure)
            {
                if (null == pathGeometry)
                    pathGeometry = new PathGeometry();

                if (!pathGeometry.Figures.Contains(_figure))
                    pathGeometry.Figures.Add(_figure);

            }
            return pathGeometry;
        }
コード例 #29
0
        private Point DrawLine(Grid container, Brush Palette, double linethickness, Point prevPoint, LineDataPoint DataPoint)
        {
            Point Current = getLinePlottingPoint(DataPoint);
            Point[] LinePoints = Utilities.GetLinePointsOnCircle(prevPoint, Current, DataPoint.CircleRadius);


            PathFigure path = new PathFigure();
            path.StartPoint = LinePoints[0];
            path.IsClosed = false;
            LineSegment Line = new LineSegment();
            Line.Point = LinePoints[1];
            path.Segments.Add(Line);
            PathGeometry myPath = new PathGeometry();
            myPath.Figures.Add(path);
            Path output = new Path();
            output.Data = myPath;
            output.StrokeThickness = linethickness;
            output.Stroke = Palette;
            container.Children.Add(output);
            prevPoint = Current;
            return prevPoint;
        }
コード例 #30
0
ファイル: Arc.cs プロジェクト: davidvidmar/MobilnaPoraba
        /// <summary>
        /// Initializes a new instance of the <see cref="Arc"/> class"
        /// </summary>
        public Arc()
        {
            this.Stroke = new SolidColorBrush(Colors.White);
            this.StrokeThickness = 2;
            this.Fill = new SolidColorBrush(Colors.Red);
            this.UseLayoutRounding = true;

            this.pathGeometry = new PathGeometry();
            this.pathFigure = new PathFigure();

            this.pathFigure.IsClosed = true;
            this.pathFigure.IsFilled = true;

            this.arcSegment = new ArcSegment();
            this.arcSegment.IsLargeArc = false;
            this.arcSegment.SweepDirection = SweepDirection.Clockwise;
            this.lineSegment = new LineSegment();

            this.pathFigure.Segments.Add(this.arcSegment);
            this.pathFigure.Segments.Add(this.lineSegment);

            this.pathGeometry.Figures.Add(this.pathFigure);
            this.Data = this.pathGeometry;

            this.ellipseGeometry = new EllipseGeometry();

            this.Tapped += this.OnArcTapped;
        }
コード例 #31
0
ファイル: FunnelSegment.cs プロジェクト: Mohsens22/OpenPasat
        /// <summary>
        /// Updates the segments based on its data point value. This method is not
        /// intended to be called explicitly outside the Chart but it can be overriden by
        /// any derived class.
        /// </summary>
        /// <param name="transformer">Reresents the view port of chart control.(refer <see cref="IChartTransformer"/>)</param>
        public override void Update(IChartTransformer transformer)
        {
            if (!this.IsSegmentVisible)
            {
                segmentPath.Visibility = Visibility.Collapsed;
            }
            else
            {
                segmentPath.Visibility = Visibility.Visible;
            }

            Rect rect = new Rect(0, 0, transformer.Viewport.Width, transformer.Viewport.Height);

            if (rect.IsEmpty)
            {
                segmentPath.Data = null;
            }
            else
            {
                if (this.IsExploded)
                {
                    rect.X = this.explodedOffset;
                }
                PathFigure   figure = new PathFigure();
                FunnelSeries series = Series as FunnelSeries;
                if (series == null)
                {
                    return;
                }
                double minRadius = 0.5 * (1d - minimumWidth / rect.Width);
                bool   isBroken  = (topRadius >= minRadius) ^ (bottomRadius > minRadius) && series.FunnelMode == ChartFunnelMode.ValueIsHeight;
                double bottomY   = minRadius * (bottom - top) / (bottomRadius - topRadius);
                topRadius         = Math.Min(topRadius, minRadius);
                bottomRadius      = Math.Min(bottomRadius, minRadius);
                figure.StartPoint = new Point(rect.X + topRadius * rect.Width, rect.Y + top * rect.Height);
                Linesegment lineSeg1 = new Linesegment();
                lineSeg1.Point = new Point(rect.X + (1 - topRadius) * rect.Width, rect.Y + top * rect.Height);
                figure.Segments.Add(lineSeg1);
                if (isBroken)
                {
                    Linesegment lineSeg2 = new Linesegment();
                    lineSeg2.Point = new Point(rect.X + (1 - minRadius) * rect.Width, rect.Y + bottomY * rect.Height);
                    figure.Segments.Add(lineSeg2);
                }

                Linesegment lineSeg3 = new Linesegment();
                lineSeg3.Point = new Point(rect.X + (1 - bottomRadius) * rect.Width, rect.Y + bottom * rect.Height - series.StrokeThickness / 2);
                figure.Segments.Add(lineSeg3);
                Linesegment lineSeg4 = new Linesegment();
                lineSeg4.Point = new Point(rect.X + bottomRadius * rect.Width, rect.Y + bottom * rect.Height - series.StrokeThickness / 2);
                figure.Segments.Add(lineSeg4);

                if (isBroken)
                {
                    Linesegment lineSeg5 = new Linesegment();
                    lineSeg5.Point = new Point(rect.X + minRadius * rect.Width, rect.Y + bottomY * rect.Height);
                    figure.Segments.Add(lineSeg5);
                }

                figure.IsClosed              = true;
                this.segmentGeometry         = new PathGeometry();
                this.segmentGeometry.Figures = new PathFigureCollection()
                {
                    figure
                };
                segmentPath.Data = segmentGeometry;

                height = ((bottom - top) * rect.Height) / 2;
            }
        }
コード例 #32
0
        /// <summary>
        /// Main parser routine, which loops over each char in received string, and performs actions according to command/parameter being passed
        /// </summary>
        /// <param name="path">String with path data definition</param>
        /// <returns>PathGeometry object created from string definition</returns>
        private PathGeometry parse(string path)
        {
            PathGeometry _pathGeometry = null;
            

            _formatProvider = CultureInfo.InvariantCulture;
            _pathString = path;
            _pathLength = path.Length;
            _curIndex = 0;

            _secondLastPoint = new Point(0, 0);
            _lastPoint = new Point(0, 0);
            _lastStart = new Point(0, 0);

            _figureStarted = false;

            bool first = true;

            char last_cmd = ' ';

            while (ReadToken()) // Empty path is allowed in XAML
            {
                char cmd = _token;

                if (first)
                {
                    if ((cmd != 'M') && (cmd != 'm'))  // Path starts with M|m 
                    {
                        ThrowBadToken();
                    }

                    first = false;
                }

                switch (cmd)
                {
                    case 'm':
                    case 'M':
                        // XAML allows multiple points after M/m
                        _lastPoint = ReadPoint(cmd, !AllowComma);

                        _figure = new PathFigure();
                        _figure.StartPoint = _lastPoint;
                        _figure.IsFilled = IsFilled;
                        _figure.IsClosed = !IsClosed;
                        //context.BeginFigure(_lastPoint, IsFilled, !IsClosed);
                        _figureStarted = true;
                        _lastStart = _lastPoint;
                        last_cmd = 'M';

                        while (IsNumber(AllowComma))
                        {
                            _lastPoint = ReadPoint(cmd, !AllowComma);

                            LineSegment _lineSegment = new LineSegment();
                            _lineSegment.Point = _lastPoint;
                            _figure.Segments.Add(_lineSegment);
                            //context.LineTo(_lastPoint, IsStroked, !IsSmoothJoin);
                            last_cmd = 'L';
                        }
                        break;

                    case 'l':
                    case 'L':
                    case 'h':
                    case 'H':
                    case 'v':
                    case 'V':
                        EnsureFigure();

                        do
                        {
                            switch (cmd)
                            {
                                case 'l': _lastPoint = ReadPoint(cmd, !AllowComma); break;
                                case 'L': _lastPoint = ReadPoint(cmd, !AllowComma); break;
                                case 'h': _lastPoint.X += ReadNumber(!AllowComma); break;
                                case 'H': _lastPoint.X = ReadNumber(!AllowComma); break;
                                case 'v': _lastPoint.Y += ReadNumber(!AllowComma); break;
                                case 'V': _lastPoint.Y = ReadNumber(!AllowComma); break;
                            }

                            LineSegment _lineSegment = new LineSegment();
                            _lineSegment.Point = _lastPoint;
                            _figure.Segments.Add(_lineSegment);
                            //context.LineTo(_lastPoint, IsStroked, !IsSmoothJoin);
                        }
                        while (IsNumber(AllowComma));

                        last_cmd = 'L';
                        break;

                    case 'c':
                    case 'C': // cubic Bezier 
                    case 's':
                    case 'S': // smooth cublic Bezier
                        EnsureFigure();

                        do
                        {
                            Point p;

                            if ((cmd == 's') || (cmd == 'S'))
                            {
                                if (last_cmd == 'C')
                                {
                                    p = Reflect();
                                }
                                else
                                {
                                    p = _lastPoint;
                                }

                                _secondLastPoint = ReadPoint(cmd, !AllowComma);
                            }
                            else
                            {
                                p = ReadPoint(cmd, !AllowComma);

                                _secondLastPoint = ReadPoint(cmd, AllowComma);
                            }

                            _lastPoint = ReadPoint(cmd, AllowComma);

                            BezierSegment _bizierSegment = new BezierSegment();
                            _bizierSegment.Point1 = p;
                            _bizierSegment.Point2 = _secondLastPoint;
                            _bizierSegment.Point3 = _lastPoint;
                            _figure.Segments.Add(_bizierSegment);
                            //context.BezierTo(p, _secondLastPoint, _lastPoint, IsStroked, !IsSmoothJoin);

                            last_cmd = 'C';
                        }
                        while (IsNumber(AllowComma));

                        break;

                    case 'q':
                    case 'Q': // quadratic Bezier 
                    case 't':
                    case 'T': // smooth quadratic Bezier
                        EnsureFigure();

                        do
                        {
                            if ((cmd == 't') || (cmd == 'T'))
                            {
                                if (last_cmd == 'Q')
                                {
                                    _secondLastPoint = Reflect();
                                }
                                else
                                {
                                    _secondLastPoint = _lastPoint;
                                }

                                _lastPoint = ReadPoint(cmd, !AllowComma);
                            }
                            else
                            {
                                _secondLastPoint = ReadPoint(cmd, !AllowComma);
                                _lastPoint = ReadPoint(cmd, AllowComma);
                            }

                            QuadraticBezierSegment _quadraticBezierSegment = new QuadraticBezierSegment();
                            _quadraticBezierSegment.Point1 = _secondLastPoint;
                            _quadraticBezierSegment.Point2 = _lastPoint;
                            _figure.Segments.Add(_quadraticBezierSegment);
                            //context.QuadraticBezierTo(_secondLastPoint, _lastPoint, IsStroked, !IsSmoothJoin);

                            last_cmd = 'Q';
                        }
                        while (IsNumber(AllowComma));

                        break;

                    case 'a':
                    case 'A':
                        EnsureFigure();

                        do
                        {
                            // A 3,4 5, 0, 0, 6,7
                            double w = ReadNumber(!AllowComma);
                            double h = ReadNumber(AllowComma);
                            double rotation = ReadNumber(AllowComma);
                            bool large = ReadBool();
                            bool sweep = ReadBool();

                            _lastPoint = ReadPoint(cmd, AllowComma);

                            ArcSegment _arcSegment = new ArcSegment();
                            _arcSegment.Point = _lastPoint;
                            _arcSegment.Size = new Size(w, h);
                            _arcSegment.RotationAngle = rotation;
                            _arcSegment.IsLargeArc = large;
                            _arcSegment.SweepDirection = sweep ? SweepDirection.Clockwise : SweepDirection.Counterclockwise;
                            _figure.Segments.Add(_arcSegment);
                            //context.ArcTo(
                            //    _lastPoint,
                            //    new Size(w, h),
                            //    rotation,
                            //    large,
                            //    sweep ? SweepDirection.Clockwise : SweepDirection.Counterclockwise,
                            //    IsStroked,
                            //    !IsSmoothJoin
                            //    );
                        }
                        while (IsNumber(AllowComma));

                        last_cmd = 'A';
                        break;

                    case 'z':
                    case 'Z':
                        EnsureFigure();
                        _figure.IsClosed = IsClosed;
                        //context.SetClosedState(IsClosed);

                        _figureStarted = false;
                        last_cmd = 'Z';

                        _lastPoint = _lastStart; // Set reference point to be first point of current figure
                        break;

                    default:
                        ThrowBadToken();
                        break;
                }
            }

            if (null != _figure)
            {
                _pathGeometry = new PathGeometry();
                _pathGeometry.Figures.Add(_figure);
                
            }
            return _pathGeometry;
        }
コード例 #33
0
ファイル: NativeGeometry.cs プロジェクト: arun6202/XFSession
        public object ConvertToNative(Geometry geometry)
        {
            winMedia.Geometry winGeometry = null;

            // Determine what type of geometry we're dealing with.
            if (geometry is LineGeometry)
            {
                LineGeometry xamGeometry = geometry as LineGeometry;
                winGeometry = new winMedia.LineGeometry
                {
                    StartPoint = ConvertPoint(xamGeometry.StartPoint),
                    EndPoint   = ConvertPoint(xamGeometry.EndPoint)
                };
            }

            else if (geometry is RectangleGeometry)
            {
                Rect rect = (geometry as RectangleGeometry).Rect;
                winGeometry = new winMedia.RectangleGeometry
                {
                    Rect = new winFound.Rect(rect.X, rect.Y, rect.Width, rect.Height)
                };
            }

            else if (geometry is EllipseGeometry)
            {
                EllipseGeometry xamGeometry = geometry as EllipseGeometry;
                winGeometry = new winMedia.EllipseGeometry
                {
                    Center  = ConvertPoint(xamGeometry.Center),
                    RadiusX = xamGeometry.RadiusX,
                    RadiusY = xamGeometry.RadiusY
                };
            }

            else if (geometry is GeometryGroup)
            {
                GeometryGroup xamGeometry = geometry as GeometryGroup;
                winGeometry = new winMedia.GeometryGroup
                {
                    FillRule = ConvertFillRule(xamGeometry.FillRule)
                };

                foreach (Geometry xamChild in xamGeometry.Children)
                {
                    winMedia.Geometry winChild = ConvertToNative(xamChild) as winMedia.Geometry;
                    (winGeometry as winMedia.GeometryGroup).Children.Add(winChild);
                }
            }

            else if (geometry is PathGeometry)
            {
                PathGeometry xamPathGeometry = geometry as PathGeometry;

                winMedia.PathGeometry winPathGeometry = new winMedia.PathGeometry
                {
                    FillRule = ConvertFillRule(xamPathGeometry.FillRule)
                };

                foreach (PathFigure xamPathFigure in xamPathGeometry.Figures)
                {
                    winMedia.PathFigure winPathFigure = new winMedia.PathFigure
                    {
                        StartPoint = ConvertPoint(xamPathFigure.StartPoint),
                        IsFilled   = xamPathFigure.IsFilled,
                        IsClosed   = xamPathFigure.IsClosed
                    };
                    winPathGeometry.Figures.Add(winPathFigure);

                    foreach (PathSegment xamPathSegment in xamPathFigure.Segments)
                    {
                        // LineSegment
                        if (xamPathSegment is LineSegment)
                        {
                            LineSegment xamSegment = xamPathSegment as LineSegment;

                            winMedia.LineSegment winSegment = new winMedia.LineSegment
                            {
                                Point = ConvertPoint(xamSegment.Point)
                            };

                            winPathFigure.Segments.Add(winSegment);
                        }

                        // PolylineSegment
                        if (xamPathSegment is PolyLineSegment)
                        {
                            PolyLineSegment          xamSegment = xamPathSegment as PolyLineSegment;
                            winMedia.PolyLineSegment winSegment = new winMedia.PolyLineSegment();

                            foreach (Point point in xamSegment.Points)
                            {
                                winSegment.Points.Add(ConvertPoint(point));
                            }

                            winPathFigure.Segments.Add(winSegment);
                        }

                        // BezierSegment
                        if (xamPathSegment is BezierSegment)
                        {
                            BezierSegment xamSegment = xamPathSegment as BezierSegment;

                            winMedia.BezierSegment winSegment = new winMedia.BezierSegment
                            {
                                Point1 = ConvertPoint(xamSegment.Point1),
                                Point2 = ConvertPoint(xamSegment.Point2),
                                Point3 = ConvertPoint(xamSegment.Point3)
                            };

                            winPathFigure.Segments.Add(winSegment);
                        }

                        // PolyBezierSegment
                        else if (xamPathSegment is PolyBezierSegment)
                        {
                            PolyBezierSegment          xamSegment = xamPathSegment as PolyBezierSegment;
                            winMedia.PolyBezierSegment winSegment = new winMedia.PolyBezierSegment();

                            foreach (Point point in xamSegment.Points)
                            {
                                winSegment.Points.Add(ConvertPoint(point));
                            }

                            winPathFigure.Segments.Add(winSegment);
                        }

                        // QuadraticBezierSegment
                        if (xamPathSegment is QuadraticBezierSegment)
                        {
                            QuadraticBezierSegment xamSegment = xamPathSegment as QuadraticBezierSegment;

                            winMedia.QuadraticBezierSegment winSegment = new winMedia.QuadraticBezierSegment
                            {
                                Point1 = ConvertPoint(xamSegment.Point1),
                                Point2 = ConvertPoint(xamSegment.Point2),
                            };

                            winPathFigure.Segments.Add(winSegment);
                        }

                        // PolyQuadraticBezierSegment
                        else if (xamPathSegment is PolyQuadraticBezierSegment)
                        {
                            PolyQuadraticBezierSegment          xamSegment = xamPathSegment as PolyQuadraticBezierSegment;
                            winMedia.PolyQuadraticBezierSegment winSegment = new winMedia.PolyQuadraticBezierSegment();

                            foreach (Point point in xamSegment.Points)
                            {
                                winSegment.Points.Add(ConvertPoint(point));
                            }

                            winPathFigure.Segments.Add(winSegment);
                        }


                        // ArcSegment
                        else if (xamPathSegment is ArcSegment)
                        {
                            ArcSegment          xamSegment = xamPathSegment as ArcSegment;
                            winMedia.ArcSegment winSegment = new winMedia.ArcSegment();

                            winSegment.Size           = new winFound.Size(xamSegment.Size.Width, xamSegment.Size.Height);
                            winSegment.RotationAngle  = xamSegment.RotationAngle;
                            winSegment.IsLargeArc     = xamSegment.IsLargeArc;
                            winSegment.SweepDirection = xamSegment.SweepDirection == SweepDirection.Clockwise ? winMedia.SweepDirection.Clockwise : winMedia.SweepDirection.Counterclockwise;
                            winSegment.Point          = ConvertPoint(xamSegment.Point);

                            winPathFigure.Segments.Add(winSegment);
                        }
                    }
                }

                winGeometry = winPathGeometry;
            }

            // Set transform.
            if (geometry.Transform != null)
            {
                winGeometry.Transform = (winMedia.Transform)geometry.Transform.GetNativeObject();
            }

            return(winGeometry);
        }
コード例 #34
0
        /// <summary>
        /// Create a path object based on a list of vertices - used when creating geometry
        /// </summary>
        public static UIShapes.Shape CreatePathFromVertices(Body body, PhysicsSprite element, WinUI.Color colorFill)
        {
            List<Fixture> vertices = body.FixtureList;

            // is this an ellipse?
            if (vertices[0].Shape is CircleShape)
            {
                CircleShape cs = vertices[0].Shape as CircleShape;
                UIShapes.Ellipse el = new UIShapes.Ellipse();
                Vector2 screenSize = PhysicsCanvas.BoundaryHelper.WorldSizeToScreenSize(new Vector2(cs.Radius * 2, cs.Radius * 2));

                el.Width = screenSize.X;
                el.Height = screenSize.Y;

                el.Stroke = new SysWinMedia.SolidColorBrush(new WinUI.Color() { A = 255, R = 76, G = 108, B = 76 });
                el.StrokeThickness = 4;
                el.StrokeStartLineCap = SysWinMedia.PenLineCap.Round;
                el.Fill = new SysWinMedia.SolidColorBrush(colorFill);
                return el;
            }
            else
            {
                UIShapes.Path path = new UIShapes.Path();
                path.Stroke = new SysWinMedia.SolidColorBrush(new WinUI.Color() { A = 255, R = 76, G = 108, B = 76 });
                path.StrokeThickness = 4;
                path.StrokeStartLineCap = SysWinMedia.PenLineCap.Round;
                path.Fill = new SysWinMedia.SolidColorBrush(colorFill);


                SysWinMedia.PathGeometry pathGeom = new SysWinMedia.PathGeometry();
                SysWinMedia.PathFigureCollection figures = new SysWinMedia.PathFigureCollection();
                pathGeom.Figures = figures;

                double halfWidth = element.Width / 2d;
                double halfHeight = element.Height / 2d;
                if (halfWidth == 0) halfWidth = element.ActualWidth / 2d;
                if (halfHeight == 0) halfHeight = element.ActualHeight / 2d;

                foreach (Fixture f in vertices)
                {

                    if (f.Shape is PolygonShape)
                    {
                        SysWinMedia.PathFigure figure = new SysWinMedia.PathFigure();
                        PolygonShape p = f.Shape as PolygonShape;

                        // first vertex, create the startpoint
                        Vector2 ptStart = new Vector2((float)p.Vertices[0].X, (float)p.Vertices[0].Y);
                        ptStart = PhysicsCanvas.BoundaryHelper.WorldSizeToScreenSize(ptStart);
                        ptStart.X += (float)(halfWidth);
                        ptStart.Y += (float)(halfHeight);

                        figure.StartPoint = new SysWin.Point(ptStart.X, ptStart.Y);
                        figure.Segments = new SysWinMedia.PathSegmentCollection();
                        pathGeom.Figures.Add(figure);

                        for (int i = 1; i < p.Vertices.Count; i++)
                        {
                            SysWinMedia.LineSegment line = new SysWinMedia.LineSegment();
                            Vector2 pt = new Vector2((float)p.Vertices[i].X, (float)p.Vertices[i].Y);
                            pt = PhysicsCanvas.BoundaryHelper.WorldSizeToScreenSize(pt);
                            pt.X += (float)(halfWidth);
                            pt.Y += (float)(halfHeight);
                            line.Point = new SysWin.Point(pt.X, pt.Y); ;

                            figure.Segments.Add(line);
                        }

                    }

                }

                path.Data = pathGeom;
                return path;


            }
        }
コード例 #35
0
ファイル: Scenario3.xaml.cs プロジェクト: mbin/Win81App
        // Plots a graph of the passed easing function using the given sampling interval on the "Graph" Canvas control 
        private void PlotEasingFunctionGraph(EasingFunctionBase easingFunction, double samplingInterval)
        {
            UISettings UserSettings = new UISettings();
            Graph.Children.Clear();

            Path path = new Path();
            PathGeometry pathGeometry = new PathGeometry();
            PathFigure pathFigure = new PathFigure() { StartPoint = new Point(0, 0) };
            PathSegmentCollection pathSegmentCollection = new PathSegmentCollection();

            // Note that an easing function is just like a regular function that operates on doubles.
            // Here we plot the range of the easing function's output on the y-axis of a graph.
            for (double i = 0; i < 1; i += samplingInterval)
            {
                double x = i * GraphContainer.Width;
                double y = easingFunction.Ease(i) * GraphContainer.Height;

                LineSegment segment = new LineSegment();
                segment.Point = new Point(x, y);
                pathSegmentCollection.Add(segment);
            }

            pathFigure.Segments = pathSegmentCollection;
            pathGeometry.Figures.Add(pathFigure);
            path.Data = pathGeometry;
            path.Stroke = new SolidColorBrush(UserSettings.UIElementColor(UIElementType.ButtonText));
            path.StrokeThickness = 1;

            // Add the path to the Canvas
            Graph.Children.Add(path);
        }
コード例 #36
0
/// <summary>
/// Override for the path's redraw mehtod, controlling how the path is drawns
/// </summary>
protected override void Redraw()
{
    Debug.Assert(GetValue(StartAngleProperty) != DependencyProperty.UnsetValue);
            Debug.Assert(GetValue(RadiusProperty) != DependencyProperty.UnsetValue);
            Debug.Assert(GetValue(AngleProperty) != DependencyProperty.UnsetValue);

            if (Radius == 0 || !(Thickness > 0)) return;

            Width = Height = 2 * (Radius);
            var endAngle = StartAngle + Angle;
            var smallRadius = Radius - Thickness;

            var startX = Radius + Math.Sin(StartAngle * Math.PI / 180) * Radius;
            var startY = Radius - Math.Cos(StartAngle * Math.PI / 180) * Radius;

            // path container
            var figure = new PathFigure
            {
                StartPoint = new Point(startX, startY),
                IsClosed = true,
                IsFilled = true
            };

            // outer arc
            var outerArcX = Radius + Math.Sin(endAngle * Math.PI / 180) * Radius;
            var outerArcY = Radius - Math.Cos(endAngle * Math.PI / 180) * Radius;
            var outerArc = new ArcSegment
            {
                IsLargeArc = Angle >= 180.0,
                Point = new Point(outerArcX, outerArcY),
                Size = new Size(Radius, Radius),
                SweepDirection = SweepDirection.Clockwise,
            };
            figure.Segments.Add(outerArc);

            // start angle line
            var lineX = smallRadius + Math.Sin(endAngle * Math.PI / 180) * smallRadius;
            var lineY = smallRadius - Math.Cos(endAngle * Math.PI / 180) * smallRadius;
            var line = new LineSegment { Point = new Point(lineX + Thickness, lineY + Thickness) };
            figure.Segments.Add(line);

            // inner arc
            var innerArcX = smallRadius + Math.Sin(StartAngle * Math.PI / 180) * smallRadius ;
            var innerArcY = smallRadius - Math.Cos(StartAngle * Math.PI / 180) * smallRadius;
            var innerArc = new ArcSegment
            {
                IsLargeArc = Angle >= 180.0,
                Point = new Point(innerArcX + Thickness, innerArcY + Thickness),
                Size = new Size(smallRadius, smallRadius),
                SweepDirection = SweepDirection.Counterclockwise,
            };
            figure.Segments.Add(innerArc);

            Data = new PathGeometry { Figures = { figure } };
            InvalidateArrange();
}
コード例 #37
0
        /// <summary>
        /// Updates the segments based on its data point value. This method is not
        /// intended to be called explicitly outside the Chart but it can be overridden by
        /// any derived class.
        /// </summary>
        /// <param name="transformer">Represents the view port of chart control.(refer <see cref="IChartTransformer"/>)</param>
        public override void Update(IChartTransformer transformer)
        {
            if (isSegmentUpdated)
            {
                Series.SeriesRootPanel.Clip = null;
            }
            ChartTransform.ChartCartesianTransformer cartesianTransformer = transformer as ChartTransform.ChartCartesianTransformer;
            double      xEnd  = cartesianTransformer.XAxis.VisibleRange.End;
            DoubleRange range = cartesianTransformer.XAxis.VisibleRange;

            PathFigure         figure          = new PathFigure();
            PathGeometry       segmentGeometry = new PathGeometry();
            double             origin          = containerSeries.ActualXAxis != null ? containerSeries.ActualXAxis.Origin : 0;//setting origin value for splinearea segment
            WindowsLineSegment lineSegment;

            figure.StartPoint = transformer.TransformToVisible(segmentPoints[0].X, segmentPoints[0].Y);
            lineSegment       = new WindowsLineSegment();
            lineSegment.Point = transformer.TransformToVisible(segmentPoints[1].X, segmentPoints[1].Y);
            figure.Segments.Add(lineSegment);

            strokeGeometry = new PathGeometry();
            strokeFigure   = new PathFigure();
            strokePath     = new Path();

            if (containerSeries.IsClosed && isEmpty)
            {
                AddStroke(figure.StartPoint);
                lineSegment       = new WindowsLineSegment();
                lineSegment.Point = transformer.TransformToVisible(segmentPoints[1].X, segmentPoints[1].Y);
                strokeFigure.Segments.Add(lineSegment);
            }
            else if (!containerSeries.IsClosed)
            {
                AddStroke(transformer.TransformToVisible(segmentPoints[1].X, segmentPoints[1].Y));
            }

            int i;

            for (i = 2; i < segmentPoints.Count; i += 3)
            {
                double xVal = segmentPoints[i].X;
                if (xVal >= range.Start && xVal <= range.End || xEnd >= range.Start && xEnd <= range.End)
                {
                    if (Series.ShowEmptyPoints || ((!double.IsNaN(segmentPoints[i].Y) && !double.IsNaN(segmentPoints[i + 1].Y) && !double.IsNaN(segmentPoints[i + 2].Y))))
                    {
                        BezierSegment segment = new BezierSegment();
                        segment.Point1 = transformer.TransformToVisible(segmentPoints[i].X, segmentPoints[i].Y);
                        segment.Point2 = transformer.TransformToVisible(segmentPoints[i + 1].X, segmentPoints[i + 1].Y);
                        segment.Point3 = transformer.TransformToVisible(segmentPoints[i + 2].X, segmentPoints[i + 2].Y);
                        figure.Segments.Add(segment);
                        if ((isEmpty && !Series.ShowEmptyPoints) || !containerSeries.IsClosed)
                        {
                            BezierSegment strokeSegment = new BezierSegment();
                            strokeSegment.Point1 = segment.Point1;
                            strokeSegment.Point2 = segment.Point2;
                            strokeSegment.Point3 = segment.Point3;
                            strokeFigure.Segments.Add(strokeSegment);
                        }
                    }
                    else
                    {
                        if ((double.IsNaN(segmentPoints[i].Y) && double.IsNaN(segmentPoints[i + 1].Y) && double.IsNaN(segmentPoints[i + 2].Y)))
                        {
                            lineSegment       = new WindowsLineSegment();
                            lineSegment.Point = transformer.TransformToVisible(segmentPoints[i - 1].X, origin);
                            figure.Segments.Add(lineSegment);
                            lineSegment       = new WindowsLineSegment();
                            lineSegment.Point = transformer.TransformToVisible(segmentPoints[i + 2].X, origin);
                            figure.Segments.Add(lineSegment);
                        }
                        else if (i > 0 && (double.IsNaN(segmentPoints[i - 1].Y) || double.IsNaN(segmentPoints[i].Y)))
                        {
                            lineSegment       = new WindowsLineSegment();
                            lineSegment.Point = transformer.TransformToVisible(segmentPoints[i + 2].X, origin);

                            figure.Segments.Add(lineSegment);
                            lineSegment       = new WindowsLineSegment();
                            lineSegment.Point = transformer.TransformToVisible(segmentPoints[i + 2].X, double.IsNaN(segmentPoints[i + 2].Y) ? origin : segmentPoints[i + 2].Y);
                            if ((!Series.ShowEmptyPoints && !double.IsNaN(segmentPoints[i + 2].Y)) || !containerSeries.IsClosed)
                            {
                                strokeFigure            = new PathFigure();
                                strokeFigure.StartPoint = lineSegment.Point;
                                strokeGeometry.Figures.Add(strokeFigure);
                            }
                            figure.Segments.Add(lineSegment);
                        }
                    }
                }
            }
            Point point = transformer.TransformToVisible(segmentPoints[i - 1].X, origin);

            lineSegment       = new WindowsLineSegment();
            lineSegment.Point = point;
            figure.Segments.Add(lineSegment);
            if (containerSeries.IsClosed && !double.IsNaN(segmentPoints[i - 1].Y))
            {
                lineSegment       = new WindowsLineSegment();
                lineSegment.Point = point;
                strokeFigure.Segments.Add(lineSegment);
            }
            //figure.IsClosed = true;
            isSegmentUpdated = true;
            segmentGeometry.Figures.Add(figure);
            this.segPath.Data = segmentGeometry;
        }
コード例 #38
0
ファイル: PieSlice.cs プロジェクト: chao-zhou/PomodoroTimer
        private void UpdatePath()
        {
            var pathGeometry = new PathGeometry();
            var pathFigure = new PathFigure();
            pathFigure.StartPoint = new Point(Radius, Radius);
            pathFigure.IsClosed = true;

            // Starting Point
            var lineSegment = 
                new LineSegment 
                {
                    Point = new Point(
                        Radius + Math.Sin(StartAngle * Math.PI / 180) * Radius,
                        Radius - Math.Cos(StartAngle * Math.PI / 180) * Radius)
                };

            // Arc
            var arcSegment = new ArcSegment();
            arcSegment.IsLargeArc = (EndAngle - StartAngle) >= 180.0;
            arcSegment.Point =
                new Point(
                        Radius + Math.Sin(EndAngle * Math.PI / 180) * Radius,
                        Radius - Math.Cos(EndAngle * Math.PI / 180) * Radius);
            arcSegment.Size = new Size(Radius, Radius);
            arcSegment.SweepDirection = SweepDirection.Clockwise;
            pathFigure.Segments.Add(lineSegment);
            pathFigure.Segments.Add(arcSegment);
            pathGeometry.Figures.Add(pathFigure);
            this.Data = pathGeometry;
            this.InvalidateArrange();
        }
コード例 #39
0
        private PathGeometry GetArcGeometry(Point center, double radius, double innerRadius, double segmentStartAngle, double segmentEndAngle, bool isUnfilledPath)
        {
            if (this.IsExploded)
            {
                center = new Point(center.X + (parentSeries.ExplodeRadius * Math.Cos(AngleOfSlice)), center.Y + (parentSeries.ExplodeRadius * Math.Sin(AngleOfSlice)));
            }

            var isclockWise = segmentEndAngle > segmentStartAngle;

            var outerSegmentStartAngle = segmentStartAngle;
            var outerSegmentEndAngle   = segmentEndAngle;
            var innerSegmentStartAngle = segmentStartAngle;
            var innerSegmentEndAngle   = segmentEndAngle;

            double midRadius = 0d;

            if (parentSeries.CapStyle != DoughnutCapStyle.BothFlat && !isUnfilledPath)
            {
                var segmentRadius = (radius - innerRadius) / 2;
                midRadius = radius - segmentRadius;
                UpdateSegmentAngleForCurvePosition(ref outerSegmentStartAngle, ref outerSegmentEndAngle, ref innerSegmentStartAngle, ref innerSegmentEndAngle, segmentStartAngle, segmentEndAngle, radius, innerRadius, segmentRadius, isclockWise);
            }

            startPoint = new Point(center.X + radius * Math.Cos(outerSegmentStartAngle), center.Y + radius * Math.Sin(outerSegmentStartAngle));
            Point endPoint    = new Point(center.X + radius * Math.Cos(outerSegmentEndAngle), center.Y + radius * Math.Sin(outerSegmentEndAngle));
            Point startDPoint = new Point(center.X + innerRadius * Math.Cos(innerSegmentStartAngle), center.Y + innerRadius * Math.Sin(innerSegmentStartAngle));
            Point endDPoint   = new Point(center.X + innerRadius * Math.Cos(innerSegmentEndAngle), center.Y + innerRadius * Math.Sin(innerSegmentEndAngle));

            var isOuterDirectionClockWise = outerSegmentEndAngle > outerSegmentStartAngle;
            var isInnerDirectionClockWise = innerSegmentEndAngle > innerSegmentStartAngle;

            PathFigure figure = new PathFigure();

            figure.StartPoint = startPoint;
            ArcSegment seg = new ArcSegment();

            seg.Point          = endPoint;
            seg.Size           = new Size(radius, radius);
            seg.RotationAngle  = outerSegmentEndAngle - outerSegmentStartAngle;
            seg.IsLargeArc     = (!isOuterDirectionClockWise ? outerSegmentStartAngle - outerSegmentEndAngle : outerSegmentEndAngle - outerSegmentStartAngle) > Math.PI;
            seg.SweepDirection = !isOuterDirectionClockWise ? SweepDirection.Counterclockwise : SweepDirection.Clockwise;
            figure.Segments.Add(seg);

            if ((parentSeries.CapStyle == DoughnutCapStyle.EndCurve || parentSeries.CapStyle == DoughnutCapStyle.BothCurve) && !isUnfilledPath)
            {
                Point midEndPoint    = new Point(center.X + midRadius * Math.Cos(segmentEndAngle), center.Y + midRadius * Math.Sin(segmentEndAngle));
                var   bezierEndPoint = new Point(center.X + radius * Math.Cos(segmentEndAngle), center.Y + radius * Math.Sin(segmentEndAngle));
                var   bezSeg         = new QuadraticBezierSegment()
                {
                    Point1 = bezierEndPoint, Point2 = midEndPoint
                };
                figure.Segments.Add(bezSeg);

                var bezierEndDPoint = new Point(center.X + innerRadius * Math.Cos(segmentEndAngle), center.Y + innerRadius * Math.Sin(segmentEndAngle));
                bezSeg = new QuadraticBezierSegment()
                {
                    Point1 = bezierEndDPoint, Point2 = endDPoint
                };
                figure.Segments.Add(bezSeg);
            }
            else
            {
                WindowsLineSegment line = new WindowsLineSegment()
                {
                    Point = endDPoint
                };
                figure.Segments.Add(line);
            }

            seg                = new ArcSegment();
            seg.Point          = startDPoint;
            seg.Size           = new Size(innerRadius, innerRadius);
            seg.RotationAngle  = innerSegmentEndAngle - innerSegmentStartAngle;
            seg.IsLargeArc     = (!isInnerDirectionClockWise ? innerSegmentStartAngle - innerSegmentEndAngle : innerSegmentEndAngle - innerSegmentStartAngle) > Math.PI;
            seg.SweepDirection = isInnerDirectionClockWise ? SweepDirection.Counterclockwise : SweepDirection.Clockwise;
            figure.Segments.Add(seg);

            if ((parentSeries.CapStyle == DoughnutCapStyle.StartCurve || parentSeries.CapStyle == DoughnutCapStyle.BothCurve) && !isUnfilledPath)
            {
                Point midStartPoint     = new Point(center.X + midRadius * Math.Cos(segmentStartAngle), center.Y + midRadius * Math.Sin(segmentStartAngle));
                var   bezierStartDPoint = new Point(center.X + innerRadius * Math.Cos(segmentStartAngle), center.Y + innerRadius * Math.Sin(segmentStartAngle));
                var   bezSeg            = new QuadraticBezierSegment()
                {
                    Point1 = bezierStartDPoint, Point2 = midStartPoint
                };
                figure.Segments.Add(bezSeg);

                var bezierStartPoint = new Point(center.X + radius * Math.Cos(segmentStartAngle), center.Y + radius * Math.Sin(segmentStartAngle));
                bezSeg = new QuadraticBezierSegment()
                {
                    Point1 = bezierStartPoint, Point2 = startPoint
                };
                figure.Segments.Add(bezSeg);
            }

            figure.IsClosed = true;
            var geometry = new PathGeometry();

            geometry.Figures = new PathFigureCollection()
            {
                figure
            };
            return(geometry);
        }
コード例 #40
0
        /// <summary>
        /// Updates the segments based on its data point value. This method is not
        /// intended to be called explicitly outside the Chart but it can be overridden by
        /// any derived class.
        /// </summary>
        /// <param name="transformer">Represents the view port of chart control.(refer <see cref="IChartTransformer"/>)</param>
        public override void Update(IChartTransformer transformer)
        {
            if (!this.IsSegmentVisible)
            {
                segmentPath.Visibility = Visibility.Collapsed;
            }
            else
            {
                segmentPath.Visibility = Visibility.Visible;
            }

            segmentPath.StrokeLineJoin      = PenLineJoin.Round;
            segmentPath.Width               = transformer.Viewport.Width;
            segmentPath.Height              = transformer.Viewport.Height;
            segmentPath.VerticalAlignment   = VerticalAlignment.Center;
            segmentPath.HorizontalAlignment = HorizontalAlignment.Center;
            double actualRadius = Math.Min(transformer.Viewport.Width, transformer.Viewport.Height) / 2;
            double equalParts   = actualRadius / (pieSeriesCount);

            if (pieIndex == 0)
            {
                Point center;
                if (pieSeriesCount == 1)
                {
                    center = (Series as CircularSeriesBase).Center;
                }
                else
                {
                    center = ChartLayoutUtils.GetCenter(transformer.Viewport);
                }

                double radius = parentSeries.InternalPieCoefficient * (equalParts);
                parentSeries.Radius = radius;
                if (Math.Round((ActualEndAngle - ActualStartAngle), 2) == 6.28)
                {
                    EllipseGeometry ellipseGeometry = new EllipseGeometry()
                    {
                        Center  = center,
                        RadiusX = radius,
                        RadiusY = radius
                    };
                    this.segmentPath.Data = ellipseGeometry;
                }
                else if ((ActualEndAngle - ActualStartAngle) != 0)
                {
                    if (this.IsExploded)
                    {
                        center = new Point(center.X + (parentSeries.ExplodeRadius * Math.Cos(AngleOfSlice)), center.Y + (parentSeries.ExplodeRadius * Math.Sin(AngleOfSlice)));
                    }
                    startPoint = new Point(center.X + radius * Math.Cos(ActualStartAngle), center.Y + radius * Math.Sin(ActualStartAngle));
                    Point      endPoint = new Point(center.X + radius * Math.Cos(ActualEndAngle), center.Y + radius * Math.Sin(ActualEndAngle));
                    PathFigure figure   = new PathFigure();
                    figure.StartPoint = center;
                    WindowsLineSegment line = new WindowsLineSegment();
                    line.Point = startPoint;
                    figure.Segments.Add(line);

                    ArcSegment seg = new ArcSegment();
                    seg.Point          = endPoint;
                    seg.Size           = new Size(radius, radius);
                    seg.RotationAngle  = ActualEndAngle + ActualStartAngle;
                    seg.IsLargeArc     = ActualEndAngle - ActualStartAngle > Math.PI;
                    seg.SweepDirection = StartAngle > EndAngle ? SweepDirection.Counterclockwise : SweepDirection.Clockwise;
                    figure.Segments.Add(seg);

                    figure.IsClosed         = true;
                    this.segmentGeometry    = new PathGeometry();
                    segmentGeometry.Figures = new PathFigureCollection()
                    {
                        figure
                    };
                    this.segmentPath.Data = segmentGeometry;
                }
                else
                {
                    this.segmentPath.Data = null;
                }
            }
            else if (pieIndex >= 1)
            {
                double radius      = (equalParts * (pieIndex + 1)) - (equalParts * (1 - parentSeries.InternalPieCoefficient));
                double innerRadius = equalParts * pieIndex;
                parentSeries.Radius = radius;

                Point center = ChartLayoutUtils.GetCenter(transformer.Viewport);

                if (this.IsExploded)
                {
                    center = new Point(center.X + (parentSeries.ExplodeRadius * Math.Cos(AngleOfSlice)), center.Y + (parentSeries.ExplodeRadius * Math.Sin(AngleOfSlice)));
                }
                startPoint = new Point(center.X + radius * Math.Cos(ActualStartAngle), center.Y + radius * Math.Sin(ActualStartAngle));
                Point endPoint = new Point(center.X + radius * Math.Cos(ActualEndAngle), center.Y + radius * Math.Sin(ActualEndAngle));

                if (Math.Round((ActualEndAngle - ActualStartAngle), 2) == 6.28)
                {
                    GeometryGroup geometryGroup = new GeometryGroup();
                    geometryGroup.Children.Add(new EllipseGeometry()
                    {
                        Center  = center,
                        RadiusX = radius,
                        RadiusY = radius
                    });
                    geometryGroup.Children.Add(new EllipseGeometry()
                    {
                        Center  = center,
                        RadiusX = innerRadius,
                        RadiusY = innerRadius
                    });
                    this.segmentPath.Data = geometryGroup;
                }
                else if ((ActualEndAngle - ActualStartAngle) != 0)
                {
                    Point startDPoint = new Point(center.X + innerRadius * Math.Cos(ActualStartAngle), center.Y + innerRadius * Math.Sin(ActualStartAngle));
                    Point endDPoint   = new Point(center.X + innerRadius * Math.Cos(ActualEndAngle), center.Y + innerRadius * Math.Sin(ActualEndAngle));

                    PathFigure figure = new PathFigure();
                    figure.StartPoint = startPoint;

                    ArcSegment arcseg = new ArcSegment();
                    arcseg.Point          = endPoint;
                    arcseg.Size           = new Size(radius, radius);
                    arcseg.RotationAngle  = ActualEndAngle - ActualStartAngle;
                    arcseg.IsLargeArc     = ActualEndAngle - ActualStartAngle > Math.PI;
                    arcseg.SweepDirection = StartAngle > EndAngle ? SweepDirection.Counterclockwise : SweepDirection.Clockwise;
                    figure.Segments.Add(arcseg);

                    WindowsLineSegment line = new WindowsLineSegment();
                    line.Point = endDPoint;
                    figure.Segments.Add(line);

                    arcseg                = new ArcSegment();
                    arcseg.Point          = startDPoint;
                    arcseg.Size           = new Size(innerRadius, innerRadius);
                    arcseg.RotationAngle  = ActualEndAngle - ActualStartAngle;
                    arcseg.IsLargeArc     = ActualEndAngle - ActualStartAngle > Math.PI;
                    arcseg.SweepDirection = StartAngle < EndAngle ? SweepDirection.Counterclockwise : SweepDirection.Clockwise;
                    figure.Segments.Add(arcseg);

                    figure.IsClosed         = true;
                    this.segmentGeometry    = new PathGeometry();
                    segmentGeometry.Figures = new PathFigureCollection()
                    {
                        figure
                    };
                    this.segmentPath.Data = segmentGeometry;
                }
                else
                {
                    this.segmentPath.Data = null;
                }
            }
        }
コード例 #41
0
		private void DrawChart()
		{
			if ((dataSet != null) && (dataSet.Length > 0))
			{
				var path = new Windows.UI.Xaml.Shapes.Path();
				path.Stroke = chartColor;
				path.StrokeThickness = 15;
				path.StrokeLineJoin = PenLineJoin.Round;
				path.StrokeStartLineCap = PenLineCap.Round;
				path.StrokeEndLineCap = PenLineCap.Round;

				var geometry = new PathGeometry();

				var figure = new PathFigure();
				figure.IsClosed = false;
				figure.StartPoint = new Point(offsetList[0].OffsetX, offsetList[0].OffsetY);

				for (int i = 0; i < offsetList.Count; i++)
				{
					var segment = new LineSegment();
					segment.Point = new Point(offsetList[i].OffsetX, offsetList[i].OffsetY);
					figure.Segments.Add(segment);
				}
				geometry.Figures.Add(figure);
				path.Data = geometry;
				Children.Add(path);
			}
		}
コード例 #42
0
        /// <summary>
        /// Updates the segments based on its data point value. This method is not
        /// intended to be called explicitly outside the Chart but it can be overriden by
        /// any derived class.
        /// </summary>
        /// <param name="transformer">Reresents the view port of chart control.(refer <see cref="IChartTransformer"/>)</param>
        public override void Update(IChartTransformer transformer)
        {
            PathFigure figure = new PathFigure();

            if (this.stepAreaPoints.Count > 0)
            {
                if (isSegmentUpdated)
                {
                    Series.SeriesRootPanel.Clip = null;
                }

                figure.StartPoint = transformer.TransformToVisible(this.stepAreaPoints[1].X, this.stepAreaPoints[1].Y);

                PathGeometry       segmentGeometry = new PathGeometry();
                WindowsLinesegment linesegment;
                double             origin = Series.ActualXAxis != null ? Series.ActualXAxis.Origin : 0;

                strokeGeometry = new PathGeometry();
                strokeFigure   = new PathFigure();
                strokePolyLine = new PolyLineSegment();
                strokePath     = new Path();

                if (!(Series as StepAreaSeries).IsClosed && !double.IsNaN(this.stepAreaPoints[3].Y))
                {
                    AddStroke(transformer.TransformToVisible(this.stepAreaPoints[2].X, this.stepAreaPoints[3].Y));
                }
                else if (isEmpty)
                {
                    AddStroke(figure.StartPoint);
                }

                for (int i = 1; i < this.stepAreaPoints.Count; i += 2)
                {
                    if (!double.IsNaN(stepAreaPoints[i].Y) && !double.IsNaN(stepAreaPoints[i + 1].Y))
                    {
                        Point point1 = transformer.TransformToVisible(this.stepAreaPoints[i].X, stepAreaPoints[i].Y);
                        Point point2 = transformer.TransformToVisible(this.stepAreaPoints[i + 1].X, stepAreaPoints[i + 1].Y);
                        linesegment       = new WindowsLinesegment();
                        linesegment.Point = point1;
                        figure.Segments.Add(linesegment);
                        linesegment       = new WindowsLinesegment();
                        linesegment.Point = point2;
                        figure.Segments.Add(linesegment);
                        if (isEmpty && !Series.ShowEmptyPoints && (Series as StepAreaSeries).IsClosed)
                        {
                            strokePolyLine.Points.Add(point1);
                            if (i <= stepAreaPoints.Count - 3 && !double.IsNaN(stepAreaPoints[i + 3].Y))
                            {
                                strokePolyLine.Points.Add(point2);
                            }
                        }
                        else if (!(Series as StepAreaSeries).IsClosed)
                        {
                            if (i > 1)
                            {
                                strokePolyLine.Points.Add(point1);
                                if (i <= stepAreaPoints.Count - 3 && !double.IsNaN(stepAreaPoints[i + 3].Y))
                                {
                                    strokePolyLine.Points.Add(point2);
                                }
                            }
                        }
                    }
                    else
                    {
                        linesegment       = new WindowsLinesegment();
                        linesegment.Point = transformer.TransformToVisible(this.stepAreaPoints[i - 1].X, origin);
                        figure.Segments.Add(linesegment);
                        if (double.IsNaN(stepAreaPoints[i - 1].Y))
                        {
                            linesegment       = new WindowsLinesegment();
                            linesegment.Point = transformer.TransformToVisible(this.stepAreaPoints[i - 1].X, origin);
                            figure.Segments.Add(linesegment);
                        }
                        if (i < stepAreaPoints.Count - 1) //WPF-14682
                        {
                            linesegment       = new WindowsLinesegment();
                            linesegment.Point = transformer.TransformToVisible(this.stepAreaPoints[i + 1].X, origin);
                            figure.Segments.Add(linesegment);

                            if (double.IsNaN(stepAreaPoints[i - 1].Y) && !double.IsNaN(stepAreaPoints[i + 1].Y))
                            {
                                Point point1 = transformer.TransformToVisible(this.stepAreaPoints[i].X,
                                                                              stepAreaPoints[i + 1].Y);
                                if (!Series.ShowEmptyPoints && (Series as StepAreaSeries).IsClosed)
                                {
                                    strokeFigure            = new PathFigure();
                                    strokePolyLine          = new PolyLineSegment();
                                    strokeFigure.StartPoint = point1;
                                    strokeGeometry.Figures.Add(strokeFigure);
                                    strokeFigure.Segments.Add(strokePolyLine);
                                }
                                else if (!(Series as StepAreaSeries).IsClosed)
                                {
                                    if (i > 1)
                                    {
                                        strokeFigure            = new PathFigure();
                                        strokePolyLine          = new PolyLineSegment();
                                        strokeFigure.StartPoint = point1;
                                        strokeGeometry.Figures.Add(strokeFigure);
                                        strokeFigure.Segments.Add(strokePolyLine);
                                    }
                                }
                                linesegment       = new WindowsLinesegment();
                                linesegment.Point = point1;
                                figure.Segments.Add(linesegment);
                            }
                        }
                    }
                }
                linesegment       = new WindowsLinesegment();
                linesegment.Point = transformer.TransformToVisible(this.stepAreaPoints[stepAreaPoints.Count - 1].X, origin);
                figure.Segments.Add(linesegment);

                if ((Series as StepAreaSeries).IsClosed && (isEmpty && !double.IsNaN(stepAreaPoints[stepAreaPoints.Count - 1].Y)))
                {
                    strokePolyLine.Points.Add(linesegment.Point);
                }
                segmentGeometry.Figures.Add(figure);
                this.segPath.Data = segmentGeometry;

                isSegmentUpdated = true;
            }
        }
コード例 #43
0
ファイル: PieSlice.cs プロジェクト: alexhardwicke/Auth
        private void UpdatePath()
        {
            var radius = this.Radius - this.StrokeThickness / 2;

            if (_isUpdating ||
                this.ActualWidth == 0 ||
                radius <= 0)
            {
                return;
            }

            var pathGeometry = new PathGeometry();
            var pathFigure = new PathFigure();
            pathFigure.StartPoint = new Point(radius, radius);
            pathFigure.IsClosed = true;

            // Starting Point
            var lineSegment =
                new LineSegment
                {
                    Point = new Point(
                        radius + Math.Sin(StartAngle * Math.PI / 180) * radius,
                        radius - Math.Cos(StartAngle * Math.PI / 180) * radius)
                };

            // Arc
            var arcSegment = new ArcSegment();
            arcSegment.IsLargeArc = (EndAngle - StartAngle) >= 180.0;
            arcSegment.Point =
                new Point(
                        radius + Math.Sin(EndAngle * Math.PI / 180) * radius,
                        radius - Math.Cos(EndAngle * Math.PI / 180) * radius);
            arcSegment.Size = new Size(radius, radius);
            arcSegment.SweepDirection = SweepDirection.Clockwise;
            pathFigure.Segments.Add(lineSegment);
            pathFigure.Segments.Add(arcSegment);
            pathGeometry.Figures.Add(pathFigure);
            this.Data = pathGeometry;
            this.InvalidateArrange();
        }
コード例 #44
-7
ファイル: Scenario3.xaml.cs プロジェクト: mbin/Win81App
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            // Find the stack panels that host our AppBarButtons within the AppBar
            leftPanel = rootPage.FindName("LeftPanel") as StackPanel;
            rightPanel = rootPage.FindName("RightPanel") as StackPanel;

            CopyButtons(leftPanel, leftItems);
            CopyButtons(rightPanel, rightItems);

            // Remove existing AppBarButtons
            leftPanel.Children.Clear();
            rightPanel.Children.Clear();

            // Create the AppBarToggle button for the 'Shuffle' command
            AppBarToggleButton shuffle = new AppBarToggleButton();
            shuffle.Label = "Shuffle";
            shuffle.Icon = new SymbolIcon(Symbol.Shuffle);

            rightPanel.Children.Add(shuffle);

            // Create the AppBarButton for the 'Sun' command
            AppBarButton sun = new AppBarButton();
            sun.Label = "Sun";

            // This button will use the FontIcon class for its icon which allows us to choose
            // any glyph from any FontFamily
            FontIcon sunIcon = new FontIcon();
            sunIcon.FontFamily = new Windows.UI.Xaml.Media.FontFamily("Wingdings");
            sunIcon.FontSize = 30.0;
            sunIcon.Glyph = "\u0052";
            sun.Icon = sunIcon;

            rightPanel.Children.Add(sun);

            // Create the AppBarButton for the 'Triangle' command
            AppBarButton triangle = new AppBarButton();
            triangle.Label = "Triangle";

            // This button will use the PathIcon class for its icon which allows us to 
            // use vector data to represent the icon
            PathIcon trianglePathIcon = new PathIcon();
            PathGeometry g = new PathGeometry();
            g.FillRule = FillRule.Nonzero;

            // Just create a simple triange shape
            PathFigure f = new PathFigure();
            f.IsFilled = true;
            f.IsClosed = true;
            f.StartPoint = new Windows.Foundation.Point(20.0, 5.0);
            LineSegment s1 = new LineSegment();
            s1.Point = new Windows.Foundation.Point(30.0, 30.0);
            LineSegment s2 = new LineSegment();
            s2.Point = new Windows.Foundation.Point(10.0, 30.0);
            LineSegment s3 = new LineSegment();
            s3.Point = new Windows.Foundation.Point(20.0, 5.0);
            f.Segments.Add(s1);
            f.Segments.Add(s2);
            f.Segments.Add(s3);
            g.Figures.Add(f);

            trianglePathIcon.Data = g;

            triangle.Icon = trianglePathIcon;

            rightPanel.Children.Add(triangle);

            // Create the AppBarButton for the 'Smiley' command
            AppBarButton smiley = new AppBarButton();
            smiley.Label = "Smiley";
            smiley.Icon = new BitmapIcon { UriSource = new Uri("ms-appx:/Assets/smiley.png") };

            rightPanel.Children.Add(smiley);


        }