Example #1
0
        public void DrawStock(TimeSeries timeSeriesData, TimeSeries ts, double start, double end)
        {
            Clear();

            int lx = 230;
            int ly = 120;
            var rect = new Rect((ActualWidth - lx)/2, (ActualHeight - ly)/2 - 50, lx, ly);
            _xyAxis = new XyAxis(rect);

            double stockMin = ts.Values.Min();
            double stockMax = ts.Values.Max();

            var ampDelta = (decimal) (stockMax - stockMin);
            int timeDelta = ts.Values.Count;
            _axisAnnotations[XyAxisLabelPosition.X_Center] = timeDelta.ToString();

            IList<Stroq> ampDeltaStroqs = _letters.StringToStroqs(ampDelta + "M", 10);
            IList<Stroq> timeDeltaStroqs = _letters.StringToStroqs(timeDelta.ToString(), 10);

            Point ampDeltaCoords = _xyAxis.GetLabelCoords(XyAxisLabelPosition.Y_Center);
            ampDeltaCoords.X -= 20;
            Point timeDeltaCoords = _xyAxis.GetLabelCoords(XyAxisLabelPosition.X_Center);
            timeDeltaCoords.X += 15;
            timeDeltaCoords.Y += 10;


            _stroqs.Add(_xyAxis.Stroq);
            ts = ts.GetNormalized();
            ts.Resample(80);
            Stroq s = ts.ToStroq(rect);
            _queryStroqs.Add(s);
            _stroqs.Add(s);

            foreach (Stroq stroq in timeDeltaStroqs)
            {
                stroq.Translate(timeDeltaCoords);
                _stroqs.Add(stroq);
            }

            Redraw();
        }
Example #2
0
        public async void Consume(Stroq stroq)
        {
            stroq.ClipTo(new Rect(0, 0, ActualWidth, ActualHeight));
            _scribbleGesture.StroqsToCheck = _stroqs.ToList();
            IList<IGesture> recognizedGestures = _gesturizer.Recognize(stroq.Clone());

            foreach (IGesture recognizedGesture in recognizedGestures.ToList())
            {
                if (recognizedGesture is ScribbleGesture)
                {
                    foreach (Stroq hitStroq in _scribbleGesture.HitStroqs)
                    {
                        _stroqs.Remove(hitStroq);
                        _textStroqs.Remove(hitStroq);

                        if (_textStroqs.Count == 0)
                        {
                            _queryStrings.Clear();
                            OnTextChange(this);
                            _axisAnnotations.Clear();
                        }

                        foreach (Stroq queryStroq in _queryStroqs.ToList())
                        {
                            if (hitStroq == queryStroq)
                                _queryStroqs.Remove(queryStroq);
                        }

                        if (_xyAxis != null && hitStroq == _xyAxis.Stroq)
                        {
                            _xyAxis = null;
                            _axisAnnotations.Clear();
                            OnAxisChange(this);
                        }
                    }
                    continue;
                }

                if (recognizedGesture is XyAxisGesture && _xyAxis != null)
                {
                    recognizedGestures.Remove(recognizedGesture);
                }

                if (recognizedGesture is XyAxisGesture && _xyAxis == null)
                {
                    var axisGesture = (XyAxisGesture) recognizedGesture;
                    _xyAxis = new XyAxis(axisGesture.BoundingRect);
                    _stroqs.Add(_xyAxis.Stroq);
                    OnAxisChange(this);

                    foreach (Rect hotspot in _xyAxis._hotspots.Values)
                    {
                        var r = new Rectangle();

                        r.Width = hotspot.Width;
                        r.Height = hotspot.Height;
                        r.Fill = new SolidColorBrush(Colors.Red);
                        Children.Add(r);

                        SetLeft(r, hotspot.X);
                        SetTop(r, hotspot.Y);
                    }
                }
            }

            if (recognizedGestures.Count == 0)
            {
                if (_xyAxis != null)
                {
                    Rect stroqBB = stroq.BoundingRect.Clone();
                    stroqBB.Intersect(_xyAxis.Stroq.BoundingRect);
                    if (!stroqBB.IsEmpty && stroqBB.Area()/stroq.BoundingRect.Area() > 0.5)
                    {
                        _queryStroqs.Add(stroq);
                        OnQueryChange(this);
                    }
                }

                _stroqs.Add(stroq);
                _textStroqs.Add(stroq);
            }

            Redraw();

            IList<InkRecognitionResult> result = await _textRecognizer.Recognize(_textStroqs);
            _queryStrings.Clear();
            foreach (InkRecognitionResult inkRecognitionResult in result)
            {
                IReadOnlyList<string> candidates = inkRecognitionResult.GetTextCandidates();

                if (_xyAxis != null)
                {
                    XyAxisLabelPosition axisAnnotationPosition =
                        _xyAxis.GetLabelPosition(inkRecognitionResult.BoundingRect);

                    if (axisAnnotationPosition != XyAxisLabelPosition.None)
                    {
                        _axisAnnotations[axisAnnotationPosition] = ValidateText(candidates);
                        OnAxisChange(this);
                    }
                }
                else
                {
                    _queryStrings.Add(candidates[0].ToLower());

                    Rect bbbb = stroq.BoundingRect;
                    string str = "";
                    foreach (Point p in stroq.Points)
                    {
                        double x = (p.X - bbbb.X)/bbbb.Width;
                        double y = (p.Y - bbbb.Y)/bbbb.Height;
                        str += (x + ":" + y + ",");
                    }
                }
            }

            if (_queryStrings.Count > 0)
                OnTextChange(this);
        }
Example #3
0
 public void Clear()
 {
     Children.Clear();
     _queryStrings.Clear();
     _queryStroqs.Clear();
     _stroqs.Clear();
     _textStroqs.Clear();
     _axisAnnotations.Clear();
     _xyAxis = null;
 }