Пример #1
0
        protected override void OnRenderCore(DrawingContext dc, RenderState state)
        {
            if (DataSource == null)
            {
                return;
            }
            if (Marker == null)
            {
                return;
            }

            var transform = Plotter2D.Viewport.Transform;

            Rect bounds = Rect.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 = Rect.Union(bounds, point);
                    Marker.Render(dc, screenPoint);
                }
            }

            ContentBounds = bounds;
        }
Пример #2
0
        protected override void OnRenderCore(DrawingContext dc, RenderState state) {
            // base.OnRenderCore
            if (DataSource == null) return;
            if (Marker == null) return;
            var left = Viewport.Visible.Location.X;
            var right = Viewport.Visible.Location.X + Viewport.Visible.Size.Width;
            var top = Viewport.Visible.Location.Y;
            var bottom = Viewport.Visible.Location.Y + Viewport.Visible.Size.Height;
            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);                                       
                    if (point.X >= left && point.X <= right && point.Y >= top && point.Y <= bottom)
                    {
                        enumerator.ApplyMappings(Marker);
 
                        Point screenPoint = point.DataToScreen(transform);
 
                        bounds = DataRect.Union(bounds, point);
                        Marker.Render(dc, screenPoint);
                    }
                }
            }
            Viewport2D.SetContentBounds(this, bounds);
        }
Пример #3
0
        protected override void  OnRenderCore(DrawingContext dc, RenderState state)
        {
            if (DataSource == null)
            {
                return;
            }
            var transform = Plotter2D.Viewport.Transform;

            Rect bounds = Rect.Empty;

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

                    Point zero        = new Point(point.X, 0);
                    Point screenPoint = point.DataToScreen(transform);
                    Point screenZero  = zero.DataToScreen(transform);

                    double height = screenPoint.Y = screenZero.Y;
                    height = (height >= 0) ? height : -height;

                    dc.DrawRectangle(Fill, new Pen(Stroke, StrokeThickness),
                                     new Rect(screenPoint.X - BarWidth / 2, screenZero.Y, BarWidth, height));

                    bounds = Rect.Union(bounds, point);
                }
            }

            ContentBounds = bounds;
        }
Пример #4
0
        protected override void OnRenderCore(DrawingContext dc, RenderState state)
        {
            if (DataSource == null)
            {
                markers.Clear();
                canvas.Children.Clear();
                return;
            }

            if (Marker == null)
            {
                return;
            }

            var transform = Viewport.Transform;

            if (markers.Count == 0)
            {
                Rect bounds = Rect.Empty;
                using (IPointEnumerator enumerator = DataSource.GetEnumerator(GetContext()))
                {
                    Point point = new Point();
                    while (enumerator.MoveNext())
                    {
                        enumerator.GetCurrent(ref point);
                        enumerator.ApplyMappings(Marker);

                        Point screenPoint = point.DataToScreen(transform);
                        if (!screenPoint.IsFinite())
                        {
                            continue;
                        }

                        bounds = Rect.Union(bounds, point);
                        UIElement marker = Marker.CreateMarker();
                        Marker.SetPosition(marker, screenPoint);

                        // todo было раскомментировано. Сделать хранение маркеров и добавление их на плоттер.
                        canvas.Children.Add(marker);
                        markers.Add(marker);
                    }
                }
                ContentBounds = bounds;
            }
            else
            {
                int index = 0;
                using (IPointEnumerator enumerator = DataSource.GetEnumerator(GetContext()))
                {
                    Point point = new Point();
                    while (enumerator.MoveNext())
                    {
                        enumerator.GetCurrent(ref point);
                        Point screenPoint = point.DataToScreen(transform);
                        Marker.SetPosition(markers[index++], screenPoint);
                    }
                }
            }
        }
Пример #5
0
        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();
                    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]);
                        Point screenPoint = point.DataToScreen(transform);
                        Marker.SetPosition(canvas.Children[index], screenPoint);
                        index++;
                    }

                    while (index < canvas.Children.Count)
                    {
                        unused.Add(canvas.Children[index]);
                        canvas.Children.RemoveAt(index);
                    }
                }
            }
        }
Пример #6
0
        protected override void OnRenderCore(DrawingContext dc, RenderState state)
        {
            if (DataSource == null)
            {
                return;
            }
            if (Marker == null)
            {
                return;
            }
            if (Marker.markers == null)
            {
                return;
            }

            var transform = Plotter2D.Viewport.Transform;

            DataRect            bounds = DataRect.Empty;
            IEnumerable <Point> ps     = GetPoints();//实际值
            List <Point>        buf    = new List <Point>(ps);

            if (buf.Count < 1)
            {
                return;
            }
            double xstart = buf[0].X;

            foreach (MarkersPoint mp in Marker.markers)
            {
                try
                {
                    int   idx         = (int)((mp.x - xstart) / Step.len);
                    Point screenPoint = buf[idx].DataToScreen(transform);
                    bounds = DataRect.Union(bounds, buf[idx]);
                    Marker.Render(dc, screenPoint, mp);//画标记
                }
                catch (Exception ex)
                {
                    return;
                }
            }
            Viewport2D.SetContentBounds(this, bounds);
            return;

            using (IPointEnumerator enumerator = DataSource.GetEnumerator(GetContext()))
            {
                Point point = new Point();
                int   i     = 0;

                while (enumerator.MoveNext())
                {
                    enumerator.GetCurrent(ref point);
                    if (!Marker.markers.Contains(new MarkersPoint {
                        x = (float)point.X
                    }))
                    {
                        continue;
                    }
                    enumerator.ApplyMappings(Marker);
                    i++;
                    MarkersPoint mp = Marker.markers[i - 1];
                    //Point screenPoint = point.Transform(state.Visible, state.Output);
                    Point screenPoint = point.DataToScreen(transform);

                    bounds = DataRect.Union(bounds, point);
                    Marker.Render(dc, screenPoint, mp);                   //画标记
                }
            }

            Viewport2D.SetContentBounds(this, bounds);
        }