Esempio n. 1
0
        public void ExportToFile()
        {
            var plotModel = CreateTestModel1();
            var fileName  = Path.Combine(this.outputDirectory, "Plot1.jpg");

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

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

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

            Assert.IsTrue(File.Exists(fileName));
        }
Esempio n. 3
0
        public void ExportToStream()
        {
            var plotModel = CreateTestModel1();
            var exporter  = new JpegExporter(400, 300);
            var stream    = new MemoryStream();

            exporter.Export(plotModel, stream);

            Assert.IsTrue(stream.Length > 0);
        }
Esempio n. 4
0
        public void ExportWithDifferentBackground()
        {
            var plotModel = CreateTestModel1();

            plotModel.Background = OxyColors.Yellow;
            var fileName = Path.Combine(this.outputDirectory, "Background_Yellow.jpg");
            var exporter = new JpegExporter(400, 300);

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

            Assert.IsTrue(File.Exists(fileName));
        }
Esempio n. 5
0
        public void ExportWithResolution(double factor)
        {
            var resolution = (int)(96 * factor);
            var plotModel  = CreateTestModel1();
            var directory  = Path.Combine(this.outputDirectory, "Resolution");

            Directory.CreateDirectory(directory);

            var fileName = Path.Combine(directory, $"Resolution{resolution}.jpg");
            var exporter = new JpegExporter((int)(400 * factor), (int)(300 * factor), resolution);

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

            Assert.IsTrue(File.Exists(fileName));
        }
Esempio n. 6
0
        public void ExportWithQuality(int quality)
        {
            var plotModel = CreateTestModel1();
            var directory = Path.Combine(this.outputDirectory, "Quality");

            Directory.CreateDirectory(directory);
            var exporter = new JpegExporter {
                Width = 400, Height = 300, Quality = quality
            };

            var fileName = Path.Combine(directory, $"Quality_{quality}.jpg");

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

            Assert.IsTrue(File.Exists(fileName));
        }
Esempio n. 7
0
        public void LargeImageTest(bool interpolate)
        {
            // this is a test of the DrawImage function; don't add pointless backgrounds to your plots

            var plotModel = CreateTestModel1();

            var pixelData = new OxyColor[5, 5];

            for (int i = 0; i < pixelData.GetLength(0); i++)
            {
                for (int j = 0; j < pixelData.GetLength(1); j++)
                {
                    pixelData[i, j] = OxyColor.FromArgb(255, 128, (byte)((i * 255) / pixelData.GetLength(0)), (byte)((j * 255) / pixelData.GetLength(1)));
                }
            }

            var oxyImage        = OxyImage.Create(pixelData, ImageFormat.Png);
            var imageAnnotation = new ImageAnnotation()
            {
                ImageSource         = oxyImage,
                X                   = new PlotLength(-1, PlotLengthUnit.RelativeToViewport),
                Y                   = new PlotLength(-1, PlotLengthUnit.RelativeToViewport),
                Width               = new PlotLength(3, PlotLengthUnit.RelativeToViewport),
                Height              = new PlotLength(3, PlotLengthUnit.RelativeToViewport),
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Top,
                Interpolate         = interpolate
            };

            plotModel.Annotations.Add(imageAnnotation);

            var fileName = Path.Combine(this.outputDirectory, $"LargeImage{(interpolate ? "Interpolated" : "Pixelated")}.jpg");
            var exporter = new JpegExporter(400, 300);

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

            Assert.IsTrue(File.Exists(fileName));
        }
