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)); }
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)); }
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); }
public void Test_Bar_ChangingValues() { 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); var bmp1 = new System.Drawing.Bitmap(plt.GetBitmap(renderFirst: true)); // change the plottable bar.ys[0] += 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)); }
public void Test_AxisLine_LineWidth() { 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.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)); }
public void Test_AxisSpan_Alpha() { var plt = new ScottPlot.Plot(); plt.AntiAlias(false, false, false); // start with default settings var axSpan = new PlottableHSpan() { position1 = 1.23, position2 = 2.34 }; plt.Add(axSpan); var bmp1 = new System.Drawing.Bitmap(plt.GetBitmap(renderFirst: true)); // change the plottable axSpan.alpha /= 2; 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.IsLighterThan(before)); }
public void Test_ScaleBar_Default() { var plt = new ScottPlot.Plot(); plt.AntiAlias(false, false, false); // start plot without scalebar plt.PlotSignal(DataGen.Sin(51)); plt.PlotSignal(DataGen.Cos(51)); var bmp1 = new System.Drawing.Bitmap(plt.GetBitmap(renderFirst: true)); // add a scalebar var sb = new PlottableScaleBar() { Width = 5, Height = .25, VerticalLabel = "5 V", HorizontalLabel = "250 ms" }; plt.Add(sb); 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)); }
public void Test_ErrorBar_LineWidth() { var plt = new ScottPlot.Plot(); plt.AntiAlias(false, false, false); // start with default settings double[] xs = new double[] { 1, 3, 2, 4 }; double[] ys = new double[] { 1, 3, 2, 4 }; double[] xErrNeg = new double[] { .2, .2, .2, .2 }; double[] xErrPos = new double[] { .2, .2, .2, .2 }; double[] yErrNeg = new double[] { 1, 1, 1, 1 }; double[] yErrPos = new double[] { 1, 1, 1, 1 }; var err = new PlottableErrorBars(xs, ys, xErrPos, xErrNeg, yErrPos, yErrNeg) { }; plt.Add(err); var bmp1 = new System.Drawing.Bitmap(plt.GetBitmap(renderFirst: true)); // change the plottable err.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)); }
public void Test_ScaleBar_FontColor() { 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.FontColor = 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(after.IsMoreBlueThan(before)); }
public void Test_Scatter_LineWidth() { var plt = new ScottPlot.Plot(); plt.AntiAlias(false, false, false); // start with default settings double[] xs = { 1, 2, 3, 4 }; double[] ys = { 1, 4, 9, 16 }; double[] xErr = { .15, .15, .5, .5 }; double[] yErr = { .5, .5, 1, 1 }; var splt = new PlottableScatter(xs, ys, xErr, yErr) { }; plt.Add(splt); var bmp1 = new System.Drawing.Bitmap(plt.GetBitmap(renderFirst: true)); // change the plottable splt.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)); }
public void Test_Annotation_ShadowColor() { var plt = new ScottPlot.Plot(); plt.AntiAlias(false, false, false); // start with default settings var pa = new PlottableAnnotation() { label = "Hello", xPixel = 10, yPixel = 10 }; plt.Add(pa); var bmp1 = new System.Drawing.Bitmap(plt.GetBitmap(renderFirst: true)); // change the plottable pa.ShadowColor = System.Drawing.Color.Black; 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)); }
public void Test_function_LineStyle() { 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.lineStyle = LineStyle.Dash; 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.IsLighterThan(before)); }
public void Test_FigureBackground_SupportsTransparency() { var plt = new ScottPlot.Plot(600, 400); plt.PlotSignal(DataGen.Sin(51)); var mean1 = TestTools.MeanPixel(plt.GetBitmap()); plt.Style(figBg: Color.Transparent); var mean2 = TestTools.MeanPixel(plt.GetBitmap()); Assert.Less(mean2.A, mean1.A); }
public void Test_Axis_ExtremelySmallSpan() { var plt = new ScottPlot.Plot(600, 400); plt.PlotLine(0, 1, 1, 1.0000000000000001); plt.GetBitmap(); }
public void Test_Legend_Style() { var plt1 = new ScottPlot.Plot(600, 400); plt1.PlotScatter(DataGen.Sin(10), DataGen.Sin(10), label: "sin", color: Color.Black, lineWidth: 1); plt1.Legend(); var mean1 = TestTools.MeanPixel(plt1.GetBitmap()); var plt2 = new ScottPlot.Plot(600, 400); plt2.PlotScatter(DataGen.Sin(10), DataGen.Sin(10), label: "sin", color: Color.Black, lineWidth: 2); plt2.Legend(); var mean2 = TestTools.MeanPixel(plt2.GetBitmap()); // thicker line means darker pixel intensity Assert.Less(mean2.R, mean1.R); var plt3 = new ScottPlot.Plot(600, 400); plt3.PlotScatter(DataGen.Sin(10), DataGen.Sin(10), label: "sin", color: Color.Gray, lineWidth: 2); plt3.Legend(); var mean3 = TestTools.MeanPixel(plt3.GetBitmap()); // lighter color means greater pixel intensity Assert.Greater(mean3.R, mean2.R); }
public void Render(bool skipIfCurrentlyRendering = false, bool lowQuality = false, bool recalculateLayout = false, bool processEvents = false) { if (!isDesignerMode) { if (recalculateLayout) { plt.TightenLayout(); } if (equalAxes) { plt.AxisEqual(); } if (!(skipIfCurrentlyRendering && currentlyRendering)) { currentlyRendering = true; imagePlot.Source = BmpImageFromBmp(plt.GetBitmap(true, lowQuality || lowQualityAlways)); if (isPanningOrZooming || isMovingDraggable || processEvents) { DoEvents(); } currentlyRendering = false; Rendered?.Invoke(null, null); } } }
public void Render(bool skipIfCurrentlyRendering = false, bool lowQuality = false) { if (Process.GetCurrentProcess().ProcessName == "devenv") { try { pbPlot.Image = Tools.DesignerModeBitmap(pbPlot.Size); } catch { pbPlot.BackColor = Color.Red; } return; } lastInteractionTimer?.Stop(); if (!(skipIfCurrentlyRendering && currentlyRendering)) { currentlyRendering = true; pbPlot.Image = plt.GetBitmap(true, lowQuality); if (plt.mouseTracker.IsDraggingSomething()) { Application.DoEvents(); } currentlyRendering = false; } }
public void Render(bool skipIfCurrentlyRendering = false, bool lowQuality = false) { if (System.ComponentModel.LicenseManager.UsageMode == System.ComponentModel.LicenseUsageMode.Designtime) { try { System.Drawing.Size controlPixelSize = new System.Drawing.Size(scaledWidth, scaledHeight); System.Drawing.Bitmap bmp = Tools.DesignerModeBitmap(controlPixelSize); imagePlot.Source = Tools.bmpImageFromBmp(bmp); } catch { } return; } if (!(skipIfCurrentlyRendering && currentlyRendering)) { if (timer.IsEnabled) { timer.Stop(); } currentlyRendering = true; imagePlot.Source = Tools.bmpImageFromBmp(plt.GetBitmap(true, lowQuality)); currentlyRendering = false; } }
public void Test_FigureBackground_DefaultIsOpaqueWhite() { var plt = new ScottPlot.Plot(600, 400); plt.PlotSignal(DataGen.Sin(51)); var mean1 = TestTools.MeanPixel(plt.GetBitmap()); plt.Style(figBg: Color.White); var mean2 = TestTools.MeanPixel(plt.GetBitmap()); Assert.AreEqual(mean2.A, mean1.A); Assert.AreEqual(mean2.R, mean1.R); Assert.AreEqual(mean2.G, mean1.G); Assert.AreEqual(mean2.B, mean1.B); }
// Disabled because this test fails on Linux and MacOS due to a System.Drawing limitation //[Test] public void Test_Legend_Bold() { var plt = new ScottPlot.Plot(600, 400); plt.PlotScatter(DataGen.Consecutive(51), DataGen.Sin(51), label: "sin"); plt.PlotScatter(DataGen.Consecutive(51), DataGen.Cos(51), label: "cos"); plt.Legend(); var meanRegular = TestTools.MeanPixel(plt.GetBitmap()); plt.Legend(bold: true); var meanBold = TestTools.MeanPixel(plt.GetBitmap()); // bold text will darken the mean pixel intensity Assert.Less(meanBold.R, meanRegular.R); }
public void Test_RGB_analysis() { Random rand = new Random(0); double[] ys = DataGen.RandomWalk(rand, 100); var plt = new ScottPlot.Plot(400, 300); plt.Style(figBg: System.Drawing.Color.Gray, dataBg: System.Drawing.Color.Gray); plt.PlotSignal(ys, yOffset: 0, color: System.Drawing.Color.FromArgb(255, 0, 0), label: "red", lineWidth: 2); plt.PlotSignal(ys, yOffset: 1, color: System.Drawing.Color.FromArgb(0, 255, 0), label: "green", lineWidth: 3); plt.PlotSignal(ys, yOffset: 2, color: System.Drawing.Color.FromArgb(0, 0, 255), label: "blue", lineWidth: 4); plt.PlotSignal(ys, yOffset: 3, color: System.Drawing.Color.FromArgb(0, 0, 0), label: "black"); plt.PlotSignal(ys, yOffset: 4, color: System.Drawing.Color.FromArgb(255, 255, 255), label: "white"); plt.Legend(); System.Drawing.Bitmap bmp = plt.GetBitmap(); var means = MeanPixel(bmp); Console.WriteLine($"mean bitmap intensity (ARGB): {means.A}, {means.R}, {means.G}, {means.B}"); // mean bitmap intensity (ARGB): 255, 123.4157, 124.8481, 126.327066666667 Assert.AreEqual(means.A, 255); // image is not transparent Assert.Greater(means.B, means.G); // blue line is thicker than green line Assert.Greater(means.G, means.R); // green line is thicker than red line }
public void Test_FigureBackground_ColorCanBeSet() { var plt = new ScottPlot.Plot(600, 400); plt.PlotSignal(DataGen.Sin(51)); var mean1 = TestTools.MeanPixel(plt.GetBitmap()); plt.Style(figBg: Color.Blue); var mean2 = TestTools.MeanPixel(plt.GetBitmap()); // we made the background white->blue, meaning we preserved blue while reducing red and green Assert.AreEqual(mean2.A, mean1.A); Assert.Less(mean2.R, mean1.R); Assert.Less(mean2.G, mean1.G); Assert.AreEqual(mean2.B, mean1.B); }
public void Test_Benchmark_Toggle() { var plt = new ScottPlot.Plot(600, 400); plt.PlotSignal(DataGen.Sin(51)); var meanDefault = TestTools.MeanPixel(plt.GetBitmap()); plt.Benchmark(toggle: true); var meanBenchOn = TestTools.MeanPixel(plt.GetBitmap()); plt.Benchmark(toggle: true); var meanBenchOff = TestTools.MeanPixel(plt.GetBitmap()); // appearance of the benchmark will lessen mean pixel intensity Assert.AreEqual(meanDefault.R, meanBenchOff.R); Assert.Less(meanBenchOn.R, meanDefault.R); }
public void Test_Legend_Render() { var plt = new ScottPlot.Plot(600, 400); plt.PlotScatter(DataGen.Consecutive(51), DataGen.Sin(51), label: "sin"); plt.PlotScatter(DataGen.Consecutive(51), DataGen.Cos(51), label: "cos"); var mean1 = TestTools.MeanPixel(plt.GetBitmap()); plt.Legend(); var mean2 = TestTools.MeanPixel(plt.GetBitmap()); // the legend should darken the mean pixel intensity Assert.AreEqual(mean2.A, mean1.A); Assert.Less(mean2.R, mean1.R); Assert.Less(mean2.G, mean1.G); Assert.Less(mean2.B, mean1.B); }
public void Render(bool skipIfCurrentlyRendering = false) { if (!(skipIfCurrentlyRendering && currentlyRendering)) { currentlyRendering = true; imagePlot.Source = Tools.bmpImageFromBmp(plt.GetBitmap()); currentlyRendering = false; } }
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)); }
public void Render(bool skipIfCurrentlyRendering = false, bool lowQuality = false) { if (!isDesignerMode) { if (!(skipIfCurrentlyRendering && currentlyRendering)) { currentlyRendering = true; imagePlot.Source = BmpImageFromBmp(plt.GetBitmap(true, lowQuality)); currentlyRendering = false; } } }
public void Render(bool skipIfCurrentlyRendering = false, bool lowQuality = false) { if (!(skipIfCurrentlyRendering && currentlyRendering)) { currentlyRendering = true; pbPlot.Image = plt.GetBitmap(true, lowQuality); if (plt.mouseTracker.IsDraggingSomething()) { Application.DoEvents(); } currentlyRendering = false; } }
public void Render(bool skipIfCurrentlyRendering = false, bool lowQuality = false) { if (!(skipIfCurrentlyRendering && currentlyRendering)) { if (timer.IsEnabled) { timer.Stop(); } currentlyRendering = true; imagePlot.Source = Tools.bmpImageFromBmp(plt.GetBitmap(true, lowQuality)); currentlyRendering = false; } }
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)); }