Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/MSDIAL5/SpectrumViewer/Model/DisplayScan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using CompMs.CommonMVVM;
using System;
using System.Collections.Generic;
using System.Linq;

namespace CompMs.App.SpectrumViewer.Model
{
Expand Down Expand Up @@ -35,6 +36,7 @@ public bool IsSelected {
public ChromXs ChromXs { get => Scan.ChromXs; set => Scan.ChromXs = value; }
public IonMode IonMode { get => Scan.IonMode; set => Scan.IonMode = value; }
public double PrecursorMz { get => Scan.PrecursorMz; set => Scan.PrecursorMz = value; }
public object[] SpectrumLabel => Scan.Spectrum.Select(p => new { p.Mass, p.Intensity, NeutralLoss = p.Mass - Scan.PrecursorMz }).ToArray();
Copy link

Copilot AI Sep 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This property creates a new array every time it's accessed. Consider caching the result or making it a method to make the performance cost explicit, especially if this property is bound to UI controls that may access it frequently.

Suggested change
public object[] SpectrumLabel => Scan.Spectrum.Select(p => new { p.Mass, p.Intensity, NeutralLoss = p.Mass - Scan.PrecursorMz }).ToArray();
public object[] GetSpectrumLabel() {
return Scan.Spectrum.Select(p => new { p.Mass, p.Intensity, NeutralLoss = p.Mass - Scan.PrecursorMz }).ToArray();
}

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Sep 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using anonymous objects and object[] creates a weakly-typed API that's prone to runtime errors. Consider creating a dedicated class or struct (e.g., SpectrumLabelData) with Mass, Intensity, and NeutralLoss properties for better type safety.

Copilot uses AI. Check for mistakes.

public void AddPeak(double mass, double intensity, string comment = null) {
Scan.AddPeak(mass, intensity, comment);
Expand Down
18 changes: 14 additions & 4 deletions src/MSDIAL5/SpectrumViewer/View/ViewTemplates.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -370,12 +370,13 @@
</ToolTip>
</chart:LineSpectrumControlSlim.ToolTip>
</chart:LineSpectrumControlSlim>
<chart:Annotator ItemsSource="{Binding Spectrum}"
<chart:Annotator ItemsSource="{Binding Path=SpectrumLabel}"
HorizontalPropertyName="Mass"
VerticalPropertyName="Intensity"
Overlap="Direct, Horizontal"
OrderingPropertyName="Intensity"
LabelPropertyName="Mass"
LabelPropertyName="{Binding Path=DataContext.LabelProperty.Value, FallbackValue=Mass,
RelativeSource={RelativeSource AncestorType=ItemsControl}}"
Format="N4"
TopN="10"
Brush="{Binding Path=(ItemsControl.AlternationIndex),
Expand Down Expand Up @@ -438,12 +439,13 @@
</ToolTip>
</chart:LineSpectrumControlSlim.ToolTip>
</chart:LineSpectrumControlSlim>
<chart:Annotator ItemsSource="{Binding Spectrum}"
<chart:Annotator ItemsSource="{Binding Path=SpectrumLabel}"
HorizontalPropertyName="Mass"
VerticalPropertyName="Intensity"
Overlap="Direct, Horizontal"
OrderingPropertyName="Intensity"
LabelPropertyName="Mass"
LabelPropertyName="{Binding Path=DataContext.LabelProperty.Value, FallbackValue=Mass,
RelativeSource={RelativeSource AncestorType=ItemsControl}}"
Format="N4"
TopN="10"
Brush="{Binding Path=(ItemsControl.AlternationIndex),
Expand Down Expand Up @@ -854,6 +856,14 @@
<TextBlock Text="Lower label:" Margin="0,0,4,0" Foreground="White" VerticalAlignment="Center"/>
<CheckBox IsChecked="{Binding LowerSpectrumsViewModel.IsLabelVisible.Value}" VerticalAlignment="Center"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="8,0">
<TextBlock Text="Label type:" Margin="0,0,4,0" Foreground="White" VerticalAlignment="Center"/>
<ComboBox SelectedValuePath="Tag" SelectedIndex="0"
SelectedValue="{Binding Path=LabelProperty.Value, Mode=OneWayToSource}">
<ComboBoxItem Content="m/z" Tag="Mass"/>
<ComboBoxItem Content="NL" Tag="NeutralLoss"/>
</ComboBox>
</StackPanel>
</StackPanel>
<ContentControl Style="{StaticResource ViewChartStyle}"
Content="{Binding}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ IEnumerable<Color> cycle() {
RemoveScanCommand = new ReactiveCommand()
.WithSubscribe(model.RemoveScan)
.AddTo(Disposables);

LabelProperty = new ReactiveProperty<string>(string.Empty).AddTo(Disposables);
}

public SplitSpectrumsModel Model { get; }
Expand Down Expand Up @@ -131,5 +133,7 @@ public void AddScan(IMSScanProperty scan) {
public ReactiveCommand ShiftScanCommand { get; }

public ReactiveCommand RemoveScanCommand { get; }

public ReactiveProperty<string> LabelProperty { get; }
}
}
Loading