Exemple #1
0
        private void UserControl_MouseDown(object sender, MouseButtonEventArgs e)
        {
            CaptureMouse();

            var mousePixel = GetPixelPosition(e);

            plottableBeingDragged = plt.GetDraggableUnderMouse(mousePixel.X, mousePixel.Y);

            if (plottableBeingDragged is null)
            {
                // MouseDown event is to start a pan or zoom
                bool shiftIsPressed = Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift);
                if (e.ChangedButton == MouseButton.Left && shiftIsPressed)
                {
                    mouseMiddleDownLocation = GetPixelPosition(e);
                }
                else if (e.ChangedButton == MouseButton.Left && enablePanning)
                {
                    mouseLeftDownLocation = GetPixelPosition(e);
                }
                else if (e.ChangedButton == MouseButton.Right && enableZooming)
                {
                    mouseRightDownLocation = GetPixelPosition(e);
                }
                else if (e.ChangedButton == MouseButton.Middle)
                {
                    mouseMiddleDownLocation = GetPixelPosition(e);
                }
                axisLimitsOnMouseDown = plt.Axis();
            }
            else
            {
                // mouse is being used to drag a plottable
            }
        }
Exemple #2
0
        private void PbPlot_MouseDown(object sender, MouseEventArgs e)
        {
            draggingAxLine = settings.GetDraggableAxisLineUnderCursor(e.Location);

            if (draggingAxLine != null)
            {
                OnMouseDownOnPlottable(EventArgs.Empty);
            }
            else
            {
                // mouse is being used for click and zoom
                if (e.Button == MouseButtons.Left && ModifierKeys.HasFlag(Keys.Shift))
                {
                    mouseMiddleDownLocation = e.Location;
                }
                else if (e.Button == MouseButtons.Left && enablePanning)
                {
                    mouseLeftDownLocation = e.Location;
                }
                else if (e.Button == MouseButtons.Right && enableZooming)
                {
                    mouseRightDownLocation = e.Location;
                }
                else if (e.Button == MouseButtons.Middle)
                {
                    mouseMiddleDownLocation = e.Location;
                }
                axisLimitsOnMouseDown = plt.Axis();
            }
        }
Exemple #3
0
        private void UserControl_MouseDown(object sender, MouseButtonEventArgs e)
        {
            CaptureMouse();

            draggingAxLine = settings.GetDraggableAxisLineUnderCursor(SDPoint(GetPixelPosition(e)));

            bool shiftIsPressed = Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift);

            if (e.ChangedButton == MouseButton.Left && shiftIsPressed)
            {
                mouseMiddleDownLocation = GetPixelPosition(e);
            }
            else if (e.ChangedButton == MouseButton.Left)
            {
                mouseLeftDownLocation = GetPixelPosition(e);
            }
            else if (e.ChangedButton == MouseButton.Right)
            {
                mouseRightDownLocation = GetPixelPosition(e);
            }
            else if (e.ChangedButton == MouseButton.Middle)
            {
                mouseMiddleDownLocation = GetPixelPosition(e);
            }
            axisLimitsOnMouseDown = plt.Axis();
        }
Exemple #4
0
        private void PbPlot_MouseDown(object sender, MouseEventArgs e)
        {
            var mousePixel = e.Location;

            plottableBeingDragged = plt.GetDraggableUnderMouse(mousePixel.X, mousePixel.Y);

            if (plottableBeingDragged is null)
            {
                // MouseDown event is to start a pan or zoom
                if (e.Button == MouseButtons.Left && ModifierKeys.HasFlag(Keys.Shift))
                {
                    mouseMiddleDownLocation = e.Location;
                }
                else if (e.Button == MouseButtons.Left && enablePanning)
                {
                    mouseLeftDownLocation = e.Location;
                }
                else if (e.Button == MouseButtons.Right && enableZooming)
                {
                    mouseRightDownLocation = e.Location;
                }
                else if (e.Button == MouseButtons.Middle)
                {
                    mouseMiddleDownLocation = e.Location;
                }
                axisLimitsOnMouseDown = plt.Axis();
            }
            else
            {
                // mouse is being used to drag a plottable
                OnMouseDownOnPlottable(EventArgs.Empty);
            }
        }
