Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FeatureMapViewModel"/> class.
        /// </summary>
        /// <param name="dialogService">Dialog service for opening dialogs from the view model.</param>
        public FeatureMapViewModel(IDialogService dialogService = null)
        {
            this.dialogService = dialogService ?? new DialogService();

            ms2SeriesDictionary = new Dictionary <string, ScatterSeries>();

            ShowFoundIdMs2   = false;
            ShowFoundUnIdMs2 = false;

            IsLinearAbundanceAxis      = false;
            IsLogarithmicAbundanceAxis = true;
            FeatureSize = 0.1;

            FeatureSelectedCommand = ReactiveCommand.Create(FeatureSelectedImplementation);

            // Save As Image Command requests a file path from the user and then saves the spectrum plot as an image
            SaveAsImageCommand = ReactiveCommand.Create(SaveAsImageImplementation);

            // Initialize color axes.
            const int numColors = 5000;

            featureColorAxis = new LinearColorAxis     // Color axis for features
            {
                Title    = "Abundance",
                Position = AxisPosition.Right,
                Palette  = OxyPalette.Interpolate(numColors, IcParameters.Instance.FeatureColors),
            };

            colorDictionary = new ProteinColorDictionary();
            ms2ColorAxis    = new LinearColorAxis   // Color axis for ms2s
            {
                Key               = "ms2s",
                Position          = AxisPosition.None,
                Palette           = colorDictionary.OxyPalette,
                Minimum           = 1,
                Maximum           = colorDictionary.OxyPalette.Colors.Count,
                AxisTitleDistance = 1
            };

            // Initialize x and y axes.
            yaxis = new LinearAxis {
                Position = AxisPosition.Left, Title = "Monoisotopic Mass", StringFormat = "0.###"
            };
            xaxis = new LinearAxis {
                Position = AxisPosition.Bottom, Title = "Retention Time", StringFormat = "0.###",
            };

            // Change size of scan highlight annotation when feature map x and y axes are zoomed or panned.
            var isInternalChange = false;

            xaxis.AxisChanged += (o, e) =>
            {
                XMinimum = Math.Round(xaxis.ActualMinimum, 3);
                XMaximum = Math.Round(xaxis.ActualMaximum, 3);
                if (!isInternalChange && highlight != null &&
                    highlight.TextPosition.X >= xaxis.ActualMinimum && highlight.TextPosition.X <= xaxis.ActualMaximum &&
                    highlight.TextPosition.Y >= yaxis.ActualMinimum && highlight.TextPosition.Y <= yaxis.ActualMaximum)
                {
                    var x = highlight.TextPosition.X;
                    isInternalChange   = true;
                    highlight.MinimumX = x - ((xaxis.ActualMaximum - xaxis.ActualMinimum) * HighlightScale * 0.5);
                    highlight.MaximumX = x + ((xaxis.ActualMaximum - xaxis.ActualMinimum) * HighlightScale * 0.5);
                }

                isInternalChange = false;
            };
            yaxis.AxisChanged += (o, e) =>
            {
                YMinimum = Math.Round(yaxis.ActualMinimum, 3);
                YMaximum = Math.Round(yaxis.ActualMaximum, 3);
                if (!isInternalChange && highlight != null &&
                    highlight.TextPosition.X >= xaxis.ActualMinimum && highlight.TextPosition.X <= xaxis.ActualMaximum &&
                    highlight.TextPosition.Y >= yaxis.ActualMinimum && highlight.TextPosition.Y <= yaxis.ActualMaximum)
                {
                    var y = highlight.TextPosition.Y;
                    isInternalChange   = true;
                    highlight.MinimumY = y - ((yaxis.ActualMaximum - yaxis.ActualMinimum) * HighlightScale);
                    highlight.MaximumY = y + ((yaxis.ActualMaximum - yaxis.ActualMinimum) * HighlightScale);
                }

                isInternalChange = false;
            };

            // Initialize feature map.
            FeatureMap = new PlotModel {
                Title = "Feature Map"
            };
            FeatureMap.MouseDown += FeatureMapMouseDown;
            FeatureMap.Axes.Add(featureColorAxis);
            FeatureMap.Axes.Add(ms2ColorAxis);
            FeatureMap.Axes.Add(xaxis);
            FeatureMap.Axes.Add(yaxis);

            // When ShowNotFoundMs2 changes, update the NotFoundMs2 series
            this.WhenAnyValue(x => x.ShowFoundUnIdMs2)
            .Where(_ => FeatureMap != null && ms2SeriesDictionary.ContainsKey(string.Empty))
            .Subscribe(showFoundUnIdMs2 =>
            {
                ms2SeriesDictionary[string.Empty].IsVisible = showFoundUnIdMs2;
                FeatureMap.InvalidatePlot(true);
            });

            // When ShowFoundIdMs2 changes, update all ms2 series
            this.WhenAnyValue(x => x.ShowFoundIdMs2)
            .Where(_ => FeatureMap != null)
            .Subscribe(showFoundMs2 =>
            {
                foreach (var protein in ms2SeriesDictionary.Keys.Where(key => !string.IsNullOrWhiteSpace(key)))
                {
                    ms2SeriesDictionary[protein].IsVisible = showFoundMs2;
                }

                FeatureMap.InvalidatePlot(true);
            });

            this.WhenAnyValue(x => x.IsLinearAbundanceAxis)
            .Subscribe(isLinearAbundanceAxis => IsLogarithmicAbundanceAxis = !isLinearAbundanceAxis);

            this.WhenAnyValue(x => x.IsLogarithmicAbundanceAxis)
            .Subscribe(isLogarithmicAbundanceAxis => IsLinearAbundanceAxis = !isLogarithmicAbundanceAxis);

            // Update plot axes when FeaturePlotXMin, YMin, XMax, and YMax change
            this.WhenAnyValue(x => x.XMinimum, x => x.XMaximum)
            .Throttle(TimeSpan.FromSeconds(1), RxApp.TaskpoolScheduler)
            .Where(x => !xaxis.ActualMinimum.Equals(x.Item1) || !xaxis.ActualMaximum.Equals(x.Item2))
            .Subscribe(
                x =>
            {
                xaxis.Zoom(x.Item1, x.Item2);
                FeatureMap.InvalidatePlot(false);
            });
            this.WhenAnyValue(y => y.YMinimum, x => x.YMaximum)
            .Throttle(TimeSpan.FromSeconds(1), RxApp.TaskpoolScheduler)
            .Where(y => !yaxis.ActualMinimum.Equals(y.Item1) || !yaxis.ActualMaximum.Equals(y.Item2))
            .Subscribe(
                y =>
            {
                yaxis.Zoom(y.Item1, y.Item2);
                FeatureMap.InvalidatePlot(false);
            });

            // When SelectedPrSm is changed, update highlighted prsm on plot
            this.WhenAnyValue(x => x.SelectedPrSm)
            .Where(selectedPrSm => selectedPrSm != null)
            .Subscribe(selectedPrSm =>
            {
                SetHighlight(selectedPrSm);
                FeatureMap.InvalidatePlot(true);
                SelectedPrSm.WhenAnyValue(x => x.Scan)
                .Subscribe(scan =>
                {
                    SetHighlight(selectedPrSm);
                    FeatureMap.InvalidatePlot(true);
                });
            });

            var propMon = this.WhenAnyValue(x => x.IsLinearAbundanceAxis, x => x.FeatureSize, x => x.Features)
                          .Select(x => featureColorAxis.Title = x.Item1 ? "Abundance" : "Abundance (Log10)");

            var colorMon = IcParameters.Instance.WhenAnyValue(x => x.IdColors, x => x.Ms2ScanColor, x => x.FeatureColors)
                           .Select(x =>
            {
                var colorList = new List <OxyColor> {
                    Capacity = x.Item1.Length + 1
                };
                colorList.Add(x.Item2);
                colorList.AddRange(x.Item1);
                colorDictionary.SetColors(colorList);
                ms2ColorAxis.Palette     = colorDictionary.OxyPalette;
                featureColorAxis.Palette = OxyPalette.Interpolate(numColors, x.Item3);
                return(string.Empty);
            });

            // Link two observables to a single throttle and action.
            propMon.Merge(colorMon).Throttle(TimeSpan.FromSeconds(1), RxApp.TaskpoolScheduler).Subscribe(x => BuildPlot());
        }
        /// <summary>
        /// Build new color dictionary.
        /// </summary>
        /// <param name="length">Maximum number of colors for each base ion type.</param>
        public void BuildColorDictionary(int length)
        {
            const byte ColorMin = 150;
            const byte ColorMax = 255;

            fragmentColors = new Dictionary <string, IList <OxyColor> >();

            var ionAStart  = OxyColor.FromRgb(0, ColorMin, 0);
            var ionAEnd    = OxyColor.FromRgb(0, ColorMax, 0);
            var ionAColors = OxyPalette.Interpolate(length, ionAEnd, ionAStart);

            var ionBStart  = OxyColor.FromRgb(0, 0, ColorMin);
            var ionBEnd    = OxyColor.FromRgb(0, 0, ColorMax);
            var ionBColors = OxyPalette.Interpolate(length, ionBEnd, ionBStart);

            var ionCStart  = OxyColor.FromRgb(0, ColorMin, ColorMin);
            var ionCEnd    = OxyColor.FromRgb(0, ColorMax, ColorMax);
            var ionCColors = OxyPalette.Interpolate(length, ionCEnd, ionCStart);

            var ionDStart  = OxyColor.FromRgb(255, ColorMin / 2, 8);
            var ionDEnd    = OxyColor.FromRgb(255, ColorMin, 0);
            var ionDColors = OxyPalette.Interpolate(length, ionDEnd, ionDStart);

            var ionVStart  = OxyColor.FromRgb(210, 105, 30);
            var ionVEnd    = OxyColor.FromRgb(139, 69, 19);
            var ionVColors = OxyPalette.Interpolate(length, ionVEnd, ionVStart);

            var ionWStart  = OxyColor.FromRgb(220, 220, 220);
            var ionWEnd    = OxyColor.FromRgb(169, 169, 169);
            var ionWColors = OxyPalette.Interpolate(length, ionWEnd, ionWStart);

            var ionXStart  = OxyColors.OliveDrab;      //OxyColors.Yellow; //OxyColor.FromRgb(ColorMin, ColorMin, 0);
            var ionXEnd    = OxyColors.DarkOliveGreen; //OxyColors.Goldenrod; //OxyColor.FromRgb(ColorMax, ColorMax, 0);
            var ionXColors = OxyPalette.Interpolate(length, ionXEnd, ionXStart);

            var ionYStart  = OxyColor.FromRgb(ColorMin, 0, 0);
            var ionYEnd    = OxyColor.FromRgb(ColorMax, 0, 0);
            var ionYColors = OxyPalette.Interpolate(length, ionYEnd, ionYStart);

            var ionZStart  = OxyColor.FromRgb(ColorMin, 0, ColorMin);
            var ionZEnd    = OxyColor.FromRgb(ColorMax, 0, ColorMax);
            var ionZColors = OxyPalette.Interpolate(length, ionZEnd, ionZStart);

            var unknownIonColors = OxyPalette.Interpolate(length, OxyColors.Black, OxyColors.Black);

            foreach (var ionType in BaseIonType.AllBaseIonTypes)
            {
                IList <OxyColor> colors;
                switch (ionType.Symbol.ToLower()[0])
                {
                case 'a':
                    colors = ionAColors.Colors;
                    break;

                case 'b':
                    colors = ionBColors.Colors;
                    break;

                case 'c':
                    colors = ionCColors.Colors;
                    break;

                case 'd':
                    colors = ionDColors.Colors;
                    break;

                case 'v':
                    colors = ionVColors.Colors;
                    break;

                case 'w':
                    colors = ionWColors.Colors;
                    break;

                case 'x':
                    colors = ionXColors.Colors;
                    break;

                case 'y':
                    colors = ionYColors.Colors;
                    break;

                case 'z':
                    colors = ionZColors.Colors;
                    break;

                default:
                    colors = unknownIonColors.Colors;
                    break;
                }
                this.fragmentColors.Add(ionType.Symbol, colors);
                this.fragmentColors.Add(ionType.GetDeconvolutedIon().Symbol, colors);
            }

            this.precursorColors = new Dictionary <int, OxyColor>
            {
                { -1, OxyColors.DarkGray },
                { 0, OxyColors.Purple },
                { 1, OxyColors.Red },
                { 2, OxyColors.Blue },
                { 3, OxyColors.Green },
                { 4, OxyColors.Gold },
                { 5, OxyColors.Brown },
                { 6, OxyColors.Orange },
                { 7, OxyColors.PaleGreen },
                { 8, OxyColors.Turquoise },
                { 9, OxyColors.Olive },
                { 10, OxyColors.Beige },
                { 11, OxyColors.Lime },
                { 12, OxyColors.Salmon },
                { 13, OxyColors.MintCream },
                { 14, OxyColors.SteelBlue },
                { 15, OxyColors.Violet },
                { 16, OxyColors.Blue },
                { 17, OxyColors.Navy },
                { 18, OxyColors.Red },
                { 19, OxyColors.SpringGreen },
                { 20, OxyColors.Gold },
                { 21, OxyColors.DarkOrange }
            };
        }
