示例#1
0
        /// <summary>
        /// Handles reassigning all of the options in case they have been changed
        /// </summary>
        public void UpdateOptions()
        {
            if (m_unmatchedPoints != null && m_matchedPoints != null && m_unmatchedPoints.Count != 0 && m_matchedPoints.Count != 0)
            {
                SuspendLayout();

                if (m_options.replot)
                {
                    PlotGraph(this.m_currentPeptide, this.m_currentScanNumber, this.m_unmatchedPoints, this.m_matchedPoints);
                    m_options.replot = false;
                }
                else
                {
                    foreach (GraphPane myPane in this.MasterPane.PaneList)
                    {
                        //PointPairList oldUnmatchedPoints = (PointPairList)myPane.CurveList["Unmatched Peaks"].Points;
                        //PointPairList oldMatchedPoints = (PointPairList)myPane.CurveList["Matched Peaks"].Points;

                        myPane.CurveList.Clear();
                        myPane.GraphObjList.Clear();

                        if (!m_options.hideUnmatched)
                        {
                            OHLCBarItem unmatchedCurve = myPane.AddOHLCBar("Unmatched Peaks", m_unmatchedPoints, m_options.unmatchedColor);
                            AddAnnotations(unmatchedCurve.Points, myPane);
                        }
                        OHLCBarItem matchedCurve = myPane.AddOHLCBar("Matched Peaks", m_matchedPoints, m_options.matchedColor);
                        AddAnnotations(matchedCurve.Points, myPane);
                    }
                }

                ResumeLayout();
            }
        }
示例#2
0
        public OHLCBarDemo()
            : base("Demonstration of the OHLCBar Chart Type",
                   "OHLCBar Demo", DemoType.Bar)
        {
            GraphPane myPane = base.GraphPane;

            myPane.Title.Text       = "Open-High-Low-Close Bar Chart Demo";
            myPane.XAxis.Title.Text = "Trading Date";
            myPane.YAxis.Title.Text = "Share Price, $US";

            StockPointList spl  = new StockPointList();
            Random         rand = new Random();

            // First day is jan 1st
            XDate  xDate = new XDate(2006, 1, 1);
            double open  = 50.0;

            for (int i = 0; i < 50; i++)
            {
                double x     = xDate.XLDate;
                double close = open + rand.NextDouble() * 10.0 - 5.0;
                double hi    = Math.Max(open, close) + rand.NextDouble() * 5.0;
                double low   = Math.Min(open, close) - rand.NextDouble() * 5.0;

                StockPt pt = new StockPt(x, hi, low, open, close, 100000);
                spl.Add(pt);

                open = close;
                // Advance one day
                xDate.AddDays(1.0);
                // but skip the weekends
                if (XDate.XLDateToDayOfWeek(xDate.XLDate) == 6)
                {
                    xDate.AddDays(2.0);
                }
            }

            OHLCBarItem myCurve = myPane.AddOHLCBar("trades", spl, Color.Black);

            myCurve.Bar.IsAutoSize = true;
            myCurve.Bar.Color      = Color.Blue;

            // Use DateAsOrdinal to skip weekend gaps
            myPane.XAxis.Type      = AxisType.DateAsOrdinal;
            myPane.XAxis.Scale.Min = new XDate(2006, 1, 1);

            // pretty it up a little
            myPane.Chart.Fill = new Fill(Color.White, Color.LightGoldenrodYellow, 45.0f);
            myPane.Fill       = new Fill(Color.White, Color.FromArgb(220, 220, 255), 45.0f);

            base.ZedGraphControl.AxisChange();
        }
