Loading INAF.Apps.Uwp.SLabDataManager/App.xaml.cs +4 −4 Original line number Diff line number Diff line Loading @@ -107,14 +107,15 @@ namespace INAF.Apps.Uwp.SLabDataManager Ioc.Default.ConfigureServices( new ServiceCollection() /* singletons */ .AddSingleton<ChartAnnotationsHelper>() .AddSingleton<CustomLinesAnnotationsRepository>() .AddSingleton<SelectedRefBand>() .AddSingleton<SpectrumAlignmentConfigModel>() .AddSingleton<SpectrumChartOptionsModel>() .AddSingleton<Logger>(logger) .AddSingleton<RecentFilesHelper>() .AddSingleton<RemoteOperationsRepository>() .AddSingleton<SelectedRefBand>() .AddSingleton<SettingsHelper>() .AddSingleton<SpectrumAlignmentConfigModel>() .AddSingleton<SpectrumChartOptionsModel>() .AddSingleton<SpectraContainer>() .AddSingleton<StorageItemsSettingsHelper>() .AddSingleton<StorageItemsAccessHelper>() Loading @@ -123,7 +124,6 @@ namespace INAF.Apps.Uwp.SLabDataManager .AddSingleton<WorkingItemsModel>() /* transient */ .AddTransient<AuthenticationManager>() .AddTransient<ChartAnnotationsHelper>() .AddTransient<ConfigReader>() .AddTransient<RemoteOperationsHelper>() .AddTransient<RemoteOperationsManager>() Loading INAF.Apps.Uwp.SLabDataManager/Charts/SpectraContainer.cs +23 −13 Original line number Diff line number Diff line Loading @@ -212,17 +212,16 @@ namespace INAF.Apps.Uwp.SLabDataManager.Charts /* if a spectrum of same type is already present, then replace it... */ int index = Spectra.ToList().FindIndex(x => x.Type == spectrum.Type); if (index >= 0) { Spectra[index] = spectrum; await updateBoundariesAsync(); } } else { /* ...otherwise, add it... */ addSpectrum(spectrum); if (Spectra.Count == 1) await setBoundariesAsync(); } else await updateBoundariesAsync(); spectrum.PropertyChanged += Spectrum_PropertyChanged; } Loading Loading @@ -313,23 +312,34 @@ namespace INAF.Apps.Uwp.SLabDataManager.Charts { List<double> xvalues = new List<double>(); foreach (var spectrum in spectra) { if (spectrum.IsVisible) xvalues.AddRange(spectrum.Elements.Select(x => x.X)); } if (xvalues.Count > 0) { (double xMin, double xMax) xresult = xvalues.GetBoundaries(); xMin = xresult.xMin; xMax = xresult.xMax; } })); tasks.Add(Task.Run(() => { List<double> yvalues = new List<double>(); foreach (var spectrum in spectra) { if (spectrum.IsVisible) yvalues.AddRange(spectrum.Elements.Select(x => x.Y)); } //(double yMin, double yMax) yresult = yvalues.GetBoundaries(); //yMin = yresult.yMin; //yMax = yresult.yMax; if (yvalues.Count > 0) { yMin = yvalues.Min() * 0.9; yMax = yvalues.Max() * 1.1; } })); await Task.WhenAll(tasks); Loading INAF.Apps.Uwp.SLabDataManager/Helpers/UI/Chart/ChartAnnotationsHelper.cs +47 −24 Original line number Diff line number Diff line using INAF.Apps.Uwp.SLabDataManager.Extensions; using INAF.Apps.Uwp.SLabDataManager.Charts; using INAF.Apps.Uwp.SLabDataManager.Extensions; using INAF.Apps.Uwp.SLabDataManager.Models; using INAF.Libraries.NetStandard.ScienceModels.Extensions; using INAF.Libraries.NetStandard.ScienceModels.Lines; using INAF.Libraries.Uwp.Logging; using System; Loading @@ -14,12 +17,15 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart public sealed class ChartAnnotationsHelper { private readonly CustomLinesAnnotationsRepository customAnnotationsRepository; private readonly WorkingItemsModel workingItems; private readonly Logger logger; public ChartAnnotationsHelper(CustomLinesAnnotationsRepository customAnnotationsRepository, WorkingItemsModel workingItems, Logger logger) { this.customAnnotationsRepository = customAnnotationsRepository; this.workingItems = workingItems; this.logger = logger; } Loading @@ -29,9 +35,21 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart { System.Diagnostics.Debug.WriteLine($"mousePosition: {mousePosition.X}, {mousePosition.Y}"); try { var point = chart.ConvertPointToData(mousePosition); System.Diagnostics.Debug.WriteLine($"point: {point.Item1}, {point.Item2}"); /* recover tapped-point y-value on spectrum */ /* find mouse position boundaris on spectrum */ var spectrum = workingItems.SpectraContainer.tryGetSpectrumOfType(Libraries.NetStandard.SLabCommonModels.Enums.Enums.SpectrumType.Raw); var lowerBoundary = spectrum.Elements.Where(x => x.X <= (double)point.Item1).LastOrDefault().ToPointModel(); var higherBoundary = spectrum.Elements.Where(x => x.X >= (double)point.Item1).FirstOrDefault().ToPointModel(); /* create line with recovered points */ var line = new StraightLineModel(lowerBoundary, higherBoundary); /* calculate y on spectrum */ var yOnSpectrum = line.calculateY((double)point.Item1); /* if a point in selected position already exists, then remove it... */ var existantItem = chart.Annotations.FirstOrDefault(x => x is CartesianCustomAnnotation && (Convert.ToDouble((x as CartesianCustomAnnotation).HorizontalValue) >= ((double)point.Item1 - 12d)) && Loading @@ -44,9 +62,9 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart CartesianCustomAnnotation customAnnotation = new CartesianCustomAnnotation() { HorizontalValue = point.Item1, HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Center, VerticalValue = point.Item2, VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center, VerticalValue = yOnSpectrum, VerticalAlignment = VerticalAlignment.Center, ContentTemplate = tappedPointTemplate, }; Loading @@ -59,6 +77,11 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart /* try to create lines connecting selected points */ tryCreateLines(chart); } catch (Exception ex) { logger.Write<ChartAnnotationsHelper>($"{nameof(addOrRemoveTappedPointForContinuum)} - ex: {ex.Message}", Serilog.Events.LogEventLevel.Error); } } private void tryCreateLines(RadCartesianChart chart) { Loading INAF.Apps.Uwp.SLabDataManager/Models/Spectrum/SpectrumModelExtensions.cs +7 −1 Original line number Diff line number Diff line Loading @@ -15,7 +15,9 @@ namespace INAF.Apps.Uwp.SLabDataManager.Models.Spectrum private SettingsHelper settingsHelper; public SpectrumModel(SpectrumType spectrumType) : base(spectrumType) { } { IsVisible = true; } public SpectrumModel(IServiceProvider serviceProvider, Enums.SpectrumType spectrumType, Loading @@ -23,6 +25,8 @@ namespace INAF.Apps.Uwp.SLabDataManager.Models.Spectrum { this.serviceProvider = serviceProvider; settingsHelper = serviceProvider.GetRequiredService<SettingsHelper>(); IsVisible = true; } private SolidColorBrush color; Loading @@ -39,6 +43,8 @@ namespace INAF.Apps.Uwp.SLabDataManager.Models.Spectrum set { isSavedOnCloud = value; RaisePropertyChanged(nameof(IsSavedOnCloud)); } } public bool IsVisible { get; set; } public IServiceProvider serviceProvider { get; private set; } public void setColor(SolidColorBrush color = null) Loading INAF.Apps.Uwp.SLabDataManager/Views/ChartPage.xaml.cs +17 −6 Original line number Diff line number Diff line Loading @@ -362,12 +362,15 @@ namespace INAF.Apps.Uwp.SLabDataManager.Views chartLegend.UpdateLayout(); } private void legendItem_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e) private async void legendItem_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e) { if (!(e.OriginalSource is TextBlock)) return; var titleFromLegendItem = string.Empty; if (e.OriginalSource is TextBlock) titleFromLegendItem = (e.OriginalSource as TextBlock).Text; else if (e.OriginalSource is Ellipse) titleFromLegendItem = (((e.OriginalSource) as Ellipse).DataContext as LegendItem).Title; var titleFromLegendItem = (e.OriginalSource as TextBlock).Text; if (string.IsNullOrEmpty(titleFromLegendItem)) return; Loading @@ -381,13 +384,18 @@ namespace INAF.Apps.Uwp.SLabDataManager.Views { case Visibility.Visible: selectedSeries.Visibility = Visibility.Collapsed; ((selectedSeries.DataContext) as SpectrumModel).IsVisible = false; (sender as StackPanel).Opacity = 0.5; break; case Visibility.Collapsed: selectedSeries.Visibility = Visibility.Visible; ((selectedSeries.DataContext) as SpectrumModel).IsVisible = true; (sender as StackPanel).Opacity = 1; break; } /* refresh boundaries to match only visible spectra */ await ViewModel.WorkingItems.SpectraContainer.updateBoundariesAsync(); } private void chartLegendInfoButton_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e) Loading Loading @@ -423,7 +431,7 @@ namespace INAF.Apps.Uwp.SLabDataManager.Views #endregion #region annotations #region vertical separator annotations #region vertical separator annota.tions private void spectrumChart_Loaded(object sender, RoutedEventArgs e) { createCartesianGridLineAnnotations(sender as RadCartesianChart); Loading @@ -447,7 +455,10 @@ namespace INAF.Apps.Uwp.SLabDataManager.Views var chart = (RadCartesianChart)sender; var mousePosition = e.GetPosition(chart); chartAnnotationsHelper.addOrRemoveTappedPointForContinuum(chart, mousePosition, tappedPointTemplate); chartAnnotationsHelper.addOrRemoveTappedPointForContinuum(chart, mousePosition, tappedPointTemplate); if (customLinesAnnotationsRepository.isAnyLineAvailable()) ViewModel.trySetIsContinuumRemovalEnabled(); } Loading Loading
INAF.Apps.Uwp.SLabDataManager/App.xaml.cs +4 −4 Original line number Diff line number Diff line Loading @@ -107,14 +107,15 @@ namespace INAF.Apps.Uwp.SLabDataManager Ioc.Default.ConfigureServices( new ServiceCollection() /* singletons */ .AddSingleton<ChartAnnotationsHelper>() .AddSingleton<CustomLinesAnnotationsRepository>() .AddSingleton<SelectedRefBand>() .AddSingleton<SpectrumAlignmentConfigModel>() .AddSingleton<SpectrumChartOptionsModel>() .AddSingleton<Logger>(logger) .AddSingleton<RecentFilesHelper>() .AddSingleton<RemoteOperationsRepository>() .AddSingleton<SelectedRefBand>() .AddSingleton<SettingsHelper>() .AddSingleton<SpectrumAlignmentConfigModel>() .AddSingleton<SpectrumChartOptionsModel>() .AddSingleton<SpectraContainer>() .AddSingleton<StorageItemsSettingsHelper>() .AddSingleton<StorageItemsAccessHelper>() Loading @@ -123,7 +124,6 @@ namespace INAF.Apps.Uwp.SLabDataManager .AddSingleton<WorkingItemsModel>() /* transient */ .AddTransient<AuthenticationManager>() .AddTransient<ChartAnnotationsHelper>() .AddTransient<ConfigReader>() .AddTransient<RemoteOperationsHelper>() .AddTransient<RemoteOperationsManager>() Loading
INAF.Apps.Uwp.SLabDataManager/Charts/SpectraContainer.cs +23 −13 Original line number Diff line number Diff line Loading @@ -212,17 +212,16 @@ namespace INAF.Apps.Uwp.SLabDataManager.Charts /* if a spectrum of same type is already present, then replace it... */ int index = Spectra.ToList().FindIndex(x => x.Type == spectrum.Type); if (index >= 0) { Spectra[index] = spectrum; await updateBoundariesAsync(); } } else { /* ...otherwise, add it... */ addSpectrum(spectrum); if (Spectra.Count == 1) await setBoundariesAsync(); } else await updateBoundariesAsync(); spectrum.PropertyChanged += Spectrum_PropertyChanged; } Loading Loading @@ -313,23 +312,34 @@ namespace INAF.Apps.Uwp.SLabDataManager.Charts { List<double> xvalues = new List<double>(); foreach (var spectrum in spectra) { if (spectrum.IsVisible) xvalues.AddRange(spectrum.Elements.Select(x => x.X)); } if (xvalues.Count > 0) { (double xMin, double xMax) xresult = xvalues.GetBoundaries(); xMin = xresult.xMin; xMax = xresult.xMax; } })); tasks.Add(Task.Run(() => { List<double> yvalues = new List<double>(); foreach (var spectrum in spectra) { if (spectrum.IsVisible) yvalues.AddRange(spectrum.Elements.Select(x => x.Y)); } //(double yMin, double yMax) yresult = yvalues.GetBoundaries(); //yMin = yresult.yMin; //yMax = yresult.yMax; if (yvalues.Count > 0) { yMin = yvalues.Min() * 0.9; yMax = yvalues.Max() * 1.1; } })); await Task.WhenAll(tasks); Loading
INAF.Apps.Uwp.SLabDataManager/Helpers/UI/Chart/ChartAnnotationsHelper.cs +47 −24 Original line number Diff line number Diff line using INAF.Apps.Uwp.SLabDataManager.Extensions; using INAF.Apps.Uwp.SLabDataManager.Charts; using INAF.Apps.Uwp.SLabDataManager.Extensions; using INAF.Apps.Uwp.SLabDataManager.Models; using INAF.Libraries.NetStandard.ScienceModels.Extensions; using INAF.Libraries.NetStandard.ScienceModels.Lines; using INAF.Libraries.Uwp.Logging; using System; Loading @@ -14,12 +17,15 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart public sealed class ChartAnnotationsHelper { private readonly CustomLinesAnnotationsRepository customAnnotationsRepository; private readonly WorkingItemsModel workingItems; private readonly Logger logger; public ChartAnnotationsHelper(CustomLinesAnnotationsRepository customAnnotationsRepository, WorkingItemsModel workingItems, Logger logger) { this.customAnnotationsRepository = customAnnotationsRepository; this.workingItems = workingItems; this.logger = logger; } Loading @@ -29,9 +35,21 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart { System.Diagnostics.Debug.WriteLine($"mousePosition: {mousePosition.X}, {mousePosition.Y}"); try { var point = chart.ConvertPointToData(mousePosition); System.Diagnostics.Debug.WriteLine($"point: {point.Item1}, {point.Item2}"); /* recover tapped-point y-value on spectrum */ /* find mouse position boundaris on spectrum */ var spectrum = workingItems.SpectraContainer.tryGetSpectrumOfType(Libraries.NetStandard.SLabCommonModels.Enums.Enums.SpectrumType.Raw); var lowerBoundary = spectrum.Elements.Where(x => x.X <= (double)point.Item1).LastOrDefault().ToPointModel(); var higherBoundary = spectrum.Elements.Where(x => x.X >= (double)point.Item1).FirstOrDefault().ToPointModel(); /* create line with recovered points */ var line = new StraightLineModel(lowerBoundary, higherBoundary); /* calculate y on spectrum */ var yOnSpectrum = line.calculateY((double)point.Item1); /* if a point in selected position already exists, then remove it... */ var existantItem = chart.Annotations.FirstOrDefault(x => x is CartesianCustomAnnotation && (Convert.ToDouble((x as CartesianCustomAnnotation).HorizontalValue) >= ((double)point.Item1 - 12d)) && Loading @@ -44,9 +62,9 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart CartesianCustomAnnotation customAnnotation = new CartesianCustomAnnotation() { HorizontalValue = point.Item1, HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Center, VerticalValue = point.Item2, VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center, VerticalValue = yOnSpectrum, VerticalAlignment = VerticalAlignment.Center, ContentTemplate = tappedPointTemplate, }; Loading @@ -59,6 +77,11 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart /* try to create lines connecting selected points */ tryCreateLines(chart); } catch (Exception ex) { logger.Write<ChartAnnotationsHelper>($"{nameof(addOrRemoveTappedPointForContinuum)} - ex: {ex.Message}", Serilog.Events.LogEventLevel.Error); } } private void tryCreateLines(RadCartesianChart chart) { Loading
INAF.Apps.Uwp.SLabDataManager/Models/Spectrum/SpectrumModelExtensions.cs +7 −1 Original line number Diff line number Diff line Loading @@ -15,7 +15,9 @@ namespace INAF.Apps.Uwp.SLabDataManager.Models.Spectrum private SettingsHelper settingsHelper; public SpectrumModel(SpectrumType spectrumType) : base(spectrumType) { } { IsVisible = true; } public SpectrumModel(IServiceProvider serviceProvider, Enums.SpectrumType spectrumType, Loading @@ -23,6 +25,8 @@ namespace INAF.Apps.Uwp.SLabDataManager.Models.Spectrum { this.serviceProvider = serviceProvider; settingsHelper = serviceProvider.GetRequiredService<SettingsHelper>(); IsVisible = true; } private SolidColorBrush color; Loading @@ -39,6 +43,8 @@ namespace INAF.Apps.Uwp.SLabDataManager.Models.Spectrum set { isSavedOnCloud = value; RaisePropertyChanged(nameof(IsSavedOnCloud)); } } public bool IsVisible { get; set; } public IServiceProvider serviceProvider { get; private set; } public void setColor(SolidColorBrush color = null) Loading
INAF.Apps.Uwp.SLabDataManager/Views/ChartPage.xaml.cs +17 −6 Original line number Diff line number Diff line Loading @@ -362,12 +362,15 @@ namespace INAF.Apps.Uwp.SLabDataManager.Views chartLegend.UpdateLayout(); } private void legendItem_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e) private async void legendItem_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e) { if (!(e.OriginalSource is TextBlock)) return; var titleFromLegendItem = string.Empty; if (e.OriginalSource is TextBlock) titleFromLegendItem = (e.OriginalSource as TextBlock).Text; else if (e.OriginalSource is Ellipse) titleFromLegendItem = (((e.OriginalSource) as Ellipse).DataContext as LegendItem).Title; var titleFromLegendItem = (e.OriginalSource as TextBlock).Text; if (string.IsNullOrEmpty(titleFromLegendItem)) return; Loading @@ -381,13 +384,18 @@ namespace INAF.Apps.Uwp.SLabDataManager.Views { case Visibility.Visible: selectedSeries.Visibility = Visibility.Collapsed; ((selectedSeries.DataContext) as SpectrumModel).IsVisible = false; (sender as StackPanel).Opacity = 0.5; break; case Visibility.Collapsed: selectedSeries.Visibility = Visibility.Visible; ((selectedSeries.DataContext) as SpectrumModel).IsVisible = true; (sender as StackPanel).Opacity = 1; break; } /* refresh boundaries to match only visible spectra */ await ViewModel.WorkingItems.SpectraContainer.updateBoundariesAsync(); } private void chartLegendInfoButton_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e) Loading Loading @@ -423,7 +431,7 @@ namespace INAF.Apps.Uwp.SLabDataManager.Views #endregion #region annotations #region vertical separator annotations #region vertical separator annota.tions private void spectrumChart_Loaded(object sender, RoutedEventArgs e) { createCartesianGridLineAnnotations(sender as RadCartesianChart); Loading @@ -447,7 +455,10 @@ namespace INAF.Apps.Uwp.SLabDataManager.Views var chart = (RadCartesianChart)sender; var mousePosition = e.GetPosition(chart); chartAnnotationsHelper.addOrRemoveTappedPointForContinuum(chart, mousePosition, tappedPointTemplate); chartAnnotationsHelper.addOrRemoveTappedPointForContinuum(chart, mousePosition, tappedPointTemplate); if (customLinesAnnotationsRepository.isAnyLineAvailable()) ViewModel.trySetIsContinuumRemovalEnabled(); } Loading