Loading INAF.Apps.Uwp.SLabDataManager/App.xaml.cs +7 −0 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ using INAF.Apps.Uwp.SLabDataManager.Charts; using INAF.Apps.Uwp.SLabDataManager.Helpers; using INAF.Apps.Uwp.SLabDataManager.Helpers.ConfigHelpers; using INAF.Apps.Uwp.SLabDataManager.Helpers.RemoteOperations; using INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart; using INAF.Apps.Uwp.SLabDataManager.Models; using INAF.Apps.Uwp.SLabDataManager.Models.Spectrum; using INAF.Apps.Uwp.SLabDataManager.Services; Loading Loading @@ -68,6 +69,9 @@ namespace INAF.Apps.Uwp.SLabDataManager private ActivationService CreateActivationService() { #if DEBUG return new ActivationService(this, typeof(Views.MainPage), new Lazy<UIElement>(CreateShell)); #else /* hide left navigation pane to avoid navigation to main page if user is not allowed */ Ioc.Default.GetService<ShellViewModel>().IsPaneVisible = false; Loading @@ -80,6 +84,7 @@ namespace INAF.Apps.Uwp.SLabDataManager } return new ActivationService(this, typeof(Views.LoginPage), new Lazy<UIElement>(CreateShell)); #endif } private UIElement CreateShell() Loading @@ -95,6 +100,7 @@ namespace INAF.Apps.Uwp.SLabDataManager Ioc.Default.ConfigureServices( new ServiceCollection() /* singletons */ .AddSingleton<CustomAnnotationsRepository>() .AddSingleton<SelectedRefBand>() .AddSingleton<SpectrumAlignmentConfigModel>() .AddSingleton<SpectrumChartOptionsModel>() Loading @@ -110,6 +116,7 @@ namespace INAF.Apps.Uwp.SLabDataManager .AddSingleton<WorkingItemsModel>() /* transient */ .AddTransient<AuthenticationManager>() .AddTransient<ChartAnnotationsHelper>() .AddTransient<ConfigReader>() .AddTransient<RemoteOperationsManager>() .AddTransient<RemoteOperationsXmlReader>() Loading INAF.Apps.Uwp.SLabDataManager/Extensions/Extensions.cs +15 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,9 @@ using Windows.UI; using Windows.UI.Xaml.Media; using INAF.Libraries.NetStandard.Extensions; using INAF.Libraries.NetStandard.SLabCommonModels.Models.Files; using INAF.Libraries.NetStandard.ScienceModels; using Telerik.UI.Xaml.Controls.Chart; using System; namespace INAF.Apps.Uwp.SLabDataManager.Extensions { Loading Loading @@ -53,6 +56,18 @@ namespace INAF.Apps.Uwp.SLabDataManager.Extensions }; } public static PointModel ToPointModel(this CartesianCustomAnnotation cartesianCustomAnnotation) { try { return new PointModel(Convert.ToDouble(cartesianCustomAnnotation.HorizontalValue), Convert.ToDouble(cartesianCustomAnnotation.VerticalValue)); } catch (Exception) { return null; } } public static XmlDocument ToXml(this SpectrumModel spectrum) { XmlDocument dom = new XmlDocument(); Loading INAF.Apps.Uwp.SLabDataManager/Helpers/UI/Chart/ChartAnnotationsHelper.cs 0 → 100644 +117 −0 Original line number Diff line number Diff line using INAF.Apps.Uwp.SLabDataManager.Extensions; using INAF.Libraries.NetStandard.ScienceModels.Lines; using INAF.Libraries.Uwp.Logging; using System; using System.Linq; using Telerik.UI.Xaml.Controls.Chart; using Windows.Foundation; using Windows.UI; using Windows.UI.Xaml; using Windows.UI.Xaml.Media; namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart { public sealed class ChartAnnotationsHelper { private readonly CustomAnnotationsRepository customAnnotationsRepository; private readonly Logger logger; public ChartAnnotationsHelper(CustomAnnotationsRepository customAnnotationsRepository, Logger logger) { this.customAnnotationsRepository = customAnnotationsRepository; this.logger = logger; } public void addOrRemoveTappedPoint(RadCartesianChart chart, Point mousePosition, DataTemplate tappedPointTemplate) { System.Diagnostics.Debug.WriteLine($"mousePosition: {mousePosition.X}, {mousePosition.Y}"); var point = chart.ConvertPointToData(mousePosition); System.Diagnostics.Debug.WriteLine($"point: {point.Item1}, {point.Item2}"); /* 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) && (Convert.ToDouble((x as CartesianCustomAnnotation).HorizontalValue) <= (double)point.Item1 + 12)); if (existantItem != null) chart.Annotations.Remove(existantItem); else { /* ...otherwise add a new point */ CartesianCustomAnnotation customAnnotation = new CartesianCustomAnnotation() { HorizontalValue = point.Item1, HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Center, VerticalValue = point.Item2, VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Center, ContentTemplate = tappedPointTemplate, }; chart.Annotations.Add(customAnnotation); } chart.UpdateLayout(); /* try to create lines connecting selected points */ tryCreateLines(chart); } private void tryCreateLines(RadCartesianChart chart) { try { if (chart.Annotations.Count(x => x is CartesianCustomAnnotation) <= 1) return; /* remove existing points/lines from chart before re-generating all */ int annotationsNum = chart.Annotations.Count(); for (int i = annotationsNum - 1; i >= 0; i--) { if (chart.Annotations.ElementAt(i).GetType() == typeof(CartesianCustomLineAnnotation)) chart.Annotations.Remove(chart.Annotations.ElementAt(i)); } /* clear existing lines before re-generating all */ customAnnotationsRepository.clear(); /* order points by increasing X */ var orderedPoints = chart.Annotations .Where(x => x is CartesianCustomAnnotation) .Cast<CartesianCustomAnnotation>() .OrderBy(x => x.HorizontalValue); /* generate lines from existing points */ int count = orderedPoints.Count(); for (int i = 0; i < count - 1; i++) { var line = new StraightLineModel(orderedPoints.ElementAt(i).ToPointModel(), orderedPoints.ElementAt(i + 1).ToPointModel()); customAnnotationsRepository.add(line); } foreach (var line in customAnnotationsRepository.CustomLineAnnotations) { var lineAnnotation = new CartesianCustomLineAnnotation() { HorizontalFrom = line.P1.X, VerticalFrom = line.P1.Y, HorizontalTo = line.P2.X, VerticalTo = line.P2.Y, Stroke = new SolidColorBrush(Colors.Red), StrokeThickness = 2 }; chart.Annotations.Add(lineAnnotation); } chart.UpdateLayout(); } catch (Exception ex) { logger.Write<ChartAnnotationsHelper>($"{nameof(tryCreateLines)} - ex: {ex.Message}", Serilog.Events.LogEventLevel.Error); } } } } INAF.Apps.Uwp.SLabDataManager/Helpers/UI/Chart/CustomAnnotationsRepository.cs 0 → 100644 +25 −0 Original line number Diff line number Diff line using INAF.Libraries.NetStandard.ScienceModels.Lines; using System.Collections.Generic; namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart { public class CustomAnnotationsRepository { public CustomAnnotationsRepository() { CustomLineAnnotations = new List<StraightLineModel>(); } public List<StraightLineModel> CustomLineAnnotations { get; private set; } public void add(StraightLineModel annotation) { CustomLineAnnotations.Add(annotation); } public void clear() { CustomLineAnnotations.Clear(); } } } INAF.Apps.Uwp.SLabDataManager/Helpers/UI/CustomContainerVisualFactory.cs→INAF.Apps.Uwp.SLabDataManager/Helpers/UI/Chart/CustomContainerVisualFactory.cs +1 −1 Original line number Diff line number Diff line using Telerik.UI.Xaml.Controls.Chart; namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart { public class CustomContainerVisualFactory : ContainerVisualsFactory { Loading Loading
INAF.Apps.Uwp.SLabDataManager/App.xaml.cs +7 −0 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ using INAF.Apps.Uwp.SLabDataManager.Charts; using INAF.Apps.Uwp.SLabDataManager.Helpers; using INAF.Apps.Uwp.SLabDataManager.Helpers.ConfigHelpers; using INAF.Apps.Uwp.SLabDataManager.Helpers.RemoteOperations; using INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart; using INAF.Apps.Uwp.SLabDataManager.Models; using INAF.Apps.Uwp.SLabDataManager.Models.Spectrum; using INAF.Apps.Uwp.SLabDataManager.Services; Loading Loading @@ -68,6 +69,9 @@ namespace INAF.Apps.Uwp.SLabDataManager private ActivationService CreateActivationService() { #if DEBUG return new ActivationService(this, typeof(Views.MainPage), new Lazy<UIElement>(CreateShell)); #else /* hide left navigation pane to avoid navigation to main page if user is not allowed */ Ioc.Default.GetService<ShellViewModel>().IsPaneVisible = false; Loading @@ -80,6 +84,7 @@ namespace INAF.Apps.Uwp.SLabDataManager } return new ActivationService(this, typeof(Views.LoginPage), new Lazy<UIElement>(CreateShell)); #endif } private UIElement CreateShell() Loading @@ -95,6 +100,7 @@ namespace INAF.Apps.Uwp.SLabDataManager Ioc.Default.ConfigureServices( new ServiceCollection() /* singletons */ .AddSingleton<CustomAnnotationsRepository>() .AddSingleton<SelectedRefBand>() .AddSingleton<SpectrumAlignmentConfigModel>() .AddSingleton<SpectrumChartOptionsModel>() Loading @@ -110,6 +116,7 @@ namespace INAF.Apps.Uwp.SLabDataManager .AddSingleton<WorkingItemsModel>() /* transient */ .AddTransient<AuthenticationManager>() .AddTransient<ChartAnnotationsHelper>() .AddTransient<ConfigReader>() .AddTransient<RemoteOperationsManager>() .AddTransient<RemoteOperationsXmlReader>() Loading
INAF.Apps.Uwp.SLabDataManager/Extensions/Extensions.cs +15 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,9 @@ using Windows.UI; using Windows.UI.Xaml.Media; using INAF.Libraries.NetStandard.Extensions; using INAF.Libraries.NetStandard.SLabCommonModels.Models.Files; using INAF.Libraries.NetStandard.ScienceModels; using Telerik.UI.Xaml.Controls.Chart; using System; namespace INAF.Apps.Uwp.SLabDataManager.Extensions { Loading Loading @@ -53,6 +56,18 @@ namespace INAF.Apps.Uwp.SLabDataManager.Extensions }; } public static PointModel ToPointModel(this CartesianCustomAnnotation cartesianCustomAnnotation) { try { return new PointModel(Convert.ToDouble(cartesianCustomAnnotation.HorizontalValue), Convert.ToDouble(cartesianCustomAnnotation.VerticalValue)); } catch (Exception) { return null; } } public static XmlDocument ToXml(this SpectrumModel spectrum) { XmlDocument dom = new XmlDocument(); Loading
INAF.Apps.Uwp.SLabDataManager/Helpers/UI/Chart/ChartAnnotationsHelper.cs 0 → 100644 +117 −0 Original line number Diff line number Diff line using INAF.Apps.Uwp.SLabDataManager.Extensions; using INAF.Libraries.NetStandard.ScienceModels.Lines; using INAF.Libraries.Uwp.Logging; using System; using System.Linq; using Telerik.UI.Xaml.Controls.Chart; using Windows.Foundation; using Windows.UI; using Windows.UI.Xaml; using Windows.UI.Xaml.Media; namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart { public sealed class ChartAnnotationsHelper { private readonly CustomAnnotationsRepository customAnnotationsRepository; private readonly Logger logger; public ChartAnnotationsHelper(CustomAnnotationsRepository customAnnotationsRepository, Logger logger) { this.customAnnotationsRepository = customAnnotationsRepository; this.logger = logger; } public void addOrRemoveTappedPoint(RadCartesianChart chart, Point mousePosition, DataTemplate tappedPointTemplate) { System.Diagnostics.Debug.WriteLine($"mousePosition: {mousePosition.X}, {mousePosition.Y}"); var point = chart.ConvertPointToData(mousePosition); System.Diagnostics.Debug.WriteLine($"point: {point.Item1}, {point.Item2}"); /* 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) && (Convert.ToDouble((x as CartesianCustomAnnotation).HorizontalValue) <= (double)point.Item1 + 12)); if (existantItem != null) chart.Annotations.Remove(existantItem); else { /* ...otherwise add a new point */ CartesianCustomAnnotation customAnnotation = new CartesianCustomAnnotation() { HorizontalValue = point.Item1, HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Center, VerticalValue = point.Item2, VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Center, ContentTemplate = tappedPointTemplate, }; chart.Annotations.Add(customAnnotation); } chart.UpdateLayout(); /* try to create lines connecting selected points */ tryCreateLines(chart); } private void tryCreateLines(RadCartesianChart chart) { try { if (chart.Annotations.Count(x => x is CartesianCustomAnnotation) <= 1) return; /* remove existing points/lines from chart before re-generating all */ int annotationsNum = chart.Annotations.Count(); for (int i = annotationsNum - 1; i >= 0; i--) { if (chart.Annotations.ElementAt(i).GetType() == typeof(CartesianCustomLineAnnotation)) chart.Annotations.Remove(chart.Annotations.ElementAt(i)); } /* clear existing lines before re-generating all */ customAnnotationsRepository.clear(); /* order points by increasing X */ var orderedPoints = chart.Annotations .Where(x => x is CartesianCustomAnnotation) .Cast<CartesianCustomAnnotation>() .OrderBy(x => x.HorizontalValue); /* generate lines from existing points */ int count = orderedPoints.Count(); for (int i = 0; i < count - 1; i++) { var line = new StraightLineModel(orderedPoints.ElementAt(i).ToPointModel(), orderedPoints.ElementAt(i + 1).ToPointModel()); customAnnotationsRepository.add(line); } foreach (var line in customAnnotationsRepository.CustomLineAnnotations) { var lineAnnotation = new CartesianCustomLineAnnotation() { HorizontalFrom = line.P1.X, VerticalFrom = line.P1.Y, HorizontalTo = line.P2.X, VerticalTo = line.P2.Y, Stroke = new SolidColorBrush(Colors.Red), StrokeThickness = 2 }; chart.Annotations.Add(lineAnnotation); } chart.UpdateLayout(); } catch (Exception ex) { logger.Write<ChartAnnotationsHelper>($"{nameof(tryCreateLines)} - ex: {ex.Message}", Serilog.Events.LogEventLevel.Error); } } } }
INAF.Apps.Uwp.SLabDataManager/Helpers/UI/Chart/CustomAnnotationsRepository.cs 0 → 100644 +25 −0 Original line number Diff line number Diff line using INAF.Libraries.NetStandard.ScienceModels.Lines; using System.Collections.Generic; namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart { public class CustomAnnotationsRepository { public CustomAnnotationsRepository() { CustomLineAnnotations = new List<StraightLineModel>(); } public List<StraightLineModel> CustomLineAnnotations { get; private set; } public void add(StraightLineModel annotation) { CustomLineAnnotations.Add(annotation); } public void clear() { CustomLineAnnotations.Clear(); } } }
INAF.Apps.Uwp.SLabDataManager/Helpers/UI/CustomContainerVisualFactory.cs→INAF.Apps.Uwp.SLabDataManager/Helpers/UI/Chart/CustomContainerVisualFactory.cs +1 −1 Original line number Diff line number Diff line using Telerik.UI.Xaml.Controls.Chart; namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart { public class CustomContainerVisualFactory : ContainerVisualsFactory { Loading