From f7e2b594545ac2ed0290ac5d1b688471500b50ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Holger=20B=C3=B6rchers?= Date: Sat, 8 Jan 2022 21:56:39 +0100 Subject: [PATCH] add oxyplot --- KMeansBase/KMeans.cs | 9 +++--- KMeansGui/App.axaml | 5 +++- KMeansGui/KMeansGui.csproj | 50 +++++++++++++++++-------------- KMeansGui/Shell/ShellView.axaml | 31 ++++++++++++++----- KMeansGui/Shell/ShellViewModel.cs | 13 ++++++-- 5 files changed, 69 insertions(+), 39 deletions(-) diff --git a/KMeansBase/KMeans.cs b/KMeansBase/KMeans.cs index 0087ca8..de6c65d 100644 --- a/KMeansBase/KMeans.cs +++ b/KMeansBase/KMeans.cs @@ -4,7 +4,8 @@ public static class KMeans { private const int MaxLoops = 30; - public static void KMeansCalculation(IReadOnlyCollection points, int k, out IReadOnlyCollection centroids) + public static void KMeansCalculation(IReadOnlyCollection points, int k, + out IReadOnlyCollection centroids) { centroids = InitializeRandomCentroids(points, k).ToArray(); @@ -64,10 +65,8 @@ public static class KMeans private static IEnumerable InitializeRandomCentroids(IReadOnlyCollection points, int k) { - var minX = points.Min(p => p.X); - var maxX = points.Max(p => p.X); - var minY = points.Min(p => p.Y); - var maxY = points.Max(p => p.Y); + var (minX, maxX) = (points.Min(p => p.X), points.Max(p => p.X)); + var (minY, maxY) = (points.Min(p => p.Y), points.Max(p => p.Y)); var rnd = new Random(); for (var i = 0; i < k; i++) diff --git a/KMeansGui/App.axaml b/KMeansGui/App.axaml index 3a599b2..39b558c 100644 --- a/KMeansGui/App.axaml +++ b/KMeansGui/App.axaml @@ -3,5 +3,8 @@ x:Class="KMeansGui.App"> + + + - + \ No newline at end of file diff --git a/KMeansGui/KMeansGui.csproj b/KMeansGui/KMeansGui.csproj index 07e2ddb..e869fcc 100644 --- a/KMeansGui/KMeansGui.csproj +++ b/KMeansGui/KMeansGui.csproj @@ -1,25 +1,29 @@  - - WinExe - net5.0 - enable - - - - - - - - - - - - - - - - - ShellView.axaml - - + + WinExe + net6.0 + enable + + + + + + + + + + + + + + + + + + ShellView.axaml + + + + + diff --git a/KMeansGui/Shell/ShellView.axaml b/KMeansGui/Shell/ShellView.axaml index b97ac4d..9851906 100644 --- a/KMeansGui/Shell/ShellView.axaml +++ b/KMeansGui/Shell/ShellView.axaml @@ -2,14 +2,29 @@ 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" x:Name="LayoutRoot" + 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"> - - - - - - - + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/KMeansGui/Shell/ShellViewModel.cs b/KMeansGui/Shell/ShellViewModel.cs index bc9ca4b..7472d7c 100644 --- a/KMeansGui/Shell/ShellViewModel.cs +++ b/KMeansGui/Shell/ShellViewModel.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; +using System.Collections.Generic; +using System.Threading.Tasks; using Avalonia.Controls; using MvvmGen; @@ -7,13 +8,21 @@ namespace KMeansGui [ViewModel] public partial class ShellViewModel { - + [Property] private int _countOfCentroids; + [Property] private List _points; public async Task OpenCsvFileAsync(object parent) { if (parent is Window window) { + var fileDialogFilter = new FileDialogFilter(); + fileDialogFilter.Extensions.Add("csv"); + fileDialogFilter.Name = "comma separated file"; var fileDialog = new OpenFileDialog(); + fileDialog.AllowMultiple = false; + + fileDialog.Filters.Add(fileDialogFilter); + fileDialog.Title = "Select a csv file."; var result = await fileDialog.ShowAsync(window); } }