From 00cea761d2258ac206f78f23753552bd57474018 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Fri, 17 Apr 2020 19:09:09 +0100 Subject: [PATCH] Use oxyplot for chart drawing. --- .gitmodules | 3 + .idea/.idea.Aaru/.idea/contentModel.xml | 583 ++++++++++-------- Aaru.Gui/Aaru.Gui.csproj | 1 + Aaru.Gui/App.xaml | 1 + .../ViewModels/Windows/MediaScanViewModel.cs | 269 ++++---- Aaru.Gui/Views/Windows/MediaScan.xaml | 20 +- Aaru.sln | 10 + oxyplot-avalonia | 1 + 8 files changed, 514 insertions(+), 374 deletions(-) create mode 160000 oxyplot-avalonia diff --git a/.gitmodules b/.gitmodules index 9db4ce36f..dde46c607 100644 --- a/.gitmodules +++ b/.gitmodules @@ -22,3 +22,6 @@ [submodule "Aaru.Helpers"] path = Aaru.Helpers url = https://github.com/aaru-dps/Aaru.Helpers +[submodule "oxyplot-avalonia"] + path = oxyplot-avalonia + url = https://github.com/oxyplot/oxyplot-avalonia.git diff --git a/.idea/.idea.Aaru/.idea/contentModel.xml b/.idea/.idea.Aaru/.idea/contentModel.xml index 54adeccf2..fd2682841 100644 --- a/.idea/.idea.Aaru/.idea/contentModel.xml +++ b/.idea/.idea.Aaru/.idea/contentModel.xml @@ -1,27 +1,28 @@ - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - @@ -70,6 +71,13 @@ + + + + + + + @@ -80,18 +88,12 @@ - - - - - - @@ -100,13 +102,6 @@ - - - - - - - @@ -114,12 +109,19 @@ + + + + + + + + - @@ -178,13 +180,6 @@ - - - - - - - @@ -205,10 +200,19 @@ + + + + + + + + + @@ -217,7 +221,6 @@ - @@ -235,7 +238,6 @@ - @@ -256,8 +258,8 @@ - + @@ -267,11 +269,11 @@ - + - + @@ -285,17 +287,17 @@ - - + + - + @@ -315,19 +317,12 @@ - + - - - - - - - @@ -344,61 +339,68 @@ + + + + + + + + - - - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + + @@ -423,6 +425,7 @@ + @@ -434,12 +437,11 @@ - - + @@ -461,9 +463,9 @@ - + @@ -493,13 +495,6 @@ - - - - - - - @@ -563,11 +558,11 @@ - + @@ -587,10 +582,17 @@ + + + + + + + + - @@ -647,13 +649,6 @@ - - - - - - - @@ -666,17 +661,28 @@ - + + + + + + + + + - + + + + @@ -684,16 +690,13 @@ - - - + + - - @@ -729,13 +732,11 @@ - - - + @@ -743,14 +744,11 @@ + - - - - @@ -790,8 +788,8 @@ - + @@ -800,8 +798,8 @@ - + @@ -810,8 +808,8 @@ - + @@ -838,15 +836,8 @@ - - - - - - - - + @@ -864,11 +855,11 @@ + - @@ -891,17 +882,34 @@ + + + + + + + + + + + + - + + + + + + @@ -909,18 +917,12 @@ - - - - - - @@ -1014,12 +1016,6 @@ - - - - - - @@ -1044,6 +1040,12 @@ + + + + + + @@ -1126,8 +1128,6 @@ - - @@ -1143,18 +1143,6 @@ - - - - - - - - - - - - @@ -1167,6 +1155,18 @@ + + + + + + + + + + + + @@ -1175,14 +1175,14 @@ + + - - @@ -1205,10 +1205,12 @@ + + + - @@ -1218,8 +1220,8 @@ - + @@ -1242,16 +1244,6 @@ - - - - - - - - - - @@ -1374,6 +1366,17 @@ + + + + + + + + + + + @@ -1382,7 +1385,6 @@ - @@ -1390,6 +1392,10 @@ + + + + @@ -1397,9 +1403,6 @@ - - - @@ -1482,7 +1485,16 @@ - + + + + + + + + + + @@ -1504,16 +1516,6 @@ - - - - - - - - - - @@ -1547,6 +1549,16 @@ + + + + + + + + + + @@ -1584,16 +1596,6 @@ - - - - - - - - - - @@ -1684,8 +1686,8 @@ - + @@ -1719,17 +1721,6 @@ - - - - - - - - - - - @@ -1740,12 +1731,16 @@ - - - - - - + + + + + + + + + + @@ -1929,16 +1924,6 @@ - - - - - - - - - - @@ -1949,6 +1934,16 @@ + + + + + + + + + + @@ -1967,6 +1962,14 @@ + + + + + + + + @@ -1974,7 +1977,6 @@ - @@ -1982,13 +1984,6 @@ - - - - - - - @@ -1998,11 +1993,20 @@ - + + + + + + + + + + @@ -2011,13 +2015,19 @@ - - - + - + + + + + + + + + @@ -2051,8 +2061,8 @@ - + @@ -2060,7 +2070,7 @@ - + @@ -2083,14 +2093,105 @@ - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - \ No newline at end of file diff --git a/Aaru.Gui/Aaru.Gui.csproj b/Aaru.Gui/Aaru.Gui.csproj index a194917ec..e2f192566 100644 --- a/Aaru.Gui/Aaru.Gui.csproj +++ b/Aaru.Gui/Aaru.Gui.csproj @@ -33,6 +33,7 @@ + diff --git a/Aaru.Gui/App.xaml b/Aaru.Gui/App.xaml index 2ae89fa86..697841a9c 100644 --- a/Aaru.Gui/App.xaml +++ b/Aaru.Gui/App.xaml @@ -7,6 +7,7 @@ + diff --git a/Aaru.Gui/ViewModels/Windows/MediaScanViewModel.cs b/Aaru.Gui/ViewModels/Windows/MediaScanViewModel.cs index 67927d45d..ca6ec7817 100644 --- a/Aaru.Gui/ViewModels/Windows/MediaScanViewModel.cs +++ b/Aaru.Gui/ViewModels/Windows/MediaScanViewModel.cs @@ -6,9 +6,11 @@ using Aaru.Core.Devices.Scanning; using Aaru.Core.Media.Info; using Aaru.Devices; using Avalonia.Controls; +using Avalonia.Media; using Avalonia.Threading; using MessageBox.Avalonia; using MessageBox.Avalonia.Enums; +using OxyPlot; using ReactiveUI; using DeviceInfo = Aaru.Core.Devices.Info.DeviceInfo; @@ -19,37 +21,44 @@ namespace Aaru.Gui.ViewModels.Windows readonly Window _view; string _a; string _avgSpeed; + Color _axesColor; string _b; - - ulong _blocks; - ulong _blocksToRead; - string _c; - bool _closeVisible; - string _d; - string _devicePath; - string _e; - string _f; - ScanResults _localResults; - string _maxSpeed; - string _minSpeed; - bool _progress1Visible; - string _progress2Indeterminate; - string _progress2MaxValue; - string _progress2Text; - string _progress2Value; - string _progress2Visible; - bool _progressIndeterminate; - double _progressMaxValue; - string _progressText; - double _progressValue; - bool _progressVisible; - bool _resultsVisible; - MediaScan _scanner; - bool _startVisible; - string _stopEnabled; - bool _stopVisible; - string _totalTime; - string _unreadableSectors; + ulong _blocks; + ulong _blocksToRead; + string _c; + bool _closeVisible; + string _d; + string _devicePath; + string _e; + string _f; + Color _lineColor; + ScanResults _localResults; + string _maxSpeed; + double _maxX; + double _maxY; + string _minSpeed; + double _minX; + double _minY; + bool _progress1Visible; + string _progress2Indeterminate; + string _progress2MaxValue; + string _progress2Text; + string _progress2Value; + string _progress2Visible; + bool _progressIndeterminate; + double _progressMaxValue; + string _progressText; + double _progressValue; + bool _progressVisible; + bool _resultsVisible; + MediaScan _scanner; + bool _startVisible; + double _stepsX; + double _stepsY; + string _stopEnabled; + bool _stopVisible; + string _totalTime; + string _unreadableSectors; public MediaScanViewModel(string devicePath, DeviceInfo deviceInfo, Window view, ScsiInfo scsiInfo = null) { @@ -62,30 +71,27 @@ namespace Aaru.Gui.ViewModels.Windows StartVisible = true; CloseVisible = true; BlockMapList = new ObservableCollection<(ulong block, double duration)>(); - - /* - lineChart.AbsoluteMargins = true; - lineChart.MarginX = 5; - lineChart.MarginY = 5; - lineChart.DrawAxes = true; - lineChart.AxesColor = Colors.Black; - lineChart.ColorX = Colors.Gray; - lineChart.ColorY = Colors.Gray; - lineChart.BackgroundColor = Color.FromRgb(0x2974c1); - lineChart.LineColor = Colors.Yellow; - */ + ChartPoints = new ObservableCollection(); + StepsX = double.NaN; + StepsY = double.NaN; + AxesColor = Colors.Black; + LineColor = Colors.Yellow; + } + + public Color AxesColor + { + get => _axesColor; + set => this.RaiseAndSetIfChanged(ref _axesColor, value); + } + + public Color LineColor + { + get => _lineColor; + set => this.RaiseAndSetIfChanged(ref _lineColor, value); } - /* - static readonly Color LightGreen = Color.FromRgb(0x00FF00); - static readonly Color Green = Color.FromRgb(0x006400); - static readonly Color DarkGreen = Color.FromRgb(0x003200); - static readonly Color Yellow = Color.FromRgb(0xFFA500); - static readonly Color Orange = Color.FromRgb(0xFF4500); - static readonly Color Red = Color.FromRgb(0x800000); - static Color LightRed = Color.FromRgb(0xFF0000); - */ public ObservableCollection<(ulong block, double duration)> BlockMapList { get; } + public ObservableCollection ChartPoints { get; } public ulong Blocks { @@ -225,6 +231,42 @@ namespace Aaru.Gui.ViewModels.Windows set => this.RaiseAndSetIfChanged(ref _resultsVisible, value); } + public double MaxY + { + get => _maxY; + set => this.RaiseAndSetIfChanged(ref _maxY, value); + } + + public double MaxX + { + get => _maxX; + set => this.RaiseAndSetIfChanged(ref _maxX, value); + } + + public double MinY + { + get => _minY; + set => this.RaiseAndSetIfChanged(ref _minY, value); + } + + public double MinX + { + get => _minX; + set => this.RaiseAndSetIfChanged(ref _minX, value); + } + + public double StepsY + { + get => _stepsY; + set => this.RaiseAndSetIfChanged(ref _stepsY, value); + } + + public double StepsX + { + get => _stepsX; + set => this.RaiseAndSetIfChanged(ref _stepsX, value); + } + public string Title { get; } public ReactiveCommand StartCommand { get; } @@ -242,6 +284,7 @@ namespace Aaru.Gui.ViewModels.Windows CloseVisible = false; ProgressVisible = true; ResultsVisible = true; + ChartPoints.Clear(); new Thread(DoWork).Start(); } @@ -330,25 +373,25 @@ namespace Aaru.Gui.ViewModels.Windows WorkFinished(); } - async void ScanSpeed(ulong sector, double currentspeed) => await Dispatcher.UIThread.InvokeAsync(() => + async void ScanSpeed(ulong sector, double currentSpeed) => await Dispatcher.UIThread.InvokeAsync(() => { - /* TODO: Chart - if(currentspeed > lineChart.MaxY) - lineChart.MaxY = (float)(currentspeed + (currentspeed / 10)); + if(ChartPoints.Count == 0) + ChartPoints.Add(new DataPoint(0, currentSpeed)); - lineChart.Values.Add(new PointF(sector, (float)currentspeed)); - */ + ChartPoints.Add(new DataPoint(sector, currentSpeed)); + + if(currentSpeed > MaxY) + MaxY = currentSpeed + (currentSpeed / 10d); }); - async void InitBlockMap(ulong blocks, ulong blocksize, ulong blockstoread, ushort currentProfile) => + async void InitBlockMap(ulong blocks, ulong blockSize, ulong blocksToRead, ushort currentProfile) => await Dispatcher.UIThread.InvokeAsync(() => { - Blocks = blocks / blockstoread; - _blocksToRead = blockstoread; + Blocks = blocks / blocksToRead; + _blocksToRead = blocksToRead; - /* TODO: Chart - lineChart.MinX = 0; - lineChart.MinY = 0; + MinX = 0; + MinY = 0; switch(currentProfile) { @@ -360,17 +403,17 @@ namespace Aaru.Gui.ViewModels.Windows case 0x0021: case 0x0022: if(blocks <= 360000) - lineChart.MaxX = 360000; + MaxX = 360000; else if(blocks <= 405000) - lineChart.MaxX = 405000; + MaxX = 405000; else if(blocks <= 445500) - lineChart.MaxX = 445500; + MaxX = 445500; else - lineChart.MaxX = blocks; + MaxX = blocks; - lineChart.StepsX = lineChart.MaxX / 10f; - lineChart.StepsY = 150 * 4; - lineChart.MaxY = lineChart.StepsY * 12.5f; + StepsX = MaxX / 10; + StepsY = 150 * 4; + MaxY = StepsY * 12.5; break; case 0x0010: // DVD SL @@ -381,10 +424,10 @@ namespace Aaru.Gui.ViewModels.Windows case 0x0018: case 0x001A: case 0x001B: - lineChart.MaxX = 2298496; - lineChart.StepsX = lineChart.MaxX / 10f; - lineChart.StepsY = 1352.5f; - lineChart.MaxY = lineChart.StepsY * 26; + MaxX = 2298496; + StepsX = MaxX / 10; + StepsY = 1352.5; + MaxY = StepsY * 26; break; case 0x0015: // DVD DL @@ -392,10 +435,10 @@ namespace Aaru.Gui.ViewModels.Windows case 0x0017: case 0x002A: case 0x002B: - lineChart.MaxX = 4173824; - lineChart.StepsX = lineChart.MaxX / 10f; - lineChart.StepsY = 1352.5f; - lineChart.MaxY = lineChart.StepsY * 26; + MaxX = 4173824; + StepsX = MaxX / 10; + StepsY = 1352.5; + MaxY = StepsY * 26; break; case 0x0041: @@ -403,19 +446,19 @@ namespace Aaru.Gui.ViewModels.Windows case 0x0043: case 0x0040: // BD if(blocks <= 12219392) - lineChart.MaxX = 12219392; + MaxX = 12219392; else if(blocks <= 24438784) - lineChart.MaxX = 24438784; + MaxX = 24438784; else if(blocks <= 48878592) - lineChart.MaxX = 48878592; + MaxX = 48878592; else if(blocks <= 62500864) - lineChart.MaxX = 62500864; + MaxX = 62500864; else - lineChart.MaxX = blocks; + MaxX = blocks; - lineChart.StepsX = lineChart.MaxX / 10f; - lineChart.StepsY = 4394.5f; - lineChart.MaxY = lineChart.StepsY * 18; + StepsX = MaxX / 10; + StepsY = 4394.5; + MaxY = StepsY * 18; break; case 0x0050: // HD DVD @@ -425,26 +468,25 @@ namespace Aaru.Gui.ViewModels.Windows case 0x0058: case 0x005A: if(blocks <= 7361599) - lineChart.MaxX = 7361599; + MaxX = 7361599; else if(blocks <= 16305407) - lineChart.MaxX = 16305407; + MaxX = 16305407; else - lineChart.MaxX = blocks; + MaxX = blocks; - lineChart.StepsX = lineChart.MaxX / 10f; - lineChart.StepsY = 4394.5f; - lineChart.MaxY = lineChart.StepsY * 8; + StepsX = MaxX / 10; + StepsY = 4394.5; + MaxY = StepsY * 8; break; default: - lineChart.MaxX = blocks; - lineChart.StepsX = lineChart.MaxX / 10f; - lineChart.StepsY = 625f; - lineChart.MaxY = lineChart.StepsY; + MaxX = blocks; + StepsX = MaxX / 10; + StepsY = 625; + MaxY = StepsY; break; } - */ }); async void WorkFinished() => await Dispatcher.UIThread.InvokeAsync(() => @@ -501,9 +543,6 @@ namespace Aaru.Gui.ViewModels.Windows _localResults.Errored += _blocksToRead; UnreadableSectors = $"{_localResults.Errored} sectors could not be read."; BlockMapList.Add((sector / _blocksToRead, double.NaN)); - /* TODO: Blockmap - blockMap.ColoredSectors.Add(new ColoredBlock(sector, LightGreen)); - */ }); async void OnScanTime(ulong sector, double duration) => await Dispatcher.UIThread.InvokeAsync(() => @@ -511,51 +550,21 @@ namespace Aaru.Gui.ViewModels.Windows BlockMapList.Add((sector / _blocksToRead, duration)); if(duration < 3) - { _localResults.A += _blocksToRead; - /* TODO: Blockmap - blockMap.ColoredSectors.Add(new ColoredBlock(sector, LightGreen)); - */ - } else if(duration >= 3 && duration < 10) - { _localResults.B += _blocksToRead; - /* TODO: Blockmap - blockMap.ColoredSectors.Add(new ColoredBlock(sector, Green)); - */ - } else if(duration >= 10 && duration < 50) - { _localResults.C += _blocksToRead; - /* TODO: Blockmap - blockMap.ColoredSectors.Add(new ColoredBlock(sector, DarkGreen)); - */ - } else if(duration >= 50 && duration < 150) - { _localResults.D += _blocksToRead; - /* TODO: Blockmap - blockMap.ColoredSectors.Add(new ColoredBlock(sector, Yellow)); - */ - } else if(duration >= 150 && duration < 500) - { _localResults.E += _blocksToRead; - /* TODO: Blockmap - blockMap.ColoredSectors.Add(new ColoredBlock(sector, Orange)); - */ - } else if(duration >= 500) - { _localResults.F += _blocksToRead; - /* TODO: Blockmap - blockMap.ColoredSectors.Add(new ColoredBlock(sector, Red)); - */ - } A = $"{_localResults.A} sectors took less than 3 ms."; B = $"{_localResults.B} sectors took less than 10 ms but more than 3 ms."; diff --git a/Aaru.Gui/Views/Windows/MediaScan.xaml b/Aaru.Gui/Views/Windows/MediaScan.xaml index 49c01bfeb..2fbc5c2e2 100644 --- a/Aaru.Gui/Views/Windows/MediaScan.xaml +++ b/Aaru.Gui/Views/Windows/MediaScan.xaml @@ -2,8 +2,8 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:windows="clr-namespace:Aaru.Gui.ViewModels.Windows" xmlns:controls="clr-namespace:Aaru.Gui.Controls" - mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" x:Class="Aaru.Gui.Views.Windows.MediaScan" - Icon="/Assets/aaru-logo.png" Title="{Binding Title}"> + xmlns:avalonia="http://oxyplot.org/avalonia" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" + x:Class="Aaru.Gui.Views.Windows.MediaScan" Icon="/Assets/aaru-logo.png" Title="{Binding Title}"> @@ -33,7 +33,21 @@ - + + + + + + + + + diff --git a/Aaru.sln b/Aaru.sln index 98d5a25ba..0f63d4406 100644 --- a/Aaru.sln +++ b/Aaru.sln @@ -36,6 +36,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aaru.Dto", "Aaru.Dto\Aaru.D EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aaru.Gui", "Aaru.Gui\Aaru.Gui.csproj", "{18C4C44D-2562-4B6D-8181-32D7EA067D96}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OxyPlot.Avalonia", "oxyplot-avalonia\Source\OxyPlot.Avalonia\OxyPlot.Avalonia.csproj", "{FF61D39C-BBA1-4FB7-AAC5-AD2D30418F4C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -180,6 +182,14 @@ Global {18C4C44D-2562-4B6D-8181-32D7EA067D96}.Release|Any CPU.Build.0 = Release|Any CPU {18C4C44D-2562-4B6D-8181-32D7EA067D96}.Release|x86.ActiveCfg = Release|Any CPU {18C4C44D-2562-4B6D-8181-32D7EA067D96}.Release|x86.Build.0 = Release|Any CPU + {FF61D39C-BBA1-4FB7-AAC5-AD2D30418F4C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FF61D39C-BBA1-4FB7-AAC5-AD2D30418F4C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FF61D39C-BBA1-4FB7-AAC5-AD2D30418F4C}.Debug|x86.ActiveCfg = Debug|Any CPU + {FF61D39C-BBA1-4FB7-AAC5-AD2D30418F4C}.Debug|x86.Build.0 = Debug|Any CPU + {FF61D39C-BBA1-4FB7-AAC5-AD2D30418F4C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FF61D39C-BBA1-4FB7-AAC5-AD2D30418F4C}.Release|Any CPU.Build.0 = Release|Any CPU + {FF61D39C-BBA1-4FB7-AAC5-AD2D30418F4C}.Release|x86.ActiveCfg = Release|Any CPU + {FF61D39C-BBA1-4FB7-AAC5-AD2D30418F4C}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/oxyplot-avalonia b/oxyplot-avalonia new file mode 160000 index 000000000..cedccb8b7 --- /dev/null +++ b/oxyplot-avalonia @@ -0,0 +1 @@ +Subproject commit cedccb8b71999df74e6f9972ba0d71b7b187de64