Ejemplo n.º 1
0
        void MSGraphControl_ZoomEvent(ZedGraphControl sender, ZoomState oldState, ZoomState newState, PointF mousePosition)
        {
            MSGraphPane pane = MasterPane.FindChartRect(mousePosition) as MSGraphPane;

            if (pane == null)
            {
                mousePosition = PointToClient(new Point(ContextMenuStrip.Left, ContextMenuStrip.Top));
            }
            pane = MasterPane.FindChartRect(mousePosition) as MSGraphPane;
            if (pane == null)
            {
                return;
            }

            Graphics g = CreateGraphics();

            pane.SetScale(g);

            if (IsSynchronizeXAxes)
            {
                foreach (MSGraphPane syncPane in MasterPane.PaneList)
                {
                    if (syncPane == pane)
                    {
                        continue;
                    }

                    syncPane.SetScale(g);
                }
            }

            Refresh();
        }
Ejemplo n.º 2
0
        public MSGraphControl()
        {
            InitializeComponent();

            GraphPane = new MSGraphPane(new LabelBoundsCache()); // replace default ZedGraph.GraphPane

            IsZoomOnMouseCenter = true;
            IsEnableVZoom       = false;
            IsEnableVPan        = false;
            IsEnableHEdit       = false;
            IsEnableVEdit       = false;

            EditButtons      = MouseButtons.Left;
            EditModifierKeys = Keys.None;

            _unzoomButtons     = new MouseButtonClicks(MouseButtons.Middle);
            _unzoomButtons2    = new MouseButtonClicks(MouseButtons.None);
            _unzoomAllButtons  = new MouseButtonClicks(MouseButtons.Left, 2);
            _unzoomAllButtons2 = new MouseButtonClicks(MouseButtons.None);

            ZoomEvent        += MSGraphControl_ZoomEvent;
            MouseMoveEvent   += MSGraphControl_MouseMoveEvent;
            MouseClick       += MSGraphControl_MouseClick;
            MouseDoubleClick += MSGraphControl_MouseClick;
            Resize           += MSGraphControl_Resize;
        }
Ejemplo n.º 3
0
        bool MSGraphControl_MouseMoveEvent(ZedGraphControl sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.None)
            {
                return(false);
            }

            Point pos = MousePosition;

            pos = PointToClient(pos);
            MSGraphPane pane = MasterPane.FindChartRect(new PointF(pos.X, pos.Y)) as MSGraphPane;

            if (pane == null)
            {
                pos = PointToClient(new Point(ContextMenuStrip.Left, ContextMenuStrip.Top));
            }
            pane = MasterPane.FindChartRect(new PointF(pos.X, pos.Y)) as MSGraphPane;
            if (pane == null)
            {
                return(false);
            }

            if ((IsEnableHPan) &&
                ((e.Button == PanButtons && ModifierKeys == PanModifierKeys) ||
                 (e.Button == PanButtons2 && ModifierKeys == PanModifierKeys2)))
            {
                Graphics g = CreateGraphics();
                pane.SetScale(g);
            }
            return(false);
        }
Ejemplo n.º 4
0
        public MSGraphControl()
        {
            InitializeComponent();

            GraphPane = new MSGraphPane(new LabelBoundsCache()); // replace default ZedGraph.GraphPane

            IsZoomOnMouseCenter = true;
            IsEnableVZoom = false;
            IsEnableVPan = false;
            IsEnableHEdit = false;
            IsEnableVEdit = false;

            EditButtons = MouseButtons.Left;
            EditModifierKeys = Keys.None;

            _unzoomButtons = new MouseButtonClicks( MouseButtons.Middle );
            _unzoomButtons2 = new MouseButtonClicks( MouseButtons.None );
            _unzoomAllButtons = new MouseButtonClicks( MouseButtons.Left, 2 );
            _unzoomAllButtons2 = new MouseButtonClicks( MouseButtons.None );

            ZoomEvent += MSGraphControl_ZoomEvent;
            MouseMoveEvent += MSGraphControl_MouseMoveEvent;
            MouseClick += MSGraphControl_MouseClick;
            MouseDoubleClick += MSGraphControl_MouseClick;
            Resize += MSGraphControl_Resize;
        }
