public void UpdateUI(bool selectionChanged = true) { // Only worry about updates, if the graph is visible // And make sure it is not disposed, since rendering happens on a timer if (!Visible || IsDisposed || _msDataFileScanHelper.ScanProvider == null) { return; } GraphHelper.FormatGraphPane(graphControl.GraphPane); if (_msDataFileScanHelper.MsDataSpectra != null) { leftButton.Enabled = (_msDataFileScanHelper.ScanIndex > 0); rightButton.Enabled = (_msDataFileScanHelper.ScanIndex < _msDataFileScanHelper.ScanProvider.Times.Count - 1); lblScanId.Text = _msDataFileScanHelper.GetScanIndex().ToString(@"D"); if (!spectrumBtn.Checked) { GraphPane.SetScale(CreateGraphics()); } } else { leftButton.Enabled = rightButton.Enabled = false; lblScanId.Text = string.Empty; } graphControl.Refresh(); }
/// <summary> /// Create stick graph of a single scan. /// </summary> private void CreateSingleScan() { GraphPane.YAxis.Title.Text = Resources.AbstractMSGraphItem_CustomizeYAxis_Intensity; graphControl.IsEnableVZoom = graphControl.IsEnableVPan = false; // Create a point list for each transition, and a default point list for points not // associated with a transition. var pointLists = new PointPairList[_msDataFileScanHelper.ScanProvider.Transitions.Length]; for (int i = 0; i < pointLists.Length; i++) pointLists[i] = new PointPairList(); var defaultPointList = new PointPairList(); var allPointList = new PointPairList(); // Assign each point to a transition point list, or else the default point list. IList<double> mzs; IList<double> intensities; bool negativeScan; if (_msDataFileScanHelper.MsDataSpectra.Length == 1) { mzs = _msDataFileScanHelper.MsDataSpectra[0].Mzs; intensities = _msDataFileScanHelper.MsDataSpectra[0].Intensities; negativeScan = _msDataFileScanHelper.MsDataSpectra[0].NegativeCharge; } else { // Ion mobility being shown as 2-D spectrum mzs = new List<double>(); intensities = new List<double>(); var fullScans = _msDataFileScanHelper.GetFilteredScans(); negativeScan = fullScans.Any() && fullScans.First().NegativeCharge; double minMz; var indices = new int[fullScans.Length]; while ((minMz = FindMinMz(fullScans, indices)) < double.MaxValue) { mzs.Add(minMz); intensities.Add(SumIntensities(fullScans, minMz, indices)); } } for (int i = 0; i < mzs.Count; i++) { double mz = mzs[i]; double intensity = intensities[i]; allPointList.Add(mz, intensity); var assignedPointList = defaultPointList; for (int j = 0; j < _msDataFileScanHelper.ScanProvider.Transitions.Length; j++) { var transition = _msDataFileScanHelper.ScanProvider.Transitions[j]; // Polarity should match, because these are the spectra used for extraction Assume.IsTrue(transition.PrecursorMz.IsNegative == negativeScan); if (transition.Source != _msDataFileScanHelper.Source || mz <= transition.ProductMz.Value - transition.ExtractionWidth/2 || mz > transition.ProductMz.Value + transition.ExtractionWidth/2) continue; assignedPointList = pointLists[j]; break; } assignedPointList.Add(mz, intensity); } // Create a graph item for each point list with its own color. for (int i = 0; i < pointLists.Length; i++) { var transition = _msDataFileScanHelper.ScanProvider.Transitions[i]; if (transition.Source != _msDataFileScanHelper.Source) continue; var item = new SpectrumItem(pointLists[i], transition.Color, 2); var curveItem = _graphHelper.GraphControl.AddGraphItem(GraphPane, item, false); curveItem.Label.IsVisible = false; } // Add points that aren't associated with a transition. { var item = new SpectrumItem(defaultPointList, Color.Gray); var curveItem = _graphHelper.GraphControl.AddGraphItem(GraphPane, item, false); curveItem.Label.IsVisible = false; } // Create curve for all points to provide shading behind stick graph. if (_msDataFileScanHelper.MsDataSpectra.Length > 0 && !_msDataFileScanHelper.MsDataSpectra[0].Centroided) { var item = new SpectrumShadeItem(allPointList, Color.FromArgb(100, 225, 225, 150)); var curveItem = _graphHelper.GraphControl.AddGraphItem(GraphPane, item, false); curveItem.Label.IsVisible = false; } GraphPane.SetScale(CreateGraphics()); }