Ejemplo n.º 1
0
            public override CAAnimation AnimationForSeries(TKChart chart, TKChartSeries series, TKChartSeriesRenderState state, CGRect rect)
            {
                double             duration   = 0.5;
                List <CAAnimation> animations = new List <CAAnimation> ();

                for (int i = 0; i < (int)state.Points.Count; i++)
                {
                    string              keyPath = string.Format("seriesRenderStates.{0}.points.{1}.y", series.Index, i);
                    TKChartVisualPoint  point   = (TKChartVisualPoint)state.Points.ObjectAtIndex((uint)i);
                    double              oldY    = rect.Height;
                    double              half    = oldY + (point.Y - oldY) / 2.0;
                    CAKeyFrameAnimation a       = (CAKeyFrameAnimation)CAKeyFrameAnimation.GetFromKeyPath(keyPath);
                    a.KeyTimes       = new NSNumber[] { new NSNumber(0), new NSNumber(0), new NSNumber(1) };
                    a.Values         = new NSObject[] { new NSNumber(oldY), new NSNumber(half), new NSNumber(point.Y) };
                    a.Duration       = duration;
                    a.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseOut);
                    animations.Add(a);
                }

                CAAnimationGroup group = new CAAnimationGroup();

                group.Duration   = duration;
                group.Animations = animations.ToArray();

                return(group);
            }
Ejemplo n.º 2
0
        public void applyGravity(object sender, EventArgs e)
        {
            animator = new UIDynamicAnimator(chart.PlotView);

            TKChartVisualPoint[] points = chart.VisualPointsForSeries(chart.Series [0]);

            for (int i = 0; i < points.Length; i++)
            {
                TKChartVisualPoint point  = points [i];
                CGPoint            center = originalValues [i];
                if (point.Animator != null)
                {
                    point.Animator.RemoveAllBehaviors();
                    point.Animator = null;
                }
                point.Center = center;
            }

            UICollisionBehavior collision = new UICollisionBehavior(points);

            collision.TranslatesReferenceBoundsIntoBoundary = true;

            UIGravityBehavior gravity = new UIGravityBehavior(points);

            gravity.GravityDirection = new CGVector(0.0f, 2.0f);

            UIDynamicItemBehavior dynamic = new UIDynamicItemBehavior(points);

            dynamic.Elasticity = 0.5f;

            animator.AddBehavior(dynamic);
            animator.AddBehavior(gravity);
            animator.AddBehavior(collision);
        }
Ejemplo n.º 3
0
        public override void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);

            TKChartVisualPoint[] points = chart.VisualPointsForSeries(chart.Series [0]);
            originalValues = new List <CGPoint> ();
            foreach (TKChartVisualPoint p in points)
            {
                originalValues.Add(p.CGPoint);
            }
            TKChartVisualPoint point = points[4];

            UISnapBehavior snap = new UISnapBehavior(point, point.Center);

            snap.Damping = 0.2f;

            UIPushBehavior push = new UIPushBehavior(new IUIDynamicItem[] { point }, UIPushBehaviorMode.Instantaneous);

            push.PushDirection = new CGVector(0.0f, -1.0f);
            push.Magnitude     = 0.003f;

            UIDynamicAnimator animator = new UIDynamicAnimator();

            animator.AddBehavior(snap);
            animator.AddBehavior(push);

            point.Animator = animator;
        }
