Exemplo n.º 1
0
        /// <summary>
        /// Calculates the length of the data points.
        /// </summary>
        protected void CalculateDataPointLength()
        {
            if (!(ActualIndependentAxis is ICategoryAxis))
            {
                IEnumerable <UnitValue> values =
                    ActiveDataPoints
                    .Select(dataPoint => ActualIndependentAxis.GetPlotAreaCoordinate(dataPoint.ActualIndependentValue))
                    .Where(value => ValueHelper.CanGraph(value.Value))
                    .OrderBy(value => value.Value)
                    .ToList();

                _dataPointlength =
                    EnumerableFunctions.Zip(
                        values,
                        values.Skip(1),
                        (left, right) => new Range <double>(left.Value, right.Value))
                    .Select(range => range.Maximum - range.Minimum)
                    .MinOrNullable();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the minimum distance between the given elements.
        /// </summary>
        /// <param name="orderedElements">Elements in the order they are arranged.</param>
        /// <param name="lengthSelector">Function that gets the length of a given element.</param>
        /// <returns>Minimum distance between the items.</returns>
        private double GetMinimumDistanceBetweenItems(IList <UIElement> orderedElements, Func <UIElement, double> lengthSelector)
        {
            if (orderedElements.Count < 2)
            {
                return(0);
            }

            return(EnumerableFunctions.Zip(
                       orderedElements,
                       orderedElements.Skip(1),
                       (leftElement, rightElement) =>
            {
                double halfLeftLength = lengthSelector(leftElement) / 2;
                double leftCenterCoordinate = GetCenterCoordinate(leftElement);

                double halfRightLength = lengthSelector(rightElement) / 2;
                double rightCenterCoordinate = GetCenterCoordinate(rightElement);

                return (rightCenterCoordinate - halfRightLength) - (leftCenterCoordinate + halfLeftLength);
            }).Min());
        }
Exemplo n.º 3
0
        private static Storyboard CreateStoryboard(
            FrameworkElement target,
            DependencyProperty animatingDependencyProperty,
            string propertyPath,
            ref object toValue,
            TimeSpan durationTimeSpan,
            EasingFunctionBase easingFunction)
        {
            object fromValue = target.GetValue(animatingDependencyProperty);

            double fromDoubleValue;
            double toDoubleValue;

            DateTime fromDateTime;
            DateTime toDateTime;

            Storyboard storyBoard = new Storyboard();

            Storyboard.SetTarget(storyBoard, target);

            Storyboard.SetTargetProperty(storyBoard, propertyPath);

            if ((fromValue != null && toValue != null))
            {
                if (ValueHelper.TryConvert(fromValue, out fromDoubleValue) && ValueHelper.TryConvert(toValue, out toDoubleValue))
                {
                    DoubleAnimation doubleAnimation = new DoubleAnimation();
                    doubleAnimation.EnableDependentAnimation = true;
#if !NO_EASING_FUNCTIONS
                    doubleAnimation.EasingFunction = easingFunction;
#endif
                    doubleAnimation.Duration = durationTimeSpan;
                    doubleAnimation.To       = ValueHelper.ToDouble(toValue);
                    toValue = doubleAnimation.To;

                    storyBoard.Children.Add(doubleAnimation);
                }
                else if (ValueHelper.TryConvert(fromValue, out fromDateTime) && ValueHelper.TryConvert(toValue, out toDateTime))
                {
                    ObjectAnimationUsingKeyFrames keyFrameAnimation = new ObjectAnimationUsingKeyFrames();
                    keyFrameAnimation.EnableDependentAnimation = true;
                    keyFrameAnimation.Duration = durationTimeSpan;

                    long intervals = (long)(durationTimeSpan.TotalSeconds * KeyFramesPerSecond);
                    if (intervals < 2L)
                    {
                        intervals = 2L;
                    }

                    IEnumerable <TimeSpan> timeSpanIntervals =
                        ValueHelper.GetTimeSpanIntervalsInclusive(durationTimeSpan, intervals);

                    IEnumerable <DateTime> dateTimeIntervals =
                        ValueHelper.GetDateTimesBetweenInclusive(fromDateTime, toDateTime, intervals);

                    IEnumerable <DiscreteObjectKeyFrame> keyFrames =
                        EnumerableFunctions.Zip(
                            dateTimeIntervals,
                            timeSpanIntervals,
                            (dateTime, timeSpan) => new DiscreteObjectKeyFrame()
                    {
                        Value = dateTime, KeyTime = timeSpan
                    });

                    foreach (DiscreteObjectKeyFrame keyFrame in keyFrames)
                    {
                        keyFrameAnimation.KeyFrames.Add(keyFrame);
                        toValue = keyFrame.Value;
                    }

                    storyBoard.Children.Add(keyFrameAnimation);
                }
            }

            if (storyBoard.Children.Count == 0)
            {
                ObjectAnimationUsingKeyFrames keyFrameAnimation = new ObjectAnimationUsingKeyFrames();
                keyFrameAnimation.EnableDependentAnimation = true;
                DiscreteObjectKeyFrame endFrame = new DiscreteObjectKeyFrame()
                {
                    Value = toValue, KeyTime = new TimeSpan(0, 0, 0)
                };
                keyFrameAnimation.KeyFrames.Add(endFrame);

                storyBoard.Children.Add(keyFrameAnimation);
            }

            return(storyBoard);
        }
Exemplo n.º 4
0
        protected override Size MeasureOverride(Size availableSize)
        {
            double offset = 0.0;

            if (Children.Count > 0)
            {
                Size totalSize = new Size(double.PositiveInfinity, double.PositiveInfinity);
                foreach (UIElement child in this.Children)
                {
                    child.Measure(totalSize);
                }

                Func <UIElement, double> lengthSelector = null;
                Func <UIElement, double> offsetSelector = null;

                if (Orientation == Orientation.Horizontal)
                {
                    lengthSelector = child => GetCorrectedDesiredSize(child).Width;
                    offsetSelector = child => GetCorrectedDesiredSize(child).Height;
                }
                else
                {
                    lengthSelector = child => GetCorrectedDesiredSize(child).Height;
                    offsetSelector = child => GetCorrectedDesiredSize(child).Width;
                }

                IEnumerable <IGrouping <int, UIElement> > priorityGroups =
                    from child in Children
                    group child by GetPriority(child) into priorityGroup
                    select priorityGroup;

                ActualMinimumDistanceBetweenChildren =
                    (from priorityGroup in priorityGroups
                     let orderedElements =
                         (from element in priorityGroup
                          orderby GetCenterCoordinate(element) ascending
                          select element).ToList()
                         select GetMinimumDistanceBetweenItems(orderedElements, lengthSelector))
                    .Min();

                IEnumerable <int> priorities =
                    Children.Select(child => GetPriority(child)).Distinct().OrderBy(priority => priority).ToList();

                PriorityOffsets = new Dictionary <int, double>();
                foreach (int priority in priorities)
                {
                    PriorityOffsets[priority] = 0.0;
                }

                IEnumerable <Tuple <int, int> > priorityPairs =
                    EnumerableFunctions.Zip(priorities, priorities.Skip(1), (previous, next) => new Tuple <int, int>(previous, next));

                foreach (Tuple <int, int> priorityPair in priorityPairs)
                {
                    IEnumerable <UIElement> currentPriorityChildren = Children.Where(child => GetPriority(child) == priorityPair.Item1).ToList();

                    IEnumerable <Range <double> > currentPriorityRanges =
                        GetRanges(currentPriorityChildren, lengthSelector);

                    IEnumerable <UIElement> nextPriorityChildren = Children.Where(child => GetPriority(child) == priorityPair.Item2).ToList();

                    IEnumerable <Range <double> > nextPriorityRanges =
                        GetRanges(nextPriorityChildren, lengthSelector);

                    bool intersects =
                        (from currentPriorityRange in currentPriorityRanges
                         from nextPriorityRange in nextPriorityRanges
                         select currentPriorityRange.IntersectsWith(nextPriorityRange))
                        .Any(value => value);

                    if (intersects)
                    {
                        double maxCurrentPriorityChildOffset =
                            currentPriorityChildren
                            .Select(child => offsetSelector(child))
                            .Max();

                        offset += maxCurrentPriorityChildOffset + OffsetPadding;
                    }
                    PriorityOffsets[priorityPair.Item2] = offset;
                }

                offset =
                    (Children
                     .GroupBy(child => GetPriority(child))
                     .Select(
                         group =>
                         group
                         .Select(child => PriorityOffsets[group.Key] + offsetSelector(child))
                         .Max()))
                    .Select(num => num)
                    .Max();
            }

            if (Orientation == Orientation.Horizontal)
            {
                return(new Size(0, offset));
            }
            else
            {
                return(new Size(offset, 0));
            }
        }