Exemple #5
0
        public void Test_Bar_ShowValues()
        {
            var plt = new ScottPlot.Plot();

            plt.AntiAlias(false, false, false);

            // start with default settings
            double[] ys  = new double[] { 1, 3, 2, 4 };
            var      bar = new PlottableBar(null, ys, null, null)
            {
            };

            plt.Add(bar);
            plt.Axis(-1, 4, -1, 5);
            var bmp1 = new System.Drawing.Bitmap(plt.GetBitmap(renderFirst: true));

            // change the plottable
            bar.showValues = 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));
        }
Exemple #6
0
        public void Test_Bar_MultiSeries()
        {
            Random rand = new Random(0);

            string[] groupNames  = { "one", "two", "three", "four", "five" };
            string[] seriesNames = { "alpha", "beta", "gamma" };

            int groupCount = groupNames.Length;

            double[] xs   = DataGen.Consecutive(groupCount);
            double[] ys1  = DataGen.RandomNormal(rand, groupCount, 20, 5);
            double[] ys2  = DataGen.RandomNormal(rand, groupCount, 20, 5);
            double[] ys3  = DataGen.RandomNormal(rand, groupCount, 20, 5);
            double[] err1 = DataGen.RandomNormal(rand, groupCount, 5, 2);
            double[] err2 = DataGen.RandomNormal(rand, groupCount, 5, 2);
            double[] err3 = DataGen.RandomNormal(rand, groupCount, 5, 2);

            var plt = new ScottPlot.Plot(600, 400);

            plt.PlotBarGroups(
                groupLabels: groupNames,
                seriesLabels: seriesNames,
                ys: new double[][] { ys1, ys2, ys3 },
                yErr: new double[][] { err1, err2, err3 });

            plt.Axis(y1: 0);
            plt.Grid(enableVertical: false, lineStyle: LineStyle.Dot);
            plt.Legend(location: Alignment.UpperRight);
            TestTools.SaveFig(plt);
        }
Exemple #7
0
        public void Test_RenderingArtifacts_Demonstrate()
        {
            // Due to a bug in System.Drawing the drawing of perfectly straight lines is
            // prone to rendering artifacts (diagonal lines) when anti-aliasing is off.
            // https://github.com/swharden/ScottPlot/issues/327
            // https://github.com/swharden/ScottPlot/issues/401

            var plt = new ScottPlot.Plot(400, 300);

            plt.Grid(xSpacing: 2, ySpacing: 2, color: Color.Red);
            plt.Axis(-13, 13, -10, 10);

            // create conditions to reveal rendering artifact
            plt.AntiAlias(false, false, false);
            plt.Grid(enableVertical: false);

            // save the figure (bmpData + bmpFigure)
            TestTools.SaveFig(plt);

            // save the data bitmap too
            string gfxFilePath = System.IO.Path.GetFullPath("diag.png");

            plt.GetSettings(false).bmpData.Save(gfxFilePath, ImageFormat.Png);
            Console.WriteLine($"SAVED: {gfxFilePath}");
        }
Exemple #8
0
        public void Test_function_LineStyle()
        {
            var plt = new ScottPlot.Plot();

            // start with default settings
            double?func(double x) => Math.Sqrt(x);

            var funcPlot = new FunctionPlot(func)
            {
            };

            plt.Axis(-1, 1, -.5, 1.5);

            plt.Add(funcPlot);
            var bmp1 = TestTools.GetLowQualityBitmap(plt);

            // change the plottable
            funcPlot.lineStyle = LineStyle.Dash;
            var bmp2 = TestTools.GetLowQualityBitmap(plt);

            // 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.IsLighterThan(before));
        }
Exemple #9
0
        public void Test_function_LineWidth()
        {
            var plt = new ScottPlot.Plot();

            plt.AntiAlias(false, false, false);

            // start with default settings
            double?func(double x) => Math.Sqrt(x);

            var funcPlot = new PlottableFunction(func)
            {
            };

            plt.Axis(-1, 1, -.5, 1.5);

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

            // change the plottable
            funcPlot.lineWidth += 1;
            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));
        }