Ejemplo n.º 5
0
 public MSGraphPane(MSGraphPane other)
     : base(other)
 {
     _currentItemType  = other._currentItemType;
     _pointAnnotations = new GraphObjList();
     _manualLabels     = new Dictionary <TextObj, RectangleF>();
     _labelBoundsCache = other._labelBoundsCache;
 }
Ejemplo n.º 6
0
 public MSGraphPane(MSGraphPane other)
     : base(other)
 {
     _currentItemType = other._currentItemType;
     _pointAnnotations = new GraphObjList();
     _manualLabels = new Dictionary<TextObj, RectangleF>();
     _labelBoundsCache = other._labelBoundsCache;
 }
Ejemplo n.º 7
0
        void MSGraphControl_MouseClick(object sender, MouseEventArgs e)
        {
            MSGraphPane pane = MasterPane.FindChartRect(e.Location) as MSGraphPane;

            if (pane != null && (IsEnableHZoom || IsEnableVZoom))
            {
                if ((_unzoomButtons.MatchesEvent(e) && ModifierKeys == _unzoomModifierKeys) ||
                    (_unzoomButtons2.MatchesEvent(e) && ModifierKeys == _unzoomModifierKeys2))
                {
                    if (IsSynchronizeXAxes)
                    {
                        foreach (MSGraphPane syncPane in MasterPane.PaneList)
                        {
                            syncPane.ZoomStack.Pop(syncPane);
                        }
                    }
                    else
                    {
                        pane.ZoomStack.Pop(pane);
                    }
                }
                else if (_unzoomAllButtons.MatchesEvent(e) ||
                         _unzoomAllButtons2.MatchesEvent(e))
                {
                    if (IsSynchronizeXAxes)
                    {
                        foreach (MSGraphPane syncPane in MasterPane.PaneList)
                        {
                            syncPane.ZoomStack.PopAll(syncPane);
                        }
                    }
                    else
                    {
                        pane.ZoomStack.PopAll(pane);
                    }
                }
                else
                {
                    return;
                }

                Graphics g = CreateGraphics();
                if (IsSynchronizeXAxes)
                {
                    foreach (MSGraphPane syncPane in MasterPane.PaneList)
                    {
                        syncPane.SetScale(g);
                    }
                }
                else
                {
                    pane.SetScale(g);
                }

                Refresh();
            }
        }
Ejemplo n.º 8
0
        public CurveItem AddGraphItem(MSGraphPane pane, IMSGraphItemInfo item, bool setScale)
        {
            if (item.GraphItemType != pane.CurrentItemType)
            {
                pane.CurveList.Clear();
                pane.CurrentItemType = item.GraphItemType;
                pane.ZoomStack.PopAll(pane);
                item.CustomizeXAxis(pane.XAxis);
                item.CustomizeYAxis(pane.YAxis);
            }

            CurveItem newItem = makeMSGraphItem(item);

            pane.CurveList.Add(newItem);
            // If you are adding multiple graph items, it is quickest to set the scale
            // once at the end.
            if (setScale)
            {
                pane.SetScale(CreateGraphics());
            }
            return(newItem);
        }
