// constructor for a full scan public SeemsScan(ManagedScan scan) { this.scan = scan; id = scan.ScanNumber.ToString(); pointList = new SeemsPointList(scan); }
public void SetDataLabelsVisible(bool visible) { //zedGraphControl1.GraphPane.GraphObjList.Clear(); foreach (ZedGraph.GraphObj dataLabel in dataLabels) { zedGraphControl1.GraphPane.GraphObjList.Remove(dataLabel); } if (visible) { if (!(AnnotationSettings.ShowChromatogramPointTimes || AnnotationSettings.ShowScanPointMZs || AnnotationSettings.ShowChromatogramPointIntensities || AnnotationSettings.ShowScanPointIntensities || AnnotationSettings.ShowUnmatchedAnnotations || AnnotationSettings.ShowMatchedAnnotations)) { return; } // set direct references ZedGraph.GraphPane pane = zedGraphControl1.GraphPane; ZedGraph.Axis xAxis = pane.XAxis; ZedGraph.Axis yAxis = pane.YAxis; yAxis.Scale.MinAuto = false; yAxis.Scale.Min = 0; // setup axes scales to enable the Transform method xAxis.Scale.SetupScaleData(pane, xAxis); yAxis.Scale.SetupScaleData(pane, yAxis); Graphics g = zedGraphControl1.CreateGraphics(); //pane.Draw( g ); pane.CurveList.Draw(g, pane, 1.0f); System.Drawing.Bitmap gmap = new Bitmap(Convert.ToInt32(pane.Rect.Width), Convert.ToInt32(pane.Rect.Height)); zedGraphControl1.DrawToBitmap(gmap, Rectangle.Round(pane.Rect)); Region chartRegion = new Region(pane.Chart.Rect); Region clipRegion = new Region(); clipRegion.MakeEmpty(); g.SetClip(zedGraphControl1.MasterPane.Rect, CombineMode.Replace); g.SetClip(chartRegion, CombineMode.Exclude); /*Bitmap clipBmp = new Bitmap( Convert.ToInt32( pane.Rect.Width ), Convert.ToInt32( pane.Rect.Height ) ); * Graphics clipG = Graphics.FromImage( clipBmp ); * clipG.Clear( Color.White ); * clipG.FillRegion( new SolidBrush( Color.Black ), g.Clip ); * clipBmp.Save( "C:\\clip.bmp" );*/ PointDataMap <SeemsPointAnnotation> matchedAnnotations = new PointDataMap <SeemsPointAnnotation>(); // add automatic labels foreach (ZedGraph.CurveItem curve in pane.CurveList) { SeemsPointList pointList = (SeemsPointList)curve.Points; for (int i = 0; i < pointList.MaxCount; i++) { ZedGraph.PointPair pt = pointList.GetPointAtIndex(pointList.ScaledMaxIndexList[i]); if (pt.X < xAxis.Scale.Min || pt.Y > yAxis.Scale.Max || pt.Y < yAxis.Scale.Min) { continue; } if (pt.X > xAxis.Scale.Max) { break; } StringBuilder pointLabel = new StringBuilder(); Color pointColor = curve.Color; // Add annotation double annotationX = 0.0; SeemsPointAnnotation annotation = null; if (CurrentScan.IsMassSpectrum) { PointDataMap <SeemsPointAnnotation> .MapPair annotationPair = AnnotationSettings.ScanPointAnnotations.FindNear(pt.X, AnnotationSettings.ScanMatchTolerance); if (annotationPair != null) { annotationX = annotationPair.Key; annotation = annotationPair.Value; matchedAnnotations.Add(annotationPair); } } else { PointDataMap <SeemsPointAnnotation> .MapPair annotationPair = AnnotationSettings.ChromatogramPointAnnotations.FindNear(pt.X, AnnotationSettings.ChromatogramMatchTolerance); if (annotationPair != null) { annotationX = annotationPair.Key; annotation = annotationPair.Value; matchedAnnotations.Add(annotationPair); } } if (AnnotationSettings.ShowMatchedAnnotations && annotation != null) { pointLabel.AppendLine(annotation.Label); pointColor = annotation.Color; //if( curve is ZedGraph.StickItem ) { ZedGraph.LineObj stickOverlay = new ZedGraph.LineObj(annotationX, 0, annotationX, pt.Y); //stickOverlay.IsClippedToChartRect = true; stickOverlay.Location.CoordinateFrame = ZedGraph.CoordType.AxisXYScale; stickOverlay.Line.Width = annotation.Width; stickOverlay.Line.Color = pointColor; zedGraphControl1.GraphPane.GraphObjList.Add(stickOverlay); dataLabels.Add(stickOverlay); //( (ZedGraph.StickItem) curve ).Color = pointColor; //( (ZedGraph.StickItem) curve ).Line.Width = annotation.Width; } } if (CurrentScan.IsMassSpectrum) { if (AnnotationSettings.ShowScanPointMZs) { pointLabel.AppendLine(pt.X.ToString("f2")); } if (AnnotationSettings.ShowScanPointIntensities) { pointLabel.AppendLine(pt.Y.ToString("f2")); } } else { if (AnnotationSettings.ShowChromatogramPointTimes) { pointLabel.AppendLine(pt.X.ToString("f2")); } if (AnnotationSettings.ShowChromatogramPointIntensities) { pointLabel.AppendLine(pt.Y.ToString("f2")); } } string pointLabelString = pointLabel.ToString(); if (pointLabelString.Length == 0) { continue; } // Create a text label from the X data value ZedGraph.TextObj text = new ZedGraph.TextObj(pointLabelString, pt.X, yAxis.Scale.ReverseTransform(yAxis.Scale.Transform(pt.Y) - 5), ZedGraph.CoordType.AxisXYScale, ZedGraph.AlignH.Center, ZedGraph.AlignV.Bottom); text.ZOrder = ZedGraph.ZOrder.A_InFront; //text.IsClippedToChartRect = true; text.FontSpec.FontColor = pointColor; // Hide the border and the fill text.FontSpec.Border.IsVisible = false; text.FontSpec.Fill.IsVisible = false; //text.FontSpec.Fill = new Fill( Color.FromArgb( 100, Color.White ) ); // Rotate the text to 90 degrees text.FontSpec.Angle = 0; string shape, coords; text.GetCoords(pane, g, 1.0f, out shape, out coords); if (shape != "poly") { throw new InvalidOperationException("shape must be 'poly'"); } string[] textBoundsPointStrings = coords.Split(",".ToCharArray()); if (textBoundsPointStrings.Length != 9) { throw new InvalidOperationException("coords length must be 8"); } Point[] textBoundsPoints = new Point[] { new Point(Convert.ToInt32(textBoundsPointStrings[0]), Convert.ToInt32(textBoundsPointStrings[1])), new Point(Convert.ToInt32(textBoundsPointStrings[2]), Convert.ToInt32(textBoundsPointStrings[3])), new Point(Convert.ToInt32(textBoundsPointStrings[4]), Convert.ToInt32(textBoundsPointStrings[5])), new Point(Convert.ToInt32(textBoundsPointStrings[6]), Convert.ToInt32(textBoundsPointStrings[7])) }; byte[] textBoundsPointTypes = new byte[] { (byte)PathPointType.Start, (byte)PathPointType.Line, (byte)PathPointType.Line, (byte)PathPointType.Line }; GraphicsPath textBoundsPath = new GraphicsPath(textBoundsPoints, textBoundsPointTypes); textBoundsPath.CloseFigure(); Region textBoundsRegion = new Region(textBoundsPath); textBoundsRegion.Intersect(pane.Chart.Rect); RectangleF[] textBoundsRectangles = textBoundsRegion.GetRegionScans(g.Transform); bool overlapDetected = false; for (int j = 0; j < textBoundsRectangles.Length && !overlapDetected; ++j) { if (g.Clip.IsVisible(textBoundsRectangles[j])) { overlapDetected = true; } for (float y = textBoundsRectangles[j].Top; y <= textBoundsRectangles[j].Bottom && !overlapDetected; ++y) { for (float x = textBoundsRectangles[j].Left; x <= textBoundsRectangles[j].Right && !overlapDetected; ++x) { if (gmap.GetPixel(Convert.ToInt32(x), Convert.ToInt32(y)).ToArgb() != pane.Chart.Fill.Color.ToArgb()) { overlapDetected = true; } } } } if (!overlapDetected) { pane.GraphObjList.Add(text); clipRegion.Union(textBoundsRegion); //g.SetClip( chartRegion, CombineMode.Replace ); g.SetClip(clipRegion, CombineMode.Replace); //clipG.Clear( Color.White ); //clipG.FillRegion( new SolidBrush( Color.Black ), g.Clip ); //clipBmp.Save( "C:\\clip.bmp" ); dataLabels.Add(text); //text.Draw( g, pane, 1.0f ); //zedGraphControl1.DrawToBitmap( gmap, Rectangle.Round( pane.Rect ) ); } } } if (AnnotationSettings.ShowUnmatchedAnnotations) { PointDataMap <SeemsPointAnnotation> annotations; if (CurrentScan.IsMassSpectrum) { annotations = AnnotationSettings.ScanPointAnnotations; } else { annotations = AnnotationSettings.ChromatogramPointAnnotations; } foreach (PointDataMap <SeemsPointAnnotation> .MapPair annotationPair in annotations) { if (matchedAnnotations.Contains(annotationPair)) { continue; } float stickLength = (yAxis.MajorTic.Size * 2) / pane.Chart.Rect.Height; ZedGraph.LineObj stickOverlay = new ZedGraph.LineObj(annotationPair.Key, 1, annotationPair.Key, -stickLength); //stickOverlay.IsClippedToChartRect = true; stickOverlay.Location.CoordinateFrame = ZedGraph.CoordType.XScaleYChartFraction; stickOverlay.Line.Width = annotationPair.Value.Width; stickOverlay.Line.Color = annotationPair.Value.Color; zedGraphControl1.GraphPane.GraphObjList.Add(stickOverlay); dataLabels.Add(stickOverlay); } } g.Dispose(); } else { // remove labels } }
// constructor for an SRM/MRM scan public SeemsScan(ManagedScan chromatogram, string id) { this.scan = chromatogram; this.id = id; pointList = new SeemsPointList(chromatogram); }
private void showData(int dataIndex, bool isOverlay) { SeemsScan scan = dataSource.CurrentScanHeaders[dataIndex]; ZedGraph.GraphPane pane = zedGraphControl1.GraphPane; if (isOverlay && pane.CurveList.Count > overlayColors.Length) { MessageBox.Show("SeeMS only supports up to " + overlayColors.Length + " simultaneous overlays.", "Too many overlays", MessageBoxButtons.OK, MessageBoxIcon.Stop); } // set form title if (!isOverlay) { Text = String.Format("{0} - {1}", System.IO.Path.GetFileName(dataSource.CurrentFilepath), scan.Id); } else { Text += "," + scan.Id; } if (!isOverlay) { pane.CurveList.Clear(); } if (shownScan != null && scan.IsMassSpectrum != shownScan.IsMassSpectrum) { zedGraphControl1.RestoreScale(pane); zedGraphControl1.ZoomOutAll(pane); } bool isScaleAuto = !pane.IsZoomed; //pane.GraphObjList.Clear(); SeemsPointList pointList = scan.PointList; if (pointList.FullCount == 0) { // the header does not have the data points, assume it is a mass spectrum pane.YAxis.Title.Text = "Intensity"; pane.XAxis.Title.Text = "m/z"; bool doCentroid = SeemsMdiParent.CentroidMenuItem.Enabled && SeemsMdiParent.CentroidMenuItem.Checked; dataSource.InstrumentInterface.setCentroiding(doCentroid, doCentroid, SeemsMdiParent.UseVendorCentroidMenuItem.Checked); SeemsScan scanWithData = new SeemsScan(dataSource.InstrumentInterface.getScan(scan.Scan.ScanNumber)); pointList = scanWithData.PointList; int bins = (int)pane.CalcChartRect(zedGraphControl1.CreateGraphics()).Width; if (isScaleAuto) { pointList.SetScale(bins, pointList[0].X, pointList[pointList.Count - 1].X); } else { pointList.SetScale(bins, pane.XAxis.Scale.Min, pane.XAxis.Scale.Max); } if (doCentroid || scanWithData.Scan.IsCentroided) { ZedGraph.StickItem stick = pane.AddStick(scan.Id, pointList, Color.Gray); stick.Symbol.IsVisible = false; stick.Line.Width = 1; } else { pane.AddCurve(scan.Id, pointList, Color.Gray, ZedGraph.SymbolType.None); } } else { // the header has the data points, assume it is a chromatogram int bins = (int)pane.CalcChartRect(zedGraphControl1.CreateGraphics()).Width; if (isScaleAuto) { pointList.SetScale(bins, pointList[0].X, pointList[pointList.Count - 1].X); } else { pointList.SetScale(bins, pane.XAxis.Scale.Min, pane.XAxis.Scale.Max); } pane.YAxis.Title.Text = "Total Intensity"; pane.XAxis.Title.Text = "Retention Time (in seconds)"; pane.AddCurve(scan.Id, pointList, Color.Gray, ZedGraph.SymbolType.None); } pane.AxisChange(); if (isOverlay) { pane.Legend.IsVisible = true; pane.Legend.Position = ZedGraph.LegendPos.TopCenter; for (int i = 0; i < pane.CurveList.Count; ++i) { pane.CurveList[i].Color = overlayColors[i]; } } else { pane.Legend.IsVisible = false; } SetDataLabelsVisible(true); shownScan = scan; zedGraphControl1.Refresh(); //zedGraphControl1.Focus(); }