Use oxyplot for chart drawing.

This commit is contained in:
2020-04-17 19:09:09 +01:00
parent ce16776754
commit 00cea761d2
8 changed files with 514 additions and 374 deletions

3
.gitmodules vendored
View File

@@ -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

File diff suppressed because it is too large Load Diff

View File

@@ -33,6 +33,7 @@
<ProjectReference Include="..\Aaru.Core\Aaru.Core.csproj" />
<ProjectReference Include="..\Aaru.Devices\Aaru.Devices.csproj" />
<ProjectReference Include="..\Aaru.Checksums\Aaru.Checksums.csproj" />
<ProjectReference Include="..\oxyplot-avalonia\Source\OxyPlot.Avalonia\OxyPlot.Avalonia.csproj" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Assets\Logos\Media\AIT1.png" />

View File

@@ -7,6 +7,7 @@
<StyleInclude Source="avares://Avalonia.Themes.Default/DefaultTheme.xaml" />
<StyleInclude Source="avares://Avalonia.Themes.Default/Accents/BaseLight.xaml" />
<StyleInclude Source="avares://Avalonia.Controls.DataGrid/Themes/Default.xaml" />
<StyleInclude Source="resm:OxyPlot.Avalonia.Themes.Default.xaml?assembly=OxyPlot.Avalonia"/>
</Application.Styles>
<NativeMenu.Menu>
<NativeMenu>

View File

@@ -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<DataPoint>();
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<DataPoint> 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<Unit, Unit> 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.";

View File

@@ -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}">
<Design.DataContext>
<windows:MediaScanViewModel />
</Design.DataContext>
@@ -33,7 +33,21 @@
<TabItem.Header>
<TextBlock Text="Chart" />
</TabItem.Header>
<!-- TODO: Chart -->
<avalonia:Plot Height="300" PlotMargins="50 0 0 0" PlotAreaBorderColor="#999999"
PlotAreaBackground="#2974c1">
<avalonia:Plot.Series>
<avalonia:LineSeries DataFieldX="Index" DataFieldY="Value" Items="{Binding Path=ChartPoints}"
Color="{Binding LineColor}" />
</avalonia:Plot.Series>
<avalonia:Plot.Axes>
<avalonia:LinearAxis Position="Left" Maximum="{Binding MaxY}" Minimum="{Binding MinY}"
MajorStep="{Binding StepsY}" Title="Speed" Unit="Kb/s"
AxislineColor="{Binding AxesColor}" />
<avalonia:LinearAxis Position="Bottom" Maximum="{Binding MaxX}" Minimum="{Binding MinX}"
MajorStep="{Binding StepsX}" Title="Block"
AxislineColor="{Binding AxesColor}" />
</avalonia:Plot.Axes>
</avalonia:Plot>
</TabItem>
</TabControl>
<StackPanel Orientation="Vertical" IsVisible="{Binding ProgressVisible}">

View File

@@ -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

1
oxyplot-avalonia Submodule

Submodule oxyplot-avalonia added at cedccb8b71