Ejemplo n.º 9
0
        private void AddRetentionTimeAnnotation(MSGraphPane graphPane, Graphics g, GraphObjList annotations,
            PointF ptTop, string title, GraphObjType graphObjType, Color color, ScaledRetentionTime retentionTime)
        {
            string label = string.Format("{0}\n{1:F01}", title, retentionTime.DisplayTime); // Not L10N
            FontSpec fontLabel = CreateFontSpec(color, _fontSpec.Size);
            SizeF sizeLabel = fontLabel.MeasureString(g, label, graphPane.CalcScaleFactor());
            PointF realTopPoint = ptTop;
            ptTop = new PointF(0, ptTop.Y + sizeLabel.Height + 15);
            float chartHeightWithLabel = graphPane.Chart.Rect.Height + sizeLabel.Height + 15;
            double intensityChartFraction = (ptTop.Y - realTopPoint.Y) / chartHeightWithLabel;

            LineObj stick = new LineObj(color, retentionTime.DisplayTime, intensityChartFraction, retentionTime.DisplayTime, 1)
                                {
                                    IsClippedToChartRect = true,
                                    Location = { CoordinateFrame = CoordType.XScaleYChartFraction },
                                    ZOrder = ZOrder.E_BehindCurves,
                                    Line = { Width = 1 },
                                    Tag = new GraphObjTag(this, graphObjType, retentionTime),
                                };
            annotations.Add(stick);

            ptTop = new PointF(0, ptTop.Y - 5);
            intensityChartFraction = (ptTop.Y - realTopPoint.Y) / chartHeightWithLabel;
            TextObj text = new TextObj(label, retentionTime.DisplayTime, intensityChartFraction,
                                       CoordType.XScaleYChartFraction, AlignH.Center, AlignV.Bottom)
                               {
                                   IsClippedToChartRect = true,
                                   ZOrder = ZOrder.E_BehindCurves,
                                   FontSpec = CreateFontSpec(color, _fontSpec.Size),
                                   Tag = new GraphObjTag(this, graphObjType, retentionTime),
                               };
            annotations.Add(text);
        }
Ejemplo n.º 10
0
 public abstract void AddPreCurveAnnotations(MSGraphPane graphPane, Graphics g,
     MSPointList pointList, GraphObjList annotations);
