Exemplo n.º 1
0
        //private void renderCategoryLabels()
        //{
        //	if (FocusedSegment == null)
        //	{
        //		return;
        //	}
        //	var context = new ProviderContext(Data.Count);
        //	MaterialProvider.Reset(context);
        //	_categoryLabels.Children.Clear();
        //	var diameter = _segments.RenderSize.Smallest() * CircleScale;

        //	var outerLabelRadius = (diameter / 2) * OuterLabelPositionScale;
        //	var overlayedLabelRadius = (diameter / 2) * .7;

        //	var targetAngularOffset = FocusedSegment.RequireType<ArcPath>().CalculateAngularOffset();

        //	foreach (var d in Data)
        //	{
        //		var materialSet = MaterialProvider.ProvideNext(context);
        //		var categoryNameLabel = positionLabel(d, outerLabelRadius, targetAngularOffset, true);

        //		categoryNameLabel.Content = d.CategoryName;
        //		categoryNameLabel.BindTextualPrimitive<BarTotalPrimitive>(this);
        //		categoryNameLabel.Foreground = BarTotalForeground.GetMaterial(materialSet);
        //		_categoryLabels.Children.Add(categoryNameLabel);


        //		var valueLabel = positionLabel(d, overlayedLabelRadius, targetAngularOffset);

        //		valueLabel.Content = d.Value;
        //		valueLabel.BindTextualPrimitive<ValuePrimitive>(this);
        //		valueLabel.Foreground = ValueForeground.GetMaterial(materialSet);
        //		_categoryLabels.Children.Add(valueLabel);
        //	}
        //}

        private Label positionLabel(CategoricalDouble d, double radius, double targetAngularOffset,
                                    bool horizontalPositionSkew = false)
        {
            var categoryLabel = new Label
            {
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment   = VerticalAlignment.Center,
                IsHitTestVisible    = false
            };

            var pretransformedOffset     = d.RenderedVisual.RequireType <ArcPath>().PolarOffset;
            var arcAngle                 = d.RenderedVisual.RequireType <ArcPath>().ArcAngle;
            var pretransformedLabelAngle = pretransformedOffset + (arcAngle / 2);
            var actualLabelAngle         = pretransformedLabelAngle - targetAngularOffset;

            var horizontalLabelSkew = horizontalPositionSkew
                                ? Math.Cos(CoordinateHelpers.ToRadian(actualLabelAngle)) * HorizontalLabelPositionSkew
                                : 0;

            var labelRadius     = radius;
            var polarPoint      = new PolarPoint(actualLabelAngle, labelRadius);
            var labelCoordinate = polarPoint.ToCartesian();

            categoryLabel.Margin = new Thickness(labelCoordinate.X + horizontalLabelSkew, -labelCoordinate.Y,
                                                 -labelCoordinate.X - horizontalLabelSkew, labelCoordinate.Y);
            return(categoryLabel);
        }
Exemplo n.º 2
0
        public void ToCartesianToPolar_ExpectedParameter_OriginalValue()
        {
            //----------- Arrange -----------------------------
            var origin = new PolarPoint(1, 1);

            //----------- Act ---------------------------------
            var result = origin.ToCartesian().ToPolar();

            //----------- Assert-------------------------------
            Assert.True(origin.R.Is(result.R, 1e-12) && origin.Θ.Is(result.Θ, 1e-12));
        }
Exemplo n.º 3
0
        public void ToCartesian_LargeAngle_ExpectedBehavior()
        {
            //----------- Arrange -----------------------------
            var right = new PolarPoint(1, 1000 * MathExt.TwoPi);

            //----------- Act ---------------------------------
            var ihat = right.ToCartesian();

            //----------- Assert-------------------------------
            Assert.True(ihat.X.Is(1, 1e-12) && ihat.Y.Is(0, 1e-12));
        }
