Skip to content
Merged
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
31 changes: 28 additions & 3 deletions src/Common/ChartDrawing/Chart/LineSpectrumControlSlim.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ private static void OnLineBrushPropertyChanged(DependencyObject d, DependencyPro

[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "<Pending>")]
private void OnLineBrushPropertyChanged(IBrushMapper oldValue, IBrushMapper newValue) {
Selector.Update(newValue, LineThickness);
Selector.Update(newValue, LineThickness, StrokeDashArray);
}

public static readonly DependencyProperty HuePropertyProperty =
Expand Down Expand Up @@ -310,15 +310,40 @@ private static void OnLineThicknessChanged(DependencyObject d, DependencyPropert

[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "<Pending>")]
private void OnLineThicknessChanged(double oldValue, double newValue) {
Selector.Update(LineBrush, newValue);
Selector.Update(LineBrush, newValue, StrokeDashArray);
}

public static readonly DependencyProperty StrokeDashArrayProperty =
DependencyProperty.Register(
nameof(StrokeDashArray),
typeof(DoubleCollection),
typeof(LineSpectrumControlSlim),
new FrameworkPropertyMetadata(
null,
FrameworkPropertyMetadataOptions.AffectsRender,
OnStrokeDashArrayChanged));

public DoubleCollection StrokeDashArray {
get => (DoubleCollection)GetValue(StrokeDashArrayProperty);
set => SetValue(StrokeDashArrayProperty, value);
}

private static void OnStrokeDashArrayChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) {
var c = (LineSpectrumControlSlim)d;
c.OnStrokeDashArrayChanged((DoubleCollection)e.OldValue, (DoubleCollection)e.NewValue);
}

[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "<Pending>")]
private void OnStrokeDashArrayChanged(DoubleCollection oldValue, DoubleCollection newValue) {
Selector.Update(LineBrush, LineThickness, newValue);
Comment on lines +326 to +338
}

