예제 #1
0
        public override void UpdateGraph(bool selectionChanged)
        {
            GraphObjList.Clear();
            CurveList.Clear();
            Legend.IsVisible = false;

            if (!DetectionPlotData.GetDataCache().TryGet(
                    GraphSummary.DocumentUIContainer.DocumentUI, Settings.QValueCutoff, this.DataCallback,
                    out _detectionData))
            {
                return;
            }
            AddLabels();

            BarSettings.Type          = BarType.SortedOverlay;
            BarSettings.MinClusterGap = 0.3f;

            //draw bars
            var countPoints = new PointPairList(Enumerable.Range(0, _detectionData.ReplicateCount)
                                                .Select(i => new PointPair(i, TargetData.Histogram[i] / YScale)).ToList());

            CurveList.Insert(0, MakeBarItem(countPoints, Color.FromArgb(180, 220, 255)));

            //axes formatting
            XAxis.Scale.Max = _detectionData.ReplicateCount + 1;

            YAxis.Scale.Max = TargetData.Histogram.Max() / YScale * 1.15;
        }
예제 #2
0
        public override void Draw(Graphics g)
        {
            GraphObjList.Clear();

            // Force Axes to recalculate to ensure proper layout of labels
            AxisChange(g);

            base.Draw(g);
        }
예제 #3
0
        public override void Draw(Graphics g)
        {
            GraphObjList.Clear();

            if (_graphData != null)
            {
                // Force Axes to recalculate to ensure proper layout of labels
                AxisChange(g);

                // Reposition the regression label.
                RectangleF rectChart = Chart.Rect;
                PointF     ptTop     = rectChart.Location;

                // Setup axes scales to enable the ReverseTransform method
                XAxis.Scale.SetupScaleData(this, XAxis);
                YAxis.Scale.SetupScaleData(this, YAxis);

                float    yNext    = ptTop.Y;
                double   left     = XAxis.Scale.ReverseTransform(ptTop.X + 8);
                FontSpec fontSpec = GraphSummary.CreateFontSpec(COLOR_LINE_REGRESSION);
                if (_labelRegression != null)
                {
                    // Add regression text
                    double  top  = YAxis.Scale.ReverseTransform(yNext);
                    TextObj text = new TextObj(_labelRegression, left, top,
                                               CoordType.AxisXYScale, AlignH.Left, AlignV.Top)
                    {
                        IsClippedToChartRect = true,
                        ZOrder   = ZOrder.E_BehindCurves,
                        FontSpec = fontSpec,
                    };
                    //                text.FontSpec.Size = 12;
                    GraphObjList.Add(text);
                }

                if (_labelRegressionCurrent != null)
                {
                    // Add text for current regression
                    SizeF sizeLabel = fontSpec.MeasureString(g, _labelRegression, CalcScaleFactor());
                    yNext += sizeLabel.Height + 3;
                    double  top  = YAxis.Scale.ReverseTransform(yNext);
                    TextObj text = new TextObj(_labelRegressionCurrent, left, top,
                                               CoordType.AxisXYScale, AlignH.Left, AlignV.Top)
                    {
                        IsClippedToChartRect = true,
                        ZOrder   = ZOrder.E_BehindCurves,
                        FontSpec = GraphSummary.CreateFontSpec(COLOR_LINE_REGRESSION_CURRENT),
                    };
//                    text.FontSpec.Size = 12;
                    GraphObjList.Add(text);
                }
            }

            base.Draw(g);
        }
예제 #4
0
        public override void Draw(Graphics g)
        {
            GraphObjList.Clear();

            YAxis.Scale.Min = 0.0;

            AxisChange(g);
            AddLabels(g);

            base.Draw(g);
        }
