コード例 #1
0
ファイル: Bar.cs プロジェクト: yongmingxia/ScottPlot
        public void Test_Bar_ErrorLineWidth()
        {
            var plt = new ScottPlot.Plot();

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

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

            // change the plottable
            bar.ErrorLineWidth += 1;
            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.IsDarkerThan(before));
        }
コード例 #2
0
ファイル: Text.cs プロジェクト: yongmingxia/ScottPlot
        public void Test_Text_Alignment()
        {
            var plt = new ScottPlot.Plot(400, 300);

            // start with default settings
            var txt = new ScottPlot.Plottable.Text()
            {
                Label = "hello"
            };

            plt.Add(txt);
            var    bmp1  = TestTools.GetLowQualityBitmap(plt);
            string hash1 = ScottPlot.Tools.BitmapHash(bmp1);

            // change the plottable
            txt.Alignment = Alignment.MiddleCenter;
            var    bmp2  = TestTools.GetLowQualityBitmap(plt);
            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);
        }
コード例 #3
0
ファイル: Text.cs プロジェクト: yongmingxia/ScottPlot
        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(400, 300);

            // start with default settings
            var txt = new ScottPlot.Plottable.Text()
            {
                Label = "hello", FontSize = 12
            };

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

            // change the plottable
            txt.FontBold = true;
            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.IsDarkerThan(before));
        }
コード例 #4
0
ファイル: Text.cs プロジェクト: yongmingxia/ScottPlot
        public void Test_Text_FontSize()
        {
            var plt = new ScottPlot.Plot(400, 300);

            // start with default settings
            var txt = new ScottPlot.Plottable.Text()
            {
                Label = "hello", FontSize = 12
            };

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

            // change the plottable
            txt.FontSize = 36;
            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.IsDarkerThan(before));
        }
コード例 #5
0
ファイル: Text.cs プロジェクト: yongmingxia/ScottPlot
        public void Test_Text_FontColor()
        {
            var plt = new ScottPlot.Plot(400, 300);

            // start with default settings
            var txt = new ScottPlot.Plottable.Text()
            {
                Label = "hello", Color = System.Drawing.Color.Gray
            };

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

            // change the plottable
            txt.Color = System.Drawing.Color.Blue;
            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(before.IsGray());
            Assert.That(after.IsNotGray());
            Assert.That(after.IsMoreBlueThan(before));
        }
コード例 #6
0
ファイル: Scatter.cs プロジェクト: Jmerk523/ScottPlot
        public void Test_Scatter_ChangeOnlyYErrorData()
        {
            var plt = new ScottPlot.Plot();

            // set errorY but NOT errorX
            double[] xs   = { 1, 2, 3, 4 };
            double[] ys   = { 1, 4, 9, 16 };
            double[] yErr = { .5, .5, 1, 1 };
            var      splt = new ScatterPlot(xs, ys, errorY: yErr)
            {
            };

            plt.Add(splt);
            var bmp = TestTools.GetLowQualityBitmap(plt);

            Console.WriteLine(new MeanPixel(bmp));

            Assert.That(bmp != null);
        }
コード例 #7
0
        /// <summary>
        /// Return a new Plot with all the same Plottables (and some of the styles) of this one.
        /// This is called when you right-click a plot in a control and hit "open in new window".
        /// </summary>
        public Plot Copy()
        {
            Settings oldSettings = settings;
            Plot     oldPlot     = this;

            Plot newPlot = new Plot(oldSettings.Width, oldSettings.Height);

            foreach (IPlottable oldPlottable in oldPlot.GetPlottables())
            {
                newPlot.Add(oldPlottable);
            }
            newPlot.AxisAuto();

            newPlot.XLabel(oldSettings.XAxis.Label());
            newPlot.YLabel(oldSettings.YAxis.Label());
            newPlot.Title(oldSettings.XAxis2.Label());

            return(newPlot);
        }
コード例 #8
0
        public void Test_ScaleBar_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);

            // create plot with generic scalebar settings
            plt.PlotSignal(DataGen.Sin(51));
            plt.PlotSignal(DataGen.Cos(51));
            var sb = new PlottableScaleBar()
            {
                Width           = 5,
                Height          = .25,
                VerticalLabel   = "5 V",
                HorizontalLabel = "250 ms"
            };

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

            // customize the scalebar
            sb.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));
        }