Ejemplo n.º 4
0
            public override CAAnimation AnimationForSeries(TKChart chart, TKChartSeries series, TKChartSeriesRenderState state, CGRect rect)
            {
                double             duration   = 0;
                List <CAAnimation> animations = new List <CAAnimation> ();

                for (int i = 0; i < (int)state.Points.Count; i++)
                {
                    TKChartVisualPoint point = (TKChartVisualPoint)state.Points.ObjectAtIndex((uint)i);

                    if (Grow)
                    {
                        string keyPath = string.Format("seriesRenderStates.{0}.points.{1}.x", series.Index, i);

                        CABasicAnimation animation = (CABasicAnimation)CABasicAnimation.FromKeyPath(keyPath);
                        animation.Duration       = 0.1 * (i + 0.2);
                        animation.From           = new NSNumber(0);
                        animation.To             = new NSNumber(point.X);
                        animation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseOut);
                        animations.Add(animation);

                        duration = animation.Duration;
                    }
                    else
                    {
                        string keyPath = string.Format("seriesRenderStates.{0}.points.{1}.y", series.Index, i);
                        nfloat oldY    = rect.Height;

                        if (i > 0)
                        {
                            CAKeyFrameAnimation animation = (CAKeyFrameAnimation)CAKeyFrameAnimation.GetFromKeyPath(keyPath);
                            animation.Duration       = 0.1 * (i + 1);
                            animation.Values         = new NSNumber[] { new NSNumber(oldY), new NSNumber(oldY), new NSNumber(point.Y) };
                            animation.KeyTimes       = new NSNumber[] { new NSNumber(0), new NSNumber(i / (i + 1.0)), new NSNumber(1) };
                            animation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseOut);
                            animations.Add(animation);

                            duration = animation.Duration;
                        }
                        else
                        {
                            CABasicAnimation animation = (CABasicAnimation)CABasicAnimation.FromKeyPath(keyPath);
                            animation.From     = new NSNumber(oldY);
                            animation.To       = new NSNumber(point.Y);
                            animation.Duration = 0.1f;
                            animations.Add(animation);
                        }
                    }
                }

                CAAnimationGroup group = new CAAnimationGroup();

                group.Duration   = duration;
                group.Animations = animations.ToArray();

                return(group);
            }
Ejemplo n.º 5
0
        public void applyGravity()
        {
            if (firstTime)
            {
                firstTime = false;

                TKChartVisualPoint[] points1 = chart.VisualPointsForSeries(chart.Series [0]);
                originalValues = new List <CGPoint> ();
                foreach (TKChartVisualPoint p in points1)
                {
                    originalValues.Add(p.CGPoint);
                }
                TKChartVisualPoint point1 = points1 [4];
                originalLocation = point1.Center;
            }
            // >> chart-anim-gravity-cs
            animator = new UIDynamicAnimator(chart.PlotView);
            TKChartVisualPoint[] points = chart.VisualPointsForSeries(chart.Series [0]);
            TKChartVisualPoint   point  = points [4];

            for (int i = 0; i < originalValues.Count; i++)
            {
                TKChartVisualPoint pt = points [i];
                if (pt.Animator != null)
                {
                    pt.Animator.RemoveAllBehaviors();
                    pt.Animator = null;
                }
                pt.Center = ((CGPoint)originalValues[i]);
            }

            point.Center = new CGPoint(originalLocation.X, 0);

            UICollisionBehavior collision = new UICollisionBehavior(points);

            collision.TranslatesReferenceBoundsIntoBoundary = true;

            UIGravityBehavior gravity = new UIGravityBehavior(points);

            gravity.GravityDirection = new CGVector(0.0f, 2.0f);

            UIDynamicItemBehavior dynamic = new UIDynamicItemBehavior(points);

            dynamic.Elasticity = 0.5f;

            animator.AddBehavior(dynamic);
            animator.AddBehavior(gravity);
            animator.AddBehavior(collision);
            // << chart-anim-gravity-cs
        }
Ejemplo n.º 6
0
        public override void TouchesBegan(NSSet touches, UIEvent evt)
        {
            base.TouchesBegan(touches, evt);

            UITouch touch      = (UITouch)touches.AnyObject;
            CGPoint touchPoint = touch.LocationInView(chart.PlotView);
            TKChartSelectionInfo hitTestInfo = chart.HitTestForPoint(touchPoint);

            if (hitTestInfo != null)
            {
                selectedPoint    = chart.VisualPointForSeries(hitTestInfo.Series, hitTestInfo.DataPointIndex);
                originalLocation = touchPoint;
                if (selectedPoint != null)
                {
                    selectedPoint.Animator = null;
                    originalPosition       = selectedPoint.Center;
                }
            }
        }
