Exemplo n.º 1
0
        //public float Factor{ get; set;}

        public XGrid(ActivityState activityState)
        {
            var factor = activityState.GridFactor;
            var height = activityState.Height;
            var width  = activityState.Width;
            var hsteps = (int)(activityState.Steps / factor);
            var hstep  = (int)(activityState.Step * factor);
            var vsteps = (int)(activityState.VSteps / factor);
            var vstep  = (int)(activityState.VStep * factor);

            Func <int, XLine> vline = x => new XLine(x, 0, x, height);
            Func <int, XLine> hline = y => new XLine(0, y, width, y);

            //Calculate Grid
            Vlines = Enumerable
                     .Range(0, hsteps)
                     .Select(x => x * hstep)
                     .Select(vline)
                     .ToArray();
            //Log.Debug(TAG, "x: "  + vlines.Select(x=> x.XEnd).Select (x=>x.ToString ()).AsStringValues ());
            Hlines = Enumerable
                     .Range(0, vsteps)
                     .Select(x => x * vstep)
                     .Select(hline)
                     .ToArray();
            //Log.Debug(TAG, "x: "  + hlines.Select(x=> x.YEnd).Select (x=>x.ToString ()).AsStringValues ());
        }
Exemplo n.º 2
0
        public XPoints Arrange(ActivityState context, RPoint rawSignal)
        {
            var step = context.Step;

            var last = context.Steps + 1;

            var m = rawSignal.X % (last);

            var next = Points.Count + 1;

            var index = next == m + 1 ? m : next;

            var skip = rawSignal.X / last != 0;

            if (skip)
            {
                Points = Points
                         //.Skip (skip ? 1: 0)
                         .Select(x => new RPoint(x.X - 1, x.Y))
                         //.Take(last)
                         .Where(x => x.X >= 0)
                         .ToList();
            }

            Points.Add(new RPoint(skip? context.Steps: index, rawSignal.Y));

            //Scale
            return(Points.Select(x => new XPoint(x.X * step, x.Y)).ToArray());
        }
Exemplo n.º 3
0
        public static void DrawRotatedText(this Canvas canvas,
                                           ActivityState activityState,
                                           string text,
                                           float yPosition, Paint paint,
                                           float margin = 2, bool textOnTop = true)
        {
            var textGap       = margin + paint.TextSize;
            var invertedY     = activityState.Height - yPosition;
            var upDown        = invertedY >= activityState.Height - textGap ? -1 : 1;
            var textYPosition = (activityState.Height - yPosition + (textGap * upDown));
            var middle        = activityState.HalfWidth;

            canvas
            //.RotateY (activityState)
            .DrawText(text, middle, textYPosition, paint);
            canvas.RotateY(activityState);
        }
Exemplo n.º 4
0
 public static bool IsRelativeFirst(this ActivityState context, XPoint x)
 {
     return((((int)x.X) - 1) % context.Steps == 0);
 }
Exemplo n.º 5
0
 public static bool IsThereRoomFor(this ActivityState context, XPoint x)
 {
     return(!context.IsScreenFull(x));
 }
Exemplo n.º 6
0
 public static bool IsScreenFull(this ActivityState context, XPoint x)
 {
     return(x.X > context.Steps || context.Steps == 0);
 }
Exemplo n.º 7
0
 public Util(ActivityState activityState)
 {
     ActivityState = activityState;
 }
Exemplo n.º 8
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.Main);

            _surface = FindViewById <Xurface> (Resource.Id.surfaceView1);

            ActivityState = new ActivityState();

            ActivityState.Scale        = 10;
            ActivityState.SamplingRate = 200;
            ActivityState.SignalRate   = 200;


            Func <float> getSignal = () => {
                var halfHeight = ActivityState.Height / 2;
                var r          = _random.Next(-halfHeight, halfHeight);
                return(halfHeight + r);
            };

            var signalSource = Observable.Interval(TimeSpan.FromMilliseconds(ActivityState.SignalRate))
                               .Select(x => getSignal());

            var timer = Observable.Interval(TimeSpan.FromMilliseconds(ActivityState.SamplingRate))
                        .Select(x => (int)x);

            var signalSources = timer
                                // Setup , dimensions
                                .Do(x =>
                                    ActivityState.SetDimensions(_surface.Width, _surface.Height))
                                //Merge Signal and TimeLine
                                .Zip(signalSource, (x, y) => XPointFty.New(x, y));

            //IEnumerable<XPoint> points = new List<XPoint> ();

            _signalPreProcessor = PreProcessorFty.Create(_signalPreProcessor, PreProcessorType);

            subscribe = () => {
                //points = new List<XPoint>();
                if (_subscription != null)
                {
                    _subscription.Dispose();
                }
                _subscription = signalSources
                                .TakeWhile(x => ActivityState.State == States.Running)
                                //Arrange
                                .Select(rawSignal => {
                    return(_signalPreProcessor.Arrange(ActivityState, rawSignal).ToArray());
                })
                                .Subscribe(xpoints => {
                    var canvasActions = new List <Action <Canvas> >();

                    //Before Signal
                    canvasActions.AddRange(CanvasActions
                                           .Where(plugin => plugin.IsEnabled && plugin.Order == CanvasActionOrder.BeforeSignal)
                                           .Select(plugin => plugin.GetAction(xpoints, ActivityState)));

                    // Highlander principle : Only One
                    canvasActions.Add(SignalRenders.FirstOrDefault(x => x.IsEnabled).GetAction(xpoints, ActivityState));

                    //After Signal
                    canvasActions.AddRange(CanvasActions
                                           .Where(plugin => plugin.IsEnabled && plugin.Order == CanvasActionOrder.AfterSignal)
                                           .Select(plugin => plugin.GetAction(xpoints, ActivityState)));

                    using (var _canvas = new Canvas()){
                        _surface.Drawit(_canvas, canvasActions.ToArray());
                    }

                    RunOnUiThread(_surface.Invalidate);
                }, /*onCompleted*/ subscribe);
            };


            Action Unsubscribe = () => {
                if (_subscription != null)
                {
                    _subscription.Dispose();
                }
            };

            ActivityState
            .Changed
            .Where(p => p.Name == "State")
            .Subscribe(p => {
                var state = p.Value as States?;

                switch (state)
                {
                case States.Running:
                    subscribe();
                    break;

                case States.Stopped:
                    Unsubscribe();
                    break;
                }
            });
        }
Exemplo n.º 9
0
 XPoint Expand(ActivityState context, XPoint rawSignal)
 {
     return(XPointFty.New(rawSignal.X * context.Step, rawSignal.Y));
 }
Exemplo n.º 10
0
 public static Canvas RotateY(this Canvas canvas, ActivityState activityState)
 {
     canvas.Scale(1, -1, activityState.Width / 2, activityState.Height / 2);
     return(canvas);
 }
Exemplo n.º 11
0
 public XPoints Arrange(ActivityState context, RPoint rawSignal)
 {
     return(_arranger(context, Points, rawSignal));
 }