private void Save_OnClick(object sender, RoutedEventArgs e)
    {
        var vm  = (StatisticsViewModel)DataContext;
        var sfd = new SaveFileDialog
        {
            Filter           = "Scalable Vector Graphics (*.svg)|*.svg|Portable Network Graphics (*.png)|*.png",
            InitialDirectory = vm.WorkingDir
        };

        if (sfd.ShowDialog(this) != true)
        {
            return;
        }
        var filename = sfd.FileName;

        switch (Path.GetExtension(filename))
        {
        case ".svg":
            new SvgExporter
            {
                Width  = Settings.Instance.ExportWidth,
                Height = Settings.Instance.ExportHeight,
                Dpi    = Settings.Instance.ExportDPI
            }.Export(vm.PlotModel, File.Create(filename));
            break;

        case ".png":
            PngExporter.Export(vm.PlotModel, File.Create(filename), (int)Settings.Instance.ExportWidth, (int)Settings.Instance.ExportHeight, Settings.Instance.ExportDPI);
            break;

        default: throw new InvalidOperationException();
        }
    }
Exemplo n.º 2
0
        /// <summary>
        /// Export the graph to the specified 'bitmap'
        /// </summary>
        /// <param name="bitmap">Bitmap to write to</param>
        /// <param name="legendOutside">Put legend outside of graph?</param>
        public void Export(ref Bitmap bitmap, Rectangle r, bool legendOutside)
        {
            //TODO: This will only save the last bitmap. Might need to change the interface.
            foreach (PlotView plot in plots)
            {
                ///DockStyle saveStyle = plot.Dock;
                ///plot.Dock = DockStyle.None;
                ///plot.Width = bitmap.Width;
                ///plot.Height = bitmap.Height;

                LegendPosition savedLegendPosition = LegendPosition.RightTop;
                if (legendOutside)
                {
                    savedLegendPosition        = plot.Model.LegendPosition;
                    plot.Model.LegendPlacement = LegendPlacement.Outside;
                    plot.Model.LegendPosition  = LegendPosition.RightTop;
                }

                System.IO.MemoryStream stream      = new System.IO.MemoryStream();
                PngExporter            pngExporter = new PngExporter();
                pngExporter.Width  = r.Width;
                pngExporter.Height = r.Height;
                pngExporter.Export(plot.Model, stream);
                bitmap = new Bitmap(stream);

                if (legendOutside)
                {
                    plot.Model.LegendPlacement = LegendPlacement.Inside;
                    plot.Model.LegendPosition  = savedLegendPosition;
                }

                // plot.Dock = saveStyle;
            }
        }
Exemplo n.º 3
0
        public async Task SendEmail(Student student, List <Grade> grades)
        {
            var gradesTable = GenerateGradesTable(grades, student.OverallGrade);

            var studentSubject = string.Format(STUDENT_SUBJECT, student.FullName);

            //todo: this pull grades from the DB a second time, maybe an overload that just takes grades
            var chart = _chartGenerator.ChartByTests(student);

            using (var memoryStream = new MemoryStream())
            {
                var pngExporter = new PngExporter {
                    Width = grades.Count * 256, Height = 700
                };
                pngExporter.Export(chart, memoryStream);

                var gradesChart = new LinkedResource(memoryStream, "image/png");

                gradesChart.ContentStream.Position = 0;

                gradesChart.ContentId = Guid.NewGuid().ToString();

                await SendEmail(student.ParentEmailAddress, student.EmailAddress, studentSubject, gradesTable, null,
                                gradesChart);
            }
        }