예제 #5
0
        private void SetMappedItem(string itemID)
        {
            if (m_MappedItem == itemID)
            {
                return;
            }

            GraphObjList.Clear();

            CurveItem item = GetCurve(m_MappedItem);

            if (item != null)
            {
                item.IsVisible = true;
            }

            m_MappedItem = itemID;

            item = CurveList[itemID];

            if (item != null)
            {
                item.IsVisible = false;
                List <GraphObj> objects = new List <GraphObj>();

                for (int index = 0; index < item.Points.Count; index++)
                {
                    PointPair point = item[index];

                    LineObj line = new LineObj(Color.Gray, point.X, 0, point.X, 1);
                    line.Tag = point.Y;
                    line.Location.CoordinateFrame = CoordType.XScaleYChartFraction;
                    line.ZOrder = ZOrder.E_BehindCurves;


                    TextObj text = new TextObj(point.Y.ToString(), point.X, 1);
                    text.Location.CoordinateFrame  = CoordType.XScaleYChartFraction;
                    text.IsClippedToChartRect      = false;
                    text.FontSpec.Border.IsVisible = false;
                    text.Location.AlignV           = AlignV.Bottom;
                    text.Location.AlignH           = AlignH.Right;
                    text.FontSpec.Angle            = -90;
                    text.FontSpec.Fill.IsVisible   = false;
                    objects.Add(line);
                    objects.Add(text);
                }

                GraphObjList.AddRange(objects);
            }

            m_HasChanged = true;
            m_Parent.UpdateGraph();
        }
        public override void Draw(Graphics g)
        {
            GraphObjList.Clear();

            var data = Data;

            if (data != null && RTGraphController.PlotType == PlotTypeRT.correlation)
            {
                // Force Axes to recalculate to ensure proper layout of labels
                AxisChange(g);
                data.AddLabels(this, g);
            }

            base.Draw(g);
        }
예제 #7
0
        public override void Draw(Graphics g)
        {
            GraphObjList.Clear();

            YAxis.Scale.Min = 0.0;

            AxisChange(g);

            foreach (var l in _lineItems)
            {
                if (l != null)
                {
                    l[0].X = XAxis.Scale.Min;
                    l[1].X = XAxis.Scale.Max;
                }
            }

            base.Draw(g);
        }
예제 #8
0
        /// <summary>
        /// Highlight the interiorPos position of selected planets or averages.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (currentIndicators.Count != 0)
            {
                foreach (GraphObj obj in currentIndicators)
                {
                    zedLongTerm.GraphPane.GraphObjList.Remove(obj);
                }
                currentIndicators.Clear();
            }

            #region Draw the line to highlight interiorPos planet positions
            DateTimeOffset now        = DateTimeOffset.UtcNow;
            string         timeString = DateTimeOffset.Now.ToString("MM-dd HH:mm");

            now = new DateTimeOffset(now.Year, now.Month, now.Day, now.Hour, now.Minute, 0, TimeSpan.Zero);

            double x = now.DateTime.ToOADate();

            LineObj nowIndicator = new LineObj(x, zedLongTerm.GraphPane.YAxis.Scale.Min - 10, x, zedLongTerm.GraphPane.YAxis.Scale.Max + 10);
            nowIndicator.Line.Style = System.Drawing.Drawing2D.DashStyle.Dash;
            nowIndicator.Line.Color = Color.Gray;
            currentIndicators.Add(nowIndicator);

            #region With the lable of local time under the line

            TextObj timeIndicator = new TextObj(timeString, x, 0, CoordType.AxisXYScale);
            timeIndicator.Location.AlignH           = AlignH.Center;
            timeIndicator.Location.AlignV           = AlignV.Top;
            timeIndicator.FontSpec.Fill.Color       = Color.Yellow;
            timeIndicator.FontSpec.Fill.IsVisible   = true;
            timeIndicator.FontSpec.Border.IsVisible = true;
            timeIndicator.FontSpec.Size             = 6f;
            currentIndicators.Add(timeIndicator);

            #endregion


            if (checkBoxReadings.Checked)
            {
                for (int i = 0; i < CurrentEphemeris.Luminaries.Count; i++)
                {
                    CheckBox cb  = panelStars.Controls[i] as CheckBox;
                    Position pos = null;

                    if (cb != null && cb.Checked)
                    {
                        PlanetId id    = CurrentEphemeris.Luminaries[i];
                        string   label = null;
                        double   y     = 180;

                        if (id < PlanetId.SE_FICT_OFFSET)
                        {
                            pos   = CurrentEphemeris[now, id];
                            y     = pos.Longitude;
                            label = string.Format("{0}: {1} ({2})", Planet.Glyphs[id], pos.Longitude.ToString("F1"), Rectascension.AstroStringOf(pos.Longitude));
                        }
                        else if (OrbitsDict[PositionValueIndex.Longitude].ContainsKey(id))
                        {
                            int    todayIndex = (int)Math.Floor(x - since.DateTime.ToOADate());
                            double y1         = OrbitsDict[PositionValueIndex.Longitude][id][todayIndex];
                            double y2         = OrbitsDict[PositionValueIndex.Longitude][id][todayIndex + 1];
                            y = y1 + (y2 - y1) / (x - since.DateTime.ToOADate());

                            label = string.Format("{0}: {1:F1} ({2})", Planet.Glyphs[id], y, Rectascension.AstroStringOf(y));
                        }

                        TextObj posText = lableOf(label, x, y);
                        posText.Location.AlignV = y < 180 ? AlignV.Bottom : AlignV.Top;
                        currentIndicators.Add(posText);
                    }
                }
            }

            #endregion

            foreach (GraphObj obj in currentIndicators)
            {
                zedLongTerm.GraphPane.GraphObjList.Add(obj);
            }

            zedLongTerm.Invalidate();
        }
 public void Clear()
 {
     Data = null;
     CurveList.Clear();
     GraphObjList.Clear();
 }
