public override Value Evaluate(FSharpList<Value> args) { CurveList curves = new CurveList(); var input = (args[0] as Value.List).Item; foreach (Value v in input) { Curve c = ((Value.Container)v).Item as Curve; curves.Add(c); } _surface = Surface.by_patch(curves); return Value.NewContainer(_surface); }
// Revision: JCarpenter 10/06 /// <summary> /// Find any objects that exist within the specified (screen) rectangle. This method will search through all of the graph objects, such as /// <see cref="Axis"/>, <see cref="Legend"/>, <see cref="PaneBase.Title"/>, /// <see cref="GraphObj"/>, and <see cref="CurveItem"/>. and see if the objects' bounding boxes are within the specified (screen) rectangle This method /// returns true if any are found. /// </summary> /// <param name="rectF"> /// The rect F. /// </param> /// <param name="g"> /// The g. /// </param> /// <param name="containedObjs"> /// The contained Objs. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> public bool FindContainedObjects(RectangleF rectF, Graphics g, out CurveList containedObjs) { containedObjs = new CurveList(); foreach (CurveItem ci in this.CurveList) { for (int i = 0; i < ci.Points.Count; i++) { if (ci.Points[i].X > rectF.Left && ci.Points[i].X < rectF.Right && ci.Points[i].Y > rectF.Bottom && ci.Points[i].Y < rectF.Top) { containedObjs.Add(ci); } } } return containedObjs.Count > 0; }
/// <summary> /// Find the data point that lies closest to the specified mouse (screen) point for the specified curve. /// </summary> /// <remarks> /// This method will search only through the points for the specified curve to determine which point is nearest the mouse point. It will only consider /// points that are within /// <see cref="Default.NearestTol"/> pixels of the screen point. /// </remarks> /// <param name="mousePt"> /// The screen point, in pixel coordinates. /// </param> /// <param name="targetCurve"> /// A <see cref="CurveItem"/> object containing the data points to be searched. /// </param> /// <param name="nearestCurve"> /// A reference to the <see cref="CurveItem"/> /// instance that contains the closest point. nearestCurve will be null if no data points are available. /// </param> /// <param name="iNearest"> /// The index number of the closest point. The actual data vpoint will then be <see cref="CurveItem.Points">CurveItem.Points[iNearest]</see> /// . iNearest will be -1 if no data points are available. /// </param> /// <returns> /// true if a point was found and that point lies within /// <see cref="Default.NearestTol"/> pixels of the screen point, false otherwise. /// </returns> public bool FindNearestPoint(PointF mousePt, CurveItem targetCurve, out CurveItem nearestCurve, out int iNearest) { CurveList targetCurveList = new CurveList(); targetCurveList.Add(targetCurve); return this.FindNearestPoint(mousePt, targetCurveList, out nearestCurve, out iNearest); }
/// <summary> /// Forces a update of the scatter plot. /// </summary> /// public void UpdateGraph() { zedGraphControl.GraphPane.Title.Text = scatterplot.Title; zedGraphControl.GraphPane.XAxis.Title.Text = Scatterplot.XAxisTitle; zedGraphControl.GraphPane.YAxis.Title.Text = Scatterplot.YAxisTitle; classes.Clear(); if (scatterplot.Classes != null) { if (scatterplot.Classes.Count == 0) { zedGraphControl.GraphPane.Legend.IsVisible = false; // Create space for unlabelled data PointPairList list = new PointPairList(scatterplot.XAxis, scatterplot.YAxis); LineItem item = new LineItem(String.Empty, list, Color.Black, SymbolType.Default); item.Line.IsVisible = LinesVisible; item.Symbol.Border.IsVisible = false; item.Symbol.Fill = new Fill(Color.Black); if (SymbolSize == 0) { item.Symbol.IsVisible = false; } else { item.Symbol.Size = SymbolSize; } classes.Add(item); } else { zedGraphControl.GraphPane.Legend.IsVisible = true; var colors = new ColorSequenceCollection(scatterplot.Classes.Count); // Create a curve item for each of the labels for (int i = 0; i < scatterplot.Classes.Count; i++) { // retrieve the x,y pairs for the label double[] x = scatterplot.Classes[i].XAxis; double[] y = scatterplot.Classes[i].YAxis; PointPairList list = new PointPairList(x, y); LineItem item = new LineItem(scatterplot.Classes[i].Text, list, colors[i], SymbolType.Default); item.Line.IsVisible = LinesVisible; item.Symbol.Border.IsVisible = false; item.Symbol.Fill = new Fill(colors[i]); if (SymbolSize == 0) { item.Symbol.IsVisible = false; } else { item.Symbol.Size = SymbolSize; } classes.Add(item); } } zedGraphControl.AxisChange(); zedGraphControl.Invalidate(); if (!ScaleTight) { zedGraphControl.ZoomPane(zedGraphControl.GraphPane, 1.1, PointF.Empty, false); } else { zedGraphControl.RestoreScale(zedGraphControl.GraphPane); } } }
private void DisplayCalibrationCurve() { CalibrationCurveOptions options = Settings.Default.CalibrationCurveOptions; zedGraphControl.GraphPane.YAxis.Type = zedGraphControl.GraphPane.XAxis.Type = options.LogPlot ? AxisType.Log : AxisType.Linear; zedGraphControl.GraphPane.Legend.IsVisible = options.ShowLegend; _scatterPlots = null; CalibrationCurve = null; SrmDocument document = DocumentUiContainer.DocumentUI; if (!document.Settings.HasResults) { zedGraphControl.GraphPane.Title.Text = QuantificationStrings.CalibrationForm_DisplayCalibrationCurve_No_results_available; return; } PeptideDocNode peptide = null; PeptideGroupDocNode peptideGroup = null; SequenceTree sequenceTree = _skylineWindow.SequenceTree; if (null != sequenceTree) { PeptideTreeNode peptideTreeNode = sequenceTree.GetNodeOfType <PeptideTreeNode>(); if (null != peptideTreeNode) { peptide = peptideTreeNode.DocNode; } PeptideGroupTreeNode peptideGroupTreeNode = sequenceTree.GetNodeOfType <PeptideGroupTreeNode>(); if (null != peptideGroupTreeNode) { peptideGroup = peptideGroupTreeNode.DocNode; } } if (null == peptide) { zedGraphControl.GraphPane.Title.Text = QuantificationStrings .CalibrationForm_DisplayCalibrationCurve_Select_a_peptide_to_see_its_calibration_curve; return; } PeptideQuantifier peptideQuantifier = PeptideQuantifier.GetPeptideQuantifier(document.Settings, peptideGroup, peptide); CalibrationCurveFitter curveFitter = new CalibrationCurveFitter(peptideQuantifier, document.Settings); if (peptideQuantifier.QuantificationSettings.RegressionFit == RegressionFit.NONE) { if (string.IsNullOrEmpty( peptideQuantifier.QuantificationSettings.NormalizationMethod.IsotopeLabelTypeName)) { zedGraphControl.GraphPane.Title.Text = QuantificationStrings.CalibrationForm_DisplayCalibrationCurve_Use_the_Quantification_tab_on_the_Peptide_Settings_dialog_to_control_the_conversion_of_peak_areas_to_concentrations_; } else { if (!peptide.InternalStandardConcentration.HasValue) { zedGraphControl.GraphPane.Title.Text = string.Format(QuantificationStrings.CalibrationForm_DisplayCalibrationCurve_To_convert_peak_area_ratios_to_concentrations__specify_the_internal_standard_concentration_for__0__, peptide); } else { zedGraphControl.GraphPane.Title.Text = null; } } } else { if (curveFitter.GetStandardConcentrations().Any()) { zedGraphControl.GraphPane.Title.Text = null; } else { zedGraphControl.GraphPane.Title.Text = QuantificationStrings.CalibrationForm_DisplayCalibrationCurve_To_fit_a_calibration_curve__set_the_Sample_Type_of_some_replicates_to_Standard__and_specify_their_concentration_; } } zedGraphControl.GraphPane.XAxis.Title.Text = curveFitter.GetXAxisTitle(); zedGraphControl.GraphPane.YAxis.Title.Text = curveFitter.GetYAxisTitle(); CalibrationCurve = curveFitter.GetCalibrationCurve(); double minX = double.MaxValue, maxX = double.MinValue; _scatterPlots = new CurveList(); foreach (var sampleType in SampleType.ListSampleTypes()) { if (!Options.DisplaySampleType(sampleType)) { continue; } PointPairList pointPairList = new PointPairList(); for (int iReplicate = 0; iReplicate < document.Settings.MeasuredResults.Chromatograms.Count; iReplicate++) { ChromatogramSet chromatogramSet = document.Settings.MeasuredResults.Chromatograms[iReplicate]; if (!Equals(sampleType, chromatogramSet.SampleType)) { continue; } double?y = curveFitter.GetYValue(iReplicate); double?x = curveFitter.GetSpecifiedXValue(iReplicate) ?? curveFitter.GetCalculatedXValue(CalibrationCurve, iReplicate); if (y.HasValue && x.HasValue) { PointPair point = new PointPair(x.Value, y.Value) { Tag = iReplicate }; pointPairList.Add(point); if (!Options.LogPlot || x.Value > 0) { minX = Math.Min(minX, x.Value); } maxX = Math.Max(maxX, x.Value); } } if (pointPairList.Any()) { var lineItem = zedGraphControl.GraphPane.AddCurve(sampleType.ToString(), pointPairList, sampleType.Color, sampleType.SymbolType); lineItem.Line.IsVisible = false; lineItem.Symbol.Fill = new Fill(sampleType.Color); _scatterPlots.Add(lineItem); } } List <string> labelLines = new List <String>(); RegressionFit regressionFit = document.Settings.PeptideSettings.Quantification.RegressionFit; if (regressionFit != RegressionFit.NONE) { if (minX <= maxX) { int interpolatedLinePointCount = 100; if (!options.LogPlot) { if (regressionFit == RegressionFit.LINEAR_THROUGH_ZERO) { minX = Math.Min(0, minX); } if (regressionFit != RegressionFit.QUADRATIC) { interpolatedLinePointCount = 2; } } LineItem interpolatedLine = CreateInterpolatedLine(CalibrationCurve, minX, maxX, interpolatedLinePointCount, Options.LogPlot); if (null != interpolatedLine) { zedGraphControl.GraphPane.CurveList.Add(interpolatedLine); } } labelLines.Add(CalibrationCurve.ToString()); if (CalibrationCurve.RSquared.HasValue) { labelLines.Add(QuantificationStrings.CalibrationForm_DisplayCalibrationCurve_ + CalibrationCurve.RSquared.Value.ToString("0.####")); // Not L10N } if (!Equals(curveFitter.QuantificationSettings.RegressionWeighting, RegressionWeighting.NONE)) { labelLines.Add(string.Format("{0}: {1}", // Not L10N QuantificationStrings.Weighting, curveFitter.QuantificationSettings.RegressionWeighting)); } } if (options.ShowSelection) { double?ySelected = curveFitter.GetYValue(_skylineWindow.SelectedResultsIndex); double?xSelected = curveFitter.GetCalculatedXValue(CalibrationCurve, _skylineWindow.SelectedResultsIndex); if (xSelected.HasValue && ySelected.HasValue) { ArrowObj arrow = new ArrowObj(xSelected.Value, ySelected.Value, xSelected.Value, ySelected.Value) { Line = { Color = GraphSummary.ColorSelected } }; zedGraphControl.GraphPane.GraphObjList.Insert(0, arrow); } var quantificationResult = curveFitter.GetQuantificationResult(_skylineWindow.SelectedResultsIndex); if (quantificationResult.CalculatedConcentration.HasValue) { labelLines.Add(string.Format("{0} = {1}", // Not L10N QuantificationStrings.Calculated_Concentration, quantificationResult)); } else if (!quantificationResult.NormalizedArea.HasValue) { labelLines.Add(QuantificationStrings.CalibrationForm_DisplayCalibrationCurve_The_selected_replicate_has_missing_or_truncated_transitions); } } if (labelLines.Any()) { TextObj text = new TextObj(TextUtil.LineSeparate(labelLines), .01, 0, CoordType.ChartFraction, AlignH.Left, AlignV.Top) { IsClippedToChartRect = true, ZOrder = ZOrder.E_BehindCurves, FontSpec = GraphSummary.CreateFontSpec(Color.Black), }; zedGraphControl.GraphPane.GraphObjList.Add(text); } }
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); // Not L10N 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(); }
public override void UpdateGraph(bool selectionChanged) { SrmDocument document = GraphSummary.DocumentUIContainer.DocumentUI; var results = document.Settings.MeasuredResults; bool resultsAvailable = results != null; Clear(); if (!resultsAvailable) { Title.Text = Resources.RTReplicateGraphPane_UpdateGraph_No_results_available; EmptyGraph(document); return; } var selectedTreeNode = GraphSummary.StateProvider.SelectedNode as SrmTreeNode ?? GraphSummary.StateProvider.SelectedNodes.OfType <SrmTreeNode>().FirstOrDefault(); if (selectedTreeNode == null || document.FindNode(selectedTreeNode.Path) == null) { EmptyGraph(document); return; } Title.Text = null; DisplayTypeChrom displayType = GraphChromatogram.GetDisplayType(document, selectedTreeNode); DocNode selectedNode = selectedTreeNode.Model; IdentityPath selectedPath = selectedTreeNode.Path; DocNode parentNode = selectedNode; IdentityPath parentPath = 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; selectedPath = 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 = ((DocNodeParent)selectedNode).Children; if (children.Count == 1 && displayType != DisplayTypeChrom.total) { selectedNode = parentNode = children[0]; selectedPath = new IdentityPath(parentPath, children[0].Id); } } else if (!(selectedTreeNode is PeptideGroupTreeNode) && !(selectedTreeNode is TransitionGroupTreeNode)) { Title.Text = Resources.RTReplicateGraphPane_UpdateGraph_Select_a_peptide_to_see_the_retention_time_graph; CanShowRTLegend = 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 if (!results.Chromatograms.Contains(chrom => chrom.OptimizationFunction != null)) { displayType = DisplayTypeChrom.all; } } var rtTransformOp = GraphSummary.StateProvider.GetRetentionTimeTransformOperation(); var rtValue = RTPeptideGraphPane.RTValue; ReplicateGroupOp replicateGroupOp; if (rtValue == RTPeptideValue.All) { replicateGroupOp = ReplicateGroupOp.FromCurrentSettings(document.Settings, GraphValues.AggregateOp.MEAN); } else { replicateGroupOp = ReplicateGroupOp.FromCurrentSettings(document.Settings); } var retentionTimeValue = new GraphValues.RetentionTimeTransform(rtValue, rtTransformOp, replicateGroupOp.AggregateOp); YAxis.Title.Text = retentionTimeValue.GetAxisTitle(); var peptidePaths = GetSelectedPeptides().GetUniquePeptidePaths().ToList(); // if PeptideGroupTreeNode is selected but has only one child isMultiSelect should still be true IsMultiSelect = peptidePaths.Count > 1 || (peptidePaths.Count == 1 && GraphSummary.StateProvider.SelectedNodes.FirstOrDefault() is PeptideGroupTreeNode); GraphData graphData = new RTGraphData(document, IsMultiSelect ? peptidePaths : new[] { selectedPath }.AsEnumerable(), displayType, retentionTimeValue, replicateGroupOp); CanShowRTLegend = graphData.DocNodes.Count != 0; InitFromData(graphData); int selectedReplicateIndex = SelectedIndex; double minRetentionTime = double.MaxValue; double maxRetentionTime = -double.MaxValue; 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 identityPath = graphData.DocNodePaths[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; var isSelected = false; var nodeGroup = docNode as TransitionGroupDocNode; if (IsMultiSelect) { var peptides = peptidePaths.Select(path => document.FindNode(path)) .Cast <PeptideDocNode>().ToArray(); var peptideDocNode = peptides.FirstOrDefault( peptide => 0 <= peptide.FindNodeIndex(docNode.Id)); if (peptideDocNode == null) { continue; } color = GraphSummary.StateProvider.GetPeptideGraphInfo(peptideDocNode).Color; if (identityPath.Equals(selectedTreeNode.Path) && step == 0) { color = ChromGraphItem.ColorSelected; isSelected = true; } } else if (parentNode is PeptideDocNode) { // Resharper code inspection v9.0 on TC gets this one wrong // ReSharper disable ExpressionIsAlwaysNull int iColorGroup = GetColorIndex(nodeGroup, countLabelTypes, ref charge, ref iCharge); // ReSharper restore ExpressionIsAlwaysNull color = COLORS_GROUPS[iColorGroup % COLORS_GROUPS.Count]; } else if (displayType == DisplayTypeChrom.total) { color = COLORS_GROUPS[iColor % COLORS_GROUPS.Count]; } else if (ReferenceEquals(docNode, selectedNode) && step == 0) { color = ChromGraphItem.ColorSelected; isSelected = true; } else { color = COLORS_TRANSITION[(iColor + colorOffset) % COLORS_TRANSITION.Count]; } iColor++; string label = graphData.DocNodeLabels[i]; if (step != 0) { label = string.Format(Resources.RTReplicateGraphPane_UpdateGraph_Step__0__, step); } CurveItem curveItem; if (IsMultiSelect) { if (rtValue != RTPeptideValue.All) { curveItem = CreateLineItem(label, pointPairList, color); } else { curveItem = CreateMultiSelectBarItem(label, pointPairList, color); } } else if (HiLowMiddleErrorBarItem.IsHiLoMiddleErrorList(pointPairList)) { curveItem = new HiLowMiddleErrorBarItem(label, pointPairList, color, Color.Black); BarSettings.Type = BarType.Cluster; } else if (rtValue == RTPeptideValue.All) { curveItem = new MeanErrorBarItem(label, pointPairList, color, Color.Black); BarSettings.Type = BarType.Cluster; } else { curveItem = CreateLineItem(label, pointPairList, color); } if (curveItem != null) { curveItem.Tag = identityPath; var barItem = curveItem as BarItem; if (barItem != null) { barItem.Bar.Border.IsVisible = false; barItem.Bar.Fill.Brush = GetBrushForNode(document.Settings, docNode, color); if (!isSelected) { barItem.SortedOverlayPriority = 1; } } CurveList.Add(curveItem); if (selectedReplicateIndex != -1 && selectedReplicateIndex < pointPairList.Count) { PointPair pointPair = pointPairList[selectedReplicateIndex]; if (!pointPair.IsInvalid) { minRetentionTime = Math.Min(minRetentionTime, pointPair.Z); maxRetentionTime = Math.Max(maxRetentionTime, pointPair.Y); } } } } } // Draw a box around the currently selected replicate if (ShowSelection && minRetentionTime != double.MaxValue) { AddSelection(selectedReplicateIndex, maxRetentionTime, minRetentionTime); } // Reset the scale when the parent node changes if (_parentNode == null || !ReferenceEquals(_parentNode.Id, parentNode.Id)) { XAxis.Scale.MaxAuto = XAxis.Scale.MinAuto = true; YAxis.Scale.MaxAuto = YAxis.Scale.MinAuto = true; } _parentNode = parentNode; Legend.IsVisible = !IsMultiSelect && Settings.Default.ShowRetentionTimesLegend; GraphSummary.GraphControl.Invalidate(); AxisChange(); }
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(); }
public override void UpdateGraph(bool selectionChanged) { Clear(); TransitionGroupDocNode selectedGroup = null; PeptideGroupDocNode selectedProtein = null; var selectedTreeNode = GraphSummary.StateProvider.SelectedNode as SrmTreeNode; if (selectedTreeNode != null) { if (selectedTreeNode is TransitionTreeNode) { selectedGroup = (TransitionGroupDocNode)selectedTreeNode.SrmParent.Model; } else if (selectedTreeNode is TransitionGroupTreeNode) { selectedGroup = (TransitionGroupDocNode)selectedTreeNode.Model; } else { var node = selectedTreeNode as PeptideTreeNode; if (node != null) { var nodePep = node.DocNode; selectedGroup = nodePep.TransitionGroups.FirstOrDefault(); } } var proteinTreeNode = selectedTreeNode.GetNodeOfType <PeptideGroupTreeNode>(); if (proteinTreeNode != null) { selectedProtein = proteinTreeNode.DocNode; } } SrmDocument document = GraphSummary.DocumentUIContainer.DocumentUI; var displayType = GraphChromatogram.GetDisplayType(document, selectedTreeNode); _graphData = CreateGraphData(document, selectedProtein, selectedGroup, displayType); int iColor = 0; int colorOffset = 0; if (selectedGroup != 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(selectedGroup, DisplayTypeChrom.precursors).Count(); } foreach (var pointPairList in _graphData.PointPairLists) { Color color = displayType == DisplayTypeChrom.total ? COLORS_GROUPS[iColor++ % COLORS_GROUPS.Count] : COLORS_TRANSITION[(iColor++ + colorOffset) % COLORS_TRANSITION.Count]; BarItem curveItem; if (HiLowMiddleErrorBarItem.IsHiLoMiddleErrorList(pointPairList)) { curveItem = new HiLowMiddleErrorBarItem(string.Empty, pointPairList, color, Color.Black); } else { curveItem = new MeanErrorBarItem(string.Empty, pointPairList, color, Color.Black); } curveItem.Bar.Border.IsVisible = false; curveItem.Bar.Fill.Brush = new SolidBrush(color); CurveList.Add(curveItem); } if (ShowSelection && SelectedIndex != -1) { double yValue = _graphData.SelectedMaxY; double yMin = _graphData.SelectedMinY; double height = yValue - yMin; GraphObjList.Add(new BoxObj(SelectedIndex + .5, yValue, 0.99, height, Color.Black, Color.Empty) { IsClippedToChartRect = true, }); } UpdateAxes(); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { var gc = new GetObject(); gc.SetCommandPrompt("Select some FANCY curves"); gc.GeometryFilter = ObjectType.Curve; gc.GetMultiple(1, 0); if (gc.CommandResult() != Result.Success) { return(gc.CommandResult()); } int linecount = 0; int arccount = 0; int circlecount = 0; int polylinecount = 0; //create a collection of curves // var curves = new List<Curve>(gc.ObjectCount); OR var curves = new CurveList(); for (var i = 0; i < gc.ObjectCount; i++) { var curve = gc.Object(i).Curve(); if (null != curve) { curves.Add(curve); } // ADD THE CURVE TO THE CURVES LIST, expanding dynamically through the loop LineCurve line_curve = curve as LineCurve; //check if curve is a line, 'as' is simplest form of casting if (line_curve != null) // so long as the selection is not null, the our curve is a line { linecount++; // then we can increase our linecount } PolylineCurve polyline_curve = curve as PolylineCurve; if (polyline_curve != null) { polylinecount++; } ArcCurve arc_curve = curve as ArcCurve; if (arc_curve != null) { if (arc_curve.IsCircle()) { circlecount++; } else { arccount++; } } curve.Domain = new Interval(0, 1); //this will force all curves to have the Domain from 0 to 1 doc.Objects.AddPoint(curve.PointAtStart); doc.Objects.AddPoint(curve.PointAtEnd); doc.Objects.AddPoint(curve.PointAt(0.75)); //add points along the domain... var format = string.Format("F{0}", doc.DistanceDisplayPrecision); string crvinfo = string.Format("The curve {0} has the length {1} and domain: {2} to {3}. Degree {4}. Points at 0,0.75 and 1 of domain.", i, curve.GetLength().ToString(format), curve.Domain.T0.ToString(format), curve.Domain.T1.ToString(format), curve.Degree.ToString(format)); RhinoApp.WriteLine(crvinfo); } doc.Views.Redraw(); string s = string.Format("{0} line(s), {1} polyline(s), {2} circle(s), {3} arc(s) and {4} curve(s) selected in total", linecount.ToString(), polylinecount.ToString(), circlecount.ToString(), arccount.ToString(), curves.Count.ToString()); RhinoApp.WriteLine(s); return(Result.Success); }