Exemplo n.º 4
0
        public void plotCurrent(int iteration)
        {
            var myModel = new PlotModel {
                Title = "Example 1"
            };
            var scatterSeries = new ScatterSeries {
                MarkerType = MarkerType.Circle
            };

            for (int i = 0; i < K; i++)
            {
                var currentColorValue = new Hsl {
                    H = i * 50, S = 50, L = 50
                };
                var clus = vectorToCluster.Where(x => x.Value == i).Select(x => x.Key).ToList();
                foreach (var v in clus)
                {
                    scatterSeries.Points.Add(new ScatterPoint(v[0], v[1], 1, i));
                }
            }

            int index = 0;

            foreach (var v in this.centroids)
            {
                scatterSeries.Points.Add(new ScatterPoint(v[0], v[1], 3, index));
                index++;
            }
            myModel.Axes.Add(new LinearColorAxis {
                Position = AxisPosition.None, Minimum = 0.1, Maximum = 0.9, HighColor = OxyColors.Red, LowColor = OxyColors.Black
            });
            myModel.Series.Add(scatterSeries);
            PngExporter.Export(myModel, String.Format("{0}-plot.png", iteration), 800, 500);
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            var outputToFile          = "test-oxyplot-static-export-file.png";
            var outputExportStreamOOP = "test-oxyplot-export-stream.png";

            var width      = 1024;
            var height     = 768;
            var background = OxyColors.LightGray;
            var resolution = 96d;

            var model = BuildPlotModel();

            // export to file using static methods
            PngExporter.Export(model, outputToFile, width, height, background, resolution);

            // export using the instance methods
            using (var stream = new MemoryStream())
            {
                var pngExporter = new PngExporter {
                    Width = width, Height = height, Background = background, Resolution = resolution
                };
                pngExporter.Export(model, stream);
                System.IO.File.WriteAllBytes(outputExportStreamOOP, stream.ToArray());
            }
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            var pm = new PlotModel
            {
                Title = "Test"
            };

            pm.Axes.Add(new LinearAxis {
                Title = "Bottom", Position = AxisPosition.Bottom, AxisTitleDistance = 10
            });
            pm.Axes.Add(new LinearAxis {
                Title = "Left", Position = AxisPosition.Left
            });
            pm.Series.Add(new FunctionSeries(Math.Sin, 0, 10, 0.01));
            var e = new PngExporter();

            e.Width      = 800;
            e.Height     = 500;
            e.Background = OxyColors.LightBlue;
            var path = "test.png";

            using (var stream = File.Create(path))
                e.Export(pm, stream);
            // Process.Start(path);
        }
Exemplo n.º 7
0
 private void btnSaveGraph_Click(object sender, EventArgs e)
 {
     if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
     {
         PngExporter.Export(myModel, saveFileDialog.FileName, 800, 600, OxyColors.White);
     }
 }
        public void AddChartToPage(PlotModel model,
                                   Document pdfDoc,
                                   int width, int height,
                                   float spacingBefore   = 50,
                                   float spacingAfter    = 10,
                                   float widthPercentage = 80)
        {
            using (var chartimage = new MemoryStream())
            {
                //BMP gives the best compression result
                var pngExporter = new PngExporter {
                    Width = width, Height = height, Background = OxyColors.White
                };
                pngExporter.Export(model, chartimage);

                var imageBytes      = chartimage.ToArray();
                var iTextSharpImage = PdfImageHelper.GetITextSharpImageFromByteArray(imageBytes);
                iTextSharpImage.Alignment = Element.ALIGN_CENTER;

                var table = new PdfGrid(1)
                {
                    WidthPercentage = widthPercentage,
                    SpacingBefore   = spacingBefore,
                    SpacingAfter    = spacingAfter
                };
                table.AddCell(iTextSharpImage);

                pdfDoc.Add(table);
            }
        }
        /// <summary>
        /// The write plot.
        /// </summary>
        /// <param name="plot">The plot.</param>
        public void WritePlot(PlotFigure plot)
        {
            if (this.FileName == null)
            {
                return;
            }

            var directory = Path.GetDirectoryName(this.FileName);

            if (directory == null)
            {
                return;
            }

            var source = string.Format(
                "{0}_Plot{1}.png", Path.GetFileNameWithoutExtension(this.FileName), plot.FigureNumber);
            var sourceFullPath = Path.Combine(directory, source);

            // write to a png
            // todo: write to a stream, not to disk
            PngExporter.Export(plot.PlotModel, sourceFullPath, (int)plot.Width, (int)plot.Height, OxyColors.Automatic);

            // append the image to the document
            this.AppendImage(sourceFullPath, "Plot" + plot.FigureNumber);

            this.body.AppendChild(CreateParagraph(plot.GetFullCaption(this.style), FigureTextId));
        }