Exemplo n.º 3
0
 public OxyPaletteMap(string name, LinearGradientBrush brush, OxyPalette palette)
 {
     Name    = name;
     Brush   = brush;
     Palette = palette;
 }
Exemplo n.º 4
0
 public OxyPalette GetColorAxisPalette(Axis axis)
 {
     return(OxyPalette.Interpolate(64, R.HuePalette.GetPalette(64, 15, 15 + 315).ToArray()));
 }
Exemplo n.º 5
0
        public static PlotModel ConfusionMatrix()
        {
            // Example provided by Pau Climent Pérez
            // See also http://en.wikipedia.org/wiki/Confusion_matrix
            var data = new double[3, 3];

            data[0, 0] = 1;
            data[1, 1] = 0.8;
            data[1, 2] = 0.2;
            data[2, 2] = 1;

            // I guess this is where the confusion comes from?
            data = data.Transpose();

            string[] cat1 = { "class A", "class B", "class C" };

            var model = new PlotModel {
                Title = "Confusion Matrix"
            };

            var palette = OxyPalette.Interpolate(50, OxyColors.White, OxyColors.Black);

            var lca = new LinearColorAxis {
                Position = AxisPosition.Right, Palette = palette, HighColor = OxyColors.White, LowColor = OxyColors.White
            };

            model.Axes.Add(lca);

            var axis1 = new CategoryAxis {
                Position = AxisPosition.Top, Title = "Actual class"
            };

            axis1.Labels.AddRange(cat1);
            model.Axes.Add(axis1);

            // We invert this axis, so that they look "symmetrical"
            var axis2 = new CategoryAxis {
                Position = AxisPosition.Left, Title = "Predicted class"
            };

            axis2.Labels.AddRange(cat1);
            axis2.Angle         = -90;
            axis2.StartPosition = 1;
            axis2.EndPosition   = 0;

            model.Axes.Add(axis2);

            var hms = new HeatMapSeries
            {
                Data          = data,
                Interpolate   = false,
                LabelFontSize = 0.25,
                X0            = 0,
                X1            = data.GetLength(1) - 1,
                Y0            = 0,
                Y1            = data.GetLength(0) - 1,
            };

            model.Series.Add(hms);
            return(model);
        }
Exemplo n.º 6
0
        public void Constructor()
        {
            var palette = new OxyPalette(OxyColors.Blue, OxyColors.White, OxyColors.Red);

            Assert.AreEqual(3, palette.Colors.Count);
        }
Exemplo n.º 7
0
 public IList <OxyColor> GetDefaultColors(int count)
 {
     return(OxyPalette.Interpolate(count, Colors.ToArray()).Colors);
 }
Exemplo n.º 8
0
 public static PlotModel CreateRandomScatterSeriesWithColorAxisPlotModel(int n, OxyPalette palette,
                                                                         MarkerType markerType             // = MarkerType.Square
                                                                         , AxisPosition colorAxisPosition) // = AxisPosition.Right
 //, OxyColor highColor// = null
 //, OxyColor lowColor)// = null)
 {
     return(CreateRandomScatterSeriesWithColorAxisPlotModel(n, palette, markerType, colorAxisPosition,
                                                            null,
                                                            null));
 }
