internal virtual void CheckBottomScrollableBounds()
        {
            double lastItemBottom          = this.GetRealizedItemsBottom();
            double scrollableContentBottom = this.GetScrollableContentEnd();

            bool isLastItemRealized = this.owner.GetItemAfter(this.owner.lastItemCache.associatedDataItem) == null;

            if (!RadMath.AreClose(lastItemBottom, scrollableContentBottom) || !isLastItemRealized)
            {
                if (isLastItemRealized)
                {
                    double offset = lastItemBottom - scrollableContentBottom;
                    this.CorrectScrollableContentSize(offset);
                    this.owner.OnBottomEdgeCorrected();
                }
                else if (scrollableContentBottom < this.scrollableContentHeightAdjustment + this.ViewportLength)
                {
                    //     this.CorrectScrollableContentSize(this.scrollableItemsLength - this.ScrollableContentLength);
                    double amount = this.owner.GetDataItemCount() - Math.Max(this.owner.GetLastItemCacheIndex(), 0);
                    this.CorrectScrollableContentSize(amount * this.averageItemLength);
                }
                else
                {
                    this.CheckResizeScrollableContentWhenAllItemsRealized();
                }
            }

            //this.owner.previousScrollOffset = scrollOffset;
        }
示例#2
0
        private static void OnValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
        {
            RadRating rating = sender as RadRating;

            if (rating.settingValuePropertySilently)
            {
                return;
            }

            if (!rating.IsTemplateApplied)
            {
                return;
            }

            double oldValue = (double)args.OldValue;
            double newValue = RadMath.CoerceValue((double)args.NewValue, 0, rating.itemsSource.Count);

            if (newValue != rating.Value)
            {
                rating.SetValuePropertySilently(ValueProperty, newValue);
            }

            if (newValue != oldValue)
            {
                rating.HandleValueChange(oldValue, newValue);
            }
        }
示例#3
0
        protected override RadRect ArrangeCore(RadRect rect)
        {
            double   radius = rect.Width / 2;
            RadPoint center = rect.Center;
            NumericalAxisPlotInfo polarPlot = this.firstPlotInfo as NumericalAxisPlotInfo;
            double       pointRadius        = polarPlot.NormalizedValue * radius;
            AxisPlotInfo anglePlot          = this.secondPlotInfo;

            this.angle = 0d;

            NumericalAxisPlotInfo numericalAnglePlot = anglePlot as NumericalAxisPlotInfo;

            if (numericalAnglePlot != null)
            {
                this.angle = numericalAnglePlot.ConvertToAngle();
            }
            else
            {
                CategoricalAxisPlotInfo categoricalAnglePlot = anglePlot as CategoricalAxisPlotInfo;
                if (categoricalAnglePlot != null)
                {
                    this.angle = categoricalAnglePlot.ConvertToAngle(this.GetChartArea <PolarChartAreaModel>());
                }
            }

            RadPoint arcPosition = RadMath.GetArcPoint(this.angle, center, pointRadius);
            RadSize  desiredSize = this.Measure();

            return(new RadRect(arcPosition.X, arcPosition.Y, desiredSize.Width, desiredSize.Height));
        }
