Beispiel #1
0
        public void Test_Text_Alignment()
        {
            var plt = new ScottPlot.Plot();

            plt.AntiAlias(false, false, false);

            // start with default settings
            var txt = new PlottableText()
            {
                text = "hello"
            };

            plt.Add(txt);
            var    bmp1  = new System.Drawing.Bitmap(plt.GetBitmap(renderFirst: true));
            string hash1 = ScottPlot.Tools.BitmapHash(bmp1);

            // change the plottable
            txt.alignment = TextAlignment.middleCenter;
            var    bmp2  = new System.Drawing.Bitmap(plt.GetBitmap(renderFirst: true));
            string hash2 = ScottPlot.Tools.BitmapHash(bmp2);

            // measure what changed
            //TestTools.SaveFig(bmp1, "1");
            //TestTools.SaveFig(bmp2, "2");
            Console.WriteLine($"Before: {hash1}");
            Console.WriteLine($"After: {hash2}");

            Assert.AreNotEqual(hash1, hash2);
        }
Beispiel #2
0
        public void Test_Text_FontSize()
        {
            var plt = new ScottPlot.Plot();

            plt.AntiAlias(false, false, false);

            // start with default settings
            var txt = new PlottableText()
            {
                text = "hello", FontSize = 12
            };

            plt.Add(txt);
            var bmp1 = new System.Drawing.Bitmap(plt.GetBitmap(renderFirst: true));

            // change the plottable
            txt.FontSize = 36;
            var bmp2 = new System.Drawing.Bitmap(plt.GetBitmap(renderFirst: true));

            // measure what changed
            //TestTools.SaveFig(bmp1, "1");
            //TestTools.SaveFig(bmp2, "2");
            var before = new MeanPixel(bmp1);
            var after  = new MeanPixel(bmp2);

            Console.WriteLine($"Before: {before}");
            Console.WriteLine($"After: {after}");

            Assert.That(after.IsDarkerThan(before));
        }
Beispiel #3
0
 public void SetData(IReadOnlyList <RectWithVector> field)
 {
     Plt.Clear();
     _highlightedText = null;
     field1           = field;
     PlotVectorField(field);
 }
Beispiel #4
0
        public void Test_Text_FrameColor()
        {
            var plt = new ScottPlot.Plot();

            plt.AntiAlias(false, false, false);

            // start with default settings
            var txt = new PlottableText()
            {
                text = "hello", frame = true, frameColor = System.Drawing.Color.Gray
            };

            plt.Add(txt);
            var bmp1 = new System.Drawing.Bitmap(plt.GetBitmap(renderFirst: true));

            // change the plottable
            txt.frameColor = System.Drawing.Color.Blue;
            var bmp2 = new System.Drawing.Bitmap(plt.GetBitmap(renderFirst: true));

            // measure what changed
            //TestTools.SaveFig(bmp1, "1");
            //TestTools.SaveFig(bmp2, "2");
            var before = new MeanPixel(bmp1);
            var after  = new MeanPixel(bmp2);

            Console.WriteLine($"Before: {before}");
            Console.WriteLine($"After: {after}");

            Assert.That(before.IsGray());
            Assert.That(after.IsNotGray());
            Assert.That(after.IsMoreBlueThan(before));
        }
