示例#1
0
        /// <summary>
        /// Apply animation for point chart
        /// </summary>
        /// <param name="pointGrid">Point chart grid</param>
        /// <param name="storyboard">Stroyboard</param>
        /// <param name="width">Width of the chart canvas</param>
        /// <param name="height">Height of the chart canvas</param>
        /// <returns>Storyboard</returns>
        private static Storyboard ApplyPointChartAnimation(DataSeries currentDataSeries, Panel pointGrid, Storyboard storyboard, Double width, Double height)
        {   
#if WPF
            if (storyboard != null && storyboard.GetValue(System.Windows.Media.Animation.Storyboard.TargetProperty) != null)
                storyboard.Stop();
#else
            if (storyboard != null)
                storyboard.Stop();
#endif

            TransformGroup group = new TransformGroup();
            ScaleTransform scaleTransform = new ScaleTransform() { ScaleX = 0, ScaleY = 0, CenterX = 0.5, CenterY = 0.5 };
            TranslateTransform translateTransform = new TranslateTransform() { X = 0, Y = 0 };
            group.Children.Add(scaleTransform);
            group.Children.Add(translateTransform);

            pointGrid.RenderTransform = group;

            Random rand = new Random((Int32)DateTime.Now.Ticks);
            double begin = rand.NextDouble();

            pointGrid.Measure(new Size(Double.MaxValue, Double.MaxValue));

            DoubleCollection times = Graphics.GenerateDoubleCollection(0, 0.5, 0.75, 1);
            DoubleCollection scaleValues = Graphics.GenerateDoubleCollection(0, 1, 0.5, 1);
            DoubleCollection translateXValues = Graphics.GenerateDoubleCollection(pointGrid.DesiredSize.Width / 2, 0, pointGrid.DesiredSize.Width / 4, 0);
            DoubleCollection translateYValues = Graphics.GenerateDoubleCollection(pointGrid.DesiredSize.Height / 2, 0, pointGrid.DesiredSize.Height / 4, 0);
            List<KeySpline> splines1 = AnimationHelper.GenerateKeySplineList(new Point(0, 0.5), new Point(0.5, 1), new Point(0, 0.5), new Point(0.5, 1), new Point(0, 0.5), new Point(0.5, 1), new Point(0, 0.5), new Point(0.5, 1));
            List<KeySpline> splines2 = AnimationHelper.GenerateKeySplineList(new Point(0, 0.5), new Point(0.5, 1), new Point(0, 0.5), new Point(0.5, 1), new Point(0, 0.5), new Point(0.5, 1), new Point(0, 0.5), new Point(0.5, 1));
            List<KeySpline> splines3 = AnimationHelper.GenerateKeySplineList(new Point(0, 0.5), new Point(0.5, 1), new Point(0, 0.5), new Point(0.5, 1), new Point(0, 0.5), new Point(0.5, 1), new Point(0, 0.5), new Point(0.5, 1));
            List<KeySpline> splines4 = AnimationHelper.GenerateKeySplineList(new Point(0, 0.5), new Point(0.5, 1), new Point(0, 0.5), new Point(0.5, 1), new Point(0, 0.5), new Point(0.5, 1), new Point(0, 0.5), new Point(0.5, 1));

            DoubleAnimationUsingKeyFrames xScaleAnimation = AnimationHelper.CreateDoubleAnimation(currentDataSeries, scaleTransform, "(ScaleTransform.ScaleX)", begin + 0.5, times, scaleValues, splines1);
            DoubleAnimationUsingKeyFrames yScaleAnimation = AnimationHelper.CreateDoubleAnimation(currentDataSeries, scaleTransform, "(ScaleTransform.ScaleY)", begin + 0.5, times, scaleValues, splines2);
            DoubleAnimationUsingKeyFrames xTranslateAnimation = AnimationHelper.CreateDoubleAnimation(currentDataSeries, translateTransform, "(TranslateTransform.X)", begin + 0.5, times, translateXValues, splines3);
            DoubleAnimationUsingKeyFrames yTranslateAnimation = AnimationHelper.CreateDoubleAnimation(currentDataSeries, translateTransform, "(TranslateTransform.Y)", begin + 0.5, times, translateYValues, splines4);

            storyboard.Children.Add(xScaleAnimation);
            storyboard.Children.Add(yScaleAnimation);
            storyboard.Children.Add(xTranslateAnimation);
            storyboard.Children.Add(yTranslateAnimation);

            return storyboard;
        }