Exemplo n.º 4
0
        private static PathGeometry SelectedGeometry(Size renderSpace)
        {
            var leftBaseAnchor  = new Point(0, 0);
            var rightBaseAnchor = leftBaseAnchor.PushHorizontal(renderSpace.Width);

            var slopeVerticalPosition = renderSpace.Height / 2;

            var rightTopAnchor = rightBaseAnchor.PushVertical(slopeVerticalPosition);
            var leftTopAnchor  = leftBaseAnchor.PushVertical(slopeVerticalPosition);

            var leftTopAnchorControlVector  = new PolarPoint(45, 30);
            var rightTopAnchorControlVector = new PolarPoint(135, 30);

            var leftTopAnchorControlPoint  = leftTopAnchor.Add(leftTopAnchorControlVector.ToCartesian());
            var rightTopAnchorControlPoint = rightTopAnchor.Add(rightTopAnchorControlVector.ToCartesian());

            var topCenterAnchor = new Point(renderSpace.Width / 2, renderSpace.Height);

            return(new PathGeometry
            {
                Figures = new PathFigureCollection
                {
                    new PathFigure
                    {
                        StartPoint = leftBaseAnchor.LocalizeInCartesianSpace(renderSpace),
                        Segments = new PathSegmentCollection
                        {
                            new LineSegment {
                                Point = rightBaseAnchor.LocalizeInCartesianSpace(renderSpace)
                            },
                            new LineSegment {
                                Point = rightTopAnchor.LocalizeInCartesianSpace(renderSpace)
                            },
                            new QuadraticBezierSegment
                            {
                                Point1 = rightTopAnchorControlPoint.LocalizeInCartesianSpace(renderSpace),
                                Point2 = topCenterAnchor.LocalizeInCartesianSpace(renderSpace)
                            },
                            new QuadraticBezierSegment
                            {
                                Point1 = leftTopAnchorControlPoint.LocalizeInCartesianSpace(renderSpace),
                                Point2 = leftTopAnchor.LocalizeInCartesianSpace(renderSpace)
                            },
                            new LineSegment {
                                Point = leftBaseAnchor.LocalizeInCartesianSpace(renderSpace)
                            }
                        }
                    }
                }
            });
        }
Exemplo n.º 5
0
        public static Geometry CalculateArcPath(Size size, double radius, double arcWidth, double angle, double offsetAngle)
        {
            if (radius <= 0 || arcWidth <= 0 || radius - arcWidth < 0)
            {
                return(Geometry.Empty);
            }

            var startOuterPolar = new PolarPoint(offsetAngle, radius);
            var endOuterPolar   = new PolarPoint(offsetAngle + angle, radius);
            var startInnerPolar = new PolarPoint(offsetAngle, radius - arcWidth);
            var endInnerPolar   = new PolarPoint(offsetAngle + angle, radius - arcWidth);

            var isLargeArc = angle > 180;

            var startOuter = startOuterPolar.ToCartesian().LocalizeInPolarSpace(size);
            var endOuter   = endOuterPolar.ToCartesian().LocalizeInPolarSpace(size);
            var startInner = startInnerPolar.ToCartesian().LocalizeInPolarSpace(size);
            var endInner   = endInnerPolar.ToCartesian().LocalizeInPolarSpace(size);

            return(new PathGeometry
            {
                Figures = new PathFigureCollection
                {
                    new PathFigure
                    {
                        StartPoint = startOuter,
                        Segments = new PathSegmentCollection
                        {
                            new ArcSegment
                            {
                                Size = new Size(radius, radius),
                                Point = endOuter,
                                IsLargeArc = isLargeArc
                            },
                            new LineSegment
                            {
                                Point = endInner
                            },
                            new ArcSegment
                            {
                                Size = new Size(radius - arcWidth, radius - arcWidth),
                                Point = startInner,
                                SweepDirection = SweepDirection.Clockwise,
                                IsLargeArc = isLargeArc
                            }
                        }
                    }
                }
            });
        }