Ejemplo n.º 11
0
        public override void AddPreCurveAnnotations(MSGraphPane graphPane, Graphics g,
            MSPointList pointList, GraphObjList annotations)
        {
            if (Chromatogram == null)
                return;

            // Give priority to showing the best peak text object above all other annotations
            if (DragInfo != null || (!HideBest && TransitionChromInfo != null) || CurveAnnotation != null)
            {
                // Show text and arrow for the best peak
                double intensityBest = 0;
                if (_bestPeakTimeIndex != -1)
                {
                    ScaledRetentionTime timeBest = new ScaledRetentionTime(_measuredTimes[_bestPeakTimeIndex], _displayTimes[_bestPeakTimeIndex]);
                    float xBest = graphPane.XAxis.Scale.Transform(timeBest.DisplayTime);
                    intensityBest = _intensities[_bestPeakTimeIndex];
                    float yBest = graphPane.YAxis.Scale.Transform(intensityBest);

                    if (GraphChromatogram.ShowRT != ShowRTChrom.none || DragInfo != null)
                    {
                        // Best peak gets its own label to avoid curve overlap detection
                        double intensityLabel = graphPane.YAxis.Scale.ReverseTransform(yBest - 5);
                        float? massError = Settings.Default.ShowMassError && TransitionChromInfo != null
                                               ? TransitionChromInfo.MassError
                                               : null;
                        double dotProduct = _dotProducts != null ? _bestProduct : 0;

                        TextObj text;
                        if (CurveAnnotation != null)
                        {
                            // Darken peptide name a little so light colors stand out against the white background.
                            var color = FontSpec.FontColor;
                            if (!GraphInfo.IsSelected)
                                color = Color.FromArgb(color.R*7/10, color.G*7/10, color.B*7/10);
                            var fontSpec = new FontSpec(FontSpec) { FontColor = color, Angle = 90 };
                            if (GraphInfo.IsSelected)
                                fontSpec = new FontSpec(fontSpec) {IsBold = true, Size = fontSpec.Size + 2, IsAntiAlias = true};

                            // Display peptide name label using vertical text.
                            text = new TextObj(CurveAnnotation, timeBest.DisplayTime, intensityLabel,
                                CoordType.AxisXYScale, AlignH.Left, AlignV.Center)
                            {
                                ZOrder = ZOrder.A_InFront,
                                IsClippedToChartRect = true,
                                FontSpec = fontSpec,
                                Tag = new GraphObjTag(this, GraphObjType.best_peak, timeBest),
                            };
                        }
                        else
                        {
                            string label = FormatTimeLabel(timeBest.DisplayTime, massError, dotProduct);

                            text = new TextObj(label, timeBest.DisplayTime, intensityLabel,
                                CoordType.AxisXYScale, AlignH.Center, AlignV.Bottom)
                            {
                                ZOrder = ZOrder.A_InFront,
                                IsClippedToChartRect = true,
                                FontSpec = FontSpec,
                                Tag = new GraphObjTag(this, GraphObjType.best_peak, timeBest),
                            };
                        }

                        annotations.Add(text);
                    }

                    // If showing multiple peptides, skip the best peak arrow indicator.
                    if (CurveAnnotation == null)
                    {
                        // Show the best peak arrow indicator
                        double timeArrow = graphPane.XAxis.Scale.ReverseTransform(xBest - 4);
                        double intensityArrow = graphPane.YAxis.Scale.ReverseTransform(yBest - 2);

                        ArrowObj arrow = new ArrowObj(COLOR_BEST_PEAK, 12f,
                            timeArrow, intensityArrow, timeArrow, intensityArrow)
                        {
                            Location = {CoordinateFrame = CoordType.AxisXYScale},
                            IsArrowHead = true,
                            IsClippedToChartRect = true,
                            ZOrder = ZOrder.A_InFront
                        };
                        annotations.Add(arrow);
                    }
                }

                // Show the best peak boundary lines
                if (CurveAnnotation == null)
                {
                    double startTime = 0, endTime = 0;
                    if (DragInfo != null)
                    {
                        startTime = DragInfo.StartTime.MeasuredTime;
                        endTime = DragInfo.EndTime.MeasuredTime;
                    }
                    else if (TransitionChromInfo != null)
                    {
                        var tranPeakInfo = TransitionChromInfo;
                        startTime = tranPeakInfo.StartRetentionTime;
                        endTime = tranPeakInfo.EndRetentionTime;
                    }
                    AddPeakBoundaries(graphPane, annotations, true,
                        ScaleRetentionTime(startTime), ScaleRetentionTime(endTime), intensityBest);
                }
            }
        }