示例#4
0
 internal override void SetValueFromAxis(AxisModel axis, object newValue)
 {
     if (axis is NumericalAxisModel)
     {
         this.numericalPlot = newValue as NumericalAxisPlotInfo;
         if (this.numericalPlot != null)
         {
             this.isInNumericalRange = true;
             this.isPositive         = this.numericalPlot.NormalizedValue >= this.numericalPlot.NormalizedOrigin;
             //// inverse axis with negative point value is equivalent to regular axis with positive point value
             if (this.numericalPlot.Axis.IsInverse && !RadMath.AreClose(this.numericalPlot.NormalizedValue, this.numericalPlot.NormalizedOrigin))
             {
                 this.isPositive ^= true;
             }
         }
         else
         {
             this.isInNumericalRange = false;
             this.isPositive         = false;
         }
     }
     else if (axis is CategoricalAxisModel || axis is DateTimeContinuousAxisModel)
     {
         this.categoricalPlot      = newValue as CategoricalAxisPlotInfo;
         this.isInCategoricalRange = true;
     }
 }
        public void SnapPointToGridLine(CategoricalDataPoint point)
        {
            if (point.numericalPlot == null)
            {
                return;
            }

            if (point.numericalPlot.SnapTickIndex < 0 ||
                point.numericalPlot.SnapTickIndex >= point.numericalPlot.Axis.ticks.Count)
            {
                return;
            }

            AxisTickModel tick = point.numericalPlot.Axis.ticks[point.numericalPlot.SnapTickIndex];

            if (!RadMath.AreClose(point.numericalPlot.NormalizedValue, (double)tick.normalizedValue))
            {
                return;
            }

            if (this.PlotDirection == AxisPlotDirection.Vertical)
            {
                CategoricalSeriesRoundLayoutContext.SnapToGridLineVertical(point, tick.layoutSlot);
            }
            else
            {
                CategoricalSeriesRoundLayoutContext.SnapToGridLineHorizontal(point, tick.layoutSlot);
            }
        }
        private void UpdateLabels(RadSize availableSize)
        {
            RadRect availableRect = new RadRect(availableSize.Width, availableSize.Height);
            RadRect ellipseRect   = RadRect.ToSquare(availableRect, false);

            ellipseRect = RadRect.CenterRect(ellipseRect, availableRect);
            double   radius = ellipseRect.Width / 2;
            RadPoint center = ellipseRect.Center;
            RadPoint arcPosition;

            foreach (AxisLabelModel label in this.owner.labels)
            {
                if (!label.isVisible)
                {
                    continue;
                }

                double angle = this.owner.IsInverse ? 360 - (double)label.normalizedPosition * 360 : (double)label.normalizedPosition * 360;
                arcPosition = RadMath.GetArcPoint(angle, center, radius);

                this.UpdateMargins(ellipseRect, label.desiredSize, arcPosition);
            }

            double offset = this.owner.LineThickness + this.owner.MajorTickLength;

            this.margins.Left   += offset;
            this.margins.Top    += offset;
            this.margins.Right  += offset;
            this.margins.Bottom += offset;
        }
        protected override RadRect ArrangeCore(RadRect rect)
        {
            double       radius    = rect.Width / 2;
            RadPoint     center    = rect.Center;
            AxisPlotInfo anglePlot = this.plotInfo;
            double       angle     = 0d;

            NumericalAxisPlotInfo numericalAnglePlot = anglePlot as NumericalAxisPlotInfo;

            if (numericalAnglePlot != null)
            {
                angle = numericalAnglePlot.ConvertToAngle();
            }
            else
            {
                CategoricalAxisPlotInfo categoricalAnglePlot = anglePlot as CategoricalAxisPlotInfo;
                if (categoricalAnglePlot != null)
                {
                    angle = categoricalAnglePlot.ConvertToAngle(this.GetChartArea <PolarChartAreaModel>());
                }
            }

            RadPoint arcPoint = RadMath.GetArcPoint(angle, center, radius);

            this.radialLine = new RadPolarVector()
            {
                Point = arcPoint, Angle = angle, Center = center
            };

            return(new RadRect(center, arcPoint));
        }
        internal virtual void CheckTopScrollableBounds()
        {
            double firstItemTop = this.GetRealizedItemsTop();

            bool isFirstItemRealized = this.owner.firstItemCache != null && this.owner.GetItemBefore(this.owner.firstItemCache.associatedDataItem) == null;

            if (firstItemTop != this.ScrollOffset)
            {
                if (isFirstItemRealized && !RadMath.AreClose(firstItemTop, 0, 0.01) || (firstItemTop < 0 && this.ScrollOffset < this.ViewportLength / 4))
                {
                    double currentScrollOffset = this.ScrollOffset;
                    double newOffset           = this.ScrollOffset - firstItemTop;
                    if (!RadMath.AreClose(newOffset, this.ScrollOffset, 0.01))
                    {
                        // if (newOffset < 0 || (firstItemTop < 0 && RadMath.AreClose(0, this.ScrollOffset, Epsilon)))
                        {
                            this.EnsureCorrectLayout();
                        }
                    }
                }
                else
                {
                    this.CheckResizeScrollableContentWhenAllItemsRealized();
                }
            }
        }
示例#9
0
        internal override double GetPolarDistance(Point point)
        {
            var coordinates = RadMath.ToPolarCoordinates(new RadPoint(point.X, point.Y), new RadPoint(this.CenterPoint.X, this.CenterPoint.Y));

            var normalizedStartAngle = this.startAngle % 360;

            if (this.CenterPoint.X < point.X && this.CenterPoint.Y < point.Y)
            {
                // IV quadrant
                if (this.startAngle + this.sweepAngle > 360)
                {
                    normalizedStartAngle = this.startAngle - 360;
                }
            }

            var pointRadius = coordinates.Item1;

            // Outside of bounds.
            if (coordinates.Item2 <= normalizedStartAngle || coordinates.Item2 >= normalizedStartAngle + this.sweepAngle)
            {
                pointRadius = double.PositiveInfinity;
            }

            return(Math.Max(0, pointRadius - (this.Radius - this.InnerRadius) / 2 + this.InnerRadius));
        }
示例#10
0
        internal override IEnumerable <AxisTickModel> GenerateTicks(ValueRange <decimal> currentVisibleRange)
        {
            if (this.majorStep <= 0 || this.actualRange.maximum == this.actualRange.minimum)
            {
                yield break;
            }

            decimal tickStep           = (decimal)this.majorStep;
            decimal normalizedTickStep = tickStep / 360;

            decimal startTick   = 0;
            decimal endTick     = 1;
            decimal currentTick = startTick;
            decimal value       = 0;

            while (currentTick < endTick || RadMath.AreClose((double)currentTick, (double)endTick))
            {
                AxisTickModel tick = new MajorTickModel();
                tick.normalizedValue = this.IsInverse ? 1 - currentTick : currentTick;
                tick.value           = value;
                currentTick         += normalizedTickStep;
                value += tickStep;

                yield return(tick);
            }
        }
