add oxyplot
This commit is contained in:
parent
c317ab897f
commit
f7e2b59454
@ -4,7 +4,8 @@ public static class KMeans
|
||||
{
|
||||
private const int MaxLoops = 30;
|
||||
|
||||
public static void KMeansCalculation(IReadOnlyCollection<Point> points, int k, out IReadOnlyCollection<Point> centroids)
|
||||
public static void KMeansCalculation(IReadOnlyCollection<Point> points, int k,
|
||||
out IReadOnlyCollection<Point> centroids)
|
||||
{
|
||||
centroids = InitializeRandomCentroids(points, k).ToArray();
|
||||
|
||||
@ -64,10 +65,8 @@ public static class KMeans
|
||||
|
||||
private static IEnumerable<Point> InitializeRandomCentroids(IReadOnlyCollection<Point> 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++)
|
||||
|
@ -3,5 +3,8 @@
|
||||
x:Class="KMeansGui.App">
|
||||
<Application.Styles>
|
||||
<FluentTheme Mode="Light"/>
|
||||
|
||||
<!-- Add the line below to get OxyPlot UI theme applied. -->
|
||||
<StyleInclude Source="resm:OxyPlot.Avalonia.Themes.Default.xaml?assembly=OxyPlot.Avalonia"/>
|
||||
</Application.Styles>
|
||||
</Application>
|
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
@ -13,6 +13,7 @@
|
||||
<!--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" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Shell\" />
|
||||
@ -22,4 +23,7 @@
|
||||
<DependentUpon>ShellView.axaml</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\KMeansBase\KMeansBase.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
@ -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">
|
||||
<Window.DataContext>
|
||||
<kMeansGui:ShellViewModel />
|
||||
</Window.DataContext>
|
||||
<Grid RowDefinitions="*,*" ColumnDefinitions="*,*">
|
||||
<Button Command="{Binding OpenCsvFileAsync}" CommandParameter="{Binding ElementName=LayoutRoot}" >Load CSV file</Button>
|
||||
<Grid ColumnDefinitions="*,*">
|
||||
<StackPanel Grid.Row="0" Grid.Column="0" Spacing="10">
|
||||
<Button HorizontalAlignment="Stretch" Command="{Binding OpenCsvFileAsync}"
|
||||
CommandParameter="{Binding ElementName=LayoutRoot}">
|
||||
Load CSV file
|
||||
</Button>
|
||||
<TextBox UseFloatingWatermark="True" Watermark="Hello" Text="{Binding CountOfCentroids}"></TextBox>
|
||||
</StackPanel>
|
||||
<avalonia:Plot Height="150" Grid.Column="1"
|
||||
PlotMargins="50 0 0 0"
|
||||
PlotAreaBorderColor="#999999">
|
||||
<avalonia:Plot.Series>
|
||||
<avalonia:ScatterSeries Items="{Binding Points}" />
|
||||
</avalonia:Plot.Series>
|
||||
</avalonia:Plot>
|
||||
</Grid>
|
||||
</Window>
|
@ -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<KMeansBase.Point> _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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user