Ejemplo n.º 7
0
        public override void DrawInContext(CGContext context, CGRect bounds, TKChartVisualPoint visualPoint)
        {
            UIGraphics.PushContext (context);
            TKFill fill = this.Style.Fill;
            TKStroke stroke = new TKStroke (UIColor.Black);
            TKBalloonShape shape = new TKBalloonShape (TKBalloonShapeArrowPosition.Bottom, bounds.Size);
            shape.DrawInContext (context, new CGPoint (bounds.GetMidX (), bounds.GetMidY ()), new TKDrawing[]{ fill, stroke });
            CGRect textRect = new CGRect (bounds.Left, bounds.Top - this.Style.Insets.Top, bounds.Size.Width, bounds.Size.Height + this.Style.Insets.Bottom);

            NSMutableParagraphStyle paragraphStyle = new NSMutableParagraphStyle ();
            paragraphStyle.Alignment = this.Style.TextAlignment;
            NSDictionary attributes = new NSDictionary (UIStringAttributeKey.Font, UIFont.SystemFontOfSize (18),
                                          UIStringAttributeKey.ForegroundColor, this.Style.TextColor,
                                          UIStringAttributeKey.ParagraphStyle, paragraphStyle);

            NSString text = new NSString (this.Text);
            text.WeakDrawString (textRect, NSStringDrawingOptions.TruncatesLastVisibleLine | NSStringDrawingOptions.UsesLineFragmentOrigin, attributes, null);
            UIGraphics.PopContext ();
        }
Ejemplo n.º 8
0
        public override void DrawInContext(CGContext context, CGRect bounds, TKChartVisualPoint visualPoint, UIColor color)
        {
            UIGraphics.PushContext(context);
            TKFill         fill   = this.Style.Fill;
            TKStroke       stroke = new TKStroke(UIColor.Black);
            TKBalloonShape shape  = new TKBalloonShape(TKBalloonShapeArrowPosition.Bottom, bounds.Size);

            shape.DrawInContext(context, new CGPoint(bounds.GetMidX(), bounds.GetMidY()), new TKDrawing[] { fill, stroke });
            CGRect textRect = new CGRect(bounds.Left, bounds.Top - this.Style.Insets.Top, bounds.Size.Width, bounds.Size.Height + this.Style.Insets.Bottom);

            NSMutableParagraphStyle paragraphStyle = new NSMutableParagraphStyle();

            paragraphStyle.Alignment = this.Style.TextAlignment;
            NSDictionary attributes = new NSDictionary(UIStringAttributeKey.Font, UIFont.SystemFontOfSize(16),
                                                       UIStringAttributeKey.ForegroundColor, this.Style.TextColor,
                                                       UIStringAttributeKey.ParagraphStyle, paragraphStyle);

            NSString text = new NSString(this.Text);

            text.WeakDrawString(textRect, NSStringDrawingOptions.TruncatesLastVisibleLine | NSStringDrawingOptions.UsesLineFragmentOrigin, attributes, null);
            UIGraphics.PopContext();
        }
Ejemplo n.º 9
0
		public override void TouchesBegan (NSSet touches, UIEvent evt)
		{
			base.TouchesBegan (touches, evt);

			UITouch touch = (UITouch)touches.AnyObject;
			CGPoint touchPoint = touch.LocationInView(chart.PlotView);
			TKChartSelectionInfo hitTestInfo = chart.HitTestForPoint(touchPoint);
			if (hitTestInfo != null) {
				selectedPoint = chart.VisualPointForSeries (hitTestInfo.Series, hitTestInfo.DataPointIndex);
				originalLocation = touchPoint;
				if (selectedPoint != null) {
					selectedPoint.Animator = null;
					originalPosition = selectedPoint.Center;
				}
			}
		}