示例#2
0
        /// <summary>
        /// Create exploding in animation for 3D Pie/Doughnut
        /// </summary>
        /// <param name="dataPoint">DataPoint</param>
        /// <param name="storyboard">Stroyboard used for animation</param>
        /// <param name="pathElements">Path elements reference</param>
        /// <param name="label">Label reference</param>
        /// <param name="labelLine">Label line reference</param>
        /// <param name="unExplodedPoints">Unexploded points</param>
        /// <param name="explodedPoints">Exploded points</param>
        /// <param name="xOffset">X offset</param>
        /// <param name="yOffset">Y offset</param>
        /// <returns>Storyboard</returns>
        private static Storyboard CreateExplodingIn3DAnimation(DataSeries currentDataSeries, DataPoint dataPoint, Storyboard storyboard, List<Shape> pathElements, Panel label, Path labelLine, PieDoughnut3DPoints unExplodedPoints, PieDoughnut3DPoints explodedPoints, Double xOffset, Double yOffset)
        {
            DoubleCollection values;
            DoubleCollection frames;
            List<KeySpline> splines;

#if WPF
            if (storyboard != null && storyboard.GetValue(System.Windows.Media.Animation.Storyboard.TargetProperty) != null)
                storyboard.Stop();
#else
            if (storyboard != null)
                storyboard.Stop();
#endif

            #region Animating Slice

            foreach (Shape path in pathElements)
            {
                if (path == null) continue;

                TranslateTransform translateTransform = path.RenderTransform as TranslateTransform;

                values = Graphics.GenerateDoubleCollection(xOffset, 0);
                frames = Graphics.GenerateDoubleCollection(0, 0.4);
                splines = AnimationHelper.GenerateKeySplineList
                    (
                        new Point(0, 0), new Point(1, 1),
                        new Point(0, 0), new Point(0, 1)
                    );

                DoubleAnimationUsingKeyFrames sliceXAnimation = CreateDoubleAnimation(currentDataSeries, dataPoint, translateTransform, "(TranslateTransform.X)", 0, frames, values, splines);

                values = Graphics.GenerateDoubleCollection(yOffset, 0);
                frames = Graphics.GenerateDoubleCollection(0, 0.4);
                splines = AnimationHelper.GenerateKeySplineList
                    (
                        new Point(0, 0), new Point(1, 1),
                        new Point(0, 0), new Point(0, 1)
                    );

                DoubleAnimationUsingKeyFrames sliceYAnimation = CreateDoubleAnimation(currentDataSeries, dataPoint, translateTransform, "(TranslateTransform.Y)", 0, frames, values, splines);

                storyboard.Children.Add(sliceXAnimation);
                storyboard.Children.Add(sliceYAnimation);
            }

            #endregion Animating Slice

            #region Animating Label

            if (dataPoint.LabelStyle == LabelStyles.Inside)
            {
                if (label != null)
                {
                    TranslateTransform translateTransform = label.RenderTransform as TranslateTransform;

                    values = Graphics.GenerateDoubleCollection(xOffset, 0);
                    frames = Graphics.GenerateDoubleCollection(0, 0.4);
                    splines = AnimationHelper.GenerateKeySplineList
                        (
                            new Point(0, 0), new Point(1, 1),
                            new Point(0, 0), new Point(0, 1)
                        );

                    DoubleAnimationUsingKeyFrames labelXAnimation1 = CreateDoubleAnimation(currentDataSeries, dataPoint, translateTransform, "(TranslateTransform.X)", 0, frames, values, splines);

                    values = Graphics.GenerateDoubleCollection(yOffset, 0);
                    frames = Graphics.GenerateDoubleCollection(0, 0.4);
                    splines = AnimationHelper.GenerateKeySplineList
                        (
                            new Point(0, 0), new Point(1, 1),
                            new Point(0, 0), new Point(0, 1)
                        );

                    DoubleAnimationUsingKeyFrames labelYAnimation2 = CreateDoubleAnimation(currentDataSeries, dataPoint, translateTransform, "(TranslateTransform.Y)", 0, frames, values, splines);

                    storyboard.Children.Add(labelXAnimation1);
                    storyboard.Children.Add(labelYAnimation2);
                }
            }
            else
            {
                values = Graphics.GenerateDoubleCollection(explodedPoints.LabelPosition.X, unExplodedPoints.LabelPosition.X);
                frames = Graphics.GenerateDoubleCollection(0, 0.4);
                splines = AnimationHelper.GenerateKeySplineList
                    (
                        new Point(0, 0), new Point(1, 1),
                        new Point(0, 0), new Point(0, 1)
                    );

                DoubleAnimationUsingKeyFrames labelXAnimation = CreateDoubleAnimation(currentDataSeries, dataPoint, label, "(Canvas.Left)", 0, frames, values, splines);
                storyboard.Children.Add(labelXAnimation);
            }

            #endregion Animating Label

            #region Animating Label Line
            if (labelLine != null)
            {
                TranslateTransform translateTransform = labelLine.RenderTransform as TranslateTransform;

                values = Graphics.GenerateDoubleCollection(xOffset, 0);
                frames = Graphics.GenerateDoubleCollection(0, 0.4);
                splines = AnimationHelper.GenerateKeySplineList
                    (
                        new Point(0, 0), new Point(1, 1),
                        new Point(0, 0), new Point(0, 1)
                    );

                DoubleAnimationUsingKeyFrames sliceXAnimation = CreateDoubleAnimation(currentDataSeries, dataPoint, translateTransform, "(TranslateTransform.X)", 0, frames, values, splines);

                values = Graphics.GenerateDoubleCollection(yOffset, 0);
                frames = Graphics.GenerateDoubleCollection(0, 0.4);
                splines = AnimationHelper.GenerateKeySplineList
                    (
                        new Point(0, 0), new Point(1, 1),
                        new Point(0, 0), new Point(0, 1)
                    );

                DoubleAnimationUsingKeyFrames sliceYAnimation = CreateDoubleAnimation(currentDataSeries, dataPoint, translateTransform, "(TranslateTransform.Y)", 0, frames, values, splines);

                storyboard.Children.Add(sliceXAnimation);
                storyboard.Children.Add(sliceYAnimation);


                PathFigure figure = (labelLine.Data as PathGeometry).Figures[0];
                PathSegmentCollection segments = figure.Segments;
                storyboard = CreateLabelLineInteractivityAnimation(currentDataSeries, dataPoint, storyboard, segments[0], explodedPoints.LabelLineMidPoint, unExplodedPoints.LabelLineMidPoint);
                storyboard = CreateLabelLineInteractivityAnimation(currentDataSeries, dataPoint, storyboard, segments[1], explodedPoints.LabelLineEndPoint, unExplodedPoints.LabelLineEndPoint);
            }
            #endregion Animating Label Line

            return storyboard;
        }
示例#3
0
        internal static Storyboard CreateUnExplodingAnimation(DataSeries dataSeries, DataPoint dataPoint, Storyboard storyboard, Panel visual, Double targetValue)
        {
#if WPF
            if (storyboard != null && storyboard.GetValue(System.Windows.Media.Animation.Storyboard.TargetProperty) != null)
                storyboard.Stop();
#else
            if (storyboard != null)
                storyboard.Stop();
#endif

            Double fromValue = (Double)visual.GetValue(Canvas.TopProperty);
            DoubleCollection values = Graphics.GenerateDoubleCollection(fromValue, targetValue);
            DoubleCollection frames = Graphics.GenerateDoubleCollection(0, .2);
            List<KeySpline> splines = AnimationHelper.GenerateKeySplineList(frames.Count);
            DoubleAnimationUsingKeyFrames topAnimation = PieChart.CreateDoubleAnimation(dataSeries, dataPoint, visual, "(Canvas.Top)", 0, frames, values, splines);
            storyboard.Children.Add(topAnimation);

            return storyboard;
        }