Exemple #1
0
        public void Test_Scatter_Offset()
        {
            Random rand = new(0);

            double[] xs = DataGen.Random(rand, 20);
            double[] ys = DataGen.Random(rand, 20);

            var plt     = new ScottPlot.Plot(400, 300);
            var scatter = plt.AddScatter(xs, ys);

            scatter.XError = DataGen.Random(rand, 20, .1);
            scatter.YError = DataGen.Random(rand, 20, .1);

            plt.AxisAuto();
            var limits1 = plt.GetAxisLimits();

            //TestTools.SaveFig(plt, "beforeOffset");
            Assert.Less(limits1.XMax, 10);
            Assert.Less(limits1.YMax, 20);

            scatter.OffsetX = 10;
            scatter.OffsetY = 20;

            plt.AxisAuto();
            var limits2 = plt.GetAxisLimits();

            //TestTools.SaveFig(plt, "afterOffset");
            Assert.Greater(limits2.XMax, 10);
            Assert.Greater(limits2.YMax, 20);
        }
Exemple #2
0
        public void Test_AutoAxis_ShrinkWhenNeeded()
        {
            var plt = new ScottPlot.Plot();

            // small area
            plt.PlotLine(-5, -5, 5, 5);
            plt.AxisAuto();
            var limitsA = plt.GetAxisLimits();

            Console.WriteLine($"limits A: {limitsA}");

            // expand to large area
            plt.SetAxisLimits(-123, 123, -123, 123);
            var limitsB = plt.GetAxisLimits();

            Console.WriteLine($"limits B: {limitsB}");

            // shrink back to small area
            plt.AxisAuto();
            var limitsC = plt.GetAxisLimits();

            Console.WriteLine($"limits C: {limitsC}");

            Assert.That(limitsB.XMin < limitsA.XMin);
            Assert.That(limitsB.XMax > limitsA.XMax);
            Assert.That(limitsB.YMin < limitsA.YMin);
            Assert.That(limitsB.YMax > limitsA.YMax);

            Assert.That(limitsB.XMin < limitsC.XMin);
            Assert.That(limitsB.XMax > limitsC.XMax);
            Assert.That(limitsB.YMin < limitsC.YMin);
            Assert.That(limitsB.YMax > limitsC.YMax);
        }
Exemple #3
0
        public void Test_AutoAxis_ExpandXY()
        {
            var plt = new ScottPlot.Plot();

            // small area
            plt.PlotLine(-5, -5, 5, 5);
            plt.AxisAuto();
            var limitsA = plt.GetAxisLimits();

            // large area
            plt.PlotLine(-99, -99, 99, 99);
            plt.AxisAuto();
            var limitsB = plt.GetAxisLimits();

            Assert.That(limitsB.XMin < limitsA.XMin);
            Assert.That(limitsB.XMax > limitsA.XMax);
            Assert.That(limitsB.YMin < limitsA.YMin);
            Assert.That(limitsB.YMax > limitsA.YMax);
        }
Exemple #4
0
        public void Test_AutoAxis_WorksAfterClear()
        {
            var plt = new ScottPlot.Plot();

            plt.PlotPoint(0.1, 0.1);
            plt.PlotPoint(-0.1, -0.1);
            plt.AxisAuto();
            plt.Render(); // force a render
            Assert.Greater(plt.GetAxisLimits().XMin, -5);

            plt.PlotPoint(999, 999);
            plt.PlotPoint(-999, -999);
            plt.AxisAuto();
            plt.Render(); // force a render
            Assert.Less(plt.GetAxisLimits().XMin, -800);

            plt.Clear();
            plt.PlotPoint(0.1, 0.1);
            plt.PlotPoint(-0.1, -0.1);
            plt.Render(); // force a render
            Assert.Greater(plt.GetAxisLimits().XMin, -5);
        }
Exemple #5
0
        public void Test_TickAlignment_SnapEdgePixel()
        {
            Random rand = new Random(0);

            double[] xs = DataGen.Range(0, 10, .1, true);
            double[] ys = DataGen.RandomWalk(rand, xs.Length, .5);

            var plt = new ScottPlot.Plot(320, 240);

            plt.AddScatter(xs, ys, markerSize: 0);
            plt.AddScatter(ys, xs, markerSize: 0);
            plt.AxisAuto(0, 0);

            TestTools.SaveFig(plt);
        }
Exemple #6
0
        public void Test_AutoAxis_ScatterVerticalLine()
        {
            var plt = new ScottPlot.Plot();

            plt.PlotScatter(
                xs: new double[] { 1, 1 },
                ys: new double[] { 1, 2 }
                );
            plt.AxisAuto();

            var limits = plt.GetAxisLimits();

            Assert.Greater(limits.XSpan, 0);
            Assert.Greater(limits.YSpan, 0);
        }
