public override Rect Apply(Rect oldDataRect, Rect newDataRect, Viewport2D viewport)
        {
            Rect output = viewport.Output;

            if (output.Width == 0 || output.Height == 0)
            {
                return(newDataRect);
            }

            double screenRatio   = output.Width / output.Height;
            double viewportRatio = newDataRect.Width / newDataRect.Height;
            double ratio         = screenRatio / viewportRatio;
            double width         = proportionRatio * newDataRect.Width * ratio;
            double height        = newDataRect.Height;

            if (width < newDataRect.Width)
            {
                height = newDataRect.Height / proportionRatio / ratio;
                width  = newDataRect.Width;
            }

            Point center = newDataRect.GetCenter();
            Rect  res    = RectExtensions.FromCenterSize(center, width, height);

            return(res);
        }
        private void UpdateLittleVisible(Point pos)
        {
            Size littleSize = new Size(Plotter2D.Viewport.Visible.Width / zoomCoeff * ActualWidth / Plotter2D.Viewport.Output.Width,
                                       Plotter2D.Viewport.Visible.Height / zoomCoeff * ActualHeight / Plotter2D.Viewport.Output.Height);
            Rect littleVisible = RectExtensions.FromCenterSize(pos.ScreenToViewport(Plotter2D.Viewport.Transform), littleSize);

            littlePlotter.Viewport.Visible = littleVisible;
        }
Beispiel #3
0
        void pt_PositionChanged(object sender, PositionChangedEventArgs e)
        {
            DraggablePoint pt = (DraggablePoint)sender;

            Ellipse ellipse = (Ellipse)pt.Tag;
            Rect    bounds  = RectExtensions.FromCenterSize(e.Position, xSize, ySize);

            //ViewportRectPanel.SetPoint1(ellipse, bounds.TopLeft);
            //ViewportRectPanel.SetPoint2(ellipse, bounds.BottomRight);
        }
Beispiel #4
0
        protected Rect EnlargeRect(Rect rect)
        {
            Size newSize = rect.Size;

            newSize.Width  += 1;
            newSize.Height += 1;
            Rect result = RectExtensions.FromCenterSize(rect.GetCenter(), newSize);

            return(result);

            //double coeff = 1 + 1.0 / tileWidth;
            //return EnlargeRect(rect, coeff);
        }
        public override Rect Apply(Rect oldDataRect, Rect newDataRect, Viewport2D viewport)
        {
            double ratio = newDataRect.Width / newDataRect.Height;
            double coeff = Math.Sqrt(ratio);

            double newWidth  = newDataRect.Width / coeff;
            double newHeight = newDataRect.Height * coeff;

            Point center = newDataRect.GetCenter();
            Rect  res    = RectExtensions.FromCenterSize(center, newWidth, newHeight);

            return(res);
        }
Beispiel #6
0
        public override void Render(DrawingContext dc, Point screenPoint)
        {
            FormattedText textToDraw = new FormattedText(Text, Thread.CurrentThread.CurrentCulture,
                                                         FlowDirection.LeftToRight, new Typeface("Arial"), 12, Brushes.Black);

            double width  = textToDraw.Width;
            double height = textToDraw.Height;

            const double verticalShift = -20;             // px

            Rect bounds = RectExtensions.FromCenterSize(new Point(screenPoint.X, screenPoint.Y + verticalShift - height / 2),
                                                        new Size(width, height));

            Point loc = bounds.Location;

            bounds = CoordinateUtilities.RectZoom(bounds, 1.05, 1.15);

            dc.DrawLine(new Pen(Brushes.Black, 1), Point.Add(screenPoint, new Vector(0, verticalShift)), screenPoint);
            dc.DrawRectangle(Brushes.White, new Pen(Brushes.Black, 1), bounds);
            dc.DrawText(textToDraw, loc);
        }