Exemplo n.º 10
0
        private string ExportToPng(BarSeries bar, CategoryAxis axis, string title, int fontSize = 18)
        {
            var model = new PlotModel {
                Title           = title,
                DefaultFontSize = fontSize
            };

            var max = bar.ItemsSource.Cast <BarItem>().Max(x => x.Value) + 10;

            bar.LabelPlacement = LabelPlacement.Inside;

            model.Series.Add(bar);
            model.Axes.Add(axis);


            var path = Path.Combine(Path.GetTempPath(), $"{ Guid.NewGuid().ToString("N")}.png");

            var pngExporter = new PngExporter {
                Width = 1400, Height = 600, Background = OxyColors.White
            };

            using (var stream = new FileStream(path, FileMode.Create)) {
                pngExporter.Export(model, stream);
                return(path);
            }
        }
Exemplo n.º 11
0
        static void Main(string[] args)
        {
            var outputToFile          = "test-oxyplot-static-export-file.png";
            var outputExportStreamOOP = "test-oxyplot-ExportToStream.png";
            var outputExportFileOOP   = "test-oxyplot-ExportToFile.png";

            var width      = 1024;
            var height     = 768;
            var background = OxyColors.LightGray;
            var resolution = 96d;

            var model = BuildPlotModel();

            // export to file using static methods
            PngExporter.Export(model, outputToFile, width, height, resolution);

            // export using the instance methods
            using (var stream = new MemoryStream())
            {
                var pngExporter = new PngExporter {
                    Width = width, Height = height, Resolution = resolution
                };
                pngExporter.Export(model, stream);
                System.IO.File.WriteAllBytes(outputExportStreamOOP, stream.ToArray());
            }

            var pngExporter2 = new PngExporter {
                Width = width, Height = height, Resolution = resolution
            };
            var bitmap = pngExporter2.ExportToBitmap(model);

            bitmap.Save(outputExportFileOOP, System.Drawing.Imaging.ImageFormat.Png);
            bitmap.Save(Path.ChangeExtension(outputExportFileOOP, ".gif"), System.Drawing.Imaging.ImageFormat.Gif);
        }
Exemplo n.º 12
0
        private static void MakeLinePlot([JetBrains.Annotations.NotNull] string outputPath, [ItemNotNull][JetBrains.Annotations.NotNull] List <Column> columns, int position, int day)
        {
            var p          = OxyPalettes.HueDistinct(columns.Count);
            var plotModel1 = new PlotModel
            {
                LegendPosition    = LegendPosition.BottomCenter,
                LegendPlacement   = LegendPlacement.Outside,
                LegendOrientation = LegendOrientation.Horizontal,
                Title             = "Day " + day
            };
            var linearAxis1 = new LinearAxis
            {
                Position = AxisPosition.Bottom
            };

            plotModel1.Axes.Add(linearAxis1);

            for (var i = 1; i < columns.Count; i++)
            {
                var lineSeries1 = new LineSeries
                {
                    Title = columns[i].HHNumber,
                    Color = p.Colors[i]
                };
                for (var j = position; j < position + 1440; j++)
                {
                    lineSeries1.Points.Add(new DataPoint(j, columns[i].Values[j]));
                }
                plotModel1.Series.Add(lineSeries1);
            }
            var path = Path.Combine(outputPath, "Plot." + day + ".line.png");

            PngExporter.Export(plotModel1, path, 3200, 1600, OxyColor.FromRgb(255, 255, 255), 100);
        }
