public static Storyboard CreateAnimation(this DependencyObject target, Dictionary <string, StoryboardInfo> storyboards, DependencyProperty animatingDependencyProperty, string propertyPath, string propertyKey, object initialValue, object targetValue, TimeSpan timeSpan, IEasingFunction easingFunction, Action releaseAction)
        {
            StoryboardInfo storyboardInfo;

            storyboards.TryGetValue(DependencyPropertyAnimationHelper.GetStoryboardKey(propertyKey), out storyboardInfo);
            if (storyboardInfo != null)
            {
                DependencyObject storyboardTarget = storyboardInfo.StoryboardTarget;
                storyboardInfo.Storyboard.Stop();
                storyboards.Remove(DependencyPropertyAnimationHelper.GetStoryboardKey(propertyKey));
                if (storyboardInfo.ReleaseAction != null)
                {
                    storyboardInfo.ReleaseAction();
                    storyboardInfo.ReleaseAction = (Action)null;
                }
            }
            storyboardInfo                       = new StoryboardInfo();
            storyboardInfo.Storyboard            = DependencyPropertyAnimationHelper.CreateStoryboard(target, animatingDependencyProperty, propertyPath, propertyKey, ref targetValue, timeSpan, easingFunction);
            storyboardInfo.ReleaseAction         = releaseAction;
            storyboardInfo.StoryboardTarget      = target;
            storyboardInfo.AnimateFrom           = initialValue;
            storyboardInfo.Storyboard.Completed += (EventHandler)((source, args) =>
            {
                storyboards.Remove(DependencyPropertyAnimationHelper.GetStoryboardKey(propertyKey));
                if (storyboardInfo.ReleaseAction == null)
                {
                    return;
                }
                storyboardInfo.ReleaseAction();
                storyboardInfo.ReleaseAction = (Action)null;
            });
            storyboards.Add(DependencyPropertyAnimationHelper.GetStoryboardKey(propertyKey), storyboardInfo);
            return(storyboardInfo.Storyboard);
        }
예제 #2
0
        private void ChangeDataPointYValue(XYDataPoint dataPoint, object newValue)
        {
            if (dataPoint == null)
            {
                return;
            }
            double yvalueInScaleUnits = dataPoint.YValueInScaleUnits;
            double d = this.Series.YAxis.Scale == null ? double.NaN : this.Series.YAxis.Scale.ProjectDataValue(newValue);

            dataPoint.YValueInScaleUnitsWithoutAnimation = d;
            if (!double.IsNaN(d) && !double.IsNaN(yvalueInScaleUnits) && (this.IsSeriesAnimationEnabled && this.ChartArea != null))
            {
                DependencyPropertyAnimationHelper.BeginAnimation(this.ChartArea, "YValueInScaleUnits", (object)yvalueInScaleUnits, (object)d, (Action <object, object>)((value1, value2) =>
                {
                    if (double.IsNaN(dataPoint.YValueInScaleUnitsWithoutAnimation))
                    {
                        return;
                    }
                    dataPoint.YValueInScaleUnits = (double)value2;
                }), dataPoint.Storyboards, this.Series.ActualTransitionDuration, this.Series.ActualTransitionEasingFunction);
            }
            else
            {
                this.SkipToFillValueAnimation(dataPoint, "YValueInScaleUnits");
                dataPoint.YValueInScaleUnits = d;
            }
        }
예제 #3
0
        internal void SkipToFillValueAnimation(XYDataPoint dataPoint, string propertyName)
        {
            string         storyboardKey  = DependencyPropertyAnimationHelper.GetStoryboardKey(propertyName);
            StoryboardInfo storyboardInfo = (StoryboardInfo)null;

            if (!dataPoint.Storyboards.TryGetValue(storyboardKey, out storyboardInfo) || storyboardInfo.Storyboard.Children.Count <= 0)
            {
                return;
            }
            storyboardInfo.Storyboard.SkipToFill();
        }
 public static void BeginAnimation(ChartArea seriesHost, string propertyName, object currentValue, object targetValue, Action <object, object> propertyUpdateAction, Dictionary <string, StoryboardInfo> storyboards, TimeSpan timeSpan, IEasingFunction easingFunction)
 {
     if (timeSpan == TimeSpan.Zero)
     {
         propertyUpdateAction(currentValue, targetValue);
     }
     else
     {
         DependencyPropertyAnimationHelper.CreateAnimation(seriesHost, propertyName, currentValue, targetValue, propertyUpdateAction, storyboards, timeSpan, easingFunction).Begin();
     }
 }