示例#11
0
        private RadRect InflateCellDecorationVertically(RadRect layoutSlot, Border decoration)
        {
            if (decoration.BorderBrush == null)
            {
                return(layoutSlot);
            }

            if (layoutSlot.Y < this.dayNamesLineSlot.Bottom)
            {
                layoutSlot.Y      -= decoration.BorderThickness.Bottom;
                layoutSlot.Height += decoration.BorderThickness.Bottom;
            }
            else if (RadMath.AreClose(layoutSlot.Bottom, this.Owner.CalendarViewSize.Height))
            {
                layoutSlot.Y      -= decoration.BorderThickness.Top;
                layoutSlot.Height += decoration.BorderThickness.Top + decoration.BorderThickness.Bottom;
            }
            else
            {
                layoutSlot.Y -= decoration.BorderThickness.Top;

                if (this.Owner.HasHorizontalGridLines)
                {
                    layoutSlot.Height += decoration.BorderThickness.Top + decoration.BorderThickness.Bottom;
                }
                else
                {
                    layoutSlot.Height += decoration.BorderThickness.Top;
                }
            }

            return(layoutSlot);
        }
        private static void SnapToLowGridLine(OhlcDataPoint point)
        {
            if (point.numericalPlot.SnapBaseTickIndex == -1 ||
                point.numericalPlot.SnapBaseTickIndex >= point.numericalPlot.Axis.ticks.Count)
            {
                return;
            }

            var baseTick = point.numericalPlot.Axis.ticks[point.numericalPlot.SnapBaseTickIndex];

            if (!RadMath.AreClose(point.numericalPlot.NormalizedLow, (double)baseTick.normalizedValue))
            {
                return;
            }

            var    tickRect = baseTick.layoutSlot;
            double gridLine = tickRect.Y + (int)(tickRect.Height / 2);

            double difference = gridLine - point.layoutSlot.Bottom;

            point.layoutSlot.Height += difference;

            if (point.layoutSlot.Height < 0)
            {
                point.layoutSlot.Height = 0;
            }
        }
        private static void SnapToHighGridLine(OhlcDataPoint point)
        {
            if (point.numericalPlot.SnapTickIndex < 0 ||
                point.numericalPlot.SnapTickIndex >= point.numericalPlot.Axis.ticks.Count)
            {
                return;
            }

            var topTick = point.numericalPlot.Axis.ticks[point.numericalPlot.SnapTickIndex];

            if (!RadMath.AreClose(point.numericalPlot.NormalizedHigh, (double)topTick.normalizedValue))
            {
                return;
            }

            var    tickRect = topTick.layoutSlot;
            double gridLine = tickRect.Y + (int)(tickRect.Height / 2);

            double difference = point.layoutSlot.Y - gridLine;

            point.layoutSlot.Y      -= difference;
            point.layoutSlot.Height += difference;

            if (point.layoutSlot.Height < 0)
            {
                point.layoutSlot.Height = 0;
            }
        }
示例#14
0
        private RadRect InflateCellDecorationHorizontally(RadRect layoutSlot, Border decoration)
        {
            if (decoration.BorderBrush == null)
            {
                return(layoutSlot);
            }

            if (layoutSlot.X < this.weekNumbersLineSlot.Right)
            {
                layoutSlot.X     -= decoration.BorderThickness.Right;
                layoutSlot.Width += decoration.BorderThickness.Right;
            }
            else if (RadMath.AreClose(layoutSlot.Right, this.Owner.CalendarViewSize.Width))
            {
                layoutSlot.X     -= decoration.BorderThickness.Left;
                layoutSlot.Width += decoration.BorderThickness.Left + decoration.BorderThickness.Right;
            }
            else
            {
                layoutSlot.X -= decoration.BorderThickness.Left;

                if (this.Owner.HasVerticalGridLines)
                {
                    layoutSlot.Width += decoration.BorderThickness.Left + decoration.BorderThickness.Right;
                }
                else
                {
                    layoutSlot.Width += decoration.BorderThickness.Left;
                }
            }

            return(layoutSlot);
        }
示例#15
0
        public void SnapPointToGridLine(RangeDataPoint point)
        {
            if (point.numericalPlot.SnapTickIndex >= 0 && point.numericalPlot.SnapTickIndex < point.numericalPlot.Axis.ticks.Count)
            {
                AxisTickModel highTick = point.numericalPlot.Axis.ticks[point.numericalPlot.SnapTickIndex];
                if (RadMath.AreClose(point.numericalPlot.NormalizedHigh, (double)highTick.normalizedValue))
                {
                    if (this.PlotDirection == AxisPlotDirection.Vertical)
                    {
                        SnapHighToVerticalGridLine(point, highTick.layoutSlot);
                    }
                    else
                    {
                        SnapHighToHorizontalGridLine(point, highTick.layoutSlot);
                    }
                }
            }

            if (point.numericalPlot.SnapBaseTickIndex >= 0 && point.numericalPlot.SnapBaseTickIndex < point.numericalPlot.Axis.ticks.Count)
            {
                AxisTickModel lowTick = point.numericalPlot.Axis.ticks[point.numericalPlot.SnapBaseTickIndex];
                if (RadMath.AreClose(point.numericalPlot.NormalizedLow, (double)lowTick.normalizedValue))
                {
                    if (this.PlotDirection == AxisPlotDirection.Vertical)
                    {
                        SnapLowToVerticalGridLine(point, lowTick.layoutSlot);
                    }
                    else
                    {
                        SnapLowToHorizontalGridLine(point, lowTick.layoutSlot);
                    }
                }
            }
        }
