public void CopySvg() { var rc = new ShapesRenderContext(null); var svg = SvgExporter.ExportToString(this.Model, this.Plot.ActualWidth, this.Plot.ActualHeight, true, rc); Clipboard.SetText(svg); }
public static string ExportToSvgString(PlotModel model, double width, double height, bool isDocument) { var ex = new OxyPlot.SvgExporter() { Width = width, Height = height, IsDocument = isDocument }; var svg = ex.ExportToString(model); return(isDocument ? svg : RemoveHtmlHeaderFromSvg(svg)); }
public void TestMsFeatureScatterPlot(string path1, string path2, string pngPath) { // Convert relative paths to absolute paths path1 = GetPath(path1); path2 = GetPath(path2); pngPath = GetPath(pngPath); var fiOutput = new FileInfo(pngPath); var didirectory = fiOutput.Directory; if (didirectory == null) throw new DirectoryNotFoundException(pngPath); if (!didirectory.Exists) didirectory.Create(); var aligner = new LcmsWarpFeatureAligner(); var baselineMs = UmcLoaderFactory.LoadMsFeatureData(path1); var aligneeMs = UmcLoaderFactory.LoadMsFeatureData(path2); var finder = FeatureFinderFactory.CreateFeatureFinder(FeatureFinderType.TreeBased); var tolerances = new FeatureTolerances { FragmentationWindowSize = .5, Mass = 13, DriftTime = .3, Net = .01 }; var options = new LcmsFeatureFindingOptions(tolerances); options.MaximumNetRange = .002; var baseline = finder.FindFeatures(baselineMs, options, null); var alignee = finder.FindFeatures(aligneeMs, options, null); var alignmentResults = aligner.Align(baseline, alignee); var plotModel1 = new PlotModel { Subtitle = "Interpolated, cartesian axes", Title = "HeatMapSeries" }; var palette = OxyPalettes.Hot(200); var linearColorAxis1 = new LinearColorAxis { InvalidNumberColor = OxyColors.Gray, Position = AxisPosition.Right, Palette = palette }; plotModel1.Axes.Add(linearColorAxis1); // linearColorAxis1. var linearAxis1 = new LinearAxis {Position = AxisPosition.Bottom}; plotModel1.Axes.Add(linearAxis1); var linearAxis2 = new LinearAxis(); plotModel1.Axes.Add(linearAxis2); var heatMapSeries1 = new HeatMapSeries { X0 = 0, X1 = 1, Y0 = 0, Y1 = 1, FontSize = .2 }; var scores = alignmentResults.heatScores; var width = scores.GetLength(0); var height = scores.GetLength(1); heatMapSeries1.Data = new double[width, height]; var seriesData = heatMapSeries1.Data; for (var i = 0; i < width; i++) { for (var j = 0; j < height; j++) { seriesData[i, j] = Convert.ToDouble(scores[i, j]); } } plotModel1.Series.Add(heatMapSeries1); var svg = new SvgExporter(); var svgString = svg.ExportToString(plotModel1); var xml = new XmlDocument(); xml.LoadXml(svgString); var x = SvgDocument.Open(xml); // Svg.SvgDocument(); var bmp = x.Draw(); bmp.Save(pngPath); var heatmap = HeatmapFactory.CreateAlignedHeatmap(alignmentResults.heatScores); var netHistogram = HistogramFactory.CreateHistogram(alignmentResults.netErrorHistogram, "NET Error", "NET Error"); var massHistogram = HistogramFactory.CreateHistogram(alignmentResults.massErrorHistogram, "Mass Error", "Mass Error (ppm)"); var baseName = Path.Combine(didirectory.FullName, Path.GetFileNameWithoutExtension(fiOutput.Name)); var encoder = new SvgEncoder(); PlotImageUtility.SaveImage(heatmap, baseName + "_heatmap.svg", encoder); PlotImageUtility.SaveImage(netHistogram, baseName + "_netHistogram.svg", encoder); PlotImageUtility.SaveImage(massHistogram, baseName + "_massHistogram.svg", encoder); }
public void TestSimpleCreation() { var random = new Random(); var points = new List<int> {100, 1000, 10000, 100000}; foreach (var totalPoints in points) { var start = DateTime.Now; var plotModel1 = new PlotModel {Subtitle = "No 'binning'", Title = "ScatterSeries (n=32768)"}; var linearAxis1 = new LinearAxis {Position = AxisPosition.Bottom}; plotModel1.Axes.Add(linearAxis1); var linearAxis2 = new LinearAxis(); plotModel1.Axes.Add(linearAxis2); var scatterSeries1 = new ScatterSeries { MarkerSize = 1, MarkerStrokeThickness = 0, MarkerType = MarkerType.Diamond, Title = "Series 1" + totalPoints }; var pointList = new List<ScatterPoint>(); for (var i = 0; i < totalPoints; i++) { var point = new ScatterPoint { X = random.NextDouble(), Y = random.NextDouble() }; pointList.Add(point); } Console.WriteLine(); var end = DateTime.Now; Console.WriteLine("Creation Part of Test Took: {0:.00} seconds for {1} points", end.Subtract(start).TotalSeconds, totalPoints); start = DateTime.Now; scatterSeries1.Points.AddRange(pointList); plotModel1.Series.Add(scatterSeries1); end = DateTime.Now; Console.WriteLine("Scatter Plot Part of Test Took: {0:.00} seconds for {1} points", end.Subtract(start).TotalSeconds, totalPoints); start = DateTime.Now; var svg = new SvgExporter(); var svgString = svg.ExportToString(plotModel1); var xml = new XmlDocument(); xml.LoadXml(svgString); var x = SvgDocument.Open(xml); // Svg.SvgDocument(); var bmp = x.Draw(); var outputFilePath = GetPath(@"testResults\ScatterPlot\testScatter" + totalPoints + ".jpg"); bmp.Save(outputFilePath); end = DateTime.Now; Console.WriteLine("Saving Part of Test Took: {0:.00} seconds for {1} points", end.Subtract(start).TotalSeconds, totalPoints); } }
/// <summary> /// Create an svg model and return it as a string. /// </summary> /// <param name="width">The width (points).</param> /// <param name="height">The height (points).</param> /// <param name="isDocument">if set to <c>true</c>, the xml headers will be included (?xml and !DOCTYPE).</param> /// <param name="textMeasurer">The text measurer.</param> /// <returns>The svg string.</returns> public string ToSvg(double width, double height, bool isDocument, IRenderContext textMeasurer) { return(SvgExporter.ExportToString(this, width, height, isDocument, textMeasurer)); }
public void TestLcmsWarpAlignment(string path1, string path2, string svgPath) { // Convert relative paths to absolute paths path1 = GetPath(path1); path2 = GetPath(path2); svgPath = GetPath(HEATMAP_RESULTS_FOLDER_BASE + svgPath); var aligner = new LcmsWarpFeatureAligner(); var baselineMs = UmcLoaderFactory.LoadMsFeatureData(path1); var aligneeMs = UmcLoaderFactory.LoadMsFeatureData(path2); var finder = FeatureFinderFactory.CreateFeatureFinder(FeatureFinderType.TreeBased); var tolerances = new FeatureTolerances { FragmentationWindowSize = .5, Mass = 13, DriftTime = .3, Net = .01 }; var options = new LcmsFeatureFindingOptions(tolerances) { MaximumNetRange = .002 }; var baseline = finder.FindFeatures(baselineMs, options, null); var alignee = finder.FindFeatures(aligneeMs, options, null); var data = aligner.Align(baseline, alignee); var plotModel1 = new PlotModel { Subtitle = "Interpolated, cartesian axes", Title = "HeatMapSeries" }; var palette = OxyPalettes.Hot(200); var linearColorAxis1 = new LinearColorAxis { InvalidNumberColor = OxyColors.Gray, Position = AxisPosition.Right, Palette = palette }; plotModel1.Axes.Add(linearColorAxis1); // linearColorAxis1. var linearAxis1 = new LinearAxis {Position = AxisPosition.Bottom}; plotModel1.Axes.Add(linearAxis1); var linearAxis2 = new LinearAxis(); plotModel1.Axes.Add(linearAxis2); var heatMapSeries1 = new HeatMapSeries { X0 = 0, X1 = 1, Y0 = 0, Y1 = 1, FontSize = .2 }; var scores = data.heatScores; var width = scores.GetLength(0); var height = scores.GetLength(1); heatMapSeries1.Data = new double[width, height]; for (var i = 0; i < width; i++) { for (var j = 0; j < height; j++) { heatMapSeries1.Data[i, j] = Convert.ToDouble(scores[i, j]); } } plotModel1.Series.Add(heatMapSeries1); var svg = new SvgExporter(); var svgString = svg.ExportToString(plotModel1); using (var writer = File.CreateText(svgPath + ".svg")) { writer.Write(svgString); } }
public void TestSimpleCreation() { var plotModel1 = new PlotModel { PlotType = PlotType.Cartesian, Subtitle = "Interpolated, cartesian axes", Title = "HeatMapSeries" }; var palette = OxyPalettes.Hot(200); var linearColorAxis1 = new LinearColorAxis { InvalidNumberColor = OxyColors.Gray, Position = AxisPosition.Right, Palette = palette }; plotModel1.Axes.Add(linearColorAxis1); var linearAxis1 = new LinearAxis {Position = AxisPosition.Bottom}; plotModel1.Axes.Add(linearAxis1); var linearAxis2 = new LinearAxis(); plotModel1.Axes.Add(linearAxis2); var heatMapSeries1 = new HeatMapSeries { X0 = 0.0, X1 = 1.0, Y0 = 0.0, Y1 = 1.0, FontSize = .2, Data = new Double[2, 3] }; //heatMapSeries1.LabelFontSize = 0.2; heatMapSeries1.Data[0, 0] = 0; heatMapSeries1.Data[0, 1] = 10.2; heatMapSeries1.Data[0, 2] = 20.4; heatMapSeries1.Data[1, 0] = 0.1; heatMapSeries1.Data[1, 1] = 0.3; heatMapSeries1.Data[1, 2] = 0.2; plotModel1.Series.Add(heatMapSeries1); var svg = new SvgExporter(); var svgString = svg.ExportToString(plotModel1); var xml = new XmlDocument(); xml.LoadXml(svgString); var x = SvgDocument.Open(xml); // Svg.SvgDocument(); var bmp = x.Draw(); bmp.Save(GetPath(HEATMAP_RESULTS_FOLDER_BASE + "testbmp.jpg")); var encoder = new PngPlotModelEncoder(); encoder.SaveImage(plotModel1, GetPath(HEATMAP_RESULTS_FOLDER_BASE + "mine.png")); }