Exemplo n.º 9
0
        /// <summary>
        /// Build new color dictionary.
        /// </summary>
        /// <param name="length">Maximum number of colors for each base ion type.</param>
        public void BuildColorDictionary(int length)
        {
            const byte ColorMin = 150;
            const byte ColorMax = 255;

            this.fragmentColors = new Dictionary <string, IList <OxyColor> >();

            var ionAStart  = OxyColor.FromRgb(0, ColorMin, 0);
            var ionAEnd    = OxyColor.FromRgb(0, ColorMax, 0);
            var ionAColors = OxyPalette.Interpolate(length, ionAEnd, ionAStart);

            this.fragmentColors.Add(BaseIonType.A.Symbol, ionAColors.Colors);
            this.fragmentColors.Add(BaseIonType.A.GetDeconvolutedIon().Symbol, ionAColors.Colors);
            this.fragmentColors.Add(BaseIonType.Ar.Symbol, ionAColors.Colors);
            this.fragmentColors.Add(BaseIonType.Ar.GetDeconvolutedIon().Symbol, ionAColors.Colors);

            var ionBStart  = OxyColor.FromRgb(0, 0, ColorMin);
            var ionBEnd    = OxyColor.FromRgb(0, 0, ColorMax);
            var ionBColors = OxyPalette.Interpolate(length, ionBEnd, ionBStart);

            this.fragmentColors.Add(BaseIonType.B.Symbol, ionBColors.Colors);
            this.fragmentColors.Add(BaseIonType.B.GetDeconvolutedIon().Symbol, ionBColors.Colors);

            var ionCStart  = OxyColor.FromRgb(0, ColorMin, ColorMin);
            var ionCEnd    = OxyColor.FromRgb(0, ColorMax, ColorMax);
            var ionCColors = OxyPalette.Interpolate(length, ionCEnd, ionCStart);

            this.fragmentColors.Add(BaseIonType.C.Symbol, ionCColors.Colors);
            this.fragmentColors.Add(BaseIonType.C.GetDeconvolutedIon().Symbol, ionCColors.Colors);

            var ionDStart  = OxyColor.FromRgb(255, ColorMin / 2, 8);
            var ionDEnd    = OxyColor.FromRgb(255, ColorMin, 0);
            var ionDColors = OxyPalette.Interpolate(length, ionDEnd, ionDStart);

            this.fragmentColors.Add(BaseIonType.D.Symbol, ionDColors.Colors);
            this.fragmentColors.Add(BaseIonType.D.GetDeconvolutedIon().Symbol, ionDColors.Colors);

            var ionVStart  = OxyColor.FromRgb(210, 105, 30);
            var ionVEnd    = OxyColor.FromRgb(139, 69, 19);
            var ionVColors = OxyPalette.Interpolate(length, ionVEnd, ionVStart);

            this.fragmentColors.Add(BaseIonType.V.Symbol, ionVColors.Colors);
            this.fragmentColors.Add(BaseIonType.V.GetDeconvolutedIon().Symbol, ionVColors.Colors);

            var ionWStart  = OxyColor.FromRgb(220, 220, 220);
            var ionWEnd    = OxyColor.FromRgb(169, 169, 169);
            var ionWColors = OxyPalette.Interpolate(length, ionWEnd, ionWStart);

            this.fragmentColors.Add(BaseIonType.W.Symbol, ionWColors.Colors);
            this.fragmentColors.Add(BaseIonType.W.GetDeconvolutedIon().Symbol, ionWColors.Colors);

            var ionXStart  = OxyColors.OliveDrab;      //OxyColors.Yellow; //OxyColor.FromRgb(ColorMin, ColorMin, 0);
            var ionXEnd    = OxyColors.DarkOliveGreen; //OxyColors.Goldenrod; //OxyColor.FromRgb(ColorMax, ColorMax, 0);
            var ionXColors = OxyPalette.Interpolate(length, ionXEnd, ionXStart);

            this.fragmentColors.Add(BaseIonType.X.Symbol, ionXColors.Colors);
            this.fragmentColors.Add(BaseIonType.X.GetDeconvolutedIon().Symbol, ionXColors.Colors);
            this.fragmentColors.Add(BaseIonType.Xr.Symbol, ionXColors.Colors);
            this.fragmentColors.Add(BaseIonType.Xr.GetDeconvolutedIon().Symbol, ionXColors.Colors);

            var ionYStart  = OxyColor.FromRgb(ColorMin, 0, 0);
            var ionYEnd    = OxyColor.FromRgb(ColorMax, 0, 0);
            var ionYColors = OxyPalette.Interpolate(length, ionYEnd, ionYStart);

            this.fragmentColors.Add(BaseIonType.Y.Symbol, ionYColors.Colors);
            this.fragmentColors.Add(BaseIonType.Y.GetDeconvolutedIon().Symbol, ionYColors.Colors);

            var ionYM1Start  = OxyColor.FromRgb(ColorMin, 0, 0);
            var ionYM1End    = OxyColor.FromRgb(ColorMax, 0, 0);
            var ionYM1Colors = OxyPalette.Interpolate(length, ionYM1End, ionYM1Start);

            this.fragmentColors.Add(BaseIonType.YM1.Symbol, ionYM1Colors.Colors);
            this.fragmentColors.Add(BaseIonType.YM1.GetDeconvolutedIon().Symbol, ionYM1Colors.Colors);

            var ionZStart  = OxyColor.FromRgb(ColorMin, 0, ColorMin);
            var ionZEnd    = OxyColor.FromRgb(ColorMax, 0, ColorMax);
            var ionZColors = OxyPalette.Interpolate(length, ionZEnd, ionZStart);

            this.fragmentColors.Add(BaseIonType.Z.Symbol, ionZColors.Colors);
            this.fragmentColors.Add(BaseIonType.Z.GetDeconvolutedIon().Symbol, ionZColors.Colors);
            this.fragmentColors.Add(BaseIonType.Zr.Symbol, ionZColors.Colors);
            this.fragmentColors.Add(BaseIonType.Zr.GetDeconvolutedIon().Symbol, ionZColors.Colors);

            this.precursorColors = new Dictionary <int, OxyColor>
            {
                { -1, OxyColors.DarkGray },
                { 0, OxyColors.Purple },
                { 1, OxyColors.Red },
                { 2, OxyColors.Blue },
                { 3, OxyColors.Green },
                { 4, OxyColors.Gold },
                { 5, OxyColors.Brown },
                { 6, OxyColors.Orange },
                { 7, OxyColors.PaleGreen },
                { 8, OxyColors.Turquoise },
                { 9, OxyColors.Olive },
                { 10, OxyColors.Beige },
                { 11, OxyColors.Lime },
                { 12, OxyColors.Salmon },
                { 13, OxyColors.MintCream },
                { 14, OxyColors.SteelBlue },
                { 15, OxyColors.Violet },
                { 16, OxyColors.Blue },
                { 17, OxyColors.Navy },
                { 18, OxyColors.Red },
                { 19, OxyColors.SpringGreen },
                { 20, OxyColors.Gold },
                { 21, OxyColors.DarkOrange }
            };
        }