예제 #10
0
 void clear()
 {
     CurveList.Clear();
     GraphObjList.Clear();
 }
예제 #11
0
        public override void UpdateGraph(bool selectionChanged)
        {
            if (!GraphSummary.DocumentUIContainer.DocumentUI.Settings.HasResults)
            {
                _areaCVGraphData = null;
                return;
            }

            var settings = new AreaCVGraphData.AreaCVGraphSettings(GraphSummary.Type);

            _document = GraphSummary.DocumentUIContainer.DocumentUI;

            var factor = AreaGraphController.GetAreaCVFactorToDecimal();

            BarSettings.Type = BarType.SortedOverlay;
            BarSettings.ClusterScaleWidth = Settings.Default.AreaCVHistogramBinWidth;
            BarSettings.MinClusterGap     = 0.0f;

            _percentage = !Settings.Default.AreaCVShowDecimals;
            _decimals   = _percentage ? 1 : 3;

            GraphObjList.Clear();
            CurveList.Clear();
            _stickItems.Clear();

            var gotData = _cache.TryGet(_document, settings, DataCallback, out _areaCVGraphData);

            if (!gotData || !_areaCVGraphData.IsValid)
            {
                return;
            }

            var fontHeight = GraphSummary.CreateFontSpec(Color.Black).GetHeight(CalcScaleFactor());
            var height     = PaneHeightToYValue(fontHeight);

            var heightFactor = 1;

            if (Settings.Default.AreaCVShowMedianCV)
            {
                var stick = AddStickItem(_areaCVGraphData.MedianCV * factor, _areaCVGraphData.MedianCV * factor, 0.0, _areaCVGraphData.MaxFrequency + heightFactor++ *height, Color.Blue);
                CurveList.Add(stick);
                _stickItems.Add(stick);
            }

            if (Settings.Default.AreaCVShowCVCutoff)
            {
                var stick = AddStickItem(Settings.Default.AreaCVCVCutoff, Settings.Default.AreaCVCVCutoff, 0.0, _areaCVGraphData.MaxFrequency + heightFactor++ *height, Color.Red);
                CurveList.Add(stick);
                _stickItems.Add(stick);
            }

            var selected = HistogramHelper.GetSelectedPeptides(GraphSummary).NodePeps.OrderBy(p => p.Id.GlobalIndex).ToList();
            var comparer = Comparer <PeptideDocNode> .Create((a, b) => a.Id.GlobalIndex.CompareTo(b.Id.GlobalIndex));

            var selectedPoints  = new PointPairList();
            var selectedPoints2 = new PointPairList();
            var otherPoints     = new PointPairList();

            foreach (var d in _areaCVGraphData.Data)
            {
                int frequency;
                var x = d.CV * factor + Settings.Default.AreaCVHistogramBinWidth / 2.0f;

                var pt = new PointPair(x, d.Frequency)
                {
                    Tag = d
                };
                if (Settings.Default.ShowReplicateSelection &&
                    (frequency = d.PeptideAnnotationPairs.Count(pair => selected.BinarySearch(pair.Peptide, comparer) >= 0)) > 0)
                {
                    selectedPoints.Add(pt);
                    selectedPoints2.Add(new PointPair(x, frequency)
                    {
                        Tag = d
                    });
                }
                else
                {
                    otherPoints.Add(pt);
                }
            }

            CurveList.Insert(0, MakeBarItem(selectedPoints2, Color.Red));
            CurveList.Insert(1, MakeBarItem(selectedPoints, Color.FromArgb(Color.Red.ToArgb() & 0x7FFFFFFF)));
            CurveList.Insert(2, MakeBarItem(otherPoints, Color.FromArgb(180, 220, 255)));

            XAxis.Title.Text = Resources.AreaCVHistogramGraphPane_UpdateGraph_CV + (_percentage ? @" (%)" : string.Empty);
            YAxis.Title.Text = Resources.AreaCVHistogramGraphPane_UpdateGraph_Frequency;

            XAxis.Scale.Min     = YAxis.Scale.Min = 0;
            XAxis.Scale.MinAuto = XAxis.Scale.MaxAuto = YAxis.Scale.MinAuto = YAxis.Scale.MaxAuto = false;

            if (!double.IsNaN(Settings.Default.AreaCVMaxCV))
            {
                XAxis.Scale.Max = Settings.Default.AreaCVMaxCV;
            }
            else
            {
                XAxis.Scale.Max = _areaCVGraphData.MaxCV * factor + Settings.Default.AreaCVHistogramBinWidth;
            }

            if (!double.IsNaN(Settings.Default.AreaCVMaxFrequency))
            {
                YAxis.Scale.Max = Settings.Default.AreaCVMaxFrequency;
            }
            else
            {
                YAxis.Scale.Max = _areaCVGraphData.MaxFrequency + heightFactor * height;
            }

            AxisChange();
        }