Exemple #7
0
        public void Test_AutoAxis_ScatterSinglePoint()
        {
            var plt = new ScottPlot.Plot();

            plt.AddScatter(
                xs: new double[] { 1, 2 },
                ys: new double[] { 1, 2 }
                );
            plt.AxisAuto();

            var limits = plt.GetAxisLimits();

            Assert.Greater(limits.XSpan, 0);
            Assert.Greater(limits.YSpan, 0);
        }
Exemple #8
0
        public void Test_ScaleBar_Simple()
        {
            var plt = new ScottPlot.Plot(400, 300);

            plt.PlotSignal(DataGen.Sin(51));
            plt.PlotSignal(DataGen.Cos(51, mult: 1.5));

            plt.PlotScaleBar(5, .25, "5 ms", "250 pA");

            plt.Grid(false);
            plt.Frame(false);
            plt.Ticks(false, false);
            plt.AxisAuto(0);
            plt.LayoutFrameless();

            TestTools.SaveFig(plt);
        }
Exemple #9
0
        private void UserControl_MouseUp(object sender, MouseButtonEventArgs e)
        {
            ReleaseMouseCapture();

            draggingAxLine = null;

            if (mouseMiddleDownLocation != null)
            {
                double x1 = Math.Min(mouseLocation.X, ((Point)mouseMiddleDownLocation).X);
                double x2 = Math.Max(mouseLocation.X, ((Point)mouseMiddleDownLocation).X);
                double y1 = Math.Min(mouseLocation.Y, ((Point)mouseMiddleDownLocation).Y);
                double y2 = Math.Max(mouseLocation.Y, ((Point)mouseMiddleDownLocation).Y);

                Point topLeft  = new Point(x1, y1);
                Size  size     = new Size(x2 - x1, y2 - y1);
                Point botRight = new Point(topLeft.X + size.Width, topLeft.Y + size.Height);

                if ((size.Width > 2) && (size.Height > 2))
                {
                    // only change axes if suffeciently large square was drawn
                    plt.Axis(
                        x1: plt.CoordinateFromPixel((int)topLeft.X, (int)topLeft.Y).X,
                        x2: plt.CoordinateFromPixel((int)botRight.X, (int)botRight.Y).X,
                        y1: plt.CoordinateFromPixel((int)botRight.X, (int)botRight.Y).Y,
                        y2: plt.CoordinateFromPixel((int)topLeft.X, (int)topLeft.Y).Y
                        );
                }
                else
                {
                    plt.AxisAuto();
                }
            }

            mouseLeftDownLocation    = null;
            mouseRightDownLocation   = null;
            mouseMiddleDownLocation  = null;
            axisLimitsOnMouseDown    = null;
            settings.mouseMiddleRect = null;
            Render();
        }
Exemple #10
0
        public void Test_MultiAxis_AutoAxis()
        {
            double[] xs = { 1, 2, 3 };
            double[] ys = { 4, 5, 6 };

            var plt = new ScottPlot.Plot(400, 300);
            var sp  = plt.AddScatter(xs, ys);

            sp.YAxisIndex = 1;
            sp.XAxisIndex = 1;
            plt.Render();
            var limitsA = plt.GetAxisLimits(1, 1);

            xs[0] = 999;
            ys[0] = 999;
            plt.AxisAuto(0.05, .01, 1, 1);
            plt.Render();
            var limitsB = plt.GetAxisLimits(1, 1);

            Assert.Greater(limitsB.XMax, limitsA.XMax);
            Assert.Greater(limitsB.YMax, limitsA.YMax);
        }
        private ScottPlot.Plot TestColormap(Palette cset, int lineWidth, bool dark = false)
        {
            var plt = new ScottPlot.Plot(600, 400);

            for (int i = 0; i < cset.Count(); i++)
            {
                double[] ys  = DataGen.Sin(51, phase: -i / Math.PI / cset.Count());
                var      sig = plt.AddSignal(ys, color: cset.GetColor(i));
                sig.MarkerSize = 0;
                sig.LineWidth  = lineWidth;
            }

            if (dark)
            {
                plt.Style(Style.Gray1);
                plt.Style(darkColor, darkColor);
            }

            plt.Title($"Colorset '{cset.Name}' has {cset.Count()} colors");
            plt.AxisAuto(0);

            return(plt);
        }
