public MainWindowModel() { PlotModel = new PlotModel(); var s1 = new OxyPlot.Series.LineSeries(); s1.Points.Add(new DataPoint(0, 4)); s1.Points.Add(new DataPoint(10, 13)); s1.Points.Add(new DataPoint(20, 15)); s1.Points.Add(new DataPoint(30, 16)); s1.Points.Add(new DataPoint(40, 12)); s1.Points.Add(new DataPoint(50, 12)); PlotModel.Series.Add(s1); var l1 = new OxyPlot.Annotations.LineAnnotation(); l1.Type = OxyPlot.Annotations.LineAnnotationType.Horizontal; l1.Y = 5; l1.MinimumX = 2; l1.MaximumX = 15; l1.LineStyle = OxyPlot.LineStyle.Solid; PlotModel.Annotations.Add(l1); double x; l1.MouseDown += (s, e) => { x = (l1 as OxyPlot.Annotations.LineAnnotation).InverseTransform(e.Position).X; l1.MinimumX = x; PlotModel.RefreshPlot(true); PlotModel.InvalidatePlot(true); //OnPropertyChanged("PlotModel"); e.Handled = true; }; }
/// <summary> /// The association hypothesis plot. /// </summary> /// <param name="hypothesis"> /// The hypothesis. /// </param> /// <param name="datasetName"> /// The dataset name. /// </param> /// <param name="targetDescriptor"> /// The target descriptor. /// </param> /// <returns> /// The <see cref="PlotModel"/>. /// </returns> private PlotModel AssociationHypothesisPlot(AssociationHypothesis hypothesis, string datasetName, IImsTarget target, bool plotXAxisFromZero = false) { PlotModel model = new PlotModel(); model.LegendBorderThickness = 0; model.LegendOrientation = LegendOrientation.Vertical; model.LegendPlacement = LegendPlacement.Inside; model.LegendPosition = LegendPosition.LeftTop; model.TitlePadding = 0; model.Title = "Optimal Association Hypothesis Plot"; model.Subtitle = string.Format("Target: {0}, dataset: {1}", target.TargetDescriptor, datasetName) ; model.Axes.Add( new LinearAxis { Title = "IMS arrival time (milliseconds)", MajorGridlineStyle = LineStyle.Solid, Position = AxisPosition.Left, }); model.Axes.Add( new LinearAxis { Title = "P/(T*V) with P and T nondimensionalized (1/V)", Position = AxisPosition.Bottom, MajorGridlineStyle = LineStyle.Solid, }); // Add all the points IEnumerable<ObservedPeak> onTrackPeaks = hypothesis.OnTrackObservations; IEnumerable<ObservedPeak> offTrackPeaks = hypothesis.AllObservations.Where(x => !hypothesis.IsOnTrack(x)); Func<ObservedPeak, ScatterPoint> fitPointMap = obj => { ObservedPeak observation = obj; ContinuousXYPoint xyPoint = observation.ToContinuousXyPoint(false, 0); double size = MapToPointSize(observation); ScatterPoint sp = new ScatterPoint(xyPoint.X, xyPoint.Y, size); return sp; }; var ontrackSeries= new ScatterSeries { Title = "[Peaks On Tracks]", MarkerFill = OxyColors.BlueViolet, MarkerType = MarkerType.Circle }; var offtrackSeries= new ScatterSeries { Title = "[Peaks Off Tracks]", MarkerFill = OxyColors.Red, MarkerType = MarkerType.Circle }; ontrackSeries.Points.AddRange(onTrackPeaks.Select(x => fitPointMap(x))); offtrackSeries.Points.AddRange(offTrackPeaks.Select(x => fitPointMap(x))); model.Series.Add(ontrackSeries); model.Series.Add(offtrackSeries); var allTracks = hypothesis.Tracks; // Add the tracks as linear axes int count = 1; foreach (var track in allTracks) { FitLine fitline = track.FitLine; LineAnnotation annotation = new LineAnnotation(); annotation.Slope = fitline.Slope; annotation.Intercept = fitline.Intercept; annotation.TextPadding = 3; annotation.TextMargin = 2; annotation.Text = string.Format("Conformer {0} - mz: {1:F2}; ccs: {2:F2}, Isotopic Score: {3:F3}; Track Probability: {4:F2}; R2: {5:F5};", count, track.AverageMzInDalton, track.GetMobilityInfoForTarget(target).CollisionCrossSectionArea, track.TrackStatistics.IsotopicScore, track.TrackProbability, track.FitLine.RSquared); count++; model.Annotations.Add(annotation); //Func<object, DataPoint> lineMap = obj => //{ // ObservedPeak observation = (ObservedPeak)obj; // ContinuousXYPoint xyPoint = observation.ToContinuousXyPoint(); // double x = xyPoint.X; // double y = fitline.ModelPredictX2Y(x); // DataPoint sp = new DataPoint(x, y); // return sp; //}; //model.Series.Add(new LineSeries() //{ // Mapping = lineMap, // ItemsSource = track.ObservedPeaks, // Color = OxyColors.Purple //}); } return model; }