예제 #12
0
        public override void UpdateGraph(bool selectionChanged)
        {
            GraphObjList.Clear();
            CurveList.Clear();
            Legend.IsVisible = false;
            if (!DetectionPlotData.GetDataCache().TryGet(
                    GraphSummary.DocumentUIContainer.DocumentUI, Settings.QValueCutoff, this.DataCallback,
                    out _detectionData))
            {
                return;
            }

            AddLabels();
            BarSettings.Type          = BarType.SortedOverlay;
            BarSettings.MinClusterGap = 0.3f;
            Legend.IsVisible          = Settings.ShowLegend;

            var emptySymbol = new Symbol(SymbolType.None, Color.Transparent);
            //draw bars
            var counts      = TargetData.TargetsCount;
            var countPoints = new PointPairList(Enumerable.Range(0, _detectionData.ReplicateCount)
                                                .Select(i => new PointPair(i, counts[i] / YScale)).ToList());

            CurveList.Insert(0, MakeBarItem(countPoints, Color.FromArgb(180, 220, 255)));
            //draw cumulative curve
            counts = TargetData.TargetsCumulative;
            var cumulativePoints = new PointPairList(Enumerable.Range(0, _detectionData.ReplicateCount)
                                                     .Select(i => new PointPair(i, counts[i] / YScale)).ToList());

            CurveList.Insert(1,
                             new LineItem(Resources.DetectionPlotPane_CumulativeLine_Name)
            {
                Points = cumulativePoints,
                Symbol = emptySymbol,
                Line   = new Line()
                {
                    Color = Color.Coral, Width = 2
                }
            });
            //draw inclusive curve
            counts = TargetData.TargetsAll;
            var allPoints = new PointPairList(Enumerable.Range(0, _detectionData.ReplicateCount)
                                              .Select(i => new PointPair(i, counts[i] / YScale)).ToList());

            CurveList.Insert(2,
                             new LineItem(Resources.DetectionPlotPane_AllRunsLine_Name)
            {
                Symbol = emptySymbol,
                Points = allPoints,
                Line   = new Line()
                {
                    Color = Color.Black, Width = 2
                }
            });

            //axes formatting
            XAxis.Scale.Max = _detectionData.ReplicateCount + 1;
            YAxis.Scale.Max = _detectionData.GetTargetData(Settings.TargetType).MaxCount / YScale * 1.15;
            if (Settings.ShowAtLeastN)
            {
                double lineY       = TargetData.getCountForMinReplicates(Settings.RepCount);
                var    atLeastLine = new Line()
                {
                    Width = 1, Color = Color.Blue, Style = DashStyle.Dash
                };
                var dummyPoints = new PointPairList(new[] { new PointPair(0, 0) });
                var line        = new LineObj(Color.Blue, 0, lineY / YScale, XAxis.Scale.Max, lineY / YScale)
                {
                    IsClippedToChartRect = true,
                    Line = atLeastLine
                };
                GraphObjList.Add(line);

                //This is a placeholder to make sure the line shows in the legend.
                CurveList.Insert(3,
                                 new LineItem(String.Format(CultureInfo.CurrentCulture,
                                                            Resources.DetectionPlotPane_AtLeastLine_Name,
                                                            Settings.RepCount, _detectionData.ReplicateCount, lineY))
                {
                    Symbol = emptySymbol,
                    Points = dummyPoints,
                    Line   = atLeastLine
                });
            }

            if (Settings.ShowSelection)
            {
                var selectedIndex = GraphSummary.StateProvider.SelectedResultsIndex;
                var lineLength    = TargetData.TargetsCount[selectedIndex] / YScale + YAxis.Scale.Max * 0.05;
                GraphObjList.Add(
                    new LineObj(Color.Black, selectedIndex + 1, 0, selectedIndex + 1, lineLength)
                {
                    IsClippedToChartRect = true,
                    Line = new Line()
                    {
                        Width = 1, Color = Color.Black, Style = DashStyle.Dash
                    }
                });
            }

            if (Settings.ShowMean)
            {
                var stats     = new Statistics(TargetData.TargetsCount.Select((x) => (double)x));
                var labelText = String.Format(CultureInfo.CurrentCulture,
                                              TextUtil.LineSeparate(new[]
                {
                    Resources.DetectionPlotPane_Label_Mean,
                    Resources.DetectionPlotPane_Label_Stddev
                }
                                                                    ),
                                              stats.Mean(), stats.StdDev());
                GraphObjList.Add(new TextObj(labelText, 0.1, YAxis.Scale.Max,
                                             CoordType.AxisXYScale, AlignH.Left, AlignV.Top)
                {
                    IsClippedToChartRect = true,
                    ZOrder   = ZOrder.E_BehindCurves,
                    FontSpec = GraphSummary.CreateFontSpec(Color.Black),
                });
            }
        }