Exemple #12
0
        private ScottPlot.Plot TestColormap(Colorset cset, int lineWidth, bool dark = false)
        {
            var plt = new ScottPlot.Plot(600, 400);

            for (int i = 0; i < cset.Count(); i++)
            {
                double[] ys = DataGen.Sin(51,
                                          //mult: 1 - .5 * i / cset.Count(),
                                          phase: -i / Math.PI / cset.Count());
                plt.PlotSignal(ys, color: cset.GetColor(i), markerSize: 0, lineWidth: lineWidth);
            }

            if (dark)
            {
                plt.Style(Style.Gray1);
                plt.Style(darkColor, darkColor);
            }

            plt.Title($"Colorset '{cset.Name}' has {cset.Count()} colors");
            plt.AxisAuto(0);

            return(plt);
        }
Exemple #13
0
 private void UserControl_MouseUp(object sender, MouseButtonEventArgs e)
 {
     if (e.ChangedButton == MouseButton.Left || e.ChangedButton == MouseButton.Right)
     {
         plt.mouseTracker.MouseUp(e.GetPosition(this));
         if (plt.mouseTracker.lowQualityWhileInteracting && plt.mouseTracker.mouseUpHQRenderDelay > 0)
         {
             Render(false, true);
             timer.Interval = TimeSpan.FromMilliseconds(plt.mouseTracker.mouseUpHQRenderDelay);
             timer.Start();
         }
         else
         {
             Render(skipIfCurrentlyRendering: false);
         }
     }
     else if (e.ChangedButton == MouseButton.Middle)
     {
         plt.AxisAuto();
         Render(skipIfCurrentlyRendering: false);
     }
     ReleaseMouseCapture();
 }
Exemple #14
0
        public void MatchAxis(Plot sourcePlot, bool horizontal = true, bool vertical = true)
        {
            if (!sourcePlot.GetSettings(showWarning: false).axes.hasBeenSet)
            {
                sourcePlot.AxisAuto();
            }

            if (!settings.axes.hasBeenSet)
            {
                AxisAuto();
            }

            if (horizontal)
            {
                settings.axes.x.min = sourcePlot.settings.axes.x.min;
                settings.axes.x.max = sourcePlot.settings.axes.x.max;
            }
            if (vertical)
            {
                settings.axes.y.min = sourcePlot.settings.axes.y.min;
                settings.axes.y.max = sourcePlot.settings.axes.y.max;
            }
            Resize();
        }
Exemple #15
0
        private void PbPlot_MouseUp(object sender, MouseEventArgs e)
        {
            if (mouseMiddleDownLocation != null)
            {
                int x1 = Math.Min(mouseLocation.X, ((Point)mouseMiddleDownLocation).X);
                int x2 = Math.Max(mouseLocation.X, ((Point)mouseMiddleDownLocation).X);
                int y1 = Math.Min(mouseLocation.Y, ((Point)mouseMiddleDownLocation).Y);
                int y2 = Math.Max(mouseLocation.Y, ((Point)mouseMiddleDownLocation).Y);

                Point topLeft  = new Point(x1, y1);
                Size  size     = new Size(x2 - x1, y2 - y1);
                Point botRight = new Point(topLeft.X + size.Width, topLeft.Y + size.Height);

                if ((size.Width > 2) && (size.Height > 2))
                {
                    // only change axes if suffeciently large square was drawn
                    plt.Axis(
                        x1: plt.CoordinateFromPixel(topLeft).X,
                        x2: plt.CoordinateFromPixel(botRight).X,
                        y1: plt.CoordinateFromPixel(botRight).Y,
                        y2: plt.CoordinateFromPixel(topLeft).Y
                        );
                }
                else
                {
                    plt.AxisAuto();
                }
            }

            if (mouseRightDownLocation != null)
            {
                int deltaX = Math.Abs(((Point)mouseRightDownLocation).X - mouseLocation.X);
                int deltaY = Math.Abs(((Point)mouseRightDownLocation).Y - mouseLocation.Y);
                if (deltaX < 3 && deltaY < 3)
                {
                    OnMenuDeployed();
                }
            }

            if (isMouseDragging)
            {
                OnMouseDragged(EventArgs.Empty);
            }

            if (isMouseDragging)
            {
                OnAxisChanged();
            }

            if (draggingAxLine != null)
            {
                OnMouseDropPlottable(EventArgs.Empty);
            }

            OnMouseClicked(e);

            mouseLeftDownLocation    = null;
            mouseRightDownLocation   = null;
            mouseMiddleDownLocation  = null;
            axisLimitsOnMouseDown    = null;
            settings.mouseMiddleRect = null;
            draggingAxLine           = null;
            Render();
        }