示例#16
0
        protected override RadRect ArrangeCore(RadRect rect)
        {
            this.radius = rect.Width / 2;
            RadPoint center = rect.Center;

            AxisPlotInfo anglePlot1 = this.firstPlotInfo;
            double       angle1     = 0d;

            NumericalAxisPlotInfo numericalAnglePlot1 = anglePlot1 as NumericalAxisPlotInfo;

            if (numericalAnglePlot1 != null)
            {
                angle1 = numericalAnglePlot1.ConvertToAngle();
            }
            else
            {
                CategoricalAxisPlotInfo categoricalAnglePlot1 = anglePlot1 as CategoricalAxisPlotInfo;
                if (categoricalAnglePlot1 != null)
                {
                    angle1 = categoricalAnglePlot1.ConvertToAngle(this.GetChartArea <PolarChartAreaModel>());
                }
            }

            RadPoint arcPoint1 = RadMath.GetArcPoint(angle1, center, this.radius);

            this.polarVector1 = new RadPolarVector()
            {
                Point = arcPoint1, Angle = angle1, Center = center
            };

            AxisPlotInfo anglePlot2 = this.secondPlotInfo;
            double       angle2     = 0d;

            NumericalAxisPlotInfo numericalAnglePlot2 = anglePlot2 as NumericalAxisPlotInfo;

            if (numericalAnglePlot2 != null)
            {
                angle2 = numericalAnglePlot2.ConvertToAngle();
            }
            else
            {
                CategoricalAxisPlotInfo categoricalAnglePlot2 = anglePlot2 as CategoricalAxisPlotInfo;
                if (categoricalAnglePlot2 != null)
                {
                    angle2 = categoricalAnglePlot2.ConvertToAngle(this.GetChartArea <PolarChartAreaModel>());
                }
            }

            RadPoint arcPoint2 = RadMath.GetArcPoint(angle2, center, this.radius);

            this.polarVector2 = new RadPolarVector()
            {
                Point = arcPoint2, Angle = angle2, Center = center
            };

            return(rect);
        }
示例#17
0
        internal override IEnumerable <AxisTickModel> GenerateTicks(ValueRange <decimal> currentVisibleRange)
        {
            // use the decimal type for higher accuracy; see the XML comments on the GetVisibleRange method
            decimal delta = (decimal)this.actualRange.maximum - (decimal)this.actualRange.minimum;

            if (delta <= 0)
            {
                yield break;
            }

            double scale = this.layoutStrategy.GetZoom();
            double step  = this.majorStep;

            if (scale != 1d)
            {
                step = NumericalAxisModel.NormalizeStep(step / scale);
            }

            decimal tickStep           = (decimal)step;
            decimal normalizedTickStep = tickStep / delta;

            currentVisibleRange.minimum -= currentVisibleRange.minimum % normalizedTickStep;
            currentVisibleRange.maximum += normalizedTickStep - (currentVisibleRange.maximum % normalizedTickStep);

            decimal startTick, endTick;

            if (this.IsInverse)
            {
                startTick = Math.Max(0, 1 - currentVisibleRange.maximum);
                endTick   = Math.Min(1, 1 - currentVisibleRange.minimum);
            }
            else
            {
                startTick = Math.Max(0, currentVisibleRange.minimum);
                endTick   = Math.Min(1, currentVisibleRange.maximum);
            }

            decimal currentTick = startTick;
            decimal value       = (decimal)this.actualRange.minimum + currentTick * delta;

            int virtualIndex = (int)((value - (decimal)this.actualRange.minimum) / tickStep);

            while (currentTick < endTick || RadMath.AreClose((double)currentTick, (double)endTick))
            {
                AxisTickModel tick = new MajorTickModel();
                tick.normalizedValue = this.IsInverse ? 1 - currentTick : currentTick;
                tick.value           = (decimal)this.ReverseTransformValue((double)value);
                tick.virtualIndex    = virtualIndex;

                currentTick += normalizedTickStep;
                value       += tickStep;
                virtualIndex++;

                yield return(tick);
            }
        }