예제 #13
0
 public void Clear()
 {
     CurveList.Clear();
     GraphObjList.Clear();
 }
예제 #14
0
        public override void UpdateGraph(bool selectionChanged)
        {
            CurveList.Clear();
            GraphObjList.Clear();
            SrmDocument document         = GraphSummary.DocumentUIContainer.DocumentUI;
            var         selectedTreeNode = GraphSummary.StateProvider.SelectedNode as SrmTreeNode;

            if (selectedTreeNode == null || document.FindNode(selectedTreeNode.Path) == null)
            {
                Title.Text = Helpers.PeptideToMoleculeTextMapper.Translate(Resources.MassErrorReplicateGraphPane_UpdateGraph_Select_a_peptide_to_see_the_mass_error_graph, document.DocumentType);
                EmptyGraph(document);
                return;
            }
            if (!document.Settings.HasResults)
            {
                Title.Text = Resources.AreaReplicateGraphPane_UpdateGraph_No_results_available;
                EmptyGraph(document);
                return;
            }
            DisplayTypeChrom displayType;

            if (Equals(PaneKey, PaneKey.PRECURSORS))
            {
                displayType = DisplayTypeChrom.precursors;
            }
            else if (Equals(PaneKey, PaneKey.PRODUCTS))
            {
                displayType = DisplayTypeChrom.products;
            }
            else
            {
                displayType = GraphChromatogram.GetDisplayType(document, selectedTreeNode);
            }
            Title.Text = null;
            var aggregateOp = GraphValues.AggregateOp.FromCurrentSettings();

            YAxis.Title.Text = aggregateOp.Cv
                ? aggregateOp.AnnotateTitle(Resources.MassErrorReplicateGraphPane_UpdateGraph_Mass_Error_No_Ppm)
                : Resources.MassErrorReplicateGraphPane_UpdateGraph_Mass_Error;
            DocNode      selectedNode = selectedTreeNode.Model;
            DocNode      parentNode   = selectedNode;
            IdentityPath identityPath = selectedTreeNode.Path;

            // If the selected tree node is a transition, then its siblings are displayed.
            if (selectedTreeNode is TransitionTreeNode)
            {
                if (displayType != DisplayTypeChrom.single)
                {
                    SrmTreeNode parentTreeNode = selectedTreeNode.SrmParent;
                    parentNode   = parentTreeNode.Model;
                    identityPath = parentTreeNode.Path;
                }
            }
            // If the selected node is a peptide with one child, then show the children,
            // unless chromatogram display type is total
            else if (selectedTreeNode is PeptideTreeNode)
            {
                var children = ((PeptideDocNode)selectedNode).TransitionGroups
                               .Where(PaneKey.IncludesTransitionGroup)
                               .ToArray();
                if (children.Length == 1 && displayType != DisplayTypeChrom.total)
                {
                    selectedNode = parentNode = children[0];
                    identityPath = new IdentityPath(identityPath, parentNode.Id);
                }
            }
            else if (!(selectedTreeNode is TransitionGroupTreeNode))
            {
                Title.Text = Helpers.PeptideToMoleculeTextMapper.Translate(Resources.MassErrorReplicateGraphPane_UpdateGraph_Select_a_peptide_to_see_the_mass_error_graph, document.DocumentType);
                EmptyGraph(document);
                CanShowMassErrorLegend = false;
                return;
            }
            // If a precursor is going to be displayed with display type single
            if (parentNode is TransitionGroupDocNode && displayType == DisplayTypeChrom.single)
            {
                // If no optimization data, then show all the transitions
                displayType = DisplayTypeChrom.all;
            }

            var       replicateGroupOp = ReplicateGroupOp.FromCurrentSettings(document.Settings);
            GraphData graphData        = new MassErrorGraphData(document,
                                                                identityPath,
                                                                displayType,
                                                                replicateGroupOp,
                                                                PaneKey);

            CanShowMassErrorLegend = graphData.DocNodes.Count != 0;
            InitFromData(graphData);

            int    selectedReplicateIndex = SelectedIndex;
            double minRetentionTime       = double.MaxValue;
            double maxRetentionTime       = double.MinValue;

            int iColor = 0, iCharge = -1;
            var charge                 = Adduct.EMPTY;
            int countLabelTypes        = document.Settings.PeptideSettings.Modifications.CountLabelTypes;
            int colorOffset            = 0;
            var transitionGroupDocNode = parentNode as TransitionGroupDocNode;

            if (transitionGroupDocNode != null && displayType == DisplayTypeChrom.products)
            {
                // If we are only displaying product ions, we want to use an offset in the colors array
                // so that we do not re-use colors that would be used for any precursor ions.
                colorOffset =
                    GraphChromatogram.GetDisplayTransitions(transitionGroupDocNode, DisplayTypeChrom.precursors).Count();
            }
            for (int i = 0; i < graphData.DocNodes.Count; i++)
            {
                var docNode        = graphData.DocNodes[i];
                var pointPairLists = graphData.PointPairLists[i];
                int numSteps       = pointPairLists.Count / 2;
                for (int iStep = 0; iStep < pointPairLists.Count; iStep++)
                {
                    int   step          = iStep - numSteps;
                    var   pointPairList = pointPairLists[iStep];
                    Color color;
                    // ReSharper disable ExpressionIsAlwaysNull
                    var nodeGroup = docNode as TransitionGroupDocNode;
                    if (parentNode is PeptideDocNode)
                    {
                        int iColorGroup = GetColorIndex(nodeGroup, countLabelTypes, ref charge, ref iCharge);
                        color = COLORS_GROUPS[iColorGroup % COLORS_GROUPS.Count];
                    }
                    else if (displayType == DisplayTypeChrom.total)
                    {
                        color = COLORS_GROUPS[iColor % COLORS_GROUPS.Count];
                    }
                    else if (docNode.Equals(selectedNode) && step == 0)
                    {
                        color = ChromGraphItem.ColorSelected;
                    }
                    else
                    {
                        color = COLORS_TRANSITION[(iColor + colorOffset) % COLORS_TRANSITION.Count];
                    }
                    // ReSharper restore ExpressionIsAlwaysNull
                    iColor++;

                    string label = graphData.DocNodeLabels[i];
                    if (step != 0)
                    {
                        label = string.Format(Resources.RTReplicateGraphPane_UpdateGraph_Step__0__, step);
                    }
                    BarItem curveItem = new MeanErrorBarItem(label, pointPairList, color, Color.Black);

                    if (selectedReplicateIndex != -1 && selectedReplicateIndex < pointPairList.Count)
                    {
                        PointPair pointPair = pointPairList[selectedReplicateIndex];
                        if (!pointPair.IsInvalid)
                        {
                            minRetentionTime = Math.Min(minRetentionTime, pointPair.Y);
                            maxRetentionTime = Math.Max(maxRetentionTime, pointPair.Y);
                        }
                    }

                    curveItem.Bar.Border.IsVisible = false;
                    curveItem.Bar.Fill.Brush       = new SolidBrush(color);
                    curveItem.Tag = new IdentityPath(identityPath, docNode.Id);
                    CurveList.Add(curveItem);
                }
            }

            // Draw a box around the currently selected replicate
            if (ShowSelection && minRetentionTime != double.MaxValue)
            {
                maxRetentionTime = Math.Max(maxRetentionTime, 0);
                minRetentionTime = Math.Min(minRetentionTime, 0);
                GraphObjList.Add(new BoxObj(selectedReplicateIndex + .5, maxRetentionTime, 1,
                                            maxRetentionTime - minRetentionTime, Color.Black, Color.Empty)
                {
                    IsClippedToChartRect = true,
                });
            }

            XAxis.Scale.MinAuto = XAxis.Scale.MaxAuto = selectionChanged;
            YAxis.Scale.MinAuto = YAxis.Scale.MaxAuto = true;
            if (Settings.Default.MinMassError != 0)
            {
                YAxis.Scale.Min = Settings.Default.MinMassError;
            }
            if (Settings.Default.MaxMassError != 0)
            {
                YAxis.Scale.Max = Settings.Default.MaxMassError;
            }
            Legend.IsVisible = Settings.Default.ShowMassErrorLegend;
            AxisChange();
        }
