updated avalonia

This commit is contained in:
Holger Börchers 2023-07-31 10:53:45 +02:00
parent 6970ec8f09
commit a8f68d6ae7
5 changed files with 55 additions and 32 deletions

View File

@ -2,9 +2,8 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="KMeansGui.App">
<Application.Styles>
<FluentTheme Mode="Light"/>
<FluentTheme />
<!-- Add the line below to get OxyPlot UI theme applied. -->
<StyleInclude Source="resm:OxyPlot.Avalonia.Themes.Default.xaml?assembly=OxyPlot.Avalonia"/>
</Application.Styles>
</Application>

View File

@ -8,12 +8,13 @@
<None Remove=".gitignore" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.10.11" />
<PackageReference Include="Avalonia.Desktop" Version="0.10.11" />
<PackageReference Include="Avalonia" Version="11.0.1" />
<PackageReference Include="Avalonia.Desktop" Version="11.0.1" />
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="0.10.11" />
<PackageReference Include="MvvmGen" Version="1.1.2" />
<PackageReference Include="OxyPlot.Avalonia" Version="2.1.0-Preview1" />
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0.1" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.1" />
<PackageReference Include="MvvmGen" Version="1.2.1" />
<PackageReference Include="ScottPlot.Avalonia" Version="5.0.6-beta" />
</ItemGroup>
<ItemGroup>
<Folder Include="Shell\" />

View File

@ -1,28 +1,45 @@
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:kMeansGui="clr-namespace:KMeansGui"
xmlns:avalonia="http://oxyplot.org/avalonia"
x:Name="LayoutRoot"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="KMeansGui.ShellView"
Title="KMeansGui">
<Window
x:Class="KMeansGui.ShellView"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:control="clr-namespace:ScottPlot.Control;assembly=ScottPlot"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:kMeansGui="clr-namespace:KMeansGui"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:scottPlot="clr-namespace:ScottPlot.Avalonia;assembly=ScottPlot.Avalonia"
x:Name="LayoutRoot"
Title="KMeansGui"
d:DesignHeight="450"
d:DesignWidth="800"
mc:Ignorable="d">
<Window.DataContext>
<kMeansGui:ShellViewModel />
</Window.DataContext>
<Grid ColumnDefinitions="*,*">
<StackPanel Grid.Row="0" Grid.Column="0" Spacing="10" Margin="10">
<Button HorizontalAlignment="Stretch" Command="{Binding OpenCsvFileAsync}" Content="Load CSV file"
CommandParameter="{Binding ElementName=LayoutRoot}" HorizontalContentAlignment="Center" />
<TextBox UseFloatingWatermark="True" Watermark="Count of centroids" Text="{Binding CountOfCentroids}" />
<StackPanel
Grid.Row="0"
Grid.Column="0"
Margin="10"
Spacing="10">
<Button
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Center"
Command="{Binding OpenCsvFileAsync}"
CommandParameter="{Binding ElementName=LayoutRoot}"
Content="Load CSV file" />
<TextBox
Text="{Binding CountOfCentroids}"
UseFloatingWatermark="True"
Watermark="Count of centroids" />
</StackPanel>
<avalonia:Plot Grid.Column="1"
<scottPlot:AvaPlot Name="AvaPlot1" Grid.Column="1" />
<!--<avalonia:Plot Grid.Column="1"
PlotMargins="50 0 0 0"
PlotAreaBorderColor="#999999">
<avalonia:Plot.Series>
<avalonia:ScatterSeries Items="{Binding Points}" DataFieldX="X" DataFieldY="Y" />
</avalonia:Plot.Series>
</avalonia:Plot>
</avalonia:Plot>-->
</Grid>
</Window>

View File

@ -1,7 +1,8 @@
using ScottPlot;
using System.Diagnostics;
using System.Drawing;
using Point = KMeansBase.Point;
using ScottPlot.Legends;
using Color = ScottPlot.Color;
namespace kMeans;
@ -10,24 +11,29 @@ public static class Helper
public static Plot CreatePlot(IEnumerable<Point> points, IEnumerable<Point> centroids)
{
var plot = new Plot();
plot.Legend(true, Alignment.UpperRight);
var legend = new StandardLegend { Alignment = Alignment.UpperRight };
plot.Legends.Add(legend);
var colors = new Dictionary<int, Color>();
var colorGroups = points.GroupBy(x => x.ClusterId);
foreach (var clusterGroup in colorGroups)
{
var color = plot.GetNextColor();
var color = plot.Add.NextColor;
colors.Add(clusterGroup.Key, color);
var xs = clusterGroup.Select(p => p.X).ToArray();
var ys = clusterGroup.Select(p => p.Y).ToArray();
plot.AddScatterPoints(xs, ys, color);
plot.Add.Scatter(xs, ys);
}
const MarkerShape marker = MarkerShape.cross;
const MarkerShape marker = MarkerShape.FilledSquare;
const float size = 10f;
foreach (var (x, y, clusterId) in centroids)
{
var color = colors.TryGetValue(clusterId, out var c) ? c : plot.GetNextColor();
plot.AddScatterPoints(new[] { x }, new[] { y }, color, size, marker, $"ClusterId: {clusterId}");
var color = colors.TryGetValue(clusterId, out var c) ? c : plot.Add.NextColor;
var scatter = plot.Add.Scatter(new[] { x }, new[] { y }, color);
scatter.MarkerStyle.Size = size;
scatter.MarkerStyle.Shape = marker;
scatter.Label = $"ClusterId: {clusterId}";
}
return plot;
@ -35,7 +41,7 @@ public static class Helper
public static void ExportPlot(Plot plot, string path)
{
plot.SaveFig(path);
plot.SavePng(path, 1000, 1000);
}
public static void PreviewPlot(string path)

View File

@ -9,7 +9,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ScottPlot" Version="4.1.30" />
<PackageReference Include="ScottPlot" Version="5.0.6-beta" />
</ItemGroup>
<ItemGroup>