Esempio n. 8
0
        static void Main(string[] args)
        {
            var outputToFile          = "test-oxyplot-static-export-file";
            var outputExportStreamOOP = "test-oxyplot-export-stream";

            var width       = 1024;
            var height      = 768;
            var resolutions = new[] { 72d, 96d, 182d };

            var model = BuildPlotModel();

            foreach (var resolution in resolutions)
            {
                // export to file using static methods
                PngExporter.Export(model, $"{outputToFile}{resolution}.png", width, height, resolution);

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

                model.Background = OxyColors.White;

                // export to file using static methods
                JpegExporter.Export(model, $"{outputToFile}{resolution}.jpg", width, height, resolution);

                // export using the instance methods
                using (var stream = new MemoryStream())
                {
                    var jpegExporter = new JpegExporter(width, height, resolution);
                    jpegExporter.Export(model, stream);
                    System.IO.File.WriteAllBytes($"{outputExportStreamOOP}{resolution}.jpg", stream.ToArray());
                }
            }
        }
        public async Task <string> PrepareHistogram(List <int> relayNos, Func <Step, Task> stepHandler = null)
        {
            await stepHandler(Step.RetrievingData);

            var minutesInBucket = 6;
            var bucketsCount    = 24 * 60 / minutesInBucket;
            var buckets         = new int[relayNos.Count, bucketsCount];

            var relayNumberInChart = 0;

            foreach (var relayNo in relayNos)
            {
                var samplesForRelay = Database.Instance.GetSamplesForRelay(relayNo);
                var formerSample    = new RelaySample(relayNo, false);

                foreach (var sample in samplesForRelay)
                {
                    if (sample.CanSampleBeSquashed(formerSample))
                    {
                        continue;
                    }

                    // If current sample has positive state, but former doesn't, then this
                    // marks activation and no samples go to buckets. What's important here is
                    // deactivation - in such case we have to fill buckets accordingly.

                    if (sample.State || !formerSample.State)
                    {
                        formerSample = sample;
                        continue;
                    }

                    var startDateTime     = formerSample.Date;
                    var endDateTime       = sample.Date;
                    var startingDay       = startDateTime.Date;
                    var endingDay         = endDateTime.Date;
                    var startingBucket    = (int)startDateTime.TimeOfDay.TotalMinutes / minutesInBucket;
                    var endingBucket      = (int)endDateTime.TimeOfDay.TotalMinutes / minutesInBucket;
                    var fullDaysInBetween = (int)(endingDay - startingDay).TotalDays - 1;

                    // Yup, fullDaysInBetween can have value -1.

                    if (fullDaysInBetween == -1)
                    {
                        // Same day for turning on and off
                        for (var i = startingBucket; i <= endingBucket; i++)
                        {
                            buckets[relayNumberInChart, i]++;
                        }
                    }
                    else
                    {
                        for (var i = startingBucket; i < bucketsCount; i++)
                        {
                            buckets[relayNumberInChart, i]++;
                        }

                        if (fullDaysInBetween > 0)
                        {
                            for (var i = 0; i < bucketsCount; i++)
                            {
                                buckets[relayNumberInChart, i] += fullDaysInBetween;
                            }
                        }

                        for (var i = 0; i < endingBucket; i++)
                        {
                            buckets[relayNumberInChart, i]++;
                        }
                    }

                    formerSample = sample;
                }

                relayNumberInChart++;
            }

            await stepHandler(Step.CreatingPlot);

            var plotModel = new PlotModel {
                Title = "Histogram"
            };

            plotModel.Background = OxyColors.White;
            plotModel.Axes.Add(new LinearAxis()
            {
                Position           = AxisPosition.Bottom,
                MajorGridlineStyle = LineStyle.Solid,
                Minimum            = 0,
                Maximum            = bucketsCount,
                MaximumPadding     = 0,
                MinimumPadding     = 0,
                LabelFormatter     = value => TimeSpan.FromMinutes(minutesInBucket * value).ToString(@"h\:mm"),
            });
            plotModel.Axes.Add(new LinearAxis()
            {
                Position           = AxisPosition.Left,
                MajorGridlineStyle = LineStyle.Dot,
                Minimum            = 0,
                Maximum            = buckets.Cast <int>().Max() + 1
            });
            var legend = new OxyPlot.Legends.Legend
            {
                LegendTitle = "Legenda"
            };

            plotModel.Legends.Add(legend);

            for (var j = 0; j < relayNos.Count; j++)
            {
                var serie = new LineSeries
                {
                    Title = Globals.Relays[relayNos[j]].FriendlyName
                };
                for (var i = 0; i < bucketsCount; i++)
                {
                    serie.Points.Add(new DataPoint(i, buckets[j, i]));
                }
                plotModel.Series.Add(serie);
            }

            var chartFile = "histogram.jpg";

            await stepHandler(Step.RenderingImage);

            using (var stream = File.Create(chartFile))
            {
                var pngExporter = new JpegExporter(1300, 800, quality: 100);
                pngExporter.Export(plotModel, stream);
            }

            return(chartFile);
        }