示例#18
0
        internal override RadRect GetPosition()
        {
            // TODO: Consider better interpretation of segments in cartesian coordinates.
            var centerR   = this.Radius / 2;
            var centerAng = this.startAngle % 360 + this.SweepAngle / 2;

            var point = RadMath.ToCartesianCoordinates(centerR, centerAng);

            return(new RadRect(this.CenterPoint.X + point.X, this.CenterPoint.Y + point.Y, 1, 1));
        }
        internal virtual void CheckTopScrollableBounds()
        {
            double firstItemTop         = this.GetRealizedItemsTop();
            double scrollableContentTop = -this.ScrollOffset;

            bool isFirstItemRealized = this.owner.GetItemBefore(this.owner.firstItemCache.associatedDataItem) == null;

            if (firstItemTop != scrollableContentTop)
            {
                if (isFirstItemRealized && firstItemTop > scrollableContentTop)
                {
                    double currentScrollOffset = -scrollableContentTop;
                    double offset    = firstItemTop - scrollableContentTop;
                    double newOffset = currentScrollOffset - offset;
                    if (!RadMath.AreClose(newOffset, this.ScrollOffset, Epsilon))
                    {
                        this.ScrollToOffset(newOffset, null);
                    }
                }
                else if (isFirstItemRealized && firstItemTop < scrollableContentTop)
                {
                    double amount = this.GetElementCanvasOffset(this.owner.itemsPanel) + (scrollableContentTop - firstItemTop);
                    this.SetElementCanvasOffset(this.owner.itemsPanel, amount);
                    double newScrollOffset  = this.ScrollOffset + (scrollableContentTop - firstItemTop);
                    double heightCorrection = Math.Max(0, newScrollOffset - this.ScrollableLength);
                    if (heightCorrection > 0)
                    {
                        this.CorrectScrollableContentSize(heightCorrection);
                    }
                    //     this.ScrollToOffset(Math.Min(newScrollOffset, this.ScrollableLength), null);
                }
                else if (scrollableContentTop > -this.scrollableContentHeightAdjustment)
                {
                    double currentScrollOffset = -scrollableContentTop;
                    double adjustment          = Math.Max(this.owner.GetFirstItemCacheIndex(), 1) * this.averageItemLength;
                    double newOffset           = currentScrollOffset + adjustment;
                    double heightCorrection    = Math.Max(0, newOffset - this.ScrollableLength);
                    if (heightCorrection > 0)
                    {
                        this.CorrectScrollableContentSize(heightCorrection);
                    }
                    newOffset = Math.Min(newOffset, this.ScrollableLength);
                    //this.ScrollToOffset(newOffset, () =>
                    //{
                    //    double correction = newOffset - this.ScrollOffset;
                    //    double amount = this.GetElementCanvasOffset(this.owner.itemsPanel) + adjustment - correction;
                    //    this.SetElementCanvasOffset(this.owner.itemsPanel, amount);
                    //});
                }
                else
                {
                    this.CheckResizeScrollableContentWhenAllItemsRealized();
                }
            }
        }
示例#20
0
        /// <summary>
        /// Clips the <paramref name="rect"/> to the <paramref name="container"/>.
        /// </summary>
        /// <param name="rect">The <see cref="RadRect"/> to be clipped.</param>
        /// <param name="container">The container.</param>
        /// <param name="borderOverflow">The border (stroke thickness) of the <paramref name="rect"/>.</param>
        /// <param name="dashPatternLength">The length of the dash pattern of the <see cref="RadRect"/> stroke.</param>
        /// <returns>The clipped rectangle.</returns>
        internal static RadRect ClipRectangle(RadRect rect, RadRect container, double borderOverflow, double dashPatternLength)
        {
            // extend the container with the element border
            container.X      -= borderOverflow;
            container.Y      -= borderOverflow;
            container.Width  += 2 * borderOverflow;
            container.Height += 2 * borderOverflow;

            if (!rect.IntersectsWith(container))
            {
                return(RadRect.Empty);
            }

            // calculate the clipped rectangle, extended with the element border
            double xFrom = RadMath.CoerceValue(rect.X, container.X, container.Right);
            double yFrom = RadMath.CoerceValue(rect.Y, container.Y, container.Bottom);
            double xTo   = RadMath.CoerceValue(rect.Right, container.X, container.Right);
            double yTo   = RadMath.CoerceValue(rect.Bottom, container.Y, container.Bottom);

            if (dashPatternLength == 0 || double.IsNaN(dashPatternLength) || double.IsInfinity(dashPatternLength))
            {
                dashPatternLength = 1;
            }

            // first check if "To" values are clipped, and if so, add the additional space needed by the dash array to be rendered correctly
            if (rect.Right != xTo)
            {
                xTo += (rect.Right - xTo) % dashPatternLength;
            }

            if (rect.Bottom != yTo)
            {
                yTo += (rect.Bottom - yTo) % dashPatternLength;
            }

            // check if "From" values are clipped, and if so, add the additional space needed by the dash array to be rendered correctly and change the rect coordinates
            if (rect.X != xFrom)
            {
                xFrom -= (xFrom - rect.X) % dashPatternLength;
                rect.X = xFrom;
            }

            if (rect.Y != yFrom)
            {
                yFrom -= (yFrom - rect.Y) % dashPatternLength;
                rect.Y = yFrom;
            }

            rect.Width  = xTo - xFrom;
            rect.Height = yTo - yFrom;

            return(rect);
        }