Ejemplo n.º 12
0
        public override void AddAnnotations(MSGraphPane graphPane, Graphics g,
            MSPointList pointList, GraphObjList annotations)
        {
            if (Chromatogram == null)
                return;

            // Calculate maximum y for potential retention time indicators
            PointF ptTop = new PointF(0, graphPane.Chart.Rect.Top);

            if (GraphChromatogram.ShowRT != ShowRTChrom.none)
            {
                if (RetentionMsMs != null)
                {
                    foreach (double retentionTime in RetentionMsMs)
                    {
                        Color color = COLOR_MSMSID_TIME;
                        if (SelectedRetentionMsMs.HasValue && Equals((float) retentionTime, (float) SelectedRetentionMsMs))
                        {
                            color = ColorSelected;
                        }
                        AddRetentionTimeAnnotation(graphPane, g, annotations, ptTop,
                            Resources.ChromGraphItem_AddAnnotations_ID, GraphObjType.ms_ms_id, color,
                            ScaleRetentionTime(retentionTime));
                    }
                }
                if (AlignedRetentionMsMs != null)
                {
                    foreach (var time in AlignedRetentionMsMs)
                    {
                        var scaledTime = ScaleRetentionTime(time);
                        var line = new LineObj(COLOR_ALIGNED_MSMSID_TIME, scaledTime.DisplayTime, 0,
                                               scaledTime.DisplayTime, 1)
                        {
                            ZOrder = ZOrder.F_BehindGrid,
                            Location = { CoordinateFrame = CoordType.XScaleYChartFraction },
                            IsClippedToChartRect = true,
                            Tag = new GraphObjTag(this, GraphObjType.aligned_ms_id, scaledTime),
                        };
                        annotations.Add(line);
                    }
                }
                if (UnalignedRetentionMsMs != null)
                {
                    foreach (var time in UnalignedRetentionMsMs)
                    {
                        var scaledTime = ScaleRetentionTime(time);
                        var line = new LineObj(COLOR_UNALIGNED_MSMSID_TIME, scaledTime.DisplayTime, 0,
                                               scaledTime.DisplayTime, 1)
                        {
                            ZOrder = ZOrder.F_BehindGrid,
                            Location = { CoordinateFrame = CoordType.XScaleYChartFraction },
                            IsClippedToChartRect = true,
                            Tag = new GraphObjTag(this, GraphObjType.unaligned_ms_id, scaledTime),
                        };
                        annotations.Add(line);
                    }
                }
            }

            // Draw retention time indicator, if set
            if (RetentionPrediction.HasValue)
            {
                double time = RetentionPrediction.Value;

                // Create temporary label to calculate positions
                if (GraphChromatogram.ShowRT != ShowRTChrom.none)
                {
                    AddRetentionTimeAnnotation(graphPane,
                                               g,
                                               annotations,
                                               ptTop,
                                               Resources.ChromGraphItem_AddAnnotations_Predicted,
                                               GraphObjType.predicted_rt_window,
                                               COLOR_RETENTION_TIME,
                                               ScaleRetentionTime(time));
                }

                // Draw background for retention time window
                if (RetentionWindow > 0)
                {
                    double x1 = ScaleRetentionTime(time - RetentionWindow/2).DisplayTime;
                    double x2 = ScaleRetentionTime(time + RetentionWindow/2).DisplayTime;
                    BoxObj box = new BoxObj(x1, 0, x2-x1, 1,
                                            COLOR_RETENTION_WINDOW, COLOR_RETENTION_WINDOW)
                                     {
                                         Location = { CoordinateFrame = CoordType.XScaleYChartFraction },
                                         IsClippedToChartRect = true,
                                         ZOrder = ZOrder.F_BehindGrid
                                     };
                    annotations.Add(box);
                }
            }

            if (RetentionExplicit != null && GraphChromatogram.ShowRT != ShowRTChrom.none)
            {
                // Create temporary label to calculate positions
                AddRetentionTimeAnnotation(graphPane,
                                            g,
                                            annotations,
                                            ptTop,
                                            Resources.ChromGraphItem_AddAnnotations_Explicit,
                                            GraphObjType.predicted_rt_window,
                                            COLOR_RETENTION_TIME,
                                            ScaleRetentionTime(RetentionExplicit.RetentionTime));
            }

            for (int i = 0, len = Chromatogram.NumPeaks; i < len; i++)
            {
                if (_arrayLabelIndexes[i] == -1)
                    continue;

                double maxIntensity = _intensities[_arrayLabelIndexes[i]];

                // Show peak extent indicators, if they are far enough apart
                ChromPeak peak = Chromatogram.GetPeak(i);
                AddPeakBoundaries(graphPane, annotations, false,
                                  ScaleRetentionTime(peak.StartTime), ScaleRetentionTime(peak.EndTime), maxIntensity);
            }
        }
Ejemplo n.º 13
0
 private MSGraphPane InsertMsGraphPane(MSGraphControl graphControl, int iInsert)
 {
     var pane = new MSGraphPane
     {
         Border = { IsVisible = false },
         AllowCurveOverlap = true,
     };
     ApplySettingsToGraphPane(pane);
     var primaryPane = graphControl.GraphPane;
     pane.CurrentItemType = primaryPane.CurrentItemType;
     pane.ZoomStack.AddRange(primaryPane.ZoomStack);
     var zoomState = new ZoomState(primaryPane, ZoomState.StateType.Zoom);
     zoomState.ApplyState(pane);
     pane.YAxis.Title.Text = primaryPane.YAxis.Title.Text;
     pane.XAxis.Title.Text = primaryPane.XAxis.Title.Text;
     graphControl.MasterPane.PaneList.Insert(iInsert, pane);
     return pane;
 }