Exemplo n.º 13
0
        void Copy_OnExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            var data = new DataObject();

            using (var ms = new MemoryStream())
            {
                var pngExporter = new PngExporter();
                pngExporter.Export(plot.Model, ms);

                var bitmap = new BitmapImage();
                bitmap.BeginInit();
                bitmap.StreamSource = ms;
                bitmap.CacheOption  = BitmapCacheOption.OnLoad;
                bitmap.EndInit();
                bitmap.Freeze();

                data.SetImage(bitmap);
            }

            var svg         = new MemoryStream();
            var svgExporter = new SvgExporter();

            svgExporter.Export(plot.Model, svg);
            svg.Position = 0;
            data.SetData("image/svg+xml", svg);

            Clipboard.SetDataObject(data);
            e.Handled = true;
        }
        private void SaveGraphButton_Click(object sender, RoutedEventArgs e)
        {
            SaveFileDialog dlg = new SaveFileDialog()
            {
                Filter           = "Portable Network Graphics (*.png)|*.png|Portable Document Format (*.pdf)|*.pdf|Scalable Vector Graphics (*.svg)|*.svg",
                RestoreDirectory = true
            };

            if (dlg.ShowDialog() == true)
            {
                if (File.Exists(dlg.FileName))
                {
                    try
                    {
                        File.Delete(dlg.FileName);
                    }
                    catch (IOException)
                    {
                        MessageBox.Show("Cannot access the file " + dlg.FileName + " because it is being used by another process.",
                                        Application.Current.MainWindow.Title, MessageBoxButton.OK, MessageBoxImage.Warning);
                    }
                }

                switch (dlg.FileName.Substring(dlg.FileName.LastIndexOf('.')))
                {
                case ".png":
                    PngExporter pngExporter = new PngExporter();

                    using (FileStream fileStream = File.OpenWrite(dlg.FileName))
                    {
                        pngExporter.Export(MainPlotView.Model, fileStream);
                    }

                    break;

                case ".pdf":
                    PdfExporter pdfExporter = new PdfExporter();

                    using (FileStream fileStream = File.OpenWrite(dlg.FileName))
                    {
                        pdfExporter.Export(MainPlotView.Model, fileStream);
                    }

                    break;

                case ".svg":
                    OxyPlot.SvgExporter svgExporter = new OxyPlot.SvgExporter();

                    using (FileStream fileStream = File.OpenWrite(dlg.FileName))
                    {
                        svgExporter.Export(MainPlotView.Model, fileStream);
                    }

                    break;

                default:
                    break;
                }
            }
        }
Exemplo n.º 15
0
        public void ExportWithResolution(double factor)
        {
            var resolution = (int)(96 * factor);
            var plotModel  = CreateTestModel1();

            Directory.CreateDirectory("Actual");
            Directory.CreateDirectory("Baseline");
            var fileName = string.Format(CultureInfo.InvariantCulture, "PngExporterTests_ExportWithResolution_{0}dpi.png", resolution);
            var exporter = new PngExporter {
                Width = (int)(400 * factor), Height = (int)(300 * factor), Resolution = resolution
            };
            var actual = Path.Combine("Actual", fileName);

            using (var stream = File.OpenWrite(actual))
            {
                exporter.Export(plotModel, stream);
            }

            Assert.IsTrue(File.Exists(actual));
            var baselinePath = Path.Combine("Baseline", fileName);

            if (File.Exists(baselinePath))
            {
                PngAssert.AreEqual(baselinePath, actual, fileName, Path.Combine("Diff", fileName));
            }
            else
            {
                File.Copy(actual, baselinePath);
            }
        }
Exemplo n.º 16
0
        private void btnSaveAll_Click(object sender, EventArgs e)
        {
            _saveDialog.Filter   = "HTML file (*.html)|*.html|All Files (*.*)|*.*";
            _saveDialog.FileName = "ViewGraphs.html";
            _saveDialog.Title    = "Choose folder in which to save PNGs";
            if (_saveDialog.ShowDialog() == DialogResult.OK)
            {
                string filename = _saveDialog.FileName;

                string folder = Path.GetDirectoryName(_saveDialog.FileName);
                using (var w = new StreamWriter(_saveDialog.FileName))
                {
                    w.WriteLine("<html>");
                    w.WriteLine("<head>");
                    w.WriteLine("<title>Graphs ({0})</title>", DateTime.Now);
                    w.WriteLine("</head>");
                    w.WriteLine("<body>");
                    foreach (ChartPage page in _tabs.TabPages)
                    {
                        string imgName = G.MakeValidFileName(page.GraphId.ToString().Replace(' ', '-') + ".png");
                        string imgPath = Path.Combine(folder, imgName);
                        w.WriteLine("<p>{0}</p>", page.GraphId);
                        w.WriteLine("<img src=\"{0}\"/><br/>", imgName);
                        PngExporter.Export(page.Model, imgPath, page.Plot.Width, page.Plot.Height, Brushes.White);
                    }
                    w.WriteLine("</body>");
                    w.WriteLine("</html>");
                }
            }
        }
        /// <summary>
        /// Zapisuje wykres do PDFu
        /// </summary>
        private void SaveToPdf()
        {
            string         filePath       = string.Empty;
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.Filter = "PNG Files (*.png)|*.png|PDF Files (*.pdf)|*.pdf ";
            if (saveFileDialog.ShowDialog() == true)
            {
                filePath = saveFileDialog.FileName;
                if (filePath.Contains("pdf"))
                {
                    using (var stream = File.Create(filePath))
                    {
                        string tmp = ChartViewModel.PlotModel.Title;
                        tmp = tmp.Replace("ł", "l");
                        tmp = tmp.Replace("ś", "s");
                        ChartViewModel.PlotModel.Title = tmp;
                        PdfExporter.Export(ChartViewModel.PlotModel, stream, 600, 400);
                    }
                }
                else
                {
                    using (var stream = File.Create(filePath))
                    {
                        PngExporter.Export(ChartViewModel.PlotModel, stream, 750, 550, OxyColor.FromArgb(250, 250, 250, 250));
                    }
                }
            }
        }
