private TextObj AddLabel(string text, double x, double y, Color color) { return(new TextObj(text, x, y, CoordType.AxisXYScale, AlignH.Center, AlignV.Bottom) { FontSpec = GraphSummary.CreateFontSpec(color), IsClippedToChartRect = true }); }
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); }
private void AddLabels(Graphics g) { if (_areaCVGraphData == null) { Title.Text = Resources.AreaCVHistogramGraphPane_AddLabels_Calculating____; } else if (!_areaCVGraphData.IsValid) { Title.Text = Resources.AreaCVHistogramGraphPane_AddLabels_Not_enough_data; } else { Title.Text = string.Empty; var unit = _percentage ? @"%" : string.Empty; var factor = _percentage ? 100.0 : 1.0; var scaleFactor = CalcScaleFactor(); var fontHeight = GraphSummary.CreateFontSpec(Color.Black).GetHeight(scaleFactor); var height = PaneHeightToYValue(fontHeight); // Anchor labels at top of graph pane var y = Math.Min(PaneHeightToYValue(Rect.Height - TitleGap * Title.FontSpec.GetHeight(scaleFactor) - fontHeight * _stickItems.Count), _areaCVGraphData.MaxFrequency + height); var index = 0; if (Settings.Default.AreaCVShowMedianCV) { _stickItems[index++].Points[1].Y = y; string text = string.Format(Resources.AreaCVHistogramGraphPane_AddLabels_Median___0_, HistogramHelper.FormatDouble(_areaCVGraphData.MedianCV * factor, _decimals) + unit); GraphObjList.Add(AddLabel(text, _areaCVGraphData.MedianCV * factor, y, Color.Blue)); y += height; } if (Settings.Default.AreaCVShowCVCutoff) { _stickItems[index++].Points[1].Y = y; string text = string.Format(Resources.AreaCVHistogramGraphPane_UpdateGraph_Below__0____1_, Settings.Default.AreaCVCVCutoff + unit, HistogramHelper.FormatDouble(_areaCVGraphData.BelowCVCutoff * factor, _decimals) + unit); GraphObjList.Add(AddLabel(text, Settings.Default.AreaCVCVCutoff, y, Color.Red)); } } }
private static float AddRegressionLabel(PaneBase graphPane, Graphics g, double score, double time, RetentionTimeRegression regression, RetentionTimeStatistics statistics, Color color) { string label; if (regression == null || regression.Conversion == null || statistics == null) { label = String.Format("{0} = ?, {1} = ?\n" + "{2} = ?\n" + "r = ?", // Not L10N Resources.Regression_slope, Resources.Regression_intercept, Resources.GraphData_AddRegressionLabel_window); } else { label = String.Format("{0} = {1:F02}, {2} = {3:F02}\n" + "{4} = {5:F01}\n" + "r = {6}", // Not L10N Resources.Regression_slope, regression.Conversion.Slope, Resources.Regression_intercept, regression.Conversion.Intercept, Resources.GraphData_AddRegressionLabel_window, regression.TimeWindow, Math.Round(statistics.R, RetentionTimeRegression.ThresholdPrecision)); } TextObj text = new TextObj(label, score, time, CoordType.AxisXYScale, AlignH.Left, AlignV.Top) { IsClippedToChartRect = true, ZOrder = ZOrder.E_BehindCurves, FontSpec = GraphSummary.CreateFontSpec(color), }; graphPane.GraphObjList.Add(text); // Measure the text just added, and return its height SizeF sizeLabel = text.FontSpec.MeasureString(g, label, graphPane.CalcScaleFactor()); return(sizeLabel.Height + 3); }
public void AddLabels(GraphPane graphPane, Graphics g) { if (_bins.Length == 0) { graphPane.Title.Text = Resources.MassErrorHistogramGraphPane_AddLabels_Mass_Errors_Unavailable; return; } graphPane.Title.Text = String.Empty; var rectChart = graphPane.Chart.Rect; var ptTop = rectChart.Location; // Setup axes scales to enable the ReverseTransform method var xAxis = graphPane.XAxis; xAxis.Scale.SetupScaleData(graphPane, xAxis); var yAxis = graphPane.YAxis; yAxis.Scale.SetupScaleData(graphPane, yAxis); var yNext = ptTop.Y; var scoreLeft = xAxis.Scale.ReverseTransform(ptTop.X + 8); var timeTop = yAxis.Scale.ReverseTransform(yNext); // ReSharper disable LocalizableElement var label = string.Format("{0} = {1:F01},\n" + "{2} = {3:F01}\n", // ReSharper restore LocalizableElement Resources.MassErrorHistogramGraphPane_AddLabels_mean, _mean, Resources.MassErrorHistogramGraphPane_AddLabels_standard_deviation, _stdDev); var text = new TextObj(label, scoreLeft, timeTop, CoordType.AxisXYScale, AlignH.Left, AlignV.Top) { IsClippedToChartRect = true, ZOrder = ZOrder.E_BehindCurves, FontSpec = GraphSummary.CreateFontSpec(Color.Black) }; graphPane.GraphObjList.Add(text); }
public override void AddAnnotations(MSGraphPane graphPane, Graphics g, MSPointList pointList, GraphObjList annotations) { // ReSharper disable UseObjectOrCollectionInitializer foreach (var rmi in SpectrumInfo.PeaksMatched) { if (!IsVisibleIon(rmi)) { continue; } var matchedIon = rmi.MatchedIons.First(IsVisibleIon); Color color; switch (matchedIon.IonType) { default: color = COLOR_NONE; break; case IonType.a: color = COLOR_A; break; case IonType.x: color = COLOR_X; break; case IonType.b: color = COLOR_B; break; case IonType.y: color = COLOR_Y; break; case IonType.c: color = COLOR_C; break; case IonType.z: color = COLOR_Z; break; case IonType.custom: color = (rmi.Rank > 0) ? COLOR_OTHER_IONS : COLOR_NONE; break; // Small molecule fragments - only color if ranked case IonType.precursor: color = COLOR_PRECURSOR; break; } if (Invert) { color = InvertColor(color); } if (rmi.MatchedIons.Any(mfi => IsMatch(mfi.PredictedMz))) { color = COLOR_SELECTED; } double mz = rmi.ObservedMz; var intensity = Invert ? -rmi.Intensity : rmi.Intensity; var stick = new LineObj(color, mz, intensity, mz, 0); stick.IsClippedToChartRect = true; stick.Location.CoordinateFrame = CoordType.AxisXYScale; stick.Line.Width = LineWidth + 1; annotations.Add(stick); } //ReSharper restore UseObjectOrCollectionInitializer if (ShowScores && SpectrumInfo.Score.HasValue) { var text = new TextObj( string.Format(LocalizationHelper.CurrentCulture, Resources.AbstractSpectrumGraphItem_AddAnnotations_, SpectrumInfo.Score), 0.01, 0, CoordType.ChartFraction, AlignH.Left, AlignV.Top) { IsClippedToChartRect = true, ZOrder = ZOrder.E_BehindCurves, FontSpec = GraphSummary.CreateFontSpec(Color.Black), }; annotations.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); 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) { 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), }); } }