示例#21
0
        public static Geometry RenderArc(DoughnutSegmentData context)
        {
            PathFigure figure = new PathFigure();

            figure.IsClosed = true;
            figure.IsFilled = true;

            RadPoint startPoint = RadMath.GetArcPoint(context.StartAngle, context.Center, context.Radius1);

            figure.StartPoint = startPoint.ToPoint();

            ArcSegment firstArc = new ArcSegment();

            firstArc.Size       = new Size(context.Radius1, context.Radius1);
            firstArc.IsLargeArc = context.SweepAngle > 180 || context.SweepAngle < -180;

            var angle = context.StartAngle;

            if (context.SweepDirection == SweepDirection.Clockwise)
            {
                angle += context.SweepAngle;
            }
            else
            {
                angle -= context.SweepAngle;
            }

            firstArc.SweepDirection = context.SweepAngle > 0 ? context.SweepDirection : context.SweepDirection ^ SweepDirection.Clockwise;

            firstArc.Point = RadMath.GetArcPoint(angle, context.Center, context.Radius1).ToPoint();
            figure.Segments.Add(firstArc);

            LineSegment firstLine = new LineSegment();

            firstLine.Point = RadMath.GetArcPoint(angle, context.Center, context.Radius2).ToPoint();
            figure.Segments.Add(firstLine);

            ArcSegment secondArc = new ArcSegment();

            secondArc.Size           = new Size(context.Radius2, context.Radius2);
            secondArc.IsLargeArc     = context.SweepAngle > 180 || context.SweepAngle < -180;
            secondArc.SweepDirection = context.SweepAngle > 0 ? context.SweepDirection ^ SweepDirection.Clockwise : context.SweepDirection;
            secondArc.Point          = RadMath.GetArcPoint(context.StartAngle, context.Center, context.Radius2).ToPoint();
            figure.Segments.Add(secondArc);

            PathGeometry geometry = new PathGeometry();

            geometry.Figures.Add(figure);

            return(geometry);
        }
示例#22
0
        /// <inheritdoc/>
        protected override bool ApplyTemplateCore()
        {
            this.ratingPanel = this.GetTemplateChild("Part_RatingPanel") as StackPanel;
            if (this.ratingPanel == null)
            {
                throw new MissingTemplatePartException("Part_RatingPanel", typeof(StackPanel));
            }

            if (this.itemsSource.Count != 0)
            {
                if (!this.IsItemsSourceManual)
                {
                    throw new InvalidOperationException(AutoGeneratedItemsCountExceptionMessage);
                }

                this.SetValue(AutoGeneratedItemsCountProperty, 0);
            }
            else
            {
                if (this.AutoGeneratedItemsCount == (int)AutoGeneratedItemsCountProperty.GetMetadata(typeof(int)).DefaultValue)
                {
                    this.SetValue(AutoGeneratedItemsCountProperty, (int)AutoGeneratedItemsCountProperty.GetMetadata(typeof(int)).DefaultValue);
                }

                this.GenerateRatingItems();
            }

            this.PopulateRatingPanel();

            double coercedValue = RadMath.CoerceValue(this.Value, 0, this.itemsSource.Count);

            if (this.Value != coercedValue)
            {
                this.SetValuePropertySilently(ValueProperty, coercedValue);
            }

            double defaultValue = (double)ValueProperty.GetMetadata(typeof(double)).DefaultValue;

            if (this.Value != defaultValue)
            {
                this.HandleValueChange(defaultValue, this.Value);
            }

            this.UpdateDisplayValue();
            this.UpdateFillRatio();
            this.UpdateVisualState(false);

            return(base.ApplyTemplateCore());
        }
示例#23
0
        private bool TryTranslateItemsPanelWithPullToRefreshHeight()
        {
            var currentOffset = this.virtualizationStrategy.GetElementCanvasOffset(this.itemsPanel);

            if (RadMath.AreClose(currentOffset, 0))
            {
                var length = this.virtualizationStrategy.LayoutOrientation == Orientation.Vertical ? this.pullToRefreshIndicator.DesiredSize.Height : this.pullToRefreshIndicator.DesiredSize.Width;

                this.TranslateItemsPanel(length);

                return(true);
            }

            return(false);
        }
示例#24
0
        internal override void UpdateAxisLine(ChartLayoutContext context)
        {
            PolarChartAreaModel chartArea = this.chart.chartArea as PolarChartAreaModel;
            double   angle  = chartArea.NormalizeAngle(0);
            RadPoint center = chartArea.plotArea.layoutSlot.Center;
            RadPoint point  = RadMath.GetArcPoint(angle, center, chartArea.plotArea.layoutSlot.Width / 2);

            double antiAliasOffset = this.model.LineThickness % 2 == 1 ? 0.5 : 0;

            this.line.X1 = center.X;
            this.line.Y1 = center.Y - antiAliasOffset;
            this.line.X2 = point.X;
            this.line.Y2 = point.Y - antiAliasOffset;

            base.UpdateAxisLine(context);
        }