Exemple #10
0
        public void Test_AutoAxis_ShrinkWhenNeeded()
        {
            var plt = new ScottPlot.Plot();

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

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

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

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

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

            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 #11
0
        public void Test_TickMinor_OnePixelOffFromMajor()
        {
            // this makes the horizontal axis tick near 2.0 look bad
            var plt = new ScottPlot.Plot(400, 300);

            plt.Axis(0, 3, 0, 3);
            TestTools.SaveFig(plt);
        }
        private void UserControl_MouseDown(object sender, MouseButtonEventArgs e)
        {
            CaptureMouse();

            if (e.ChangedButton == MouseButton.Left)
            {
                mouseLeftDownLocation = e.GetPosition(this);
            }
            else if (e.ChangedButton == MouseButton.Right)
            {
                mouseRightDownLocation = e.GetPosition(this);
            }
            else if (e.ChangedButton == MouseButton.Middle)
            {
                mouseMiddleDownLocation = e.GetPosition(this);
            }
            axisLimitsOnMouseDown = plt.Axis();
        }
        public void Test_Axis_VeryBigNumbers()
        {
            var plt = new ScottPlot.Plot();

            plt.PlotSignal(DataGen.Sin(51));
            plt.PlotSignal(DataGen.Cos(51));

            plt.Axis(y1: -10e50, y2: 10e50);

            TestTools.SaveFig(plt);
        }
        static public void RunJolka(List <Solver <string> > backtracks, List <Solver <string> > backtrackfws, string heuristicB = "", string heuristicBF = "", string type = "")
        {
            var           plt     = new ScottPlot.Plot(1280, 720);
            List <double> xlist   = new List <double>();
            List <double> yfwlist = new List <double>();
            List <double> ylist   = new List <double>();

            foreach (var el in backtrackfws)
            {
                xlist.Add(el.solvedPuzzle.Puzzle.id);
                if (type == "time")
                {
                    yfwlist.Add(el.solvedPuzzle.elapsed.TotalMilliseconds);
                }
                else
                {
                    yfwlist.Add(el.solvedPuzzle.Puzzle.steps);
                }
            }
            foreach (var el in backtracks)
            {
                if (type == "time")
                {
                    ylist.Add(el.solvedPuzzle.elapsed.TotalMilliseconds);
                }
                else
                {
                    ylist.Add(el.solvedPuzzle.Puzzle.steps);
                }
            }
            double[] xs = xlist.ToArray();
            ylist.Insert(2, (double)1);
            double[] dataB  = Tools.Log10(ylist.ToArray());
            double[] dataBF = Tools.Log10(yfwlist.ToArray());
            plt.PlotBar(xs, dataB, label: "Backtrack w/ " + heuristicB, barWidth: .3, xOffset: -0.2, showValues: true);
            plt.PlotBar(xs, dataBF, label: "Backtrack with forward w/ " + heuristicBF, barWidth: .3, xOffset: 0.2, showValues: true);
            plt.Title(type + " over Jolka id");
            plt.Ticks(useExponentialNotation: false, useMultiplierNotation: false, logScaleY: true);
            plt.Axis(y1: 0);
            plt.XTicks(new string[] { "0", "1", "2", "3", "4" });
            if (type == "time")
            {
                plt.YLabel("Execution time [10 ^ y ms]");
            }
            else
            {
                plt.YLabel("Steps [10 ^ y]");
            }
            plt.XLabel("Jolka ID");
            plt.Legend(location: legendLocation.upperRight);
            plt.SaveFig(heuristicB + heuristicBF + type + "JolkaBvsBF" + ".png");
        }
        static public void RunSudoku(double[] difficulty, double[] dataB, double[] dataBF, string heuristicB = "", string heuristicBF = "", string type = "")
        {
            var plt        = new ScottPlot.Plot(1280, 720);
            int pointCount = dataB.Length;

            plt.PlotBar(difficulty, dataB, label: "Backtrack w/ " + heuristicB, barWidth: .3, xOffset: -0.2);
            plt.PlotBar(difficulty, dataBF, label: "Backtrack with forward w/ " + heuristicBF, barWidth: .3, xOffset: 0.2);
            plt.Title("Average " + type + " over sudoku difficulty");
            plt.Axis(y1: 0);
            if (type == "time")
            {
                plt.YLabel("Execution time [ms]");
            }
            else
            {
                plt.YLabel("Steps");
            }
            plt.XLabel("Difficulty");
            plt.Legend(location: legendLocation.upperRight);
            plt.Ticks(useExponentialNotation: false, useMultiplierNotation: false);
            plt.SaveFig(heuristicB + heuristicBF + type + "BvsBF" + ".png");
        }