Exemplo n.º 6
0
        public CustomPath CalculateActiveArcPath(Point center, double radius, double arcWidth, double angle)
        {
            var startOuterPolar = new PolarPoint(90, radius);
            var endOuterPolar   = new PolarPoint(90 + angle, radius);
            var startInnerPolar = new PolarPoint(90, radius - arcWidth);
            var endInnerPolar   = new PolarPoint(90 + angle, radius - arcWidth);
            var space           = new Size(PART_main.RenderSize.Width, PART_main.RenderSize.Height * 2);

            return(new CustomPath(null)
            {
                Data = new PathGeometry
                {
                    Figures = new PathFigureCollection
                    {
                        new PathFigure
                        {
                            StartPoint = startOuterPolar.ToCartesian().LocalizeInPolarSpace(space),
                            Segments = new PathSegmentCollection
                            {
                                new ArcSegment
                                {
                                    Size = new Size(radius, radius),
                                    Point = endOuterPolar.ToCartesian().LocalizeInPolarSpace(space),
                                    IsLargeArc = false
                                },
                                new LineSegment
                                {
                                    Point = endInnerPolar.ToCartesian().LocalizeInPolarSpace(space)
                                },
                                new ArcSegment
                                {
                                    Size = new Size(radius - arcWidth, radius - arcWidth),
                                    Point = startInnerPolar.ToCartesian().LocalizeInPolarSpace(space),
                                    SweepDirection = SweepDirection.Clockwise,
                                    IsLargeArc = false
                                }
                            }
                        }
                    }
                }
            });
        }
Exemplo n.º 7
0
        public void ToCartesian_FourCorners_UnitVectors()
        {
            //----------- Arrange -----------------------------
            var right = new PolarPoint(1, 0);
            var up    = new PolarPoint(1, Math.PI / 2d);
            var left  = new PolarPoint(1, Math.PI);
            var down  = new PolarPoint(1, 3 * Math.PI / 2d);

            //----------- Act ---------------------------------
            var ihat      = right.ToCartesian();
            var jhat      = up.ToCartesian();
            var minusihat = left.ToCartesian();
            var minusjhat = down.ToCartesian();

            //----------- Assert-------------------------------
            Assert.True(ihat.X.Is(1, 1e-12) && ihat.Y.Is(0, 1e-12));
            Assert.True(jhat.X.Is(0, 1e-12) && jhat.Y.Is(1, 1e-12));
            Assert.True(minusihat.X.Is(-1, 1e-12) && minusihat.Y.Is(0, 1e-12));
            Assert.True(minusjhat.X.Is(0, 1e-12) && minusjhat.Y.Is(-1, 1e-12));
        }
Exemplo n.º 8
0
        public override CustomPath CalculatePath()
        {
            var startOuterPolar = new PolarPoint(PolarOffset, outerRadius);
            var endOuterPolar   = new PolarPoint(PolarOffset + ArcAngle, outerRadius);
            var startInnerPolar = new PolarPoint(PolarOffset, outerRadius - RingWidth);
            var endInnerPolar   = new PolarPoint(PolarOffset + ArcAngle, outerRadius - RingWidth);

            return(new CustomPath(this)
            {
                Data = new PathGeometry
                {
                    Figures = new PathFigureCollection
                    {
                        new PathFigure
                        {
                            StartPoint = startOuterPolar.ToCartesian().LocalizeInPolarSpace(RenderSize),
                            Segments = new PathSegmentCollection
                            {
                                new ArcSegment
                                {
                                    Size = outerSize,
                                    Point = endOuterPolar.ToCartesian().LocalizeInPolarSpace(RenderSize),
                                    IsLargeArc = ArcAngle > 180
                                },
                                new LineSegment
                                {
                                    Point = endInnerPolar.ToCartesian().LocalizeInPolarSpace(RenderSize)
                                },
                                new ArcSegment
                                {
                                    Size = innerSize,
                                    Point = startInnerPolar.ToCartesian().LocalizeInPolarSpace(RenderSize),
                                    SweepDirection = SweepDirection.Clockwise,
                                    IsLargeArc = ArcAngle > 180
                                }
                            }
                        }
                    }
                }
            });
        }