示例#3
0
        /// <summary>
        /// Creates a new plot in the zedGraph Control
        /// </summary>
        /// <param name="peptide"></param>
        /// <param name="scanNumber"></param>
        /// <param name="unmatchedPointsList"></param>
        /// <param name="matchedPointsList"></param>
        public void PlotGraph(string peptide, string scanNumber, PointPairList unmatchedPointsList, PointPairList matchedPointsList)
        {
            //save the data
            m_currentPeptide    = peptide;
            m_currentScanNumber = scanNumber;
            m_unmatchedPoints   = unmatchedPointsList;
            m_matchedPoints     = matchedPointsList;

            //clear the masterPane
            ZedGraph.MasterPane master = this.MasterPane;
            master.GraphObjList.Clear();
            master.PaneList.Clear();

            // split the points into groups
            List <PointPairList> unmatchedPointsSection;
            List <PointPairList> matchedPointsSection;

            // Divides the points into sections, this is used when we create more than one plot
            DividePointsIntoSections(m_options.numberOfPlots, m_matchedPoints, m_unmatchedPoints, out matchedPointsSection, out unmatchedPointsSection);

            // Show the masterpane title
            master.Title.IsVisible = true;
            master.Title.Text      = "Peptide: " + peptide + " Scan: " + scanNumber;

            // Leave a margin around the masterpane, but only a small gap between panes
            master.Margin.All   = 10;
            master.InnerPaneGap = 5;

            for (int j = 0; j < m_options.numberOfPlots; j++)
            {
                // Create a new graph -- dimensions to be set later by MasterPane Layout
                GraphPane myPaneT = new GraphPane(new Rectangle(10, 10, 10, 10),
                                                  "",
                                                  "m/z",
                                                  "Relative Intensity");

                // Set the BaseDimension, so fonts are scale a little bigger
                myPaneT.BaseDimension = m_standardBaseDemension / m_options.numberOfPlots;

                // Hide the XAxis scale and title
                myPaneT.XAxis.Title.IsVisible = false;
                myPaneT.XAxis.Scale.IsVisible = false;
                // Hide the legend, border, and GraphPane title
                myPaneT.Legend.IsVisible = false;
                myPaneT.Border.IsVisible = false;
                myPaneT.Title.IsVisible  = false;

                // Restrict the scale to go right up to the last data point
                double matchedMax   = 0;
                double unmatchedMax = 0;
                double matchedMin   = double.MaxValue;
                double unmatchedMin = double.MaxValue;

                if (matchedPointsSection[j].Count > 0)
                {
                    matchedMax = matchedPointsSection[j][matchedPointsSection[j].Count - 1].X;
                    matchedMin = matchedPointsSection[j][0].X;
                }
                if (unmatchedPointsSection[j].Count > 0)
                {
                    unmatchedMax = unmatchedPointsSection[j][unmatchedPointsSection[j].Count - 1].X;
                    unmatchedMin = unmatchedPointsSection[j][0].X;
                }

                myPaneT.XAxis.Scale.Max = (matchedMax > unmatchedMax) ? matchedMax : unmatchedMax;
                myPaneT.XAxis.Scale.Min = (matchedMin < unmatchedMin) ? matchedMin : unmatchedMin;

                // Remove all margins
                myPaneT.Margin.All = 0;
                // Except, leave some top margin on the first GraphPane
                if (j == 0)
                {
                    myPaneT.XAxis.Scale.Min = myPaneT.XAxis.Scale.Min - 100;
                    myPaneT.Margin.Top      = 20;
                }
                // And some bottom margin on the last GraphPane
                // Also, show the X title and scale on the last GraphPane only
                if (j == m_options.numberOfPlots - 1)
                {
                    myPaneT.XAxis.Scale.Max       = myPaneT.XAxis.Scale.Max + 100;
                    myPaneT.XAxis.Title.IsVisible = true;
                    myPaneT.Legend.IsVisible      = m_options.showLegend;
                    myPaneT.Legend.Position       = LegendPos.BottomCenter;
                }
                myPaneT.XAxis.Scale.IsVisible = true;
                //myPaneT.Margin.Bottom = 10;
                if (j > 0)
                {
                    myPaneT.YAxis.Scale.IsSkipLastLabel = true;
                }
                // This sets the minimum amount of space for the left and right side, respectively
                // The reason for this is so that the ChartRect's all end up being the same size.
                myPaneT.YAxis.MinSpace  = 80;
                myPaneT.Y2Axis.MinSpace = 20;


                // generate the lines
                // Keep the matched points in front by drawing them first.
                OHLCBarItem matchedCurve = myPaneT.AddOHLCBar(matchedCurveName, matchedPointsSection[j], m_options.matchedColor);
                matchedCurve.Bar.Width = 2;
                AddAnnotations(matchedCurve.Points, myPaneT);
                if (!m_options.hideUnmatched)
                {
                    OHLCBarItem unmatchedCurve = myPaneT.AddOHLCBar(unmatchedCurveName, unmatchedPointsSection[j], m_options.unmatchedColor);
                    AddAnnotations(unmatchedCurve.Points, myPaneT);
                }

                // Add the GraphPane to the MasterPane.PaneList
                master.Add(myPaneT);
            }

            //Tell ZedGraph to refigure the axes since the data has changed
            using (Graphics g = this.CreateGraphics())
            {
                // Align the GraphPanes vertically
                if (m_options.numberOfPlots >= 4)
                {
                    master.SetLayout(g, PaneLayout.SquareColPreferred);
                }
                else
                {
                    master.SetLayout(g, PaneLayout.SingleColumn);
                }
                master.AxisChange(g);
                this.PerformAutoScale();
            }
        }