Exemplo n.º 18
0
 public static void ToPng(this PlotModel model, string filename, int width, int height, OxyColor?backgound = null)
 {
     using (var stream = System.IO.File.Create(filename))
     {
         PngExporter.Export(model, stream, width, height, backgound ?? OxyColors.White);
     }
 }
Exemplo n.º 19
0
        /// <summary>
        /// Save results of a single learning (a single run) - just 1 network, 1 learning.
        /// Saves error plot, regression plot, and info about the run.
        /// </summary>
        /// <param name="layersVal"></param>
        /// <param name="learningSettings"></param>
        /// <param name="report"></param>
        /// <param name="regressionPlot"></param>
        /// <param name="errorPlot"></param>
        /// <param name="network"></param>
        private void SaveSingleRunData(LearningSettings learningSettings,
                                       SingleRunReport report, PlotModel regressionPlot, PlotModel errorPlot, INetwork network) // could be refactored -> use MainWindow fields or create a class
        {
            DateTime   time      = report.Time;
            List <int> layersVal = RetrieveLayersVal(learningSettings);
            string     prefix    = report.Name;

            if (eid.ReportingOptions.ShouldSavePlots)
            {
                string regressionFileName = prefix + "_regression.png";
                string regressionSavePath = System.IO.Path.Combine(innerResultsPath, regressionFileName);
                using (FileStream fileStream = new FileStream(regressionSavePath, FileMode.CreateNew))
                {
                    PngExporter.Export(regressionPlot, fileStream, 900, 900, OxyColors.White);
                }

                string errorFileName = prefix + "_error.png";
                string errorSavePath = System.IO.Path.Combine(innerResultsPath, errorFileName);
                using (FileStream fileStream = new FileStream(errorSavePath, FileMode.CreateNew))
                {
                    PngExporter.Export(errorPlot, fileStream, 900, 900, OxyColors.White);
                }
            }

            if (eid.ReportingOptions.ShouldSaveRunInfos)
            {
                string infoFileName = prefix + "_info.txt";
                string infoSavePath = System.IO.Path.Combine(innerResultsPath, infoFileName);

                FileManager.SaveTextFile(infoSavePath,
                                         GetResultInfo(learningSettings, report.LearningResult, layersVal, network, time));
            }
        }
Exemplo n.º 20
0
        private static void MakeTotalLinePlot([JetBrains.Annotations.NotNull] string outputPath, [JetBrains.Annotations.NotNull] List <double> sums)
        {
            var plotModel1 = new PlotModel
            {
                LegendPosition    = LegendPosition.BottomCenter,
                LegendPlacement   = LegendPlacement.Outside,
                LegendOrientation = LegendOrientation.Horizontal,
                Title             = "Total"
            };
            var linearAxis1 = new LinearAxis
            {
                Position = AxisPosition.Bottom
            };

            plotModel1.Axes.Add(linearAxis1);
            var lineSeries1 = new LineSeries
            {
                Title = "Sum"
            };

            for (var j = 0; j < sums.Count; j++)
            {
                lineSeries1.Points.Add(new DataPoint(j, sums[j]));
            }
            plotModel1.Series.Add(lineSeries1);
            var path = Path.Combine(outputPath, "Sum.line.png");

            PngExporter.Export(plotModel1, path, 3200, 1600, OxyColor.FromRgb(255, 255, 255), 100);
        }