Ejemplo n.º 14
0
        public CurveItem AddGraphItem( MSGraphPane pane, IMSGraphItemInfo item, bool setScale )
        {
            if( item.GraphItemType != pane.CurrentItemType )
            {
                pane.CurveList.Clear();
                pane.CurrentItemType = item.GraphItemType;
                pane.ZoomStack.PopAll( pane );
                item.CustomizeXAxis( pane.XAxis );
                item.CustomizeYAxis( pane.YAxis );
            }

            CurveItem newItem = makeMSGraphItem( item );
            pane.CurveList.Add( newItem );
            // If you are adding multiple graph items, it is quickest to set the scale
            // once at the end.
            if (setScale)
                pane.SetScale( CreateGraphics() );
            return newItem;
        }
Ejemplo n.º 15
0
 public CurveItem AddGraphItem(MSGraphPane pane, IMSGraphItemInfo item)
 {
     return(AddGraphItem(pane, item, true));
 }
Ejemplo n.º 16
0
        public override void AddAnnotations(MSGraphPane graphPane, Graphics g, MSPointList pointList, GraphObjList annotations)
        {
            // ReSharper disable UseObjectOrCollectionInitializer
            foreach (var rmi in SpectrumInfo.PeaksMatched)
            {
                if (!IsVisibleIon(rmi))
                    continue;

                IonType type = IsVisibleIon(rmi.IonType, rmi.Ordinal, rmi.Charge) ?
                                                                                      rmi.IonType : rmi.IonType2;

                Color color;
                switch (type)
                {
                    default: color = COLOR_NONE; break;
                    case IonType.a: color = COLOR_A; break;
                    case IonType.x: color = COLOR_X; break;
                    case IonType.b: color = COLOR_B; break;
                    case IonType.y: color = COLOR_Y; break;
                    case IonType.c: color = COLOR_C; break;
                    case IonType.z: color = COLOR_Z; break;
                    // FUTURE: Add custom ions when LibraryRankedSpectrumInfo can support them
                    case IonType.precursor: color = COLOR_PRECURSOR; break;
                }

                if (IsMatch(rmi.PredictedMz))
                {
                    color = COLOR_SELECTED;
                }

                double mz = rmi.ObservedMz;
                var stick = new LineObj(color, mz, rmi.Intensity, mz, 0);
                stick.IsClippedToChartRect = true;
                stick.Location.CoordinateFrame = CoordType.AxisXYScale;
                stick.Line.Width = LineWidth + 1;
                annotations.Add(stick);
            }
            //ReSharper restore UseObjectOrCollectionInitializer
        }
Ejemplo n.º 17
0
 public CurveItem AddGraphItem( MSGraphPane pane, IMSGraphItemInfo item )
 {
     return AddGraphItem(pane, item, true);
 }
Ejemplo n.º 18
0
 public override void AddPreCurveAnnotations(MSGraphPane graphPane, Graphics g, MSPointList pointList, GraphObjList annotations)
 {
     // Do nothing
 }
Ejemplo n.º 19
0
 public override void AddAnnotations(MSGraphPane graphPane, Graphics g,
     MSPointList pointList, GraphObjList annotations)
 {
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Resets the all of the properties of a graph pane that might have changed 
 /// (or initialize the properties of a newly  created pane) so that it's ready 
 /// to be used by a different set of graphs.
 /// </summary>
 public virtual void ApplySettingsToGraphPane(MSGraphPane graphPane)
 {
     graphPane.Legend.IsVisible = ShowLegend;
     graphPane.Title.IsVisible = true;
     graphPane.Title.Text = null;
     graphPane.AllowLabelOverlap = AllowLabelOverlap;
 }