Example #1
0
 public virtual void CustomizeYAxis(ZedGraph.Axis axis)
 {
     axis.Title.FontSpec.Family = "Arial";
     axis.Title.FontSpec.Size   = 14;
     axis.Color = axis.Title.FontSpec.FontColor = Color.Black;
     axis.Title.FontSpec.Border.IsVisible = false;
     axis.Title.Text = "Intensity";
 }
Example #2
0
 string XAxis_ScaleFormatEvent(ZedGraph.GraphPane pane, ZedGraph.Axis axis, double val, int index)
 {
     try {
         int num = Convert.ToInt32(val);
         return(EPADB.GetDate(num).ToString());
     }
     catch {
         return("");
     }
 }
Example #3
0
        public virtual void CustomizeXAxis(ZedGraph.Axis axis)
        {
            axis.Title.FontSpec.Family = "Arial";
            axis.Title.FontSpec.Size   = 14;
            axis.Color = axis.Title.FontSpec.FontColor = Color.Black;
            axis.Title.FontSpec.Border.IsVisible = false;

            if (IsChromatogram)
            {
                axis.Title.Text = "Time";
            }
            else
            {
                axis.Title.Text = "m/z";
            }
        }
Example #4
0
        public virtual void CustomizeXAxis(ZedGraph.Axis axis)
        {
            axis.Title.FontSpec.Family = "Arial";
            axis.Title.FontSpec.Size   = 14;
            axis.Color = axis.Title.FontSpec.FontColor = Color.Black;
            axis.Title.FontSpec.Border.IsVisible = false;

            if (IsChromatogram)
            {
                axis.Title.Text = "Time " + (Properties.Settings.Default.TimeInMinutes ? "(min)" : "(sec)");
            }
            else
            {
                axis.Title.Text = "m/z";
            }
        }
Example #5
0
 string XAxis_ScaleFormatEvent(ZedGraph.GraphPane pane, ZedGraph.Axis axis, double val, int index)
 {
     return(DateTime.FromOADate(val).ToString("dd/MM/yyyy"));
 }
Example #6
0
        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
            }
        }