Exemplo n.º 21
0
        async Task Export()
        {
            message.Text = "Saving";
            var dialog = new SaveFileDialog();

            dialog.OverwritePrompt = true;
            dialog.Filter          = "PNG Files|*.png|SVG Files|*.svg";
            dialog.AddExtension    = true;
            if (dialog.ShowDialog(this) == true)
            {
                using (var fs = dialog.OpenFile())
                {
                    if (dialog.FileName.EndsWith(".svg", StringComparison.InvariantCultureIgnoreCase))
                    {
                        var exporter = new SvgExporter();
                        exporter.Export(plot.Model, fs);
                    }
                    else
                    {
                        var exporter = new PngExporter();
                        exporter.Export(plot.Model, fs);
                    }
                    fs.SetLength(fs.Position);
                }
            }
        }
Exemplo n.º 22
0
    public static FileInfo ToPNG(this IPlotModel Model, FileInfo File, int Width = 800, int Height = 600, double Resolution = 96)
    {
        var exporter = new PngExporter(Width, Height, Resolution);

        using var stream = File.Create();
        exporter.Export(Model, stream);
        return(File);
    }
Exemplo n.º 23
0
        public void ExportToFile_TestPlot_CheckThatFileExists()
        {
            var          plotModel = TestModels.CreateTestModel1();
            const string FileName  = "PngExporterTests_Plot1.png";

            PngExporter.Export(plotModel, FileName, 400, 300);
            Assert.IsTrue(File.Exists(FileName));
        }
Exemplo n.º 24
0
        public void ExportToStream()
        {
            var plotModel = TestModels.CreateTestModel1();
            var exporter = new PngExporter { Width = 400, Height = 300 };
            var stream = new MemoryStream();
            exporter.Export(plotModel, stream);

            Assert.IsTrue(stream.Length > 0);
        }
Exemplo n.º 25
0
        public void ExportToFile()
        {
            var plotModel = CreateTestModel1();
            var fileName  = Path.Combine(this.outputDirectory, "Plot1.png");

            PngExporter.Export(plotModel, fileName, 400, 300);

            Assert.IsTrue(File.Exists(fileName));
        }
Exemplo n.º 26
0
        public void TestEmoji()
        {
            var plotModel = ExampleLibrary.Issues.EmojiText();
            var fileName  = Path.Combine(this.outputDirectory, "Emoji.png");

            PngExporter.Export(plotModel, fileName, 700, 700);

            Assert.IsTrue(File.Exists(fileName));
        }
Exemplo n.º 27
0
        public void TestMultilineAlignment()
        {
            var plotModel = ExampleLibrary.RenderingCapabilities.DrawMultilineTextAlignmentRotation();
            var fileName  = Path.Combine(this.outputDirectory, "Text.png");

            PngExporter.Export(plotModel, fileName, 700, 700);

            Assert.IsTrue(File.Exists(fileName));
        }
Exemplo n.º 28
0
 /// <summary>
 /// Export a plot model to an image.
 /// </summary>
 /// <param name="plot">Plot model to be exported.</param>
 /// <param name="width">Desired width of the image (in px).</param>
 /// <param name="height">Desired height of the image (in px).</param>
 public Image Export(IPlotModel plot, double width, double height)
 {
     using (Stream stream = new MemoryStream())
     {
         PngExporter.Export(plot, stream, (int)width, (int)height);
         stream.Seek(0, SeekOrigin.Begin);
         return(Image.FromStream(stream));
     }
 }
Exemplo n.º 29
0
        static void Main(string[] args)
        {
            var pm = new PlotModel {
                Title = "Hello world from C#"
            };

            pm.Series.Add(new FunctionSeries(Math.Sin, 0, 10, 100));
            PngExporter.Export(pm, "HelloWorld.png", 600, 300, OxyColors.White);
        }