Beispiel #5
0
        private void Render()
        {
            if (toPlot.IsNullOrEmpty())
            {
                return;
            }

            var xs = new double[toPlot.Length];
            var ys = new double[toPlot.Length];

            formsPlot.cursor = Cursors.Cross;

            Plt.Clear();
            _highlightedText = null;
            for (var index = 0; index < toPlot.Length; index++)
            {
                var vector = toPlot[index];
                var d      = vector.Distortion;
                Plt.PlotQuiver(
                    vector.CenterOfGravity.X,
                    vector.CenterOfGravity.Y,
                    vector.CenterOfGravity.X + plotScale * d.X,
                    vector.CenterOfGravity.Y + plotScale * d.Y,
                    color: Color.Blue);
                xs[index] = vector.CenterOfGravity.X;
                ys[index] = vector.CenterOfGravity.Y;
            }

            Plt.PlotScatter(xs, ys, lineWidth: 0, markerShape: MarkerShape.none);
            //Plt.AxisScale(-1);
            // highlightedText = Plt.PlotText("", 0, 0, fontSize: 15, color: Color.Black,
            //  frameColor: Color.AliceBlue, frame: true);
            // highlightedText.visible = false;
            formsPlot.Render();
        }
            public void Render(Plot plt)
            {
                // rather than call Plot.PlotText(), create the Plottable manually
                var customPlottable = new PlottableText()
                {
                    text       = "test",
                    x          = 2,
                    y          = 3,
                    FontColor  = System.Drawing.Color.Magenta,
                    FontName   = "arial",
                    FontSize   = 26,
                    FontBold   = true,
                    alignment  = TextAlignment.middleCenter,
                    rotation   = 0,
                    frame      = false,
                    frameColor = System.Drawing.Color.Green
                };

                // you can access properties which may not be exposed by a Plot method
                customPlottable.rotation = 45;

                // add the custom plottable to the list of plottables like this
                List <Plottable> plottables = plt.GetPlottables();

                plottables.Add(customPlottable);
            }
Beispiel #7
0
        private void ShowValueOnHover_Load(object sender, EventArgs e)
        {
            int pointCount = 51;

            double[] Xs = DataGen.Consecutive(pointCount);
            double[] Ys = DataGen.Sin(pointCount, 2);
            scatterPlot = formsPlot1.plt.PlotScatter(Xs, Ys, color: Color.Blue);
            formsPlot1.plt.AxisAuto();
            formsPlot1.Render();

            // create a point and text that will be moved around to highlight the point under the cursor
            highlightedPoint = formsPlot1.plt.PlotPoint(0, 0, markerSize: 10, color: Color.Red);
            highlightedText  = formsPlot1.plt.PlotText("asdf", 0, 0, fontSize: 10, color: Color.Black);
        }
            public void Render(Plot plt)
            {
                // rather than call Plot.Text(), create the Plottable object manually
                var customPlottable = new PlottableText(text: "test", x: 2, y: 3,
                                                        color: System.Drawing.Color.Magenta, fontName: "arial", fontSize: 26,
                                                        bold: true, label: "", alignment: TextAlignment.middleCenter,
                                                        rotation: 0, frame: false, frameColor: System.Drawing.Color.Green);

                // you can access properties which may not be exposed by a Plot method
                customPlottable.rotation = 45;

                // add the custom plottable to the list of plottables like this
                List <Plottable> plottables = plt.GetPlottables();

                plottables.Add(customPlottable);
            }
        public ShowValueOnHover()
        {
            InitializeComponent();

            // plot some data
            int pointCount = 51;

            double[] Xs = DataGen.Consecutive(pointCount);
            double[] Ys = DataGen.Sin(pointCount, 2);
            scatterPlot = wpfPlot1.plt.PlotScatter(Xs, Ys, color: System.Drawing.Color.Blue);
            wpfPlot1.plt.AxisAuto();
            wpfPlot1.Render();

            // create a point and text that will be moved around to highlight the point under the cursor
            highlightedPoint         = wpfPlot1.plt.PlotPoint(0, 0, markerSize: 10, color: System.Drawing.Color.Red);
            highlightedText          = wpfPlot1.plt.PlotText("asdf", 0, 0, fontSize: 10, color: System.Drawing.Color.Black);
            highlightedPoint.visible = false;
            highlightedText.visible  = false;
        }