private PenSelector Selector {
get {
if (selector is null) {
selector = new PenSelector();
if (!(LineBrush is null)) {
selector.Update(LineBrush, LineThickness);
selector.Update(LineBrush, LineThickness, StrokeDashArray);
}
}
return selector;
Expand Down
14 changes: 12 additions & 2 deletions src/Common/ChartDrawing/Design/PenSelector.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using System.Windows.Media;
using CompMs.Graphics.Base;

Expand Down Expand Up @@ -31,11 +32,15 @@ public void Update(Pen pen) {
}

public void Update(IBrushMapper mapper, double thickness) {
Update(mapper, thickness, null);
}

public void Update(IBrushMapper mapper, double thickness, DoubleCollection strokeDashArray) {
if (mapper is null) {
Reset();
}
else {
strategy = new BrushMapStrategy(mapper, thickness);
strategy = new BrushMapStrategy(mapper, thickness, strokeDashArray);
}
}

Expand All @@ -62,13 +67,15 @@ public Pen Get(object o) {

class BrushMapStrategy : ISelectStrategy
{
public BrushMapStrategy(IBrushMapper mapper, double thickness) {
public BrushMapStrategy(IBrushMapper mapper, double thickness, DoubleCollection strokeDashArray) {
Mapper = mapper;
Thickness = thickness;
StrokeDashArray = strokeDashArray?.ToArray();
}

private readonly IBrushMapper Mapper;
private readonly double Thickness;
private readonly double[] StrokeDashArray;
private readonly Dictionary<object, Pen> cache = new Dictionary<object, Pen>();
Comment on lines 34 to 79

public Pen Get(object o) {
Expand All @@ -77,6 +84,9 @@ public Pen Get(object o) {
}
var brush = Mapper.Map(o);
var pen = new Pen(brush, Thickness);
if (StrokeDashArray is { Length: > 0 }) {
pen.DashStyle = new DashStyle(new DoubleCollection(StrokeDashArray), 0d);
}
pen.Freeze();
if (cache.Count > 1_000_000) {
cache.Clear();
Expand Down
25 changes: 24 additions & 1 deletion src/MSDIAL5/MsdialGuiApp/Model/Chart/RawDecSpectrumsModel.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using CompMs.App.Msdial.Model.Loader;
using CompMs.Common.Algorithm.Scoring;
using CompMs.CommonMVVM;
using CompMs.Graphics.Design;
using Reactive.Bindings;
using Reactive.Bindings.Extensions;
using System;
using System.Windows.Media;

namespace CompMs.App.Msdial.Model.Chart
{
Expand Down Expand Up @@ -37,17 +40,37 @@ public RawDecSpectrumsModel(SingleSpectrumModel rawSpectrumModel, SingleSpectrum
HorizontalTitle = "m/z",
VerticalTitle = "Relative abundance",
}.AddTo(Disposables);

IsRawSpectrumOverlayVisible = new ReactivePropertySlim<bool>(true).AddTo(Disposables);


var decRawOverlaySpectrumModel = rawSpectrumModel.Clone().AddTo(Disposables);
decRawOverlaySpectrumModel.IsVisible.Value = false;
decRawOverlaySpectrumModel.IsAnnotationVisible.Value = false;
decRawOverlaySpectrumModel.LineThickness.Value = 1d;
decRawOverlaySpectrumModel.StrokeDashArray.Value = new DoubleCollection { 3d, 3d };
decRawOverlaySpectrumModel.Brush = new ConstantBrushMapper<object>(Brushes.DarkGray);

DecRefSpectrumModels = new MsSpectrumModel(decSpectrumModel, referenceSpectrumModel, ms2ScanMatching)
{
GraphTitle = "Deconvolution vs. Reference",
HorizontalTitle = "m/z",
VerticalTitle = "Relative abundacne",
VerticalTitle = "Relative abundance",
}.AddTo(Disposables);
DecRefSpectrumModels.UpperSpectraModel.Insert(0, decRawOverlaySpectrumModel);

IsRawSpectrumOverlayVisible
.Subscribe(isVisible => {
decRawOverlaySpectrumModel.IsVisible.Value = isVisible;
})
.AddTo(Disposables);

RawLoader = loader;
}

public MsSpectrumModel RawRefSpectrumModels { get; }
public MsSpectrumModel DecRefSpectrumModels { get; }
public ReactivePropertySlim<bool> IsRawSpectrumOverlayVisible { get; }
public MultiMsmsRawSpectrumLoader? RawLoader { get; }
}
}
12 changes: 11 additions & 1 deletion src/MSDIAL5/MsdialGuiApp/Model/Chart/SingleSpectrumModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.IO;
using System.Linq;
using System.Reactive.Linq;
using System.Windows.Media;

namespace CompMs.App.Msdial.Model.Chart
{
Expand All @@ -24,10 +25,13 @@ public SingleSpectrumModel(ObservableMsSpectrum observableMsSpectrum, AxisProper
HorizontalProperty = HorizontalPropertySelectors.GetSelector(typeof(SpectrumPeak))?.Property ?? throw new Exception("Valid PropertySelector is not found.");
VerticalProperty = VerticalPropertySelectors.GetSelector(typeof(SpectrumPeak))?.Property ?? throw new Exception("Valid PropertySelector is not found.");
_hueItem = hueItem;
Brush = hueItem.Brush;
Labels = graphLabels;

IsVisible = new ReactivePropertySlim<bool>(true).AddTo(Disposables);
IsAnnotationVisible = new ReactivePropertySlim<bool>(true).AddTo(Disposables);
LineThickness = new ReactivePropertySlim<double>(2d).AddTo(Disposables);
StrokeDashArray = new ReactivePropertySlim<DoubleCollection?>(null).AddTo(Disposables);
}

public IObservable<MsSpectrum?> MsSpectrum => _observableMsSpectrum.MsSpectrum;
Expand All @@ -38,12 +42,14 @@ public SingleSpectrumModel(ObservableMsSpectrum observableMsSpectrum, AxisProper
public IObservable<IAxisManager<double>> VerticalAxis => VerticalPropertySelectors.AxisItemSelector.GetAxisItemAsObservable().SkipNull().Select(item => item.AxisManager);
public AxisItemSelector<double> VerticalAxisItemSelector => VerticalPropertySelectors.AxisItemSelector;
public string VerticalProperty { get; }
public IBrushMapper Brush => _hueItem.Brush;
public IBrushMapper Brush { get; set; }
public string HueProperty => _hueItem.Property;
public GraphLabels Labels { get; }
public ReadOnlyReactivePropertySlim<bool> SpectrumLoaded => _observableMsSpectrum.Loaded;
public ReactivePropertySlim<bool> IsVisible { get; }
public ReactivePropertySlim<bool> IsAnnotationVisible { get; }
public ReactivePropertySlim<double> LineThickness { get; }
public ReactivePropertySlim<DoubleCollection?> StrokeDashArray { get; }

public IObservable<bool> CanSave => _observableMsSpectrum.CanSave;

Expand Down Expand Up @@ -81,5 +87,9 @@ private SingleSpectrumModel CreateFromMsSpectrum(ObservableMsSpectrum msSpectrum
spectrumModel.Disposables.Add(msSpectrum);
return spectrumModel;
}

public SingleSpectrumModel Clone() {
return new SingleSpectrumModel(_observableMsSpectrum, HorizontalPropertySelectors, VerticalPropertySelectors, _hueItem, Labels);
}
}
}
6 changes: 6 additions & 0 deletions src/MSDIAL5/MsdialGuiApp/View/Chart/ExpRefView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@
ToolTip="Show deconvoluted spectra vs. reference spectra"
Style="{StaticResource IconRadioButton}"/>

<CheckBox VerticalAlignment="Center"
Margin="8,0,0,0"
Content="Raw (dashed)"
ToolTip="Overlay raw spectrum as dashed line on Q1Dec/Deconvolution views"
IsChecked="{Binding RawDecSpectrumsViewModel.IsRawSpectrumOverlayVisible.Value, Mode=TwoWay}"/>

<Button Name="Button_CompoundSearchPeakViewer"
Command="{Binding SearchCompoundCommand, Mode=OneTime}"
Content="/Resources/CompoundSearchIcon.ico"
Expand Down
5 changes: 4 additions & 1 deletion src/MSDIAL5/MsdialGuiApp/View/Chart/MsSpectrumView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
VerticalProperty="{Binding VerticalProperty}"
LineBrush="{Binding Brush.Value}"
LineThickness="{Binding LineThickness.Value}"
StrokeDashArray="{Binding StrokeDashArray.Value}"
HueProperty="SpectrumComment">
<chart:LineSpectrumControlSlim.ToolTip>
<ToolTip DataContext="{Binding PlacementTarget, RelativeSource={RelativeSource Self}}"
Expand All @@ -162,7 +163,8 @@
Brush="Black"
Overlap="Horizontal, Direct"
Format="F4"
ClipToBounds="True"/>
ClipToBounds="True"
Visibility="{Binding IsAnnotationVisible.Value, Converter={StaticResource BooleanToVisibility}}"/>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
Expand Down Expand Up @@ -190,6 +192,7 @@
HorizontalProperty="{Binding HorizontalProperty}"
VerticalProperty="{Binding VerticalProperty}"
LineBrush="{Binding Brush.Value}"
StrokeDashArray="{Binding StrokeDashArray.Value}"
HueProperty="SpectrumComment">
<chart:LineSpectrumControlSlim.ToolTip>
<ToolTip DataContext="{Binding PlacementTarget, RelativeSource={RelativeSource Self}}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public RawDecSpectrumsViewModel(RawDecSpectrumsModel model, Action focusAction,

public MsSpectrumViewModel RawRefSpectrumViewModels { get; }
public MsSpectrumViewModel DecRefSpectrumViewModels { get; }
public ReactivePropertySlim<bool> IsRawSpectrumOverlayVisible => _model.IsRawSpectrumOverlayVisible;

public ReadOnlyReactivePropertySlim<List<MsSelectionItem>> Ms2IdList { get; }
public ReactivePropertySlim<MsSelectionItem?> SelectedMs2Id { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.IO;
using System.Linq;
using System.Reactive.Linq;
using System.Windows.Media;

namespace CompMs.App.Msdial.ViewModel.Chart
{
Expand All @@ -26,7 +27,9 @@ public SingleSpectrumViewModel(SingleSpectrumModel model, IMessageBroker? broker
VerticalAxis = model.VerticalAxis.Cast<IAxisManager>().ToReadOnlyReactivePropertySlim().AddTo(Disposables);
Brush = Observable.Return(model.Brush).ToReadOnlyReactivePropertySlim<IBrushMapper>().AddTo(Disposables);
LineThickness = model.LineThickness;
StrokeDashArray = model.StrokeDashArray;
IsVisible = model.IsVisible;
IsAnnotationVisible = model.IsAnnotationVisible;
SelectedVerticalAxisItem = model.VerticalAxisItemSelector.GetAxisItemAsObservable().SkipNull().ToReadOnlyReactivePropertySlim().AddTo(Disposables);
if (broker is not null) {
SaveCommand = model.CanSave.ToReactiveCommand().WithSubscribe(SaveSpectrum(model.Save, filter: "NIST format(*.msp)|*.msp", broker)).AddTo(Disposables);
Expand All @@ -46,7 +49,9 @@ public SingleSpectrumViewModel(SingleSpectrumModel model, IMessageBroker? broker
public string HueProperty => _model.HueProperty;
public ReadOnlyReactivePropertySlim<bool> SpectrumLoaded => _model.SpectrumLoaded;
public ReactivePropertySlim<double> LineThickness { get; }
public ReactivePropertySlim<DoubleCollection?> StrokeDashArray { get; }
public ReactivePropertySlim<bool> IsVisible { get; }
public ReactivePropertySlim<bool> IsAnnotationVisible { get; }
public ReactiveCommand? SaveCommand { get; }

private Action SaveSpectrum(Action<Stream> handler, string filter, IMessageBroker broker) {
Expand Down
Loading