public static IPlotDemo GetPlot(string plotObjectPath) { if (!plotObjectPath.StartsWith("ScottPlot.Demo.")) { throw new ArgumentException("plot object path must start with 'ScottPlot.Demo.'"); } var type = Type.GetType(plotObjectPath); IPlotDemo demoPlot = (IPlotDemo)Activator.CreateInstance(type); return(demoPlot); }
/// <summary> /// Render the given demo plot and save it as a PNG file /// </summary> public void CreateImage(IPlotDemo recipe) { string imageFilePath = $"{outputFolder}/images/{recipe.id}.png"; if (recipe is IBitmapDemo bmpDemo) { System.Drawing.Bitmap bmp = bmpDemo.Render(width, height); bmp.Save(imageFilePath, System.Drawing.Imaging.ImageFormat.Png); } else { var plt = new Plot(width, height); recipe.Render(plt); plt.SaveFig(imageFilePath); } }
public static IPlotDemo[] GetPlots(string namespaceStartsWith = "ScottPlot.Demo.") { var plotObjectPaths = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(s => s.GetTypes()) .Where(p => typeof(IPlotDemo).IsAssignableFrom(p)) .Where(p => p.IsInterface == false) .Where(p => p.ToString().StartsWith(namespaceStartsWith)) .Select(x => x.ToString()) .ToArray(); IPlotDemo[] plots = new IPlotDemo[plotObjectPaths.Length]; for (int i = 0; i < plotObjectPaths.Length; i++) { plots[i] = GetPlot(plotObjectPaths[i]); } return(plots); }
/// <summary> /// Render the given demo plot and save it as a PNG file /// </summary> public void CreateImage(IPlotDemo recipe) { string imageFilePath = $"{outputFolder}/images/{recipe.id}.png"; if (recipe is IBitmapDemo bmpDemo) { System.Drawing.Bitmap bmp = bmpDemo.Render(width, height); bmp.Save(imageFilePath, System.Drawing.Imaging.ImageFormat.Png); } else { Plot plt; if (recipe.categoryMinor == "AllColormaps" || recipe.categoryMinor == "CustomColormap") { plt = new Plot(width, 100); } else { plt = new Plot(width, height); } recipe.Render(plt); plt.SaveFig(imageFilePath); } }