Exemplo n.º 10
0
        /// <summary>
        /// Initializes a new instance of the ErrorMapViewModel class.
        /// </summary>
        /// <param name="dialogService">
        /// The dialog Service.
        /// </param>
        public ErrorMapViewModel(IDialogService dialogService)
        {
            this.dialogService = dialogService;
            plotModel          = new ViewResolvingPlotModel {
                Title = "Error Map", PlotAreaBackground = OxyColors.DimGray
            };
            selectedPeakDataPoints      = new IList <PeakDataPoint> [0];
            minimumIonIntensity         = 0;
            ShouldCombineChargeStates   = true;
            TableShouldIncludeUnmatched = false;

            // Init x axis
            xAxis = new LinearAxis
            {
                Title           = "Amino Acid",
                Position        = AxisPosition.Top,
                AbsoluteMinimum = 0,
                Minimum         = 0,
                MajorTickSize   = 0,
                MinorStep       = 2,
                Angle           = -90,
                MinorTickSize   = 10,
                MaximumPadding  = 0,
                FontSize        = 10
            };
            plotModel.Axes.Add(xAxis);

            // Init Y axis
            yAxis = new LinearAxis
            {
                Title           = "Ion Type",
                Position        = AxisPosition.Left,
                AbsoluteMinimum = 0,
                Minimum         = 0,
                MajorStep       = 1.0,
                MajorTickSize   = 0,
                MinorStep       = 0.5,
                MinorTickSize   = 20,
                MaximumPadding  = 0,
                FontSize        = 10
            };
            plotModel.Axes.Add(yAxis);

            // Init Color axis
            var minColor = OxyColors.Navy;
            var medColor = OxyColors.White;
            var maxColor = OxyColors.DarkRed;

            colorAxis = new LinearColorAxis
            {
                Title           = "Error",
                Position        = AxisPosition.Right,
                AxisDistance    = -0.5,
                AbsoluteMinimum = 0,
                Palette         = OxyPalette.Interpolate(1000, minColor, medColor, maxColor),
                Minimum         = -1 * IcParameters.Instance.ProductIonTolerancePpm.GetValue(),
                Maximum         = IcParameters.Instance.ProductIonTolerancePpm.GetValue(),
                AbsoluteMaximum = IcParameters.Instance.ProductIonTolerancePpm.GetValue(),
                LowColor        = OxyColors.DimGray,
            };
            plotModel.Axes.Add(colorAxis);

            this.WhenAnyValue(x => x.ShouldCombineChargeStates).Subscribe(_ => UpdateNow());

            this.WhenAnyValue(x => x.TableShouldIncludeUnmatched).Subscribe(_ => UpdateNow());

            // Save As Image Command requests a file path from the user and then saves the error map as an image
            SaveAsImageCommand = ReactiveCommand.Create(SaveAsImageImpl);

            SaveDataTableCommand = ReactiveCommand.Create(SaveDataTableImpl);

            UpdateNowCommand = ReactiveCommand.Create(UpdateNow);

            ZoomOutCommand = ReactiveCommand.Create(ZoomOutPlot);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Initializes a new instance of the ErrorMapViewModel class.
        /// </summary>
        /// <param name="dialogService">
        /// The dialog Service.
        /// </param>
        public ErrorMapViewModel(IDialogService dialogService)
        {
            this.dialogService = dialogService;
            this.PlotModel     = new PlotModel {
                Title = "Error Map", PlotAreaBackground = OxyColors.Navy
            };
            this.selectedPeakDataPoints    = new IList <PeakDataPoint> [0];
            this.ShouldCombineChargeStates = true;

            // Init x axis
            this.xaxis = new LinearAxis
            {
                Title           = "Amino Acid",
                Position        = AxisPosition.Top,
                AbsoluteMinimum = 0,
                Minimum         = 0,
                MajorTickSize   = 0,
                MinorStep       = 2,
                Angle           = -90,
                MinorTickSize   = 10,
                MaximumPadding  = 0,
                FontSize        = 10
            };
            this.PlotModel.Axes.Add(this.xaxis);

            // Init Y axis
            this.yaxis = new LinearAxis
            {
                Title           = "Ion Type",
                Position        = AxisPosition.Left,
                AbsoluteMinimum = 0,
                Minimum         = 0,
                MajorStep       = 1.0,
                MajorTickSize   = 0,
                MinorStep       = 0.5,
                MinorTickSize   = 20,
                MaximumPadding  = 0,
                FontSize        = 10
            };
            this.PlotModel.Axes.Add(this.yaxis);

            // Init Color axis
            var minColor = OxyColor.FromRgb(127, 255, 0);
            var maxColor = OxyColor.FromRgb(255, 0, 0);

            this.colorAxis = new LinearColorAxis
            {
                Title           = "Error",
                Position        = AxisPosition.Right,
                AxisDistance    = -0.5,
                AbsoluteMinimum = 0,
                Palette         = OxyPalette.Interpolate(1000, minColor, maxColor),
                Minimum         = -1 * IcParameters.Instance.ProductIonTolerancePpm.GetValue(),
                Maximum         = IcParameters.Instance.ProductIonTolerancePpm.GetValue(),
                AbsoluteMaximum = IcParameters.Instance.ProductIonTolerancePpm.GetValue(),
                LowColor        = OxyColors.Navy,
            };
            this.PlotModel.Axes.Add(this.colorAxis);

            this.WhenAnyValue(x => x.ShouldCombineChargeStates).Subscribe(_ => this.SetData(this.selectedSequence, this.selectedPeakDataPoints));

            // Save As Image Command requests a file path from the user and then saves the error map as an image
            var saveAsImageCommand = ReactiveCommand.Create();

            saveAsImageCommand.Subscribe(_ => this.SaveAsImageImpl());
            this.SaveAsImageCommand = saveAsImageCommand;

            this.SaveDataTableCommand = ReactiveCommand.Create();
            this.SaveDataTableCommand.Subscribe(_ => this.SaveDataTableImpl());
        }
Exemplo n.º 12
0
        private void AddMapFeatures(PlotModel model, WeatherDataPalette wdp, OxyPalette pal, bool isWindMap)
        {
            LineSeries line = null;

            string[] lines = File.ReadAllLines("Coastline.thd");
            foreach (string s in lines)
            {
                if (s.StartsWith("#"))
                {
                    continue;
                }

                if (s.StartsWith(">>"))
                {
                    if (line != null)
                    {
                        model.Series.Add(line);
                    }

                    line = new LineSeries();
                    line.CanTrackerInterpolatePoints = true;
                    line.Color           = OxyColors.Black;
                    line.StrokeThickness = 1;
                    continue;
                }

                Point pt = Point.Parse(s);
                line.Points.Add(new DataPoint(pt.X, pt.Y));
            }

            if (line != null)
            {
                model.Series.Add(line);
            }
            line = null;

            line = null;

            lines = File.ReadAllLines("ContourRO.thd");
            foreach (string s in lines)
            {
                if (s.StartsWith("#"))
                {
                    continue;
                }

                if (s.StartsWith(">>"))
                {
                    if (line != null)
                    {
                        model.Series.Add(line);
                    }

                    line = new LineSeries();
                    line.CanTrackerInterpolatePoints = true;
                    line.Color           = OxyColors.Maroon;
                    line.StrokeThickness = 2;
                    continue;
                }

                Point pt = Point.Parse(s);
                line.Points.Add(new DataPoint(pt.X, pt.Y));
            }

            if (line != null)
            {
                model.Series.Add(line);
            }


            model.Axes.Add(new OxyPlot.Axes.LinearAxis
            {
                Unit              = "° Latitude",
                Position          = OxyPlot.Axes.AxisPosition.Left,
                FilterMinValue    = App.ControlPanelModel.SelectedViewport.MinLat,
                FilterMaxValue    = App.ControlPanelModel.SelectedViewport.MaxLat,
                AxisTitleDistance = 10,

                //MajorGridlineStyle = LineStyle.Solid,
                //MajorStep = 0.5,
            });
            model.Axes.Add(new OxyPlot.Axes.LinearAxis
            {
                Unit              = "° Longitude",
                Position          = OxyPlot.Axes.AxisPosition.Bottom,
                FilterMinValue    = App.ControlPanelModel.SelectedViewport.MinLon,
                FilterMaxValue    = App.ControlPanelModel.SelectedViewport.MaxLon,
                AxisTitleDistance = 10,
                AxislineStyle     = LineStyle.Solid,

                //MajorGridlineStyle = LineStyle.Solid,
                //MajorStep = 0.5,
            });

            model.Axes[0].Minimum = App.ControlPanelModel.SelectedViewport.MinLat;
            model.Axes[0].Maximum = App.ControlPanelModel.SelectedViewport.MaxLat;
            model.Axes[1].Minimum = App.ControlPanelModel.SelectedViewport.MinLon;
            model.Axes[1].Maximum = App.ControlPanelModel.SelectedViewport.MaxLon;

            //if (isWindMap)
            //{
            //}
            //else
            {
                model.Axes.Add(new OxyPlot.Axes.LinearColorAxis
                {
                    Unit              = wdp.Unit,
                    Position          = OxyPlot.Axes.AxisPosition.Right,
                    Palette           = pal,
                    HighColor         = OxyColors.Black,
                    LowColor          = OxyColors.Black,
                    FilterMinValue    = wdp.MinMax.Min,
                    FilterMaxValue    = wdp.MinMax.Max,
                    Minimum           = wdp.MinMax.Min,
                    Maximum           = wdp.MinMax.Max,
                    AxisDistance      = 5,
                    AxisTitleDistance = 5,
                    AxislineThickness = 100,
                });
            }

            model.PlotMargins   = new OxyThickness(40, 0, 50, 40);
            model.TitleFontSize = 14;

            //model.PlotType = PlotType.Polar;

            if (App.ControlPanelModel.SelectedViewport.Name == "Romania")
            {
                if (_roCounties == null)
                {
                    _roCounties = new ImageAnnotation
                    {
                        ImageSource = new OxyImage(File.ReadAllBytes("RO4.png")),

                        X     = new PlotLength(0.5, PlotLengthUnit.RelativeToPlotArea),
                        Width = new PlotLength(1, PlotLengthUnit.RelativeToPlotArea),

                        Y      = new PlotLength(0.51, PlotLengthUnit.RelativeToPlotArea),
                        Height = new PlotLength(0.8, PlotLengthUnit.RelativeToPlotArea),

                        HorizontalAlignment = OxyPlot.HorizontalAlignment.Center,
                        VerticalAlignment   = OxyPlot.VerticalAlignment.Middle
                    };
                }

                model.Annotations.Add(_roCounties);
            }
        }
Exemplo n.º 13
0
        private void DoReloadModel(string fieldDataFile, bool isWindMap)
        {
            // Create the plot model
            PlotModel model = this.Model;

            model.PlotMargins = new OxyThickness(30, 0, 60, 30);

            model.Axes.Clear();
            model.Series.Clear();
            model.Annotations.Clear();

            string fileTitle = Path.GetFileNameWithoutExtension(fieldDataFile);

            this.FileTitle = fileTitle;

            WeatherDataPalette wdp = WeatherDataPaletteFactory.GetPaletteForDataFile(fieldDataFile);
            bool contours          = wdp.ShowContours;
            bool heatmap           = wdp.ShowHeatmap;
            bool precipitationMap  = false;

            model.Title = string.Format("{0}: {1} [{2}]{3}",
                                        App.ControlPanelModel.SelectedViewport.Name,
                                        App.ControlPanelModel.SelectedDataType.Value,
                                        fileTitle,
                                        App.ControlPanelModel.SelectedDataType.Comments);

            DenseMatrix m = null;

            int minLon = App.ControlPanelModel.SelectedViewport.MinLon.Round();
            int maxLon = App.ControlPanelModel.SelectedViewport.MaxLon.Round();
            int minLat = App.ControlPanelModel.SelectedViewport.MinLat.Round();
            int maxLat = App.ControlPanelModel.SelectedViewport.MaxLat.Round();

            var fieldMatrix = FileSupport.LoadSubMatrixFromFile(fieldDataFile, minLon, maxLon, minLat, maxLat);

            bool interpolate = (fieldMatrix.RowCount < 10);

            if (interpolate)
            {
                fieldMatrix = fieldMatrix.Interpolate();
            }

            float[,] data  = null;
            float[,] data2 = null;

            float actualOffset = 0;

            if (wdp.ShowHeatmap)
            {
                float fOffset = (float)App.ControlPanelModel.Offset / 100;
                float delta   = wdp.MinMax.Delta;

                if (wdp.GetType() == typeof(C_00_Palette))
                {
                    delta = 100;
                }

                actualOffset = delta * fOffset;
            }

            if (wdp.GetType() == typeof(C_00_Palette))
            {
                // It's a map of the precipitation
                precipitationMap = true;

                string t01File = fieldDataFile.Replace("C_00", "T_01");
                string teFile  = fieldDataFile.Replace("C_00", "T_TE");
                string tsFile  = fieldDataFile.Replace("C_00", "T_TS");

                DenseMatrix T01 = FileSupport.LoadSubMatrixFromFile(t01File, minLon, maxLon, minLat, maxLat);
                DenseMatrix TE  = FileSupport.LoadSubMatrixFromFile(teFile, minLon, maxLon, minLat, maxLat);
                DenseMatrix TS  = FileSupport.LoadSubMatrixFromFile(tsFile, minLon, maxLon, minLat, maxLat);
                DenseMatrix C00 = fieldMatrix;

                if (interpolate)
                {
                    T01 = T01.Interpolate();
                    TE  = TE.Interpolate();
                    TS  = TS.Interpolate();
                }

                float sRain         = 0;
                float sSnow         = 300;
                float sSleet        = 600;
                float sFreezingRain = 900;

                data2 = C00.Transpose().ToArray();

                m = DenseMatrix.Create(C00.RowCount, C00.ColumnCount, (r, c) =>
                {
                    float cl = Math.Abs(C00[r, c]) + actualOffset;

                    if (cl <= 0)
                    {
                        cl = 0;
                    }
                    if (cl >= 100)
                    {
                        cl = 100;
                    }


                    float t01 = T01[r, c];
                    float te  = TE[r, c];
                    float ts  = TS[r, c];

                    float precipClThreshold = 10f;
                    float actualPrecipRate  = (cl - precipClThreshold);
                    if (actualPrecipRate >= 0)
                    {
                        return(PrecipTypeComputer <float> .Compute(

                                   // Actual temperatures
                                   te, ts, t01,

                                   // Boundary temperatures as read from simulation parameters
                                   SimulationParameters.Instance,

                                   // Computed precip type: snow
                                   () => (cl + sSnow),

                                   // Computed precip type: rain
                                   () => (cl + sRain),

                                   // Computed precip type: freezing rain
                                   () => (cl + sFreezingRain),

                                   // Computed precip type: sleet
                                   () => (cl + sSleet)
                                   ));
                    }
                    else if (cl > 5)
                    {
                        // Cloudy but without precipitation.
                        return(5);
                    }

                    // Sunny
                    return(0);
                });
            }
            else
            {
                m = DenseMatrix.Create(fieldMatrix.RowCount, fieldMatrix.ColumnCount, (r, c) =>
                                       fieldMatrix[r, c]);

                m.ADD(actualOffset);
            }

            Range <float> minMax      = wdp.MinMax;
            float         lineSpacing = wdp.LineSpacing;

            m    = m.MIN(minMax.Max).MAX(minMax.Min);
            data = m.Transpose().ToArray();

            float step = interpolate ? 0.5f : 1;

            List <float> cols = new List <float>();

            for (float i = minLon; i <= maxLon; i += step)
            {
                cols.Add(i);
            }

            List <float> rows = new List <float>();

            for (float i = maxLat; i >= minLat; i -= step)
            {
                rows.Add(i);
            }


            List <float> levels = new List <float>();

            for (float i = wdp.MinMax.Min; i <= wdp.MinMax.Max; i += wdp.LineSpacing)
            {
                levels.Add(i);
            }

            var pal = OxyPalette.Interpolate(levels.Count, wdp.ColorSteps.ToArray());

            List <OxyColor> lineColors = new List <OxyColor>();

            foreach (OxyColor c in wdp.ColorSteps)
            {
                if (heatmap)
                {
                    switch (wdp.LineColor.ColorMode)
                    {
                    case Views.LineColorMode.FixedColor:
                        lineColors.Add(wdp.LineColor.Color);
                        break;

                    case Views.LineColorMode.Best_Contrast:
                        lineColors.Add(c.Complementary());
                        break;

                    case Views.LineColorMode.Black_And_White:
                    {
                        System.Drawing.Color cw = System.Drawing.Color.FromArgb(c.R, c.G, c.B);
                        float br = cw.GetBrightness();

                        if (br < 0.5f)
                        {
                            lineColors.Add(OxyColors.White);
                        }
                        else
                        {
                            lineColors.Add(OxyColors.Black);
                        }
                    }
                    break;
                    }
                }
                else
                {
                    lineColors.Add(c);
                }
            }

            if (isWindMap)
            {
                this.FileTitle += "_WINDMAP";

                var D = (App.ControlPanelModel.SelectedViewport.MaxLon -
                         App.ControlPanelModel.SelectedViewport.MinLon);

                float hf = 1;
                if (D > 200)
                {
                    hf = 0.45f;
                }
                else if (D > 20)
                {
                    hf = 0.55f;
                }
                else
                {
                    hf = 1;
                }

                float sf = 0.9f * hf;

                DenseMatrix[] gr = fieldMatrix.ToWindComponents();
                float[,] dataX = gr[Direction.X].ToArray();
                float[,] dataY = gr[Direction.Y].ToArray();

                int rowCount = dataX.GetLength(0);
                int colCount = dataX.GetLength(1);

                for (int r = 0; r < rowCount; r++)
                {
                    for (int c = 0; c < colCount; c++)
                    {
                        float x = c + App.ControlPanelModel.SelectedViewport.MinLon;
                        float y = App.ControlPanelModel.SelectedViewport.MaxLat - r;

                        float dx = dataX[r, c];
                        float dy = -dataY[r, c];

                        int mod = (int)Math.Sqrt(dx * dx + dy * dy);

                        LineSeries line = new LineSeries();
                        line.Points.Add(new DataPoint(x, y));
                        line.Points.Add(new DataPoint(x + dx, y + dy));
                        line.StrokeThickness = 1;


                        if (mod < 2)
                        {
                            line.Color           = OxyColors.Green;
                            line.StrokeThickness = 2 * hf;
                        }
                        else if (mod < 5)
                        {
                            line.Color           = OxyColors.Red;
                            line.StrokeThickness = 2.5 * hf;
                        }
                        else
                        {
                            line.Color           = OxyColors.Magenta;
                            line.StrokeThickness = 3 * hf;
                        }

                        model.Series.Add(line);

                        ArrowAnnotation arrow = new ArrowAnnotation();
                        var             edy   = Math.Min(dy, 2);
                        arrow.StartPoint      = new DataPoint(x + sf * dx, y + sf * edy);
                        arrow.EndPoint        = new DataPoint(x + dx, y + edy);
                        arrow.Color           = line.Color;
                        arrow.StrokeThickness = line.StrokeThickness;
                        arrow.HeadWidth       = 1.5 * line.StrokeThickness;
                        arrow.HeadLength      = 3 * line.StrokeThickness;

                        model.Annotations.Add(arrow);

                        //goto MapFeatures;
                    }
                }
            }
            else
            {
                if (heatmap)
                {
                    if (precipitationMap)
                    {
                        HeatMapSeriesEx cloudMapSeries = new HeatMapSeriesEx
                        {
                            Data = data.ToDoubleArray(),
                            X0   = cols[0],
                            X1   = cols[cols.Count - 1],
                            Y0   = rows[0],
                            Y1   = rows[rows.Count - 1],
                        };
                        model.Series.Add(cloudMapSeries);
                    }
                    else
                    {
                        OxyPlot.Series.HeatMapSeries heatmapSeries = new OxyPlot.Series.HeatMapSeries
                        {
                            Data = data.ToDoubleArray(),
                            X0   = cols[0],
                            X1   = cols[cols.Count - 1],
                            Y0   = rows[0],
                            Y1   = rows[rows.Count - 1],
                        };
                        model.Series.Add(heatmapSeries);
                    }
                }

                if (contours)
                {
                    OxyPlot.Series.ContourSeries contour = new OxyPlot.Series.ContourSeries
                    {
                        ColumnCoordinates = cols.ToArray().ToDoubleArray(),
                        RowCoordinates    = rows.ToArray().ToDoubleArray(),
                        ContourLevels     = levels.ToArray().ToDoubleArray(),

                        ContourColors = lineColors.ToArray(), // Same # elements as the levels' array

                        Data = (data2 == null) ? data.ToDoubleArray() : data2.ToDoubleArray(),

                        LabelBackground  = OxyColors.Transparent,
                        ContourLevelStep = wdp.LineSpacing,
                        StrokeThickness  = wdp.LineWidth,
                        FontSize         = 15,
                        FontWeight       = 500,
                    };


                    model.Series.Add(contour);
                }
            }

MapFeatures:

            // Always do this last.
            AddMapFeatures(model, wdp, pal, isWindMap);
        }
Exemplo n.º 14
0
        public static PlotModel CreateRandomScatterSeriesWithColorAxisPlotModel(int n, OxyPalette palette,
                                                                                MarkerType markerType            // = MarkerType.Square
                                                                                , AxisPosition colorAxisPosition // = AxisPosition.Right
                                                                                , OxyColor highColor             // = null
                                                                                , OxyColor lowColor)             // = null)
        {
            var model = new PlotModel(string.Format("ScatterSeries (n={0})", n))
            {
                Background = OxyColors.LightGray
            };

            model.Axes.Add(new ColorAxis {
                Position = colorAxisPosition, Palette = palette, Minimum = -1, Maximum = 1, HighColor = highColor, LowColor = lowColor
            });

            var s1 = new ScatterSeries
            {
                MarkerType = markerType,
                MarkerSize = 6,
            };
            var random = new Random();

            for (int i = 0; i < n; i++)
            {
                double x = random.NextDouble() * 2.2 - 1.1;
                s1.Points.Add(new ScatterPoint(x, random.NextDouble())
                {
                    Value = x
                });
            }

            model.Series.Add(s1);
            return(model);
        }
Exemplo n.º 15
0
        public Tuple <OxyColor, OxyColor> GetCandleStickColors()
        {
            var colors = OxyPalette.Interpolate(2, Colors.ToArray()).Colors;

            return(Tuple.Create(colors[0], colors[1]));
        }
Exemplo n.º 16
0
 public static PlotModel CreateRandomScatterSeriesWithColorAxisPlotModel(int n, OxyPalette palette)//,
 //MarkerType markerType = MarkerType.Square, AxisPosition colorAxisPosition = AxisPosition.Right, OxyColor highColor = null, OxyColor lowColor = null)
 {
     return(CreateRandomScatterSeriesWithColorAxisPlotModel(n, palette,
                                                            MarkerType.Square, AxisPosition.Right, null, null));
 }
Exemplo n.º 17
0
 public OxyPalette GetColorAxisPalette(Axis axis)
 {
     return(OxyPalette.Interpolate(PaletteSize, Colors.ToArray()));
 }
Exemplo n.º 18
0
        private static PlotModel CreateRandomScatterSeriesWithColorAxisPlotModel(int n, OxyPalette palette, MarkerType markerType, AxisPosition colorAxisPosition, OxyColor highColor, OxyColor lowColor)
        {
            var model = new PlotModel {
                Title = string.Format("ScatterSeries (n={0})", n), Background = OxyColors.LightGray
            };
            var colorAxis = new LinearColorAxis {
                Position = colorAxisPosition, Palette = palette, Minimum = -1, Maximum = 1, HighColor = highColor, LowColor = lowColor
            };

            model.Axes.Add(colorAxis);
            model.Series.Add(CreateRandomScatterSeries(n, markerType, false, true, colorAxis));
            return(model);
        }
Exemplo n.º 19
0
        public Tuple <OxyColor, OxyColor> GetBoxPlotColors()
        {
            var colors = OxyPalette.Interpolate(2, Colors.ToArray()).Colors;

            return(Tuple.Create(OxyColors.Black, colors[0]));
        }
        private void AddLastTenLatLongWithTimeScatterSeries(PlotModel newPlot)
        {
            ScatterSeries pointsSeries;

            OxyPlotUtilities.CreateScatterPointSeries(out pointsSeries,
                                                      ChartAxisKeys.LongitudeKey, ChartAxisKeys.LatitudeKey, "Last Ten Books With Time");


            LineSeries overallSeries;

            OxyPlotUtilities.CreateLineSeries(out overallSeries, ChartAxisKeys.LongitudeKey, ChartAxisKeys.LatitudeKey, "Overall", 0);
            var faintColorBlue = OxyColor.FromArgb(80, OxyColors.Blue.R, OxyColors.Blue.G, OxyColors.Blue.B);

            overallSeries.Color           = faintColorBlue;
            overallSeries.StrokeThickness = 2;

            LineSeries lastTenSeries;

            OxyPlotUtilities.CreateLineSeries(out lastTenSeries, ChartAxisKeys.LongitudeKey, ChartAxisKeys.LatitudeKey, "Last 10", 0);
            var faintColorRed = OxyColor.FromArgb(80, OxyColors.Red.R, OxyColors.Red.G, OxyColors.Red.B);

            lastTenSeries.Color           = faintColorRed;
            lastTenSeries.StrokeThickness = 2;

            foreach (var delta in _mainModel.BookLocationDeltas)
            {
                var pointSize = 5;

                PolygonPoint latLong =
                    new PolygonPoint()
                {
                    Latitude = delta.AverageLatitudeLastTen, Longitude = delta.AverageLongitudeLastTen
                };
                double x, y;
                latLong.GetCoordinates(out x, out y);

                lastTenSeries.Points.Add(new DataPoint(x, y));

                ScatterPoint point =
                    new ScatterPoint(x, y, pointSize, delta.DaysSinceStart)
                {
                    Tag = delta.Date.ToString("ddd d MMM yyy")
                };
                pointsSeries.Points.Add(point);

                latLong =
                    new PolygonPoint()
                {
                    Latitude = delta.AverageLatitude, Longitude = delta.AverageLongitude
                };
                latLong.GetCoordinates(out x, out y);

                overallSeries.Points.Add(new DataPoint(x, y));
            }

            // don't draw these as renders the pic unusable
            //newPlot.Series.Add(lastTenSeries);
            //newPlot.Series.Add(overallSeries);

            pointsSeries.RenderInLegend      = false;
            pointsSeries.TrackerFormatString = "{Tag}\nLat/Long ( {4:0.###} ,{2:0.###} )";
            newPlot.Series.Add(pointsSeries);

            List <OxyColor> colors = new List <OxyColor>();

            foreach (var color in OxyPalettes.Jet(200).Colors)
            {
                var faintColor = OxyColor.FromArgb(80, color.R, color.G, color.B);
                colors.Add(faintColor);
            }

            OxyPalette faintPalette = new OxyPalette(colors);

            newPlot.Axes.Add(new LinearColorAxis {
                Position = AxisPosition.Right, Palette = faintPalette, Title = "Days Since Start"
            });
        }
Exemplo n.º 21
0
 /// <summary>
 /// Creates a gray-scale palette with the specified number of colors.
 /// </summary>
 /// <param name="numberOfColors">The number of colors to create for the palette.</param>
 /// <returns>A palette.</returns>
 public static OxyPalette Gray(int numberOfColors)
 {
     return(OxyPalette.Interpolate(numberOfColors, OxyColors.Black, OxyColors.White));
 }
Exemplo n.º 22
0
        public void MakeScatterChart([ItemNotNull][JetBrains.Annotations.NotNull] List <CalculationOutcome> outcomes, [JetBrains.Annotations.NotNull] string pngfullName, [ItemNotNull][JetBrains.Annotations.NotNull] List <SeriesEntry> series)
        {
            _calculationProfiler.StartPart(Utili.GetCurrentMethodAndClass());
            var plotModel1 = new PlotModel
            {
                LegendBorderThickness = 0,
                LegendOrientation     = LegendOrientation.Horizontal,
                LegendPlacement       = LegendPlacement.Outside,
                LegendPosition        = LegendPosition.BottomCenter,
                DefaultFontSize       = FontSize,
                LegendFontSize        = FontSize,
                DefaultFont           = "Arial",
                LegendFont            = "Arial"
            };
            var ca = new CategoryAxis
            {
                Minimum  = 0.4,
                Title    = "Number of Persons",
                Position = AxisPosition.Bottom
            };

            ca.Title = Xaxislabel;
            ca.Labels.Add("0");
            ca.Labels.Add("1");
            ca.Labels.Add("2");
            ca.Labels.Add("3");
            ca.Labels.Add("4");
            ca.Labels.Add("5");
            ca.Labels.Add("6");
            ca.MaximumPadding = 0.02;
            plotModel1.Axes.Add(ca);

            var la = new LinearAxis
            {
                Minimum        = 0,
                Position       = AxisPosition.Left,
                Title          = Yaxislabel,
                MaximumPadding = 0.02
            };

            plotModel1.Axes.Add(la);

            var sc = new LineSeries
            {
                LineStyle       = LineStyle.Dash,
                MarkerFill      = OxyColors.SkyBlue,
                MarkerSize      = 5,
                MarkerType      = MarkerType.Circle,
                StrokeThickness = 3
            };

            AddNRWPoints(sc, 1);
            sc.Title = Averagelabel;
            plotModel1.Series.Add(sc);

            var energyIntensities = outcomes.Select(x => x.EnergyIntensity).Distinct().ToList();

            energyIntensities.Sort((x, y) => string.Compare(x, y, StringComparison.Ordinal));
            series.Sort((x, y) => string.Compare(x.Version, y.Version, StringComparison.Ordinal));
            OxyPalette p = OxyPalettes.Hue64;

            if (series.Count > 1)
            {
                p = OxyPalettes.HueDistinct(series.Count);
            }

            var i = 0;

            for (var index = 0; index < series.Count; index++)
            {
                var seriesEntry = series[index];
                var entrylist   = outcomes
                                  .Where(x => x.EnergyIntensity == seriesEntry.EnergyIntensity &&
                                         x.LPGVersion == seriesEntry.Version)
                                  .ToList();
                var sc1 = new ScatterSeries();
                foreach (var entry in entrylist)
                {
                    sc1.Points.Add(
                        new ScatterPoint(entry.NumberOfPersons + seriesEntry.Offset, entry.ElectricityDouble));
                }

                sc1.Title = seriesEntry.DisplayName;
                var oc = p.Colors[i++];
                sc1.MarkerStroke = OxyColor.FromAColor(128, oc);
                sc1.MarkerFill   = oc;
                if (index == 0)
                {
                    sc1.MarkerType = MarkerType.Diamond;
                }
                else
                {
                    sc1.MarkerType = MarkerType.Star;
                }
                sc1.MarkerStrokeThickness = 1;
                plotModel1.Series.Add(sc1);
            }
            PngExporter.Export(plotModel1, pngfullName, _width, _height, OxyColor.FromRgb(255, 255, 255), _dpi);
            _calculationProfiler.StopPart(Utili.GetCurrentMethodAndClass());
            //ChartPDFCreator.OxyPDFCreator.Run(plotModel1, pdfFullName);
        }
Exemplo n.º 23
0
 /// <summary>
 /// Creates a blue/white/red palette with the specified number of colors.
 /// </summary>
 /// <param name="numberOfColors">The number of colors to create for the palette.</param>
 /// <returns>A palette.</returns>
 public static OxyPalette BlueWhiteRed(int numberOfColors)
 {
     return(OxyPalette.Interpolate(numberOfColors, OxyColors.Blue, OxyColors.White, OxyColors.Red));
 }
Exemplo n.º 24
0
        public static OxyPaletteMap CreateFromName(string name)
        {
            OxyPalette palette   = null;
            var        numPoints = 2;

            switch (name)
            {
            case "BlackWhiteRed":
            {
                numPoints = 3;
                palette   = OxyPalettes.BlackWhiteRed(NUM_COLORS);
                break;
            }

            case "BlueWhiteRed":
            {
                numPoints = 3;
                palette   = OxyPalettes.BlueWhiteRed(NUM_COLORS);
                break;
            }

            case "Cool":
            {
                numPoints = 3;
                palette   = OxyPalettes.Cool(NUM_COLORS);
                break;
            }

            case "Gray":
            {
                numPoints = 2;
                palette   = OxyPalettes.Gray(NUM_COLORS);
                break;
            }

            case "Hot":
            {
                numPoints = 5;
                palette   = OxyPalettes.Hot(NUM_COLORS);
                break;
            }

            case "Hue":
            {
                numPoints = 7;
                palette   = OxyPalettes.Hue(NUM_COLORS);
                break;
            }

            case "Jet":
            {
                numPoints = 5;
                palette   = OxyPalettes.Jet(NUM_COLORS);
                break;
            }

            case "Rainbow":
            {
                numPoints = 7;
                palette   = OxyPalettes.Rainbow(NUM_COLORS);
                break;
            }

            default:
            {
                return(null);

                break;
            }
            }
            var colorPoints = new Color[7];
            var brush       = new LinearGradientBrush();

            brush.StartPoint = new Point(0, 0.5);
            brush.EndPoint   = new Point(1, 0.5);
            var division = (NUM_COLORS / (numPoints - 1)) - 1;

            for (int i = 0; i < numPoints; i++)
            {
                var oxyColor = palette.Colors[(division * i)];
                colorPoints[i] = Color.FromArgb(oxyColor.A, oxyColor.R, oxyColor.G, oxyColor.B);
                brush.GradientStops.Add(new GradientStop(colorPoints[i], ((double)i / (numPoints - 1))));
            }

            return(new OxyPaletteMap(name, brush, palette));
        }
Exemplo n.º 25
0
 /// <summary>
 /// Creates a 'cool' palette with the specified number of colors.
 /// </summary>
 /// <param name="numberOfColors">The number of colors to create for the palette.</param>
 /// <returns>A palette.</returns>
 public static OxyPalette Cool(int numberOfColors)
 {
     return(OxyPalette.Interpolate(numberOfColors, OxyColors.Cyan, OxyColors.Magenta));
 }
Exemplo n.º 26
0
        static public Mat GetPresetColorMat(string strPalette)
        {
            OxyPlot.OxyPalette palette = null;
            Mat colorMap = new Mat(maxLookUpTable, 1, Emgu.CV.CvEnum.DepthType.Cv8U, 3);
            Image <Bgr, byte> colorImage = new Image <Bgr, byte>(1, maxLookUpTable);

            switch (strPalette)
            {
            case "WhiteHot":
                palette = Palette.WhiteHot(maxLookUpTable);
                break;

            case "BlackHot":
                palette = Palette.BlackHot(maxLookUpTable);
                break;

            case "ColdHot":
                palette = Palette.ColdHot(maxLookUpTable);
                break;

            case "HotSpot":
                palette = Palette.HotSpot(maxLookUpTable);
                break;

            case "ColdSpot":
                palette = Palette.ColdSpot(maxLookUpTable);
                break;

            case "Rainbow":
                palette = Palette.Rainbow(maxLookUpTable);
                break;

            case "Ironbow":
                palette = Palette.Ironbow(maxLookUpTable);
                break;

            case "Cool":
                palette = OxyPlot.OxyPalettes.Cool(maxLookUpTable);
                break;

            case "Hot":
                palette = OxyPlot.OxyPalettes.Hot(maxLookUpTable);
                break;

            case "Gray":
                palette = OxyPlot.OxyPalettes.Gray(maxLookUpTable);
                break;

            case "Hue":
                palette = OxyPlot.OxyPalettes.Hue(maxLookUpTable);
                break;

            case "Jet":
                palette = OxyPlot.OxyPalettes.Jet(maxLookUpTable);
                break;

            case "Transparent":
                palette = OxyPalette.Interpolate(maxLookUpTable, OxyColors.Transparent);
                break;

            default:
            case "None":
                //palette = null; //
                palette = OxyPlot.OxyPalettes.Gray(maxLookUpTable);       // Default "None" is gray
                break;
            }

            if (palette != null)
            {
                OxyColor[] colorTable = palette.Colors.ToArray();

                IntPtr ptrData = colorMap.DataPointer;
                for (var index = 0; index < palette.Colors.Count; index++)
                {
                    byte[] rgb = new byte[3] {
                        colorTable[index].B, colorTable[index].G, colorTable[index].R
                    };
                    Marshal.Copy(rgb, 0, ptrData + index * rgb.Length, rgb.Length);
                }
            }

            return(colorMap);
        }
Exemplo n.º 27
0
 public void Constructor()
 {
     var palette = new OxyPalette(OxyColors.Blue, OxyColors.White, OxyColors.Red);
     Assert.AreEqual(3, palette.Colors.Count);
 }
        private static PlotModel MakePlotmodel([ItemNotNull][JetBrains.Annotations.NotNull] List <string> personNames, [JetBrains.Annotations.NotNull] string yaxislabel)
        {
            var plotModel1 = new PlotModel
            {
                DefaultFontSize       = Fontsize,
                LegendFontSize        = Fontsize,
                LegendBorderThickness = 0,
                LegendOrientation     = LegendOrientation.Horizontal,
                LegendPlacement       = LegendPlacement.Outside,
                LegendPosition        = LegendPosition.BottomCenter,
                LegendSymbolMargin    = 20
            };
            var categoryAxis1 = new CategoryAxis
            {
                MajorStep      = 1,
                Minimum        = -0.5,
                MaximumPadding = 0.02,
                Title          = "Personen",
                Key            = "N",
                MinimumPadding = 0,
                FontSize       = Fontsize
            };
            var categoryAxis2 = new CategoryColorAxis
            {
                Position       = AxisPosition.Top,
                Minimum        = -0.5,
                MinimumPadding = 0,
                MajorStep      = 1
            };

            categoryAxis2.MinimumPadding = 0;
            categoryAxis2.TicklineColor  = OxyColors.White;
            categoryAxis2.MaximumPadding = 0.02;
            categoryAxis2.MajorTickSize  = 20;
            categoryAxis2.Key            = "coloraxis";
            categoryAxis2.Title          = "Haushalt";
            var lastHH        = string.Empty;
            var distancecount = 30;
            var colors        = new List <OxyColor>();
            var lastColor     = OxyColors.LightBlue;

            for (var i = 0; i < personNames.Count; i++)
            {
                distancecount++;
                var hhName = personNames[i].Substring(0, 5);
                if (lastHH != hhName)
                {
                    lastHH = hhName;
                    if (lastColor == OxyColors.LightBlue)
                    {
                        lastColor = OxyColors.Green;
                    }
                    else
                    {
                        lastColor = OxyColors.LightBlue;
                    }
                    if (distancecount > 20)
                    {
                        categoryAxis2.Labels.Add(hhName);
                        distancecount = 0;
                    }
                    else
                    {
                        categoryAxis2.Labels.Add(" ");
                    }
                }
                else
                {
                    categoryAxis2.Labels.Add(" ");
                }
                colors.Add(lastColor);
                if (i % 10 == 0)
                {
                    categoryAxis1.ActualLabels.Add(i.ToString(CultureInfo.CurrentCulture));
                }
                else
                {
                    categoryAxis1.ActualLabels.Add(" ");
                }
            }
            Logger.Info("Category labels: " + categoryAxis2.Labels.Count);
            Logger.Info("Total number of colors: " + colors.Count);
            colors.Add(OxyColors.White);
            var p2 = new OxyPalette(colors);

            categoryAxis2.Palette = p2;
            plotModel1.Axes.Add(categoryAxis2);
            categoryAxis1.GapWidth = 0;
            plotModel1.Axes.Add(categoryAxis1);
            var linearAxis1 = new LinearAxis
            {
                AbsoluteMinimum = 0,
                MaximumPadding  = 0.01,
                MinimumPadding  = 0,
                MinorTickSize   = 0,
                Title           = yaxislabel
            };

            plotModel1.Axes.Add(linearAxis1);
            return(plotModel1);
        }
        private void AddBars([JetBrains.Annotations.NotNull] CalculationProfiler.ProgramPart part, int row, double offset, int fontsize,
                             [JetBrains.Annotations.NotNull] Dictionary <int, IntervalBarSeries> itemsByLevel, [JetBrains.Annotations.NotNull] OxyPalette palette, [JetBrains.Annotations.NotNull] PlotModel pm)
        {
            var runningsum = offset;

            for (var i = 0; i < part.Children.Count; i++)
            {
                var programPart = part.Children[i];
                AddBars(programPart, row + 1, runningsum, fontsize, itemsByLevel, palette, pm);
                runningsum += programPart.Duration2;
            }

            //bar
            var item = new IntervalBarItem(offset, offset + part.Duration2)
            {
                Color = palette.Colors[_parts.IndexOf(part)]
            };

            if (!itemsByLevel.ContainsKey(1))
            {
                var series = new IntervalBarSeries
                {
                    FontSize = fontsize
                };
                itemsByLevel.Add(1, series);
            }
            var ibs = new IntervalBarSeries();

            for (var i = 0; i < row; i++)
            {
                ibs.Items.Add(new IntervalBarItem(0, 0, ""));
            }
            ibs.StrokeThickness = 0.1;
            ibs.Items.Add(item);
            pm.Series.Add(ibs);
            //  item.Title = name;

            //annotation
            if (string.IsNullOrWhiteSpace(part.Key))
            {
                throw new LPGException("Empty profiler key");
            }
            var name = part.Key;

            if (name.Length > 100)
            {
                name = name.Substring(0, 97) + "...";
            }
            var textAnnotation1 = new TextAnnotation
            {
                StrokeThickness = 0,
                FontSize        = 6,
                Padding         = new OxyThickness(10, 0, 10, 0)
            };
            var txtValue = name + " - " + part.Duration2.ToString("N1", CultureInfo.InvariantCulture) + "s";

            textAnnotation1.Text = txtValue;

            textAnnotation1.TextHorizontalAlignment = HorizontalAlignment.Left;
            textAnnotation1.TextPosition            = new DataPoint(offset, row + GetOffset(row));

            pm.Annotations.Add(textAnnotation1);
        }