Exemplo n.º 30
0
        public static void ToPNG(string fileName, string plotTitle, MeasurmentsData measData)
        {
            int resX = 1280;
            int resY = 1024;

            var delaysModel = new PlotModel {
                Title = plotTitle
            };

            delaysModel.Legends.Add(new Legend {
                LegendBackground = OxyColors.White, LegendBorder = OxyColors.Black
            });
            int i;

            foreach (var data in measData.Delays)
            {
                var line = new LineSeries {
                    Title = $"{data.Key}"
                };
                delaysModel.Series.Add(line);
                i = 0;
                line.Points.AddRange(data.Value.Select(x => new DataPoint(i++, x)));
            }

            var seqModel = new PlotModel {
                Title = "Sequence"
            };

            seqModel.Legends.Add(new Legend {
                LegendBackground = OxyColors.White, LegendBorder = OxyColors.Black
            });
            var indexedSeq = measData.Sequence.Select((x, idx) => (idx, x));

            foreach (var group in indexedSeq.GroupBy(x => x.x).OrderBy(x => x.Key))
            {
                var seqSeries = new LinearBarSeries {
                    Title = $"{group.Key}"
                };
                seqSeries.Points.AddRange(group.Select(x => new DataPoint(x.idx, 1)));
                seqModel.Series.Add(seqSeries);
            }

            using var delaysPngStream = new MemoryStream();
            using var seqPngStream    = new MemoryStream();

            PngExporter.Export(delaysModel, delaysPngStream, resX, resY / 2);
            PngExporter.Export(seqModel, seqPngStream, resX, resY / 2);

            using var b1     = new Bitmap(Image.FromStream(delaysPngStream));
            using var b2     = new Bitmap(Image.FromStream(seqPngStream));
            using var result = new Bitmap(resX, resY);
            using var g      = Graphics.FromImage(result);
            g.DrawImage(b1, 0, 0);
            g.DrawImage(b2, 0, resY / 2);
            result.Save(fileName);
        }
Exemplo n.º 31
0
        /// <summary>
        /// Export the graph to the specified 'bitmap'
        /// </summary>
        /// <param name="bitmap">Bitmap to write to</param>
        /// <param name="legendOutside">Put legend outside of graph?</param>
        public void Export(ref Bitmap bitmap, bool legendOutside)
        {
            MemoryStream stream      = new MemoryStream();
            PngExporter  pngExporter = new PngExporter();

            pngExporter.Width  = bitmap.Width;
            pngExporter.Height = bitmap.Height;
            pngExporter.Export(plot1.Model, stream);
            bitmap = new Bitmap(stream);
        }
Exemplo n.º 32
0
        public void ExportWithDifferentBackground()
        {
            var plotModel = TestModels.CreateTestModel1();
            const string FileName = "PngExporterTests_BackgroundYellow.png";
            var exporter = new PngExporter { Width = 400, Height = 300, Background = OxyColors.Yellow };
            using (var stream = File.OpenWrite(FileName))
            {
                exporter.Export(plotModel, stream);
            }

            Assert.IsTrue(File.Exists(FileName));
        }
Exemplo n.º 33
0
        public void ExportToFile()
        {
            var plotModel = TestModels.CreateTestModel1();
            const string FileName = "PngExporterTests_Plot1.png";
            var exporter = new PngExporter { Width = 400, Height = 300 };
            using (var stream = File.OpenWrite(FileName))
            {
                exporter.Export(plotModel, stream);
            }

            Assert.IsTrue(File.Exists(FileName));
        }
Exemplo n.º 34
0
        public void ExportWithResolution(double factor)
        {
            var resolution = (int)(96 * factor);
            var plotModel = TestModels.CreateTestModel1();
            var fileName = string.Format(CultureInfo.InvariantCulture, "PngExporterTests_ExportWithResolution_{0}dpi.png", resolution);
            var exporter = new PngExporter { Width = (int)(400 * factor), Height = (int)(300 * factor), Resolution = resolution };
            using (var stream = File.OpenWrite(fileName))
            {
                exporter.Export(plotModel, stream);
            }

            Assert.IsTrue(File.Exists(fileName));
            PngAssert.AreEqual(Path.Combine("Baseline", fileName), fileName, fileName, Path.Combine("Diff", fileName));
        }