示例#25
0
        private void ArrangeMenuItemControl(RadialSegment segmentModel)
        {
            var centerPointPolar      = CoordinatesUtils.GetCenterPosition(segmentModel.LayoutSlot);
            var centerPoint           = RadMath.ToCartesianCoordinates(centerPointPolar.Radius, centerPointPolar.Angle);
            var tranformedCenterPoint = new Point(centerPoint.X + this.Model.OuterRadius, this.Model.OuterRadius - centerPoint.Y);

            var element = segmentModel.Visual as RadialMenuItemControl;

            element.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));

            var arrangeSlot = new Rect(tranformedCenterPoint.X - element.DesiredSize.Width / 2.0, tranformedCenterPoint.Y - element.DesiredSize.Height / 2.0, element.DesiredSize.Width, element.DesiredSize.Height);

            element.Arrange(arrangeSlot);
            Canvas.SetLeft(element, arrangeSlot.X);
            Canvas.SetTop(element, arrangeSlot.Y);
        }
        internal virtual void CheckBottomScrollableBounds()
        {
            if (this.owner.RealizedItems.Length == 0)
            {
                return;
            }

            double lastItemBottom          = this.GetRealizedItemsBottom();
            double scrollableContentBottom = this.GetScrollableContentEnd();

            bool isFirstItemRealized = this.owner.GetItemBefore(this.owner.firstItemCache.associatedDataItem) == null;
            bool isLastItemRealized  = this.owner.GetItemAfter(this.owner.lastItemCache.associatedDataItem) == null;

            if (!RadMath.AreClose(lastItemBottom, scrollableContentBottom) || !isLastItemRealized)
            {
                if (isLastItemRealized)
                {
                    double offsetChange  = lastItemBottom - scrollableContentBottom;
                    var    lastItemEnd   = lastItemBottom;
                    var    lastItemStart = this.owner.lastItemCache.CurrentOffset;

                    if (lastItemEnd < this.ScrollOffset + this.ViewportLength && offsetChange < 0 || lastItemStart < this.ScrollOffset + this.ViewportLength || this.ScrollOffset + this.ViewportLength > this.ScrollableLength)
                    {
                        if (!RadMath.AreClose(offsetChange, 0, 0.1))
                        {
                            this.CorrectScrollableContentSize(offsetChange);
                            this.owner.OnBottomEdgeCorrected();
                        }
                    }
                }
                else if (!RadMath.AreClose(lastItemBottom, scrollableContentBottom) && !(isFirstItemRealized && isLastItemRealized))
                {
                    var estimatedLength = this.scrollableItemsLength;

                    var change = estimatedLength - scrollableContentBottom;

                    if (Math.Abs(change) > 0.01)
                    {
                        this.CorrectScrollableContentSize(change);
                    }
                }
                else if (isFirstItemRealized && isLastItemRealized)
                {
                    this.CheckResizeScrollableContentWhenAllItemsRealized();
                }
            }
        }
        internal override IEnumerable <AxisTickModel> GenerateTicks(ValueRange <decimal> currentVisibleRange)
        {
            int categoryCount = this.categories.Count;

            if (categoryCount == 0)
            {
                yield break;
            }

            int tickInterval   = this.GetMajorTickInterval();
            int emptyTickCount = 0;

            int     tickCount          = categoryCount;
            decimal tickStep           = tickCount == 1 ? 1 : 1m / tickCount;
            decimal normalizedTickStep = tickStep * 360;

            decimal startTick   = 0;
            decimal endTick     = 1 - tickStep;
            decimal currentTick = startTick;
            decimal value       = 0;

            int virtualIndex = (int)(startTick / tickStep);

            while (currentTick < endTick || RadMath.AreClose((double)currentTick, (double)endTick))
            {
                if (emptyTickCount == 0)
                {
                    AxisTickModel tick = new MajorTickModel();
                    tick.normalizedValue = this.IsInverse ? 1 - currentTick : currentTick;
                    tick.value           = value;
                    tick.virtualIndex    = virtualIndex;

                    emptyTickCount = tickInterval - 1;

                    yield return(tick);
                }
                else
                {
                    emptyTickCount--;
                }

                currentTick += tickStep;
                value       += normalizedTickStep;
                virtualIndex++;
            }
        }
