/// <summary> /// add precursor and non-matched annotations /// </summary> public override void AddAnnotations(pwiz.MSGraph.MSGraphPane graphPane, Graphics g, pwiz.MSGraph.MSPointList pointList, ZedGraph.GraphObjList annotations) { base.AddAnnotations(graphPane, g, pointList, annotations); //using( Spectrum element = Element ) { foreach (Precursor p in Element.precursors) { foreach (SelectedIon si in p.selectedIons) { double precursorMz = (double)si.cvParam(CVID.MS_selected_ion_m_z).value; int precursorCharge = 0; CVParam precursorChargeParam = si.cvParam(CVID.MS_charge_state); if (precursorChargeParam.empty()) { precursorChargeParam = si.cvParam(CVID.MS_possible_charge_state); } if (!precursorChargeParam.empty()) { precursorCharge = (int)precursorChargeParam.value; } double stickLength = 0.1; ZedGraph.LineObj stickOverlay = new ZedGraph.LineObj(precursorMz, 1, precursorMz, stickLength); stickOverlay.Location.CoordinateFrame = ZedGraph.CoordType.XScaleYChartFraction; stickOverlay.Line.Width = 3; stickOverlay.Line.Style = System.Drawing.Drawing2D.DashStyle.Dot; stickOverlay.Line.Color = Color.Green; annotations.Add(stickOverlay); // Create a text label from the X data value string precursorLabel; if (precursorCharge > 0) { precursorLabel = String.Format("{0}\n(+{1} precursor)", precursorMz.ToString("f3"), precursorCharge); } else { precursorLabel = String.Format("{0}\n(precursor of unknown charge)", precursorMz.ToString("f3")); } ZedGraph.TextObj text = new ZedGraph.TextObj(precursorLabel, precursorMz, stickLength, ZedGraph.CoordType.XScaleYChartFraction, ZedGraph.AlignH.Center, ZedGraph.AlignV.Bottom); text.ZOrder = ZedGraph.ZOrder.A_InFront; text.FontSpec.FontColor = stickOverlay.Line.Color; text.FontSpec.Border.IsVisible = false; text.FontSpec.Fill.IsVisible = false; //text.FontSpec.Fill = new Fill( Color.FromArgb( 100, Color.White ) ); text.FontSpec.Angle = 0; annotations.Add(text); } } } }
private void zedSequence_MouseMove(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { if (zedSequence.GraphPane.GraphObjList.Count != 0) { zedSequence.GraphPane.GraphObjList.Remove(MassEndValue); zedSequence.GraphPane.GraphObjList.Remove(MassDiffValue); zedSequence.GraphPane.GraphObjList.Remove(MassLine); zedSequence.Refresh(); } double outX, outY; zedSequence.GraphPane.ReverseTransform(new Point(e.X, e.Y), out outX, out outY); outY = MassStartValue.Location.Y; //Add Line MassLine = new ZedGraph.LineObj(MassStartValue.Location.X, MassStartValue.Location.Y, outX, MassStartValue.Location.Y); MassLine.Line.Style = DashStyle.Dash; MassLine.Line.Color = Color.Blue; zedSequence.GraphPane.GraphObjList.Insert(1, MassLine); MassEndValue = new ZedGraph.TextObj(outX.ToString("0.00"), outX, outY); MassEndValue.FontSpec.Border.IsVisible = false; MassEndValue.FontSpec.Size = MassEndValue.FontSpec.Size * 0.5f; zedSequence.GraphPane.GraphObjList.Insert(0, MassEndValue); double massdiff = Convert.ToDouble(MassEndValue.Text) - Convert.ToDouble(MassStartValue.Text); double diffLoc = (MassStartValue.Location.X + MassEndValue.Location.X) / 2; MassDiffValue = new ZedGraph.TextObj(Math.Abs(massdiff).ToString("0.00"), diffLoc, outY); MassDiffValue.FontSpec.Border.IsVisible = false; MassDiffValue.FontSpec.Size = MassDiffValue.FontSpec.Size * 0.8f; zedSequence.GraphPane.GraphObjList.Insert(0, MassDiffValue); zedSequence.Refresh(); } }
private void Draw() { if (DataConvertationClass.IsUndefinedElement(_dataAr)) { MessageBox.Show(Text + ". Існують не визначені елементи!"); return; } dataGridView1.ColumnCount = _degree + 2; dataGridView1.RowCount = 2; dataGridView1[0, 0].Value = "Автокореляції"; dataGridView1[0, 1].Value = "ЧАКФ"; double[] ACArray = Statistical.ACF(_dataAr, _degree); double[] PACArray = Statistical.PACF(_dataAr, _degree); double[] XList = new double[_degree + 1]; for (int i = 1; i < dataGridView1.ColumnCount; i++) { dataGridView1.Columns[i].Name = (i - 1).ToString(); dataGridView1[i, 0].Value = ACArray[i - 1].ToString("F6"); if (Math.Abs(ACArray[i - 1]) >= level) { dataGridView1[i, 0].Style.ForeColor = Color.Red; } else { dataGridView1[i, 0].Style.ForeColor = Color.Black; } dataGridView1[i, 1].Value = PACArray[i - 1].ToString("F6"); if (Math.Abs(PACArray[i - 1]) >= level) { dataGridView1[i, 1].Style.ForeColor = Color.Red; } else { dataGridView1[i, 1].Style.ForeColor = Color.Black; } XList[i - 1] = i - 1; } dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; ZedGraph.LineObj levelLine1 = new ZedGraph.LineObj(Color.Red, -1, level, _degree + 1, level); levelLine1.Line.Width = 2; ZedGraph.LineObj levelLine2 = new ZedGraph.LineObj(Color.Red, -1, -level, _degree + 1, -level); levelLine2.Line.Width = 2; ZedGraph.GraphPane ACpane = ACzedGraphControl.GraphPane; ACpane.CurveList.Clear(); ACpane.GraphObjList.Clear(); ACpane.Title.Text = "Автокореляція"; ACpane.XAxis.Title.IsVisible = false; ACpane.XAxis.MajorGrid.IsVisible = true; ACpane.XAxis.MajorGrid.DashOn = 1; ACpane.XAxis.MajorGrid.DashOff = 1; ACpane.XAxis.Scale.Min = 0; ACpane.XAxis.Scale.Max = ACArray.Length; ACpane.YAxis.Title.IsVisible = false; ACpane.YAxis.MajorGrid.IsVisible = true; ACpane.YAxis.MajorGrid.DashOn = 1; ACpane.YAxis.MajorGrid.DashOff = 1; ACpane.YAxis.Scale.Min = -2; ACpane.YAxis.Scale.Max = 2; ZedGraph.PointPairList ACList = new ZedGraph.PointPairList(XList, ACArray); ACpane.AddBar("", ACList, Color.BlanchedAlmond); ACpane.GraphObjList.Add(levelLine1); ACpane.GraphObjList.Add(levelLine2); ACzedGraphControl.Refresh(); ZedGraph.GraphPane PACpane = PACzedGraphControl.GraphPane; PACpane.CurveList.Clear(); PACpane.GraphObjList.Clear(); PACpane.Title.Text = "ЧАКФ"; PACpane.XAxis.Title.IsVisible = false; PACpane.XAxis.MajorGrid.IsVisible = true; PACpane.XAxis.MajorGrid.DashOn = 1; PACpane.XAxis.MajorGrid.DashOff = 1; PACpane.XAxis.Scale.Min = 0; PACpane.XAxis.Scale.Max = ACArray.Length; PACpane.YAxis.Title.IsVisible = false; PACpane.YAxis.MajorGrid.IsVisible = true; PACpane.YAxis.MajorGrid.DashOn = 1; PACpane.YAxis.MajorGrid.DashOff = 1; PACpane.YAxis.Scale.Min = -2; PACpane.YAxis.Scale.Max = 2; ZedGraph.PointPairList PACList = new ZedGraph.PointPairList(XList, PACArray); PACpane.AddBar("", PACList, Color.BlanchedAlmond); PACpane.GraphObjList.Add(levelLine1); PACpane.GraphObjList.Add(levelLine2); PACzedGraphControl.Refresh(); }
/// <summary> /// Emotion ZedGraph init /// </summary> private void EmotionGraphInit() { System.Windows.Forms.Integration.WindowsFormsHost emotionHost = new System.Windows.Forms.Integration.WindowsFormsHost(); emotionZedGraph = new ZedGraph.ZedGraphControl(); emotionZedGraph.IsEnableZoom = false; emotionHost.Child = emotionZedGraph; EmotionGrid.Children.Add(emotionHost); emotionGraph = new BasicDSP.Graph(emotionZedGraph.CreateGraphics(), emotionZedGraph); emotionGraphPane = emotionZedGraph.GraphPane; emotionLine = new ZedGraph.LineObj(System.Drawing.Color.Red, graphLineXPosition, emotionGraphPane.YAxis.Scale.Min, graphLineXPosition, emotionGraphPane.YAxis.Scale.Max); emotionLine.Line.Width = 1f; emotionGraphPane.GraphObjList.Add(emotionLine); EmotionZedGraphRefresh(); }
/// <summary> /// EEG ZedGraph init /// </summary> private void EEGGraphInit() { System.Windows.Forms.Integration.WindowsFormsHost host = new System.Windows.Forms.Integration.WindowsFormsHost(); eegZedGraph = new ZedGraph.ZedGraphControl(); eegZedGraph.IsEnableZoom = false; // http://goorman.free.fr/ZedGraph/zedgraph.org/wiki/indexa9f9.html?title=Edit_Points_by_Dragging_the_Mouse //zedGraph.MouseDownEvent += zedGraph_MouseDownEvent; host.Child = eegZedGraph; EEGGrid.Children.Add(host); eegGraph = new BasicDSP.Graph(eegZedGraph.CreateGraphics(), eegZedGraph); zedGraphPane = eegZedGraph.GraphPane; eegLine = new ZedGraph.LineObj(System.Drawing.Color.Red, graphLineXPosition, zedGraphPane.YAxis.Scale.Min, graphLineXPosition, zedGraphPane.YAxis.Scale.Max); eegLine.Line.Width = 1f; zedGraphPane.GraphObjList.Add(eegLine); EEGZedGraphRefresh(); }
/// <summary> /// Draw the Emotion Line on the right position depending on the video position /// </summary> private void DrawEmotionLine() { if (csvDataProcessed) { emotionGraphPane.GraphObjList.Remove(emotionLine); emotionLine = new ZedGraph.LineObj(System.Drawing.Color.Red, graphLineXPosition, emotionGraphPane.YAxis.Scale.Min, graphLineXPosition, emotionGraphPane.YAxis.Scale.Max); emotionLine.Line.Width = 1f; emotionGraphPane.GraphObjList.Add(emotionLine); emotionZedGraph.Refresh(); } }
/// <summary> /// Draw the Emotion Line on the right position depending on the video position /// </summary> private void DrawActivityLine() { if (csvDataProcessed) { activityGraphPane.GraphObjList.Remove(activityLine); activityLine = new ZedGraph.LineObj(System.Drawing.Color.Red, graphLineXPosition, activityGraphPane.YAxis.Scale.Min, graphLineXPosition, activityGraphPane.YAxis.Scale.Max); activityLine.Line.Width = 1f; activityGraphPane.GraphObjList.Add(activityLine); activityZedGraph.Refresh(); } }
/// <summary> /// Activity ZedGraph init /// </summary> private void ActivityGraphInit() { System.Windows.Forms.Integration.WindowsFormsHost activityHost = new System.Windows.Forms.Integration.WindowsFormsHost(); activityZedGraph = new ZedGraph.ZedGraphControl(); activityZedGraph.IsEnableZoom = false; activityHost.Child = activityZedGraph; ActivityGrid.Children.Add(activityHost); activityGraph = new BasicDSP.Graph(activityZedGraph.CreateGraphics(), activityZedGraph); activityGraphPane = activityZedGraph.GraphPane; activityLine = new ZedGraph.LineObj(System.Drawing.Color.Red, graphLineXPosition, activityGraphPane.YAxis.Scale.Min, graphLineXPosition, activityGraphPane.YAxis.Scale.Max); activityLine.Line.Width = 1f; activityGraphPane.GraphObjList.Add(activityLine); ActivityZedGraphRefresh(); }
public void SetDataLabelsVisible( bool visible ) { // set direct references ZedGraph.GraphPane pane = zedGraphControl1.GraphPane; ZedGraph.Axis xAxis = pane.XAxis; ZedGraph.Axis yAxis = pane.YAxis; if( CurrentGraphItem == null ) return; //zedGraphControl1.GraphPane.GraphObjList.Clear(); foreach( ZedGraph.GraphObj dataLabel in dataLabels ) zedGraphControl1.GraphPane.GraphObjList.Remove( dataLabel ); if( visible ) { if( CurrentGraphItem.IsChromatogram ) { if( !( ChromatogramAnnotationSettings.ShowPointTimes || ChromatogramAnnotationSettings.ShowPointIntensities || ChromatogramAnnotationSettings.ShowUnmatchedAnnotations || ChromatogramAnnotationSettings.ShowMatchedAnnotations ) ) return; } else { if( !( ScanAnnotationSettings.ShowPointMZs || ScanAnnotationSettings.ShowPointIntensities || ScanAnnotationSettings.ShowUnmatchedAnnotations || ScanAnnotationSettings.ShowMatchedAnnotations ) ) return; } 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(); System.Drawing.Bitmap gmap; if( pane.Chart.Rect.Width > 0 && pane.Chart.Rect.Height > 0 ) { try { //pane.Draw( g ); pane.CurveList.Draw( g, pane, 1.0f ); gmap = new Bitmap( Convert.ToInt32( pane.Rect.Width ), Convert.ToInt32( pane.Rect.Height ) ); zedGraphControl1.DrawToBitmap( gmap, Rectangle.Round( pane.Rect ) ); } catch { return; } } else return; Region textBoundsRegion; 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 precursor label(s) for tandem mass spectra if( CurrentGraphItem.IsMassSpectrum ) { MassSpectrum scanItem = (MassSpectrum) CurrentGraphItem; pwiz.CLI.msdata.PrecursorList precursorList = scanItem.Element.spectrumDescription.precursors; for( int i = 0; i < precursorList.Count; ++i ) { pwiz.CLI.msdata.Precursor precursor = precursorList[i]; pwiz.CLI.msdata.SelectedIonList selectedIons = precursor.selectedIons; if( selectedIons.Count == 0 ) continue; double precursorMz = (double) selectedIons[0].cvParam( pwiz.CLI.msdata.CVID.MS_m_z ).value; pwiz.CLI.msdata.CVParam precursorChargeParam = selectedIons[0].cvParam( pwiz.CLI.msdata.CVID.MS_charge_state ); int precursorCharge = 0; if( precursorChargeParam.cvid != pwiz.CLI.msdata.CVID.CVID_Unknown ) precursorCharge = (int) selectedIons[0].cvParam( pwiz.CLI.msdata.CVID.MS_charge_state ).value; float stickLength = ( yAxis.MajorTic.Size * 5 ) / pane.Chart.Rect.Height; ZedGraph.LineObj stickOverlay = new ZedGraph.LineObj( precursorMz, 1, precursorMz, 1 + stickLength ); stickOverlay.Location.CoordinateFrame = ZedGraph.CoordType.XScaleYChartFraction; stickOverlay.Line.Width = 3; stickOverlay.Line.Style = DashStyle.Dot; stickOverlay.Line.Color = Color.Green; pane.GraphObjList.Add( stickOverlay ); dataLabels.Add( stickOverlay ); // Create a text label from the X data value string precursorLabel; if( precursorCharge > 0 ) precursorLabel = String.Format( "{0}\n(+{1} precursor)", precursorMz.ToString( "f3" ), precursorCharge ); else precursorLabel = String.Format( "{0}\n(precursor of unknown charge)", precursorMz.ToString( "f3" ) ); ZedGraph.TextObj text = new ZedGraph.TextObj( precursorLabel, precursorMz, 1 + stickLength, ZedGraph.CoordType.XScaleYChartFraction, ZedGraph.AlignH.Center, ZedGraph.AlignV.Top ); text.ZOrder = ZedGraph.ZOrder.A_InFront; text.FontSpec.FontColor = stickOverlay.Line.Color; text.FontSpec.Border.IsVisible = false; text.FontSpec.Fill.IsVisible = false; //text.FontSpec.Fill = new Fill( Color.FromArgb( 100, Color.White ) ); text.FontSpec.Angle = 0; if( !detectLabelOverlap( pane, g, gmap, text, out textBoundsRegion ) ) { 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 ) ); } } } // add automatic labels foreach( ZedGraph.CurveItem curve in pane.CurveList ) { if( !( curve.Points is PointList ) ) continue; PointList pointList = (PointList) 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( CurrentGraphItem.IsMassSpectrum ) { PointDataMap<SeemsPointAnnotation>.MapPair annotationPair = ScanAnnotationSettings.PointAnnotations.FindNear( pt.X, ScanAnnotationSettings.MatchTolerance ); if( annotationPair != null ) { annotationX = annotationPair.Key; annotation = annotationPair.Value; matchedAnnotations.Add( annotationPair ); } } else { PointDataMap<SeemsPointAnnotation>.MapPair annotationPair = ChromatogramAnnotationSettings.PointAnnotations.FindNear( pt.X, ChromatogramAnnotationSettings.MatchTolerance ); if( annotationPair != null ) { annotationX = annotationPair.Key; annotation = annotationPair.Value; matchedAnnotations.Add( annotationPair ); } } bool showMatchedAnnotations = false; if( CurrentGraphItem.IsMassSpectrum ) showMatchedAnnotations = ScanAnnotationSettings.ShowMatchedAnnotations; else showMatchedAnnotations = ChromatogramAnnotationSettings.ShowMatchedAnnotations; if( 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( CurrentGraphItem.IsMassSpectrum ) { if( ScanAnnotationSettings.ShowPointMZs ) pointLabel.AppendLine( pt.X.ToString( "f2" ) ); if( ScanAnnotationSettings.ShowPointIntensities ) pointLabel.AppendLine( pt.Y.ToString( "f2" ) ); } else { if( ChromatogramAnnotationSettings.ShowPointTimes ) pointLabel.AppendLine( pt.X.ToString( "f2" ) ); if( ChromatogramAnnotationSettings.ShowPointIntensities ) 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; if( !detectLabelOverlap( pane, g, gmap, text, out textBoundsRegion ) ) { 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 ) ); } } } bool showUnmatchedAnnotations = false; if( CurrentGraphItem.IsMassSpectrum ) showUnmatchedAnnotations = ScanAnnotationSettings.ShowUnmatchedAnnotations; else showUnmatchedAnnotations = ChromatogramAnnotationSettings.ShowUnmatchedAnnotations; if( showUnmatchedAnnotations ) { PointDataMap<SeemsPointAnnotation> annotations = CurrentPointAnnotations; 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, 1 + 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 } }
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 } }