Beispiel #10
0
 private void Mouse_Tracker_Click(object sender, RoutedEventArgs e)
 {
     MouseTrack = !MouseTrack;
     if (MouseTrack == true)
     {
         Mouse_VLine = Graph.plt.PlotVLine(0, color: System.Drawing.Color.Red, lineStyle: LineStyle.DashDot);
         Mouse_HLine = Graph.plt.PlotHLine(0, color: System.Drawing.Color.Red, lineStyle: LineStyle.DashDot);
         Coord_text  = Graph.plt.PlotText("", 0, 0, color: System.Drawing.Color.Red, fontSize: 18, alignment: ScottPlot.TextAlignment.lowerLeft);
     }
     else
     {
         Graph.plt.Clear(Mouse_VLine);
         Graph.plt.Clear(Mouse_HLine);
         Graph.plt.Clear(Coord_text);
         if (AutoAxis == true)
         {
             Graph.plt.AxisAuto();
         }
         Graph.Render(skipIfCurrentlyRendering: true);
     }
 }
Beispiel #11
0
        public void Test_Text_FontBold()
        {
            // bold fonts are supported on all operating systems so only test on windows
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) == false)
            {
                return;
            }

            var plt = new ScottPlot.Plot();

            plt.AntiAlias(false, false, false);

            // start with default settings
            var txt = new PlottableText()
            {
                text = "hello", FontSize = 12
            };

            plt.Add(txt);
            var bmp1 = new System.Drawing.Bitmap(plt.GetBitmap(renderFirst: true));

            // change the plottable
            txt.FontBold = true;
            var bmp2 = new System.Drawing.Bitmap(plt.GetBitmap(renderFirst: true));

            // measure what changed
            //TestTools.SaveFig(bmp1, "1");
            //TestTools.SaveFig(bmp2, "2");
            var before = new MeanPixel(bmp1);
            var after  = new MeanPixel(bmp2);

            Console.WriteLine($"Before: {before}");
            Console.WriteLine($"After: {after}");

            Assert.That(after.IsDarkerThan(before));
        }
Beispiel #12
0
        private void formsPlot_MouseMoved(object sender, MouseEventArgs e)
        {
            // don't attempt to change things while we are click-dragging
            if (e.Button == MouseButtons.Left || e.Button == MouseButtons.Right || e.Button == MouseButtons.Middle)
            {
                return;
            }
            if (toPlot == null)
            {
                return;
            }

            // determine where the mouse is in coordinate space
            (double mouseX, double mouseY) = formsPlot.GetMouseCoordinates();

            // determine which point is closest to the mouse
            int    closestIndex    = 0;
            double closestDistance = double.PositiveInfinity;

            for (int i = 0; i < toPlot.Length; i++)
            {
                var    pt       = toPlot[i].CenterOfGravity;
                var    dx       = pt.X - mouseX;
                var    dy       = pt.Y - mouseY;
                double distance = dx * dx + dy * dy;
                if (distance < closestDistance)
                {
                    closestIndex    = i;
                    closestDistance = distance;
                }
            }

            var closest          = toPlot[closestIndex];
            var closestItem      = closest.CenterOfGravity;
            var closestItemPixel = Plt.CoordinateToPixel(closestItem);

            if (closestItemPixel.Dist(e.Location) < 8)
            {
                double x = closestItem.X;
                double y = closestItem.Y;

                var r    = closest.Distortion.R() * unitScale;
                var txt1 = $"{Math.Round(x, 3)}, {Math.Round(y, 3)}\n{(int) Math.Round(r)}";

                _highlightedText = _highlightedText ?? Plt.PlotText("", 0, 0, fontSize: 15, color: Color.Black,
                                                                    frameColor: Color.AliceBlue, frame: true);
                _highlightedText.visible = true;
                _highlightedText.text    = txt1;
                var pt = Plt.CoordinateToPixel(new PointF((float)x, (float)y));
                pt += new SizeF(8, -8);
                _highlightedText.x = Plt.CoordinateFromPixelX(pt.X);
                _highlightedText.y = Plt.CoordinateFromPixelY(pt.Y);
            }
            else
            {
                if (_highlightedText != null)
                {
                    _highlightedText.visible = false;
                }
            }

            formsPlot.Render();
        }