示例#28
0
        private PathGeometry BuildPolarStripe(RadPolarVector vector, RadPolarVector nextVector, bool isLargeArc)
        {
            RadPoint center = this.model.layoutSlot.Center;
            double   radius = this.model.layoutSlot.Width / 2;

            double endAngle = nextVector.Angle;

            if (endAngle == 360)
            {
                endAngle = 0;
            }
            RadPoint arcEndPoint = RadMath.GetArcPoint(endAngle, center, radius);

            PathGeometry geometry = new PathGeometry();
            PathFigure   figure   = new PathFigure();

            figure.IsClosed = true;
            figure.IsFilled = true;

            figure.StartPoint = new Point(vector.Center.X, vector.Center.Y);

            // first line
            figure.Segments.Add(new LineSegment()
            {
                Point = new Point(vector.Point.X, vector.Point.Y)
            });

            // arc
            ArcSegment arc = new ArcSegment();

            arc.SweepDirection = (this.Chart as RadPolarChart).RadialAxis.SweepDirection;
            arc.Size           = new Size(radius, radius);
            arc.IsLargeArc     = isLargeArc;
            arc.Point          = new Point(arcEndPoint.X, arcEndPoint.Y);
            figure.Segments.Add(arc);

            // second line
            figure.Segments.Add(new LineSegment()
            {
                Point = new Point(nextVector.Point.X, nextVector.Point.Y)
            });

            geometry.Figures.Add(figure);

            return(geometry);
        }
示例#29
0
        /// <summary>
        /// Clips the <paramref name="line"/> to the <paramref name="container"/>.
        /// </summary>
        /// <param name="line">The line to be clipped.</param>
        /// <param name="container">The container.</param>
        /// <param name="borderOverflow">The border (stroke thickness) of the <paramref name="line"/>.</param>
        /// <param name="dashPatternLength">The length of the dash pattern of the line stroke.</param>
        /// <returns>The clipped line.</returns>
        internal static RadLine ClipLine(RadLine line, RadRect container, double borderOverflow, double dashPatternLength)
        {
            // extend the container with the element border
            container.X      -= borderOverflow;
            container.Y      -= borderOverflow;
            container.Width  += 2 * borderOverflow;
            container.Height += 2 * borderOverflow;

            bool firstPointInside  = container.Contains(line.X1, line.Y1);
            bool secondPointInside = container.Contains(line.X2, line.Y2);

            if (firstPointInside && secondPointInside)
            {
                return(line);
            }

            if (dashPatternLength == 0 || double.IsNaN(dashPatternLength) || double.IsInfinity(dashPatternLength))
            {
                dashPatternLength = 1;
            }

            // find intersectionns of the line with the sides of the container
            double topIntersectionX    = RadMath.CalculateIntersectionX(line.X1, line.Y1, line.X2, line.Y2, container.Y);
            double bottomIntersectionX = RadMath.CalculateIntersectionX(line.X1, line.Y1, line.X2, line.Y2, container.Bottom);
            double leftIntersectionY   = RadMath.CalculateIntersectionY(line.X1, line.Y1, line.X2, line.Y2, container.X);
            double rightIntersectionY  = RadMath.CalculateIntersectionY(line.X1, line.Y1, line.X2, line.Y2, container.Right);

            // slope of the line: angle between the line ant the horizon (-pi/2, pi/2)
            var angle = Math.Atan((line.Y1 - line.Y2) / (line.X2 - line.X1));

            bool intersectsWithRect = false;

            // clip to container sides
            intersectsWithRect |= AnnotationHelper.TryClipToContainerTop(ref line, container, topIntersectionX, dashPatternLength, angle > 0 ? angle : Math.PI + angle);
            intersectsWithRect |= AnnotationHelper.TryClipToContainerBottom(ref line, container, bottomIntersectionX, dashPatternLength, angle > 0 ? angle : Math.PI + angle);
            intersectsWithRect |= AnnotationHelper.TryClipToContainerLeft(ref line, container, leftIntersectionY, dashPatternLength, angle);
            intersectsWithRect |= AnnotationHelper.TryClipToContainerRight(ref line, container, rightIntersectionY, dashPatternLength, angle);

            if (!intersectsWithRect)
            {
                line = new RadLine();
            }

            return(line);
        }
示例#30
0
        private void ArrangePolarLines()
        {
            // update polar (radius) lines
            int polarLinesIndex = 0;

            if ((this.linesVisibility & PolarGridLineVisibility.Polar) == PolarGridLineVisibility.Polar)
            {
                double antiAliasOffset = -1;

                foreach (RadPolarVector vector in this.model.polarLines)
                {
                    Line line = this.GetLineVisual(polarLinesIndex);
                    line.X1 = vector.Center.X;
                    line.Y1 = vector.Center.Y;
                    line.X2 = vector.Point.X;
                    line.Y2 = vector.Point.Y;

                    if (antiAliasOffset == -1)
                    {
                        antiAliasOffset = line.StrokeThickness % 2 == 1 ? 0.5 : 0;
                    }

                    if (RadMath.AreClose(line.Y1, line.Y2))
                    {
                        line.Y1 -= antiAliasOffset;
                        line.Y2 -= antiAliasOffset;
                    }
                    else if (RadMath.AreClose(line.X1, line.X2))
                    {
                        line.X1 += antiAliasOffset;
                        line.X2 += antiAliasOffset;
                    }

                    polarLinesIndex++;
                }
            }

            // hide not used lines
            while (polarLinesIndex < this.polarLines.Count)
            {
                this.polarLines[polarLinesIndex].Visibility = Visibility.Collapsed;
                polarLinesIndex++;
            }
        }