コード例 #9
0
        public void Test_AxisLine_ChangesPosition()
        {
            var plt = new ScottPlot.Plot();

            // start with default settings
            var axLine = new HLine()
            {
                position = 1.23
            };

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

            // change the plottable
            axLine.position += 1;
            var bmp2 = TestTools.GetLowQualityBitmap(plt);

            // measure what changed
            //TestTools.SaveFig(bmp1, "1");
            //TestTools.SaveFig(bmp2, "2");
            Assert.AreNotEqual(ScottPlot.Tools.BitmapHash(bmp1), ScottPlot.Tools.BitmapHash(bmp2));
        }
コード例 #10
0
        public void Test_Finance_AutoWidth()
        {
            var plt = new ScottPlot.Plot();

            plt.AntiAlias(false, false, false);

            // start with default settings
            var op = new PlottableOHLC()
            {
                Candle = true,
                ohlcs  = new OHLC[]
                {
                    // open, high, low, close, time, timeSpan
                    new OHLC(273, 275, 264, 265, 1, 1),
                    new OHLC(267, 276, 265, 274, 4, 1),
                    new OHLC(277, 280, 275, 278, 7, 1),
                    new OHLC(267, 276, 265, 274, 10, 1),
                }
            };

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

            // change the plottable
            op.AutoWidth = 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));
        }
コード例 #11
0
ファイル: AxisLine.cs プロジェクト: wheregone/ScottPlot
        public void Test_AxisLine_ChangesPosition()
        {
            var plt = new ScottPlot.Plot();

            plt.AntiAlias(false, false, false);

            // start with default settings
            var axLine = new PlottableHLine()
            {
                position = 1.23
            };

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

            // change the plottable
            axLine.position += 1;
            var bmp2 = new System.Drawing.Bitmap(plt.GetBitmap(renderFirst: true));

            // measure what changed
            //TestTools.SaveFig(bmp1, "1");
            //TestTools.SaveFig(bmp2, "2");
            Assert.AreNotEqual(ScottPlot.Tools.BitmapHash(bmp1), ScottPlot.Tools.BitmapHash(bmp2));
        }
コード例 #12
0
        public void Test_PlottablePopulations_MultiSeries()
        {
            // This example will display age, grouped by location, and by year.
            // This example has 3 series (years), each of which has 5 population objects (locations).

            // for this example we will simulate countries by creating random data
            Random rand = new Random(0);

            // start by collecting series data as Population[] arrays
            var ages1957 = new Population[]
            {
                new Population(rand, 54, 42, 4), // africa
                new Population(rand, 35, 56, 6), // americas
                new Population(rand, 48, 47, 5), // asia
                new Population(rand, 44, 66, 2), // europe
                new Population(rand, 14, 70, 1), // oceania
            };

            var ages1987 = new Population[]
            {
                new Population(rand, 54, 52, 8), // africa
                new Population(rand, 35, 70, 3), // americas
                new Population(rand, 48, 66, 3), // asia
                new Population(rand, 44, 75, 2), // europe
                new Population(rand, 14, 75, 1), // oceania
            };

            var ages2007 = new Population[]
            {
                new Population(rand, 54, 53, 5), // africa
                new Population(rand, 35, 72, 3), // americas
                new Population(rand, 48, 72, 4), // asia
                new Population(rand, 44, 78, 2), // europe
                new Population(rand, 14, 81, 1), // oceania
            };

            // now create a PopulationSeries object for each series
            string[] groupLabels = new string[] { "Africa", "Americas", "Asia", "Europe", "Oceania" };
            var      series1957  = new PopulationSeries(ages1957, "1957", color: System.Drawing.Color.Red);
            var      series1987  = new PopulationSeries(ages1987, "1987", color: System.Drawing.Color.Green);
            var      series2007  = new PopulationSeries(ages2007, "2007", color: System.Drawing.Color.Blue);

            // now collect all the series into a MultiSeries
            var multiSeries          = new PopulationSeries[] { series1957, series1987, series2007 };
            var plottableMultiSeries = new PopulationMultiSeries(multiSeries);
            var customPlottable      = new PopulationPlot(plottableMultiSeries);

            // plot the multi-series
            var plt = new ScottPlot.Plot();

            plt.Add(customPlottable);
            plt.XTicks(labels: groupLabels);
            plt.XAxis.TickLabelStyle(fontSize: 18);
            plt.YAxis.TickLabelStyle(fontSize: 18);

            // additional plot styling
            plt.XAxis2.Label(label: "Life Expectancy", size: 26);
            plt.YAxis.Label(label: "Age (years)", size: 18);
            plt.Legend(location: Alignment.LowerRight);
            plt.Grid(lineStyle: LineStyle.Dot);
            plt.XAxis.Grid(false);

            TestTools.SaveFig(plt);
        }