Ejemplo n.º 1
0
        protected override void UpdateCore()
        {
            if (Viewport == null || Viewport.Output == new Rect(0, 0, 0, 0) || DataSource == null)
            {
                return;
            }

            foreach (var m in Markers)
            {
                Plotter.MainCanvas.Children.Remove(m);
            }


            if (Markers.Count == 0)
            {
                return;
            }

            var transform = GetTransform();

            for (int i = 0; i < Markers.Count; i++)
            {
                var    offset = GetXValue(this);
                double X      = LineGraphWithPoints.GetXValue(Markers[i] as DependencyObject) + GetXValue(this);
                double Y      = LineGraphWithPoints.GetYValue(Markers[i] as DependencyObject);

                var p = transform.DataToScreen(new Point(X, Y));

                //Update the points
                double canvasy = p.Y - Markers[i].Height / 2;
                double canvasx = p.X - Markers[i].Width / 2;
                Canvas.SetTop(Markers[i], canvasy);
                Canvas.SetLeft(Markers[i], canvasx);

                if (canvasy < Plotter.MainCanvas.ActualHeight & canvasy > 0 & canvasx < Plotter.MainCanvas.ActualWidth & canvasx > 0)
                {
                    Plotter.MainCanvas.Children.Add(Markers[i]);
                }
            }
            ContentBounds = BoundsHelper.GetViewportBounds(GetPoints(), transform.DataTransform);
            base.UpdateCore();
        }
Ejemplo n.º 2
0
        protected override void UpdateItems()
        {
            if (Plotter != null)
            {
                foreach (var m in Markers)
                {
                    Plotter.MainCanvas.Children.Remove(m);
                }
                Markers.Clear();

                if (ItemsSource != null && ItemsSource.GetEnumerator().MoveNext())
                {
                    foreach (var p in ItemsSource)
                    {
                        var visualItem = this.ItemTemplate.LoadContent() as FrameworkElement;
                        visualItem.DataContext = p;
                        //Set the binding again to make it attach immediately
                        visualItem.SetBinding(LineGraphWithPoints.XValueProperty, visualItem.GetBindingExpression(LineGraphWithPoints.XValueProperty).ParentBinding);
                        visualItem.SetBinding(LineGraphWithPoints.YValueProperty, visualItem.GetBindingExpression(LineGraphWithPoints.YValueProperty).ParentBinding);

                        Markers.Add(visualItem);
                    }

                    var es = new Microsoft.Research.DynamicDataDisplay.DataSources.EnumerableDataSource <DependencyObject>(Markers);
                    es.SetXMapping(p => LineGraphWithPoints.GetXValue(p as DependencyObject) + GetXValue(this));
                    es.SetYMapping(p => LineGraphWithPoints.GetYValue(p as DependencyObject));
                    DataSource = es;


                    if (Viewport != null & Markers.Count > 1)
                    {
                        ((ChartPlotter)Viewport.Plotter).FitToView();
                    }
                }
            }
        }