예제 #5
0
        internal virtual void OnXScaleChanged()
        {
            DateTime now = DateTime.Now;

            if (this.ChartArea == null)
            {
                return;
            }
            this.ChartArea.UpdateSession.BeginUpdates();
            bool flag = true;

            foreach (XYDataPoint xyDataPoint in (Collection <DataPoint>) this.Series.DataPoints)
            {
                xyDataPoint.XValueInScaleUnitsWithoutAnimation = this.Series.XAxis.Scale.ProjectDataValue(xyDataPoint.XValue);
                string         storyboardKey = DependencyPropertyAnimationHelper.GetStoryboardKey("XValueInScaleUnits");
                StoryboardInfo si            = (StoryboardInfo)null;
                if (xyDataPoint.Storyboards.TryGetValue(storyboardKey, out si) && si.Storyboard.Children.Count > 0)
                {
                    DoubleAnimation doubleAnimation = si.Storyboard.Children[0] as DoubleAnimation;
                    if (doubleAnimation != null && xyDataPoint.XValue != null)
                    {
                        double?to = doubleAnimation.To;
                        double xvalueInScaleUnits = xyDataPoint.XValueInScaleUnits;
                        if ((to.GetValueOrDefault() != xvalueInScaleUnits ? 1 : (!to.HasValue ? 1 : 0)) != 0)
                        {
                            if (!this.IsAnimationDirectionChanged(si, doubleAnimation.To.Value, xyDataPoint.XValueInScaleUnitsWithoutAnimation))
                            {
                                flag = false;
                            }
                            doubleAnimation.To = new double?(xyDataPoint.XValueInScaleUnitsWithoutAnimation);
                            continue;
                        }
                    }
                }
                xyDataPoint.XValueInScaleUnits = xyDataPoint.XValueInScaleUnitsWithoutAnimation;
            }
            if (!flag)
            {
                foreach (XYDataPoint dataPoint in (Collection <DataPoint>) this.Series.DataPoints)
                {
                    this.SkipToFillValueAnimation(dataPoint, "XValueInScaleUnits");
                }
            }
            if (this.Series.LabelVisibility == Visibility.Visible)
            {
                LabelVisibilityManager manager = this.LabelVisibilityManager;
                manager.InvalidateXIntervals();
                this.ChartArea.UpdateSession.ExecuteOnceAfterUpdating((Action)(() => manager.UpdateDataPointLabelVisibility()), (object)"LabelVisibilityManager_UpdateDataPointLabelVisibility", (string)null);
            }
            this.ChartArea.UpdateSession.EndUpdates();
        }
        public static Storyboard CreateAnimation(ChartArea seriesHost, string propertyName, object currentValue, object targetValue, Action <object, object> propertyUpdateAction, Dictionary <string, StoryboardInfo> storyboards, TimeSpan timeSpan, IEasingFunction easingFunction)
        {
            ObjectPool <PropertyAnimator, object> propertyAnimatorPool = (ObjectPool <PropertyAnimator, object>)seriesHost.SingletonRegistry.GetSingleton((object)"__PropertyAnimatorPool__", (Func <object>)(() => (object)new ObjectPool <PropertyAnimator, object>((Func <PropertyAnimator>)(() => new PropertyAnimator()), (Action <PropertyAnimator, object>)((obj, context) => obj.AnimatedValue = context), (Action <PropertyAnimator>)(obj => obj.UpdateAction = (Action <object, object>)null))), (Action <object>)(obj => ((ObjectPool <PropertyAnimator, object>)obj).ReleaseAll()));
            PropertyAnimator propertyAnimator = propertyAnimatorPool.Get(currentValue);

            propertyAnimator.UpdateAction = propertyUpdateAction;
            Action releaseAction = (Action)(() =>
            {
                propertyAnimatorPool.Release(propertyAnimator);
                propertyAnimatorPool.AdjustPoolSize();
            });

            return(DependencyPropertyAnimationHelper.CreateAnimation((DependencyObject)propertyAnimator, storyboards, PropertyAnimator.AnimatedValueProperty, "AnimatedValue", propertyName, currentValue, targetValue, timeSpan, easingFunction, releaseAction));
        }
예제 #7
0
파일: DataPoint.cs 프로젝트: sulerzh/chart
        private void UpdateActualDataPointOpacity()
        {
            double         opacity        = this.Opacity;
            double         num            = this.Series == null || !this.Series.IsDataPointAppearsUnselected(this) ? (this.Series == null ? this.Opacity : Math.Min(this.Series.Opacity, this.Opacity)) : Math.Min(this.Series.UnselectedDataPointOpacity, this.UnselectedOpacity);
            string         storyboardKey  = DependencyPropertyAnimationHelper.GetStoryboardKey("ActualOpacity");
            StoryboardInfo storyboardInfo = (StoryboardInfo)null;

            if (this.Storyboards.TryGetValue(storyboardKey, out storyboardInfo) && storyboardInfo.Storyboard.Children.Count > 0)
            {
                DoubleAnimation doubleAnimation = storyboardInfo.Storyboard.Children[0] as DoubleAnimation;
                if (doubleAnimation != null)
                {
                    doubleAnimation.To = new double?(num);
                    return;
                }
            }
            this.ActualOpacity = num;
        }
        public static void SetValueWithAnimation(this DataPoint dataPoint, DependencyProperty dp, string propertyName, double value)
        {
            double num = (double)dataPoint.GetValue(dp);

            if (num == value)
            {
                return;
            }
            Series series = dataPoint.Series;

            if (series == null || series.ChartArea == null || (DoubleHelper.IsNaN(num) || DoubleHelper.IsNaN(value)))
            {
                dataPoint.SetValue(dp, (object)value);
            }
            else
            {
                DependencyPropertyAnimationHelper.BeginAnimation(series.ChartArea, propertyName, (object)num, (object)value, (Action <object, object>)((current, next) => dataPoint.SetValue(dp, next)), dataPoint.Storyboards, series.ActualTransitionDuration, series.ActualTransitionEasingFunction);
            }
        }
