protected override void OnRenderCore(DrawingContext dc, RenderState state)
        {
            if (DataSource == null)
            {
                return;
            }
            if (Marker == null)
            {
                return;
            }

            var transform = Plotter2D.Viewport.Transform;

            DataRect bounds = DataRect.Empty;

            using (IPointEnumerator enumerator = DataSource.GetEnumerator(GetContext()))
            {
                Point point = new Point();
                while (enumerator.MoveNext())
                {
                    enumerator.GetCurrent(ref point);
                    enumerator.ApplyMappings(Marker);

                    //Point screenPoint = point.Transform(state.Visible, state.Output);
                    Point screenPoint = point.DataToScreen(transform);

                    bounds = DataRect.Union(bounds, point);
                    Marker.Render(dc, screenPoint);
                }
            }

            Viewport2D.SetContentBounds(this, bounds);
        }
Ejemplo n.º 2
0
 private void UpdateBounds(IPointDataSource dataSource)
 {
     if (Plotter2D != null)
     {
         var      transform = GetTransform();
         DataRect bounds    = BoundsHelper.GetViewportBounds(dataSource.GetPoints(), transform.DataTransform);
         Viewport2D.SetContentBounds(this, bounds);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LineGraph"/> class.
        /// </summary>
        public LineGraph()
        {
            Legend.SetVisibleInLegend(this, true);
            ManualTranslate = true;

            filters.CollectionChanged += Filters_CollectionChanged;
            IsEnabledChanged          += (s, e) =>
            {
                if (!IsEnabled)
                {
                    filteredPoints = null;
                    Viewport2D.SetContentBounds(this, DataRect.Empty);
                }
            };
        }
        protected override void OnRenderCore(DrawingContext dc, RenderState state)
        {
            if (Marker == null)
            {
                return;
            }

            if (DataSource == null)             // No data is specified
            {
                if (canvas != null)
                {
                    foreach (UIElement child in canvas.Children)
                    {
                        unused.Add(child);
                    }
                    canvas.Children.Clear();
                }
            }
            else             // There is some data
            {
                int index     = 0;
                var transform = GetTransform();
                using (IPointEnumerator enumerator = DataSource.GetEnumerator(GetContext()))
                {
                    Point point = new Point();

                    DataRect bounds = DataRect.Empty;

                    while (enumerator.MoveNext())
                    {
                        enumerator.GetCurrent(ref point);
                        enumerator.ApplyMappings(Marker);

                        if (index >= canvas.Children.Count)
                        {
                            UIElement newMarker;
                            if (unused.Count > 0)
                            {
                                newMarker = unused[unused.Count - 1];
                                unused.RemoveAt(unused.Count - 1);
                            }
                            else
                            {
                                newMarker = Marker.CreateMarker();
                            }
                            canvas.Children.Add(newMarker);
                        }

                        Marker.SetMarkerProperties(canvas.Children[index]);
                        bounds.Union(point);
                        Point screenPoint = point.DataToScreen(transform);
                        Marker.SetPosition(canvas.Children[index], screenPoint);
                        index++;
                    }

                    Viewport2D.SetContentBounds(this, bounds);

                    while (index < canvas.Children.Count)
                    {
                        unused.Add(canvas.Children[index]);
                        canvas.Children.RemoveAt(index);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        protected override void UpdateCore()
        {
            if (DataSource == null)
            {
                return;
            }
            if (Plotter == null)
            {
                return;
            }
            if (!IsEnabled)
            {
                return;
            }

            Rect output    = Viewport.Output;
            var  transform = GetTransform();

            if (filteredPoints == null || !(transform.DataTransform is IdentityTransform))
            {
                IEnumerable <Point> points = GetPoints();

                var bounds = BoundsHelper.GetViewportBounds(points, transform.DataTransform);
                Viewport2D.SetContentBounds(this, bounds);

                // getting new value of transform as it could change after calculating and setting content bounds.
                transform = GetTransform();
                List <Point> transformedPoints = transform.DataToScreenAsList(points);

                // Analysis and filtering of unnecessary points
                filteredPoints = new FakePointList(FilterPoints(transformedPoints),
                                                   output.Left, output.Right);

                if (ProvideVisiblePoints)
                {
                    List <Point> viewportPointsList = null;
                    viewportPointsList = new List <Point>(transformedPoints.Count);
                    if (transform.DataTransform is IdentityTransform)
                    {
                        viewportPointsList.AddRange(points);
                    }
                    else
                    {
                        var viewportPoints = points.DataToViewport(transform.DataTransform);
                        viewportPointsList.AddRange(viewportPoints);
                    }
                    SetVisiblePoints(this, new ReadOnlyCollection <Point>(viewportPointsList));
                }
                Offset = new Vector();
            }
            else
            {
                double left  = output.Left;
                double right = output.Right;
                double shift = Offset.X;
                left  -= shift;
                right -= shift;

                filteredPoints.SetXBorders(left, right);
            }
        }