public void rescale() { double maxY = 0; double minY = 0; foreach (LineSeries s in this.Model.Series) { //in some cases s.maxY/minY are not yet set... :/ List <EPRDataPoint> dp = (List <EPRDataPoint>)s.ItemsSource; List <double> y = new List <double>(); foreach (EPRDataPoint p in dp) { y.Add(p.Y); } if (maxY < y.Max()) { maxY = y.Max(); } if (minY > y.Min()) { minY = y.Min(); } } maxY = maxY + maxY * 0.1; minY = minY + minY * 0.1; //rescale LinearAxis ya = (LinearAxis)this.Model.Axes[1]; ya.AbsoluteMaximum = maxY; ya.AbsoluteMinimum = minY; //full zoom out on y scale ya.Zoom(ya.AbsoluteMinimum, ya.AbsoluteMaximum); this.InvalidatePlot(); }
public MainWindow() { this.InitializeComponent(); this.DataContext = this; this.Model1 = new PlotModel { Title = "Model 1" }; this.Model2 = new PlotModel { Title = "Model 2" }; var axis1 = new LinearAxis { Position = AxisPosition.Bottom }; var axis2 = new LinearAxis { Position = AxisPosition.Bottom }; this.Model1.Axes.Add(axis1); this.Model2.Axes.Add(axis2); this.Model1.Series.Add(new FunctionSeries(Math.Sin, 0, 10, 1000)); this.Model2.Series.Add(new FunctionSeries(x => Math.Sin(x) / x, 0, 10, 1000)); bool isInternalChange = false; axis1.AxisChanged += (s, e) => { if (isInternalChange) { return; } isInternalChange = true; axis2.Zoom(axis1.ActualMinimum, axis1.ActualMaximum); this.Model2.InvalidatePlot(false); isInternalChange = false; }; axis2.AxisChanged += (s, e) => { if (isInternalChange) { return; } isInternalChange = true; axis1.Zoom(axis2.ActualMinimum, axis2.ActualMaximum); this.Model1.InvalidatePlot(false); isInternalChange = false; }; this.DataContext = new { Model1, Model2 }; }
public void Axis_DesiredMargin_WithPosition() { var plot = new PlotModel(); var axis1 = new LinearAxis { Position = AxisPosition.Bottom, StartPosition = 0, EndPosition = 0.5, Title = "X-axis 1" }; var axis2 = new LinearAxis { Position = AxisPosition.Bottom, StartPosition = 1, EndPosition = 0.5, Title = "X-axis 2" }; plot.Axes.Add(axis1); plot.Axes.Add(axis2); axis1.Zoom(0, 80); axis2.Zoom(0, 80); plot.UpdateAndRenderToNull(800, 600); Assert.That(axis1.DesiredMargin.Left, Is.EqualTo(5).Within(0.5), "axis1 left"); Assert.That(axis1.DesiredMargin.Top, Is.EqualTo(0).Within(1e-6), "axis1 top"); Assert.That(axis1.DesiredMargin.Right, Is.EqualTo(0).Within(1e-6), "axis1 right"); Assert.That(axis1.DesiredMargin.Bottom, Is.EqualTo(35).Within(0.5), "axis1 bottom"); Assert.That(axis2.DesiredMargin.Left, Is.EqualTo(0d).Within(1e-6), "axis2 left"); Assert.That(axis2.DesiredMargin.Top, Is.EqualTo(0d).Within(1e-6), "axis2 top"); Assert.That(axis2.DesiredMargin.Right, Is.EqualTo(5).Within(0.5), "axis2 right"); Assert.That(axis2.DesiredMargin.Bottom, Is.EqualTo(35).Within(0.5), "axis2 bottom"); // larger numbers on axis -> larger desired size axis1.Zoom(10000, 11000); axis2.Zoom(10000, 11000); plot.UpdateAndRenderToNull(800, 600); Assert.That(axis1.DesiredMargin.Left, Is.EqualTo(12.5).Within(0.5), "axis1 left"); Assert.That(axis1.DesiredMargin.Top, Is.EqualTo(0).Within(1e-6), "axis1 top"); Assert.That(axis1.DesiredMargin.Right, Is.EqualTo(0).Within(1e-6), "axis1 right"); Assert.That(axis1.DesiredMargin.Bottom, Is.EqualTo(35).Within(0.5), "axis1 bottom"); Assert.That(axis2.DesiredMargin.Left, Is.EqualTo(0d).Within(1e-6), "axis2 left"); Assert.That(axis2.DesiredMargin.Top, Is.EqualTo(0d).Within(1e-6), "axis2 top"); Assert.That(axis2.DesiredMargin.Right, Is.EqualTo(12.5).Within(0.5), "axis2 right"); Assert.That(axis2.DesiredMargin.Bottom, Is.EqualTo(35).Within(0.5), "axis2 bottom"); }
public void Axis_DesiredMargin() { var xaxis = new LinearAxis { Position = AxisPosition.Bottom, Title = "X-axis" }; var yaxis = new LinearAxis { Position = AxisPosition.Left, Title = "Y-axis" }; var plot = new PlotModel { Title = "Simple plot" }; plot.Axes.Add(xaxis); plot.Axes.Add(yaxis); var ls = new LineSeries(); ls.Points.Add(new DataPoint(3, 13)); ls.Points.Add(new DataPoint(10, 47)); ls.Points.Add(new DataPoint(30, 23)); ls.Points.Add(new DataPoint(40, 65)); ls.Points.Add(new DataPoint(80, 10)); plot.Series.Add(ls); // initial setting plot.UpdateAndRenderToNull(800, 600); Assert.That(yaxis.DesiredMargin.Left, Is.EqualTo(35.0).Within(0.5), "y-axis left"); Assert.That(yaxis.DesiredMargin.Top, Is.EqualTo(5).Within(0.5), "y-axis top"); Assert.That(yaxis.DesiredMargin.Right, Is.EqualTo(0.0).Within(1e-6), "y-axis right"); Assert.That(yaxis.DesiredMargin.Bottom, Is.EqualTo(5).Within(0.5), "y-axis bottom"); Assert.That(xaxis.DesiredMargin.Left, Is.EqualTo(5).Within(0.5), "x-axis left"); Assert.That(xaxis.DesiredMargin.Top, Is.EqualTo(0.0).Within(1e-6), "x-axis top"); Assert.That(xaxis.DesiredMargin.Right, Is.EqualTo(5).Within(0.5), "x-axis right"); Assert.That(xaxis.DesiredMargin.Bottom, Is.EqualTo(35.0).Within(0.5), "x-axis bottom"); // larger numbers on axis -> larger desired size yaxis.Zoom(10000, 11000); xaxis.Zoom(10000, 11000); plot.UpdateAndRenderToNull(800, 600); Assert.That(yaxis.DesiredMargin.Left, Is.EqualTo(50.0).Within(0.5), "y-axis left"); Assert.That(yaxis.DesiredMargin.Top, Is.EqualTo(5).Within(0.5), "y-axis top"); Assert.That(yaxis.DesiredMargin.Right, Is.EqualTo(0.0).Within(1e-6), "y-axis right"); Assert.That(yaxis.DesiredMargin.Bottom, Is.EqualTo(5).Within(0.5), "y-axis bottom"); Assert.That(xaxis.DesiredMargin.Left, Is.EqualTo(12.5).Within(0.5), "x-axis left"); Assert.That(xaxis.DesiredMargin.Top, Is.EqualTo(0.0).Within(1e-6), "x-axis top"); Assert.That(xaxis.DesiredMargin.Right, Is.EqualTo(12.5).Within(0.5), "x-axis right"); Assert.That(xaxis.DesiredMargin.Bottom, Is.EqualTo(35.0).Within(0.5), "x-axis bottom"); }
private LinearAxis CreateAxisForPlotModel(double minVal, double maxVal, string title, bool isXAxis) { var axis = new LinearAxis(); const double offset = 0.1; double range = maxVal - minVal; axis.AbsoluteMinimum = minVal - offset * range; axis.AbsoluteMaximum = maxVal + offset * range; axis.Position = isXAxis ? AxisPosition.Bottom : AxisPosition.Left; axis.Title = title; axis.Zoom(axis.AbsoluteMinimum, axis.AbsoluteMaximum); axis.IsZoomEnabled = false; axis.MajorGridlineStyle = LineStyle.Solid; axis.MinorGridlineStyle = LineStyle.Dot; return axis; }
private LinearAxis CreateAxisForPlotModel(double minVal, double maxVal, string title, bool isXAxis) { var axis = new LinearAxis(); const double offset = 0.1; double range = maxVal - minVal; axis.AbsoluteMinimum = minVal - offset * range; axis.AbsoluteMaximum = maxVal + offset * range; axis.Position = isXAxis ? AxisPosition.Bottom : AxisPosition.Left; axis.Title = title; axis.Zoom(axis.AbsoluteMinimum, axis.AbsoluteMaximum); axis.IsZoomEnabled = false; axis.MajorGridlineStyle = LineStyle.Solid; axis.MinorGridlineStyle = LineStyle.Dot; return(axis); }
static public PlotModel LineSeriesWithLabels(List <API.Data.UserJsonTypes.NetsoulRawData> netsoul) { model = new PlotModel(); model.Background = OxyColors.Transparent; model.LegendBorderThickness = 0; model.PlotAreaBorderThickness = new OxyThickness(0, 0, 0, 0); model.Padding = new OxyThickness(0, 0, 0, 0); model.PlotAreaBorderColor = OxyColors.Transparent; model.Series.Clear(); if (model.PlotView != null) { model.Axes.Clear(); } CategoryAxis a3 = new CategoryAxis { IsAxisVisible = false, Position = AxisPosition.Top, AbsoluteMinimum = 0, AbsoluteMaximum = netsoul.Count - 0.5 }; a3.Zoom(netsoul.Count - 8, netsoul.Count - 0.5); LinearAxis a1 = new LinearAxis { IsAxisVisible = true, Position = AxisPosition.Left, AbsoluteMinimum = 0, AbsoluteMaximum = 24 }; a1.Zoom(0, 24); model.Axes.Add(a3); model.Axes.Add(a1); model.Series.Add(GetActiveScoolLog(netsoul)); model.Series.Add(GetIdleScoolLog(netsoul)); model.Series.Add(GetActiveOutLog(netsoul)); model.Series.Add(GetIdleOutLog(netsoul)); model.Series.Add(GetAverageLog(netsoul)); return(model); }
public MainWindow() { this.InitializeComponent(); this.DataContext = this; this.Model1 = new PlotModel("Model 1"); this.Model2 = new PlotModel("Model 2"); var axis1 = new LinearAxis(AxisPosition.Bottom); var axis2 = new LinearAxis(AxisPosition.Bottom); this.Model1.Axes.Add(axis1); this.Model2.Axes.Add(axis2); this.Model1.Series.Add(new FunctionSeries(Math.Sin, 0, 10, 1000)); this.Model2.Series.Add(new FunctionSeries(x => Math.Sin(x) / x, 0, 10, 1000)); bool isInternalChange = false; axis1.AxisChanged += (s, e) => { if (isInternalChange) { return; } isInternalChange = true; axis2.Zoom(axis1.ActualMinimum, axis1.ActualMaximum); this.Model2.InvalidatePlot(false); isInternalChange = false; }; axis2.AxisChanged += (s, e) => { if (isInternalChange) { return; } isInternalChange = true; axis1.Zoom(axis2.ActualMinimum, axis2.ActualMaximum); this.Model1.InvalidatePlot(false); isInternalChange = false; }; }
/// <summary> /// Adjusts the Y extent. /// </summary> /// <param name="series">Series.</param> /// <param name="xaxis">Xaxis.</param> /// <param name="yaxis">Yaxis.</param> private static void AdjustYExtent(CandleStickSeries series, DateTimeAxis xaxis, LinearAxis yaxis) { var xmin = xaxis.ActualMinimum; var xmax = xaxis.ActualMaximum; var istart = series.FindByX(xmin); var iend = series.FindByX(xmax, istart); var ymin = double.MaxValue; var ymax = double.MinValue; for (int i = istart; i <= iend; i++) { var bar = series.Items[i]; ymin = Math.Min(ymin, bar.Low); ymax = Math.Max(ymax, bar.High); } var extent = ymax - ymin; var margin = extent * 0.10; yaxis.Zoom(ymin - margin, ymax + margin); }
// Only for static chart! private void AdjustYExtent(LineSeries lserie, LinearAxis xaxis, LinearAxis yaxis) { if (xaxis != null && yaxis != null && lserie.Points.Count() != 0) { double istart = xaxis.ActualMinimum; double iend = xaxis.ActualMaximum; var ptlist = lserie.Points.FindAll(p => p.X >= istart && p.X <= iend); double ymin = double.MaxValue; double ymax = double.MinValue; for (int i = 0; i <= ptlist.Count() - 1; i++) { ymin = Math.Min(ymin, ptlist[i].Y); ymax = Math.Max(ymax, ptlist[i].Y); } var extent = ymax - ymin; var margin = extent * 0; //change the 0 by a value to add some extra up and down margin yaxis.Zoom(ymin - margin, ymax + margin); } }
private PlotModel CreatePlotModel() { timeAxis.Position = AxisPosition.Bottom; timeAxis.MajorGridlineStyle = LineStyle.Solid; timeAxis.MajorGridlineThickness = 1; timeAxis.MajorGridlineColor = OxyColor.FromRgb(192, 192, 192); timeAxis.MinorGridlineStyle = LineStyle.Solid; timeAxis.MinorGridlineThickness = 1; timeAxis.MinorGridlineColor = OxyColor.FromRgb(232, 232, 232); timeAxis.StartPosition = 1; timeAxis.EndPosition = 0; timeAxis.MinimumPadding = 0; timeAxis.MaximumPadding = 0; timeAxis.AbsoluteMinimum = 0; timeAxis.Minimum = 0; timeAxis.AbsoluteMaximum = 24 * 60 * 60; timeAxis.Zoom( settings.GetValue("plotPanel.MinTimeSpan", 0.0f), settings.GetValue("plotPanel.MaxTimeSpan", 10.0f * 60)); timeAxis.StringFormat = "h:mm"; var units = new Dictionary<SensorType, string>(); units.Add(SensorType.Voltage, "V"); units.Add(SensorType.Clock, "MHz"); units.Add(SensorType.Temperature, "°C"); units.Add(SensorType.Load, "%"); units.Add(SensorType.Fan, "RPM"); units.Add(SensorType.Flow, "L/h"); units.Add(SensorType.Control, "%"); units.Add(SensorType.Level, "%"); units.Add(SensorType.Factor, "1"); units.Add(SensorType.Power, "W"); units.Add(SensorType.Data, "GB"); foreach (SensorType type in Enum.GetValues(typeof(SensorType))) { var axis = new LinearAxis(); axis.Position = AxisPosition.Left; axis.MajorGridlineStyle = LineStyle.Solid; axis.MajorGridlineThickness = 1; axis.MajorGridlineColor = timeAxis.MajorGridlineColor; axis.MinorGridlineStyle = LineStyle.Solid; axis.MinorGridlineThickness = 1; axis.MinorGridlineColor = timeAxis.MinorGridlineColor; axis.AxislineStyle = LineStyle.Solid; axis.Title = type.ToString(); axis.Key = type.ToString(); axis.Zoom( settings.GetValue("plotPanel.Min" + axis.Key, float.NaN), settings.GetValue("plotPanel.Max" + axis.Key, float.NaN)); if (units.ContainsKey(type)) axis.Unit = units[type]; axes.Add(type, axis); } var model = new PlotModel(); model.Axes.Add(timeAxis); foreach (var axis in axes.Values) model.Axes.Add(axis); model.PlotMargins = new OxyThickness(0); model.IsLegendVisible = false; return model; }
public Form1() { InitializeComponent(); lblText.Text = ""; lblStickCoords.Text = ""; plot.BackColor = Color.White; plot.Model = new PlotModel(); indexAxis.Position = AxisPosition.Bottom; indexAxis.MajorTickSize = 20; indexAxis.MinorTickSize = 5; indexAxis.Minimum = 0; indexAxis.Maximum = 100; indexAxis.Zoom(0, 100); indexAxis.TickStyle = OxyPlot.Axes.TickStyle.Inside; //indexAxis.IsZoomEnabled = false; //indexAxis.IsPanEnabled = true; plot.Model.Axes.Add(indexAxis); LinearAxis throttleAxis = new LinearAxis(); OxyColor throttleColour = OxyColors.DarkGreen; throttleAxis.Title = "Throttle"; throttleAxis.Key = throttleAxis.Title; throttleAxis.Position = AxisPosition.Left; throttleAxis.AxislineColor = throttleColour; throttleAxis.TextColor = throttleColour; throttleAxis.TicklineColor = throttleColour; throttleAxis.TitleColor = throttleColour; throttleAxis.MinorTicklineColor = throttleColour; throttleAxis.Minimum = -PLOTLIMIT; throttleAxis.Maximum = PLOTLIMIT; throttleAxis.MajorTickSize = 20; throttleAxis.MinorTickSize = 5; throttleAxis.TickStyle = OxyPlot.Axes.TickStyle.Inside; throttleAxis.IsZoomEnabled = false; //throttleAxis.IsPanEnabled = false; plot.Model.Axes.Add(throttleAxis); LinearAxis steeringAxis = new LinearAxis(); OxyColor steeringColour = OxyColors.Red; steeringAxis.Title = "Steering"; steeringAxis.Key = steeringAxis.Title; steeringAxis.Position = AxisPosition.Right; steeringAxis.AxislineColor = steeringColour; steeringAxis.TextColor = steeringColour; steeringAxis.TicklineColor = steeringColour; steeringAxis.TitleColor = steeringColour; steeringAxis.MinorTicklineColor = steeringColour; steeringAxis.Minimum = -PLOTLIMIT; steeringAxis.Maximum = PLOTLIMIT; steeringAxis.MajorTickSize = 20; steeringAxis.MinorTickSize = 5; steeringAxis.TickStyle = OxyPlot.Axes.TickStyle.Inside; steeringAxis.IsZoomEnabled = false; //steeringAxis.IsPanEnabled = false; plot.Model.Axes.Add(steeringAxis); throttleSeries.Color = throttleColour; steeringSeries.Color = steeringColour; indicatorSeries.Color = OxyColors.Pink; indicatorSeries.Points.Add(new DataPoint(0, -PLOTLIMIT)); indicatorSeries.Points.Add(new DataPoint(0, PLOTLIMIT)); throttleSeries.Title = "Throttle"; steeringSeries.Title = "Steering"; throttleSeries.YAxisKey = throttleAxis.Key; steeringSeries.YAxisKey = steeringAxis.Key; plot.Model.Series.Add(throttleSeries); plot.Model.Series.Add(steeringSeries); plot.Model.Series.Add(indicatorSeries); }
/// <summary> /// Initializes a new instance of the SpectrumPlotViewModel class. /// </summary> /// <param name="dialogService">Dialog service for opening dialogs from ViewModel.</param> /// <param name="fragSeqVm">Gets or sets the view model for the fragmentation sequence (fragment ion generator)</param> /// <param name="multiplier">How much padding should be before the lowest peak and after the highest peak?</param> /// <param name="autoZoomXAxis">Should this view model automatically zoom the plot?</param> public SpectrumPlotViewModel(IMainDialogService dialogService, IFragmentationSequenceViewModel fragSeqVm, double multiplier, bool autoZoomXAxis = true) { this.dialogService = dialogService; FragmentationSequenceViewModel = fragSeqVm; this.autoZoomXAxis = autoZoomXAxis; errorMapViewModel = new ErrorMapViewModel(dialogService); ShowUnexplainedPeaks = true; ShowFilteredSpectrum = false; ShowDeconvolutedSpectrum = false; AutoAdjustYAxis = true; Title = string.Empty; XAxis = new LinearAxis { Title = "m/z", StringFormat = "0.###", Position = AxisPosition.Bottom, }; PlotModel = new AutoAdjustedYPlotModel(XAxis, multiplier) { IsLegendVisible = false, YAxis = { Title = "Intensity", StringFormat = "0e0" } }; SequenceViewerViewModel = new SequenceViewerViewModel(); ions = new LabeledIonViewModel[0]; // When Spectrum updates, clear the filtered spectrum, deconvoluted spectrum, and filtered+deconvoluted spectrum this.WhenAnyValue(x => x.Spectrum) .Subscribe(spectrum => { spectrumDirty = true; filteredSpectrum = null; deconvolutedSpectrum = null; filteredDeconvolutedSpectrum = null; }); // If deconvolution option has changed, the X Axis should change. this.WhenAnyValue(x => x.ShowDeconvolutedSpectrum) .Subscribe(_ => spectrumDirty = true); // When Spectrum or ions change, or deconvoluted or filtered spectrum are selected, update spectrum plot this.WhenAnyValue( x => x.Spectrum, x => x.FragmentationSequenceViewModel.LabeledIonViewModels, x => x.ShowDeconvolutedSpectrum, x => x.ShowDeconvolutedIons, x => x.ShowFilteredSpectrum, x => x.ShowUnexplainedPeaks, x => x.ShowOnlyTop20Peaks) .Where(x => x.Item1 != null && x.Item2 != null) .Throttle(TimeSpan.FromMilliseconds(400), RxApp.TaskpoolScheduler) .SelectMany(async x => { var vms = await FragmentationSequenceViewModel.GetLabeledIonViewModels(); return(await Task.WhenAll( vms.Select( ion => ion.GetPeaksAsync(GetSpectrum(), ShowDeconvolutedSpectrum || ShowDeconvolutedIons)))); }) .Subscribe(dataPoints => { ions = FragmentationSequenceViewModel.LabeledIonViewModels; SetTerminalResidues(dataPoints); UpdatePlotModel(dataPoints); if (FragmentationSequenceViewModel is FragmentationSequenceViewModel model) { SequenceViewerViewModel.FragmentationSequence = model; SequenceViewerViewModel.SelectedSpectrum = Spectrum as ProductSpectrum; } }); // Update plot when data changes this.WhenAnyValue(x => x.Spectrum).Where(spectrum => spectrum == null).Subscribe( _ => { PlotModel.Annotations.Clear(); PlotModel.ClearSeries(); PlotModel.InvalidatePlot(true); }); // Update ions when relative intensity threshold changes. IcParameters.Instance.WhenAnyValue(x => x.PrecursorRelativeIntensityThreshold).Subscribe(precursorRelInt => { if (FragmentationSequenceViewModel is PrecursorSequenceIonViewModel precursorFragVm) { precursorFragVm.RelativeIntensityThreshold = precursorRelInt; } }); // Update plot when settings change IcParameters.Instance.WhenAnyValue(x => x.ProductIonTolerancePpm, x => x.IonCorrelationThreshold) .Throttle(TimeSpan.FromMilliseconds(400), RxApp.TaskpoolScheduler) .SelectMany(async x => await Task.WhenAll(ions.Select(ion => ion.GetPeaksAsync(GetSpectrum(), ShowDeconvolutedSpectrum, false)))) .Subscribe(UpdatePlotModel); // When AutoAdjustYAxis changes, update value in plot model. this.WhenAnyValue(x => x.AutoAdjustYAxis) .Subscribe(autoAdjust => { PlotModel.AutoAdjustYAxis = autoAdjust; PlotModel.YAxis.IsZoomEnabled = !autoAdjust; PlotModel.YAxis.IsPanEnabled = !autoAdjust; if (autoAdjust) { PlotModel.XAxis.Reset(); PlotModel.YAxis.Reset(); } }); // 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); PlotModel.InvalidatePlot(false); }); this.WhenAnyValue(y => y.YMinimum, y => y.YMaximum) .Throttle(TimeSpan.FromSeconds(1), RxApp.TaskpoolScheduler) .Where(y => !PlotModel.YAxis.ActualMinimum.Equals(y.Item1) || !PlotModel.YAxis.ActualMaximum.Equals(y.Item2)) .Subscribe( y => { PlotModel.YAxis.Zoom(y.Item1, y.Item2); PlotModel.InvalidatePlot(false); }); // Update X min and max properties when x axis is panned or zoomed xAxis.AxisChanged += (o, e) => { XMinimum = Math.Round(xAxis.ActualMinimum, 3); XMaximum = Math.Round(xAxis.ActualMaximum, 3); }; // Update Y min and max properties when Y axis is panned or zoomed PlotModel.YAxis.AxisChanged += (o, e) => { YMinimum = Math.Round(PlotModel.YAxis.ActualMinimum, 3); YMaximum = Math.Round(PlotModel.YAxis.ActualMaximum, 3); }; // Save As Image Command requests a file path from the user and then saves the spectrum plot as an image SaveAsImageCommand = ReactiveCommand.Create(SaveAsImageImplementation); // Error map command opens a new error map window and passes it the most abundant isotope peak data points // and the current sequence. OpenErrorMapCommand = ReactiveCommand.Create(() => dialogService.OpenErrorMapWindow(errorMapViewModel)); OpenScanSelectionCommand = ReactiveCommand.Create(OpenScanSelectionImplementation); SaveAsTsvCommand = ReactiveCommand.Create(SaveAsTsvImplementation); SaveToClipboardCommand = ReactiveCommand.Create(SaveToClipboardImplementation); }
/// <summary> /// Build the isotope plot showing theoretical isotopic profile and /// actual isotopic profile. /// </summary> /// <param name="theoretical">Actual isotopic profile.</param> /// <param name="observed">Actual isotopic profile.</param> /// <param name="isProfile">A value indicating whether the peak list is profile mode.</param> public void BuildPlot(PeakDataPoint[] theoretical, PeakDataPoint[] observed, bool isProfile) { PlotModel.Series.Clear(); // Create series for theoretical isotope profile var theoSeries = new PeakPointSeries { Title = "Theoretical", ItemsSource = theoretical, Color = OxyColor.FromArgb(120, 0, 0, 0), StrokeThickness = 3.0, TrackerFormatString = "{0}" + Environment.NewLine + "{1}: {2:0.###}" + Environment.NewLine + "{3}: {4:0.###}" + Environment.NewLine + "Index: {Index:0.###}" }; PlotModel.Series.Add(theoSeries); if (isProfile) { // Create series for actual isotope profile var actSeries = new ProfilePeakPointSeries { Title = "Observed", ItemsSource = observed, Color = OxyColor.FromArgb(120, 255, 0, 0), StrokeThickness = 1.0, TrackerFormatString = "{0}" + Environment.NewLine + "{1}: {2:0.###}" + Environment.NewLine + "{3}: {4:0.###}" + Environment.NewLine + "Index: {Index:0.###}" }; PlotModel.Series.Add(actSeries); } else { // Create series for actual isotope profile var actSeries = new PeakPointSeries { Title = "Observed", ItemsSource = observed, Color = OxyColor.FromArgb(120, 255, 0, 0), StrokeThickness = 3.0, TrackerFormatString = "{0}" + Environment.NewLine + "{1}: {2:0.###}" + Environment.NewLine + "{3}: {4:0.###}" + Environment.NewLine + "Index: {Index:0.###}" }; PlotModel.Series.Add(actSeries); } // Calculate min and max boundaries for plot var min = theoretical.Min(p => p.X); var max = theoretical.Max(p => p.X); min -= (max - min) / 3; var absMin = Math.Max(0, min - 10); max += (max - min) / 3; var absMax = max + 10; xaxis.Minimum = min; xaxis.AbsoluteMinimum = absMin; xaxis.Maximum = max; xaxis.AbsoluteMaximum = absMax; xaxis.Zoom(min, max); PlotModel.IsLegendVisible = true; PlotModel.InvalidatePlot(true); PlotModel.AdjustForZoom(); }
public FrameTimeViewModel(IEventAggregator events) { Events = events; DisplayName = "Frame Timeline"; Model = new PlotModel(); Model.LegendBackground = OxyColor.FromArgb(200, 255, 255, 255); Model.LegendBorder = OxyColors.Black; Model.LegendPlacement = LegendPlacement.Inside; Model.LegendPosition = LegendPosition.RightTop; Model.Title = "Frame Timeline"; DownSampler = new PlotDownsampler(); /* * var timeLineAxis = new TimeSpanAxis() { * MajorGridlineStyle = LineStyle.Solid, * MinorGridlineStyle = LineStyle.Dot, * IntervalLength = 30, * MajorStep = 1, * Position = AxisPosition.Bottom, * AbsoluteMinimum = 0, * }; */ BottomAxis = new LinearAxis() { AbsoluteMinimum = 0, Position = AxisPosition.Bottom, MinorStep = 1000, MajorStep = 1000 * 60, }; BottomAxis.AxisChanged += TimeLineAxis_AxisChanged; BottomAxis.LabelFormatter = t => $"{t/60000}"; Model.Axes.Add(BottomAxis); /* * var dateTimeAxis = new DateTimeAxis { * Position = AxisPosition.Bottom, * IntervalType = DateTimeIntervalType.Seconds, * MinorIntervalType = DateTimeIntervalType.Milliseconds, * //IntervalLength = 50 * }; * * plotModel.Axes.Add(dateTimeAxis); */ LeftAxis = new LinearAxis() { AbsoluteMinimum = 0, Position = AxisPosition.Left, MinorStep = 1, MajorStep = 10, Title = "Time Ms", }; Model.Axes.Add(LeftAxis); LeftAxis.Zoom(0, 40); FrameTimeSeries = new LineSeries { Title = "Frame", StrokeThickness = 1, // DataFieldX = nameof(FrameEntry.Time), //DataFieldY = nameof(FrameEntry.TimeTaken), }; Model.Series.Add(FrameTimeSeries); DownSampler.AddSeries(FrameTimeSeries, this.OnPropertyChanges(n => FrametimePoints)); SelectedTimeSeries = new LineSeries { Title = "Selected", StrokeThickness = 1, Color = OxyColors.Red, }; Model.Series.Add(SelectedTimeSeries); DownSampler.AddSeries(SelectedTimeSeries, this.OnPropertyChanges(n => SelectedNode). Where(n => n != null || PLog.NodeStats.Count == 0). Select(n => GetNodeDataPoints(n))); UpdateWorldJobTimeSeries = new LineSeries { Title = "UpdateWorldJob", StrokeThickness = 1, Color = OxyColors.Black, }; Model.Series.Add(UpdateWorldJobTimeSeries); DownSampler.AddSeries(UpdateWorldJobTimeSeries, this.OnPropertyChanges(n => FrametimePoints). Where(n => this.PLog.GetNameId("UpdateWorldJob::Run") != -1). Select(n => GetNodeDataPoints(this.PLog.GetNodeStats("UpdateWorldJob::Run"), f => f.InclusiveTime))); Ranges = PlotRangeTracker.Install(Model); Ranges.RangeCreated += Ranges_RangeCreated; Ranges.RangeMoved += Ranges_RangeCreated; Ranges.RangeRemoved += (r, min, max) => { NodeList = PLog.NodeStats; }; PLog = new ProfileLog(); }
/// <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()); }
public PlottableEPRSpectrum plotEPR(EPRPlotView plotView) { PlotModel pm = new PlotModel(); pm.IsLegendVisible = true; pm.LegendPosition = LegendPosition.RightTop; pm.DefaultFontSize = 14; pm.LegendFontSize = 14; LineSeries se = new LineSeries { ItemsSource = BPUtil.getDataPoints(getX(), getY()), Title = this.getTitle() }; LinearAxis x = new LinearAxis { Position = AxisPosition.Bottom, Title = "B/" + unit }; pm.PlotAreaBorderThickness = new OxyThickness(1.5); x.MajorGridlineThickness = 1.5; x.MinorGridlineThickness = 1.5; x.AbsoluteMaximum = getX().Last(); x.AbsoluteMinimum = getX().First(); LinearAxis y = new LinearAxis { Position = AxisPosition.Left }; y.IsAxisVisible = false; LinkedAxis g = new LinkedAxis(x, calcG, calcB); g.Position = AxisPosition.Top; g.Title = "g"; g.MajorGridlineThickness = 1.5; g.MinorGridlineThickness = 1.5; pm.Series.Add(se); pm.Axes.Add(x); pm.Axes.Add(y); pm.Axes.Add(g); //rescale y.AbsoluteMaximum = getY().Max() + getY().Max() * 0.1; y.AbsoluteMinimum = getY().Min() + getY().Min() * 0.1; //full zoom out on y scale y.Zoom(y.AbsoluteMinimum, y.AbsoluteMaximum); plotView.InvalidatePlot(); //sync bool isc = false; x.AxisChanged += (s, e) => { if (isc) { return; } isc = true; g.Zoom(calcG(x.ActualMinimum), calcG(x.ActualMaximum)); pm.InvalidatePlot(false); isc = false; }; g.AxisChanged += (s, e) => { if (isc) { return; } isc = true; x.Zoom(calcB(g.ActualMinimum), calcB(g.ActualMaximum)); pm.InvalidatePlot(false); isc = false; }; pm.MouseDown += (s, e) => Application.Current.Windows.OfType <MainWindow>().First().pm_MouseDown(s, e); pm.MouseMove += (s, e) => Application.Current.Windows.OfType <MainWindow>().First().pm_MouseMove(s, e); pm.MouseUp += (s, e) => Application.Current.Windows.OfType <MainWindow>().First().pm_MouseUp(s, e); plotView.Model = pm; plotView.spc = this; return(this); }
private PlotModel CreatePlotModel() { _timeAxis.Position = AxisPosition.Bottom; _timeAxis.MajorGridlineStyle = LineStyle.Solid; _timeAxis.MajorGridlineThickness = 1; _timeAxis.MajorGridlineColor = OxyColor.FromRgb(192, 192, 192); _timeAxis.MinorGridlineStyle = LineStyle.Solid; _timeAxis.MinorGridlineThickness = 1; _timeAxis.MinorGridlineColor = OxyColor.FromRgb(232, 232, 232); _timeAxis.StartPosition = 1; _timeAxis.EndPosition = 0; _timeAxis.MinimumPadding = 0; _timeAxis.MaximumPadding = 0; _timeAxis.AbsoluteMinimum = 0; _timeAxis.Minimum = 0; _timeAxis.AbsoluteMaximum = 24 * 60 * 60; _timeAxis.Zoom( _settings.GetValue("plotPanel.MinTimeSpan", 0.0f), _settings.GetValue("plotPanel.MaxTimeSpan", 10.0f * 60)); _timeAxis.StringFormat = "h:mm"; var units = new Dictionary <SensorType, string> { { SensorType.Voltage, "V" }, { SensorType.Clock, "MHz" }, { SensorType.Temperature, "°C" }, { SensorType.Load, "%" }, { SensorType.Fan, "RPM" }, { SensorType.Flow, "L/h" }, { SensorType.Control, "%" }, { SensorType.Level, "%" }, { SensorType.Factor, "1" }, { SensorType.Power, "W" }, { SensorType.Data, "GB" }, { SensorType.Frequency, "Hz" } }; foreach (SensorType type in Enum.GetValues(typeof(SensorType))) { string typeName = type.ToString(); var axis = new LinearAxis { Position = AxisPosition.Left, MajorGridlineStyle = LineStyle.Solid, MajorGridlineThickness = 1, MajorGridlineColor = _timeAxis.MajorGridlineColor, MinorGridlineStyle = LineStyle.Solid, MinorGridlineThickness = 1, MinorGridlineColor = _timeAxis.MinorGridlineColor, AxislineStyle = LineStyle.Solid, Title = typeName, Key = typeName, }; var annotation = new LineAnnotation { Type = LineAnnotationType.Horizontal, ClipByXAxis = false, ClipByYAxis = false, LineStyle = LineStyle.Solid, Color = OxyColors.Black, YAxisKey = typeName, StrokeThickness = 2, }; axis.AxisChanged += (sender, args) => annotation.Y = axis.ActualMinimum; axis.TransformChanged += (sender, args) => annotation.Y = axis.ActualMinimum; axis.Zoom(_settings.GetValue("plotPanel.Min" + axis.Key, float.NaN), _settings.GetValue("plotPanel.Max" + axis.Key, float.NaN)); if (units.ContainsKey(type)) { axis.Unit = units[type]; } _axes.Add(type, axis); _annotations.Add(type, annotation); } var model = new ScaledPlotModel(_dpiXScale, _dpiYScale); model.Axes.Add(_timeAxis); foreach (LinearAxis axis in _axes.Values) { model.Axes.Add(axis); } model.IsLegendVisible = false; return(model); }
private PlotModel CreatePlotModel() { timeAxis.Position = AxisPosition.Bottom; timeAxis.MajorGridlineStyle = LineStyle.Solid; timeAxis.MajorGridlineThickness = 1; timeAxis.MajorGridlineColor = OxyColor.FromRgb(192, 192, 192); timeAxis.MinorGridlineStyle = LineStyle.Solid; timeAxis.MinorGridlineThickness = 1; timeAxis.MinorGridlineColor = OxyColor.FromRgb(232, 232, 232); timeAxis.StartPosition = 1; timeAxis.EndPosition = 0; timeAxis.MinimumPadding = 0; timeAxis.MaximumPadding = 0; timeAxis.AbsoluteMinimum = 0; timeAxis.Minimum = 0; timeAxis.AbsoluteMaximum = 24 * 60 * 60; timeAxis.Zoom( settings.GetValue("plotPanel.MinTimeSpan", 0.0f), settings.GetValue("plotPanel.MaxTimeSpan", 10.0f * 60)); timeAxis.StringFormat = "h:mm"; var units = new Dictionary <SensorType, string>(); units.Add(SensorType.Voltage, "V"); units.Add(SensorType.Clock, "MHz"); units.Add(SensorType.Temperature, "°C"); units.Add(SensorType.Load, "%"); units.Add(SensorType.Fan, "RPM"); units.Add(SensorType.Flow, "L/h"); units.Add(SensorType.Control, "%"); units.Add(SensorType.Level, "%"); units.Add(SensorType.Factor, "1"); units.Add(SensorType.Power, "W"); units.Add(SensorType.Data, "GB"); units.Add(SensorType.Current, "A"); units.Add(SensorType.KWH, "kWh"); foreach (SensorType type in Enum.GetValues(typeof(SensorType))) { var axis = new LinearAxis(); axis.Position = AxisPosition.Left; axis.MajorGridlineStyle = LineStyle.Solid; axis.MajorGridlineThickness = 1; axis.MajorGridlineColor = timeAxis.MajorGridlineColor; axis.MinorGridlineStyle = LineStyle.Solid; axis.MinorGridlineThickness = 1; axis.MinorGridlineColor = timeAxis.MinorGridlineColor; axis.AxislineStyle = LineStyle.Solid; axis.Title = type.ToString(); axis.Key = type.ToString(); axis.Zoom( settings.GetValue("plotPanel.Min" + axis.Key, float.NaN), settings.GetValue("plotPanel.Max" + axis.Key, float.NaN)); if (units.ContainsKey(type)) { axis.Unit = units[type]; } axes.Add(type, axis); } var model = new PlotModel(); model.Axes.Add(timeAxis); foreach (var axis in axes.Values) { model.Axes.Add(axis); } model.PlotMargins = new OxyThickness(0); model.IsLegendVisible = false; return(model); }