예제 #9
0
 internal void UpdateAllDataPointsSize()
 {
     foreach (BubbleDataPoint bubbleDataPoint in (Collection <DataPoint>) this.DataPoints)
     {
         if (bubbleDataPoint.IsSizeValueUsed)
         {
             bubbleDataPoint.SizeValueInScaleUnitsWithoutAnimation = bubbleDataPoint.SizeValue == null ? 0.0 : ((BubbleSeriesPresenter)this.SeriesPresenter).ProjectSizeToPixels((DataPoint)bubbleDataPoint, ValueHelper.ToDouble(bubbleDataPoint.SizeValue));
             string         storyboardKey  = DependencyPropertyAnimationHelper.GetStoryboardKey("SizeValueInScaleUnits");
             StoryboardInfo storyboardInfo = (StoryboardInfo)null;
             if (bubbleDataPoint.Storyboards.TryGetValue(storyboardKey, out storyboardInfo) && storyboardInfo.Storyboard.Children.Count > 0)
             {
                 DoubleAnimation doubleAnimation = storyboardInfo.Storyboard.Children[0] as DoubleAnimation;
                 if (doubleAnimation != null)
                 {
                     doubleAnimation.To = new double?(bubbleDataPoint.SizeValueInScaleUnitsWithoutAnimation);
                     continue;
                 }
             }
             bubbleDataPoint.SizeValueInScaleUnits = bubbleDataPoint.SizeValueInScaleUnitsWithoutAnimation;
         }
     }
 }
예제 #10
0
        protected override bool StartDataPointShowingAnimation(DataPoint dataPoint)
        {
            StoryboardGroup storyboardGroup = new StoryboardGroup();

            if (!this.IsSeriesAnimationEnabled || (IAppearanceProvider)dataPoint == null)
            {
                return(false);
            }
            double actualOpacity = dataPoint.ActualOpacity;

            dataPoint.ActualOpacity = 0.0;
            storyboardGroup.Children.Add(DependencyPropertyAnimationHelper.CreateAnimation(this.ChartArea, "ActualOpacity", (object)0.0, (object)actualOpacity, (Action <object, object>)((value1, value2) => dataPoint.ActualOpacity = (double)value2), dataPoint.Storyboards, this.Series.ActualTransitionDuration, this.Series.ActualTransitionEasingFunction));
            storyboardGroup.Completed += (EventHandler)((source, args) =>
            {
                if (dataPoint.ViewState != DataPointViewState.Showing)
                {
                    return;
                }
                dataPoint.ViewState = DataPointViewState.Normal;
            });
            storyboardGroup.Begin();
            return(true);
        }
예제 #11
0
        private void ChangeDataPointSizeValue(BubbleDataPoint dataPoint, object newValue)
        {
            if (dataPoint == null)
            {
                return;
            }
            double valueInScaleUnits = dataPoint.SizeValueInScaleUnits;
            double num = this.ProjectSizeToPixels((DataPoint)dataPoint, ValueHelper.ToDouble(newValue));

            dataPoint.SizeValueInScaleUnitsWithoutAnimation = num;
            if (valueInScaleUnits == num)
            {
                return;
            }
            if (ValueHelper.CanGraph(valueInScaleUnits) && ValueHelper.CanGraph(num) && (this.IsSeriesAnimationEnabled && this.ChartArea != null))
            {
                DependencyPropertyAnimationHelper.BeginAnimation(this.ChartArea, "SizeValueInScaleUnits", (object)valueInScaleUnits, (object)num, (Action <object, object>)((value1, value2) => dataPoint.SizeValueInScaleUnits = (double)value2), dataPoint.Storyboards, this.Series.ActualTransitionDuration, this.Series.ActualTransitionEasingFunction);
            }
            else
            {
                this.SkipToFillValueAnimation((XYDataPoint)dataPoint, "SizeValueInScaleUnits");
                dataPoint.SizeValueInScaleUnits = num;
            }
        }