예제 #15
0
        private void drawLabels(Graphics g)
        {
            foreach (GraphObj pa in _pointAnnotations)
            {
                GraphObjList.Remove(pa);
            }
            _pointAnnotations.Clear();

            Axis xAxis = XAxis;
            Axis yAxis = YAxis;

            yAxis.Scale.MinAuto = false;
            yAxis.Scale.Min     = 0;

            // setup axes scales to enable the Transform method
            xAxis.Scale.SetupScaleData(this, xAxis);
            yAxis.Scale.SetupScaleData(this, yAxis);

            if (Chart.Rect.Width < 1 || Chart.Rect.Height < 1)
            {
                return;
            }

            Region textBoundsRegion;
            Region chartRegion = new Region(Chart.Rect);
            Region clipRegion  = new Region();

            clipRegion.MakeEmpty();
            g.SetClip(Rect, CombineMode.Replace);
            g.SetClip(chartRegion, CombineMode.Exclude);

            /*Bitmap clipBmp = new Bitmap(Convert.ToInt32(Chart.Rect.Width), Convert.ToInt32(Chart.Rect.Height));
             * Graphics clipG = Graphics.FromImage(clipBmp);
             * clipG.Clear(Color.White);
             * clipG.FillRegion(new SolidBrush(Color.Black), g.Clip);
             * clipBmp.Save("C:\\clip.bmp");*/


            // some dummy labels for very fast clipping
            string baseLabel = "0";

            foreach (CurveItem item in CurveList)
            {
                IMSGraphItemInfo info = item.Tag as IMSGraphItemInfo;
                if (info != null)
                {
                    PointAnnotation annotation = info.AnnotatePoint(new PointPair(0, 0));
                    if (annotation != null &&
                        annotation.Label != null &&
                        annotation.Label.Length > baseLabel.Length)
                    {
                        baseLabel = annotation.Label;
                    }
                }
            }

            TextObj baseTextObj = new TextObj(baseLabel, 0, 0);

            baseTextObj.FontSpec.Border.IsVisible = false;
            baseTextObj.FontSpec.Fill.IsVisible   = false;
            PointF[] pts = baseTextObj.FontSpec.GetBox(g, baseLabel, 0, 0,
                                                       AlignH.Center, AlignV.Bottom, 1.0f, new SizeF());
            float baseLabelWidth  = (float)Math.Round(pts[1].X - pts[0].X);
            float baseLabelHeight = (float)Math.Round(pts[2].Y - pts[0].Y);

            baseLabelWidth  = (float)xAxis.Scale.ReverseTransform(xAxis.Scale.Transform(0) + baseLabelWidth);
            baseLabelHeight = (float)yAxis.Scale.ReverseTransform(yAxis.Scale.Transform(0) - baseLabelHeight);
            float labelLengthToWidthRatio = baseLabelWidth / baseLabel.Length;

            float xAxisPixel = yAxis.Scale.Transform(0);

            double xMin = xAxis.Scale.Min;
            double xMax = xAxis.Scale.Max;
            double yMin = yAxis.Scale.Min;
            double yMax = yAxis.Scale.Max;

            // add automatic labels for MSGraphItems
            foreach (CurveItem item in CurveList)
            {
                IMSGraphItemInfo info   = item.Tag as IMSGraphItemInfo;
                MSPointList      points = item.Points as MSPointList;
                if (info == null || points == null)
                {
                    continue;
                }

                if (info.ToString().Length == 0)
                {
                    continue;
                }

                PointPairList fullList     = points.FullList;
                List <int>    maxIndexList = points.ScaledMaxIndexList;
                for (int i = 0; i < maxIndexList.Count; ++i)
                {
                    if (maxIndexList[i] < 0)
                    {
                        continue;
                    }
                    PointPair pt = fullList[maxIndexList[i]];

                    if (pt.X < xMin || pt.Y > yMax || pt.Y < yMin)
                    {
                        continue;
                    }
                    if (pt.X > xMax)
                    {
                        break;
                    }

                    float yPixel = yAxis.Scale.Transform(pt.Y);

                    // labelled points must be at least 3 pixels off the X axis
                    if (xAxisPixel - yPixel < 3)
                    {
                        continue;
                    }

                    PointAnnotation annotation = info.AnnotatePoint(pt);
                    if (annotation == null)
                    {
                        continue;
                    }

                    if (annotation.ExtraAnnotation != null)
                    {
                        GraphObjList.Add(annotation.ExtraAnnotation);
                        _pointAnnotations.Add(annotation.ExtraAnnotation);
                    }

                    if (string.IsNullOrEmpty(annotation.Label))
                    {
                        continue;
                    }

                    float pointLabelWidth = labelLengthToWidthRatio * annotation.Label.Length;

                    double labelY = yAxis.Scale.ReverseTransform(yPixel - 5);

                    if (!AllowCurveOverlap)
                    {
                        // do fast check for overlap against all MSGraphItems
                        bool overlap = false;
                        foreach (CurveItem item2 in CurveList)
                        {
                            MSPointList points2 = item2.Points as MSPointList;
                            if (points2 != null)
                            {
                                int nearestMaxIndex = points2.GetNearestMaxIndexToBin(i);
                                if (nearestMaxIndex < 0)
                                {
                                    continue;
                                }
                                RectangleF r = new RectangleF((float)pt.X - pointLabelWidth / 2,
                                                              (float)labelY - baseLabelHeight,
                                                              pointLabelWidth,
                                                              baseLabelHeight);
                                overlap = detectLabelCurveOverlap(this, points2.FullList, nearestMaxIndex, item2 is StickItem, r);
                                if (overlap)
                                {
                                    break;
                                }
                            }
                        }

                        if (overlap)
                        {
                            continue;
                        }
                    }

                    TextObj text = new TextObj(annotation.Label, pt.X, labelY,
                                               CoordType.AxisXYScale, AlignH.Center, AlignV.Bottom)
                    {
                        ZOrder   = ZOrder.A_InFront,
                        FontSpec = annotation.FontSpec
                    };
                    //text.IsClippedToChartRect = true;

                    if (!detectLabelOverlap(this, g, text, out textBoundsRegion, item.Points, maxIndexList[i], item is StickItem))
                    {
                        GraphObjList.Add(text);
                        _pointAnnotations.Add(text);


                        clipRegion.Union(textBoundsRegion);
                        g.SetClip(clipRegion, CombineMode.Replace);
                    }
                }
            }

            // add manual annotations
            foreach (CurveItem item in CurveList)
            {
                IMSGraphItemInfo info   = item.Tag as IMSGraphItemInfo;
                MSPointList      points = item.Points as MSPointList;
                if (info == null || points == null)
                {
                    continue;
                }

                info.AddAnnotations(this, g, points, _pointAnnotations);
                foreach (GraphObj obj in _pointAnnotations)
                {
                    if (!GraphObjList.Contains(obj))
                    {
                        TextObj text = obj as TextObj;
                        if (text != null)
                        {
                            if (detectLabelOverlap(this, g, text, out textBoundsRegion, item.Points, -1, item is StickItem))
                            {
                                continue;
                            }

                            clipRegion.Union(textBoundsRegion);
                            g.SetClip(clipRegion, CombineMode.Replace);
                        }

                        GraphObjList.Add(obj);
                    }
                }

                /*GraphObjList objsToRemove = new GraphObjList();
                 * foreach( GraphObj obj in GraphObjList )
                 *  if( !pointAnnotations_.Contains( obj ) )
                 *      objsToRemove.Add( obj );
                 * foreach( GraphObj obj in objsToRemove )
                 *  GraphObjList.Remove( obj );*/
            }
        }