Beispiel #7
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            var dc = drawingContext;

            Rect bounds = new Rect(RenderSize);

            dc.DrawRectangle(Brushes.Orange.MakeTransparent(0.3), null, bounds);

            if (points == null)
            {
                return;
            }

            for (int i = 0; i < points.Length; i++)
            {
                Point viewportPt  = points[i];
                var   screenPoint = new Point(viewportPt.X * bounds.Width, viewportPt.Y * bounds.Height);

                dc.DrawRectangle(Brushes.Blue, null, RectExtensions.FromCenterSize(screenPoint, new Size(2, 2)));
            }
        }
Beispiel #8
0
        protected override Size ArrangeOverride(Size finalSize)
        {
            using (new DebugDisposableTimer("ViewportPanel arrange"))
            {
                if (plotter == null)
                {
                    return(finalSize);
                }

                var transform = plotter.Viewport.Transform;

                foreach (UIElement element in base.InternalChildren)
                {
                    if (element == null)
                    {
                        continue;
                    }

                    double x = GetDataX(element);
                    if (Double.IsNaN(x))
                    {
                        x = 0;
                    }
                    double y = GetDataY(element);
                    if (Double.IsNaN(y))
                    {
                        y = 0;
                    }

                    Point screenPos = new Point(x, y).DataToScreen(transform);
                    Rect  bounds    = RectExtensions.FromCenterSize(screenPos, element.DesiredSize);

                    element.Arrange(bounds);
                }

                return(finalSize);
            }
        }
Beispiel #9
0
        private void RenderLabels(DrawingContext dc, IsolineCollection collection)
        {
            if (Plotter2D == null)
            {
                return;
            }
            if (collection == null)
            {
                return;
            }
            if (!DrawLabels)
            {
                return;
            }

            var viewportBounds = ViewportPanel.GetViewportBounds(this);

            if (viewportBounds.IsEmpty)
            {
                return;
            }

            var strokeThickness = StrokeThickness;
            var visible         = Plotter2D.Visible;
            var output          = Plotter2D.Viewport.Output;

            var transform         = Plotter2D.Transform.WithRects(viewportBounds, new Rect(RenderSize));
            var labelStringFormat = LabelStringFormat;

            // drawing constants
            var labelRectangleFill = Brushes.White;

            var biggerViewport = viewportBounds.ZoomOutFromCenter(1.1);

            // getting and filtering annotations to draw only visible ones
            Annotater.WayBeforeText = Math.Sqrt(visible.Width * visible.Width + visible.Height * visible.Height) / 8 * WayBeforeTextMultiplier;
            var annotations = Annotater.Annotate(collection, visible)
                              .Where(annotation =>
            {
                Point viewportPosition = annotation.Position.DataToViewport(transform);
                return(biggerViewport.Contains(viewportPosition));
            });

            var labelsScale = LabelsScaling;

            // drawing annotations
            foreach (var annotation in annotations)
            {
                FormattedText text     = CreateFormattedText(annotation.Value.ToString(LabelStringFormat));
                Point         position = annotation.Position.DataToScreen(transform);

                var labelTransform = CreateTransform(annotation, text, position);

                // creating rectange stroke
                double colorRatio = (annotation.Value - collection.Min) / (collection.Max - collection.Min);
                colorRatio = MathHelper.Clamp(colorRatio);
                Color           rectangleStrokeColor    = Palette.GetColor(colorRatio);
                SolidColorBrush rectangleStroke         = new SolidColorBrush(rectangleStrokeColor);
                Pen             labelRectangleStrokePen = new Pen(rectangleStroke, 2);

                dc.PushTransform(new ScaleTransform(1, labelsScale));
                dc.PushTransform(labelTransform);
                {
                    var bounds = RectExtensions.FromCenterSize(position, new Size(text.Width, text.Height));
                    bounds = bounds.ZoomOutFromCenter(1.3);
                    dc.DrawRoundedRectangle(labelRectangleFill, labelRectangleStrokePen, bounds, 8, 8);

                    DrawTextInPosition(dc, text, position);
                }
                dc.Pop();
                dc.Pop();
            }
        }