updated avalonia
This commit is contained in:
parent
6970ec8f09
commit
a8f68d6ae7
@ -2,9 +2,8 @@
|
|||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
x:Class="KMeansGui.App">
|
x:Class="KMeansGui.App">
|
||||||
<Application.Styles>
|
<Application.Styles>
|
||||||
<FluentTheme Mode="Light"/>
|
<FluentTheme />
|
||||||
|
|
||||||
<!-- Add the line below to get OxyPlot UI theme applied. -->
|
<!-- Add the line below to get OxyPlot UI theme applied. -->
|
||||||
<StyleInclude Source="resm:OxyPlot.Avalonia.Themes.Default.xaml?assembly=OxyPlot.Avalonia"/>
|
|
||||||
</Application.Styles>
|
</Application.Styles>
|
||||||
</Application>
|
</Application>
|
@ -8,12 +8,13 @@
|
|||||||
<None Remove=".gitignore" />
|
<None Remove=".gitignore" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Avalonia" Version="0.10.11" />
|
<PackageReference Include="Avalonia" Version="11.0.1" />
|
||||||
<PackageReference Include="Avalonia.Desktop" Version="0.10.11" />
|
<PackageReference Include="Avalonia.Desktop" Version="11.0.1" />
|
||||||
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
|
<!--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 Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0.1" />
|
||||||
<PackageReference Include="MvvmGen" Version="1.1.2" />
|
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.1" />
|
||||||
<PackageReference Include="OxyPlot.Avalonia" Version="2.1.0-Preview1" />
|
<PackageReference Include="MvvmGen" Version="1.2.1" />
|
||||||
|
<PackageReference Include="ScottPlot.Avalonia" Version="5.0.6-beta" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Shell\" />
|
<Folder Include="Shell\" />
|
||||||
|
@ -1,28 +1,45 @@
|
|||||||
<Window xmlns="https://github.com/avaloniaui"
|
<Window
|
||||||
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"
|
x:Class="KMeansGui.ShellView"
|
||||||
Title="KMeansGui">
|
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>
|
<Window.DataContext>
|
||||||
<kMeansGui:ShellViewModel />
|
<kMeansGui:ShellViewModel />
|
||||||
</Window.DataContext>
|
</Window.DataContext>
|
||||||
<Grid ColumnDefinitions="*,*">
|
<Grid ColumnDefinitions="*,*">
|
||||||
<StackPanel Grid.Row="0" Grid.Column="0" Spacing="10" Margin="10">
|
<StackPanel
|
||||||
<Button HorizontalAlignment="Stretch" Command="{Binding OpenCsvFileAsync}" Content="Load CSV file"
|
Grid.Row="0"
|
||||||
CommandParameter="{Binding ElementName=LayoutRoot}" HorizontalContentAlignment="Center" />
|
Grid.Column="0"
|
||||||
<TextBox UseFloatingWatermark="True" Watermark="Count of centroids" Text="{Binding CountOfCentroids}" />
|
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>
|
</StackPanel>
|
||||||
<avalonia:Plot Grid.Column="1"
|
<scottPlot:AvaPlot Name="AvaPlot1" Grid.Column="1" />
|
||||||
|
|
||||||
|
<!--<avalonia:Plot Grid.Column="1"
|
||||||
PlotMargins="50 0 0 0"
|
PlotMargins="50 0 0 0"
|
||||||
PlotAreaBorderColor="#999999">
|
PlotAreaBorderColor="#999999">
|
||||||
<avalonia:Plot.Series>
|
<avalonia:Plot.Series>
|
||||||
<avalonia:ScatterSeries Items="{Binding Points}" DataFieldX="X" DataFieldY="Y" />
|
<avalonia:ScatterSeries Items="{Binding Points}" DataFieldX="X" DataFieldY="Y" />
|
||||||
</avalonia:Plot.Series>
|
</avalonia:Plot.Series>
|
||||||
</avalonia:Plot>
|
</avalonia:Plot>-->
|
||||||
</Grid>
|
</Grid>
|
||||||
</Window>
|
</Window>
|
@ -1,7 +1,8 @@
|
|||||||
using ScottPlot;
|
using ScottPlot;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Drawing;
|
|
||||||
using Point = KMeansBase.Point;
|
using Point = KMeansBase.Point;
|
||||||
|
using ScottPlot.Legends;
|
||||||
|
using Color = ScottPlot.Color;
|
||||||
|
|
||||||
namespace kMeans;
|
namespace kMeans;
|
||||||
|
|
||||||
@ -10,24 +11,29 @@ public static class Helper
|
|||||||
public static Plot CreatePlot(IEnumerable<Point> points, IEnumerable<Point> centroids)
|
public static Plot CreatePlot(IEnumerable<Point> points, IEnumerable<Point> centroids)
|
||||||
{
|
{
|
||||||
var plot = new Plot();
|
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 colors = new Dictionary<int, Color>();
|
||||||
var colorGroups = points.GroupBy(x => x.ClusterId);
|
var colorGroups = points.GroupBy(x => x.ClusterId);
|
||||||
foreach (var clusterGroup in colorGroups)
|
foreach (var clusterGroup in colorGroups)
|
||||||
{
|
{
|
||||||
var color = plot.GetNextColor();
|
var color = plot.Add.NextColor;
|
||||||
colors.Add(clusterGroup.Key, color);
|
colors.Add(clusterGroup.Key, color);
|
||||||
var xs = clusterGroup.Select(p => p.X).ToArray();
|
var xs = clusterGroup.Select(p => p.X).ToArray();
|
||||||
var ys = clusterGroup.Select(p => p.Y).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;
|
const float size = 10f;
|
||||||
foreach (var (x, y, clusterId) in centroids)
|
foreach (var (x, y, clusterId) in centroids)
|
||||||
{
|
{
|
||||||
var color = colors.TryGetValue(clusterId, out var c) ? c : plot.GetNextColor();
|
var color = colors.TryGetValue(clusterId, out var c) ? c : plot.Add.NextColor;
|
||||||
plot.AddScatterPoints(new[] { x }, new[] { y }, color, size, marker, $"ClusterId: {clusterId}");
|
var scatter = plot.Add.Scatter(new[] { x }, new[] { y }, color);
|
||||||
|
scatter.MarkerStyle.Size = size;
|
||||||
|
scatter.MarkerStyle.Shape = marker;
|
||||||
|
scatter.Label = $"ClusterId: {clusterId}";
|
||||||
}
|
}
|
||||||
|
|
||||||
return plot;
|
return plot;
|
||||||
@ -35,7 +41,7 @@ public static class Helper
|
|||||||
|
|
||||||
public static void ExportPlot(Plot plot, string path)
|
public static void ExportPlot(Plot plot, string path)
|
||||||
{
|
{
|
||||||
plot.SaveFig(path);
|
plot.SavePng(path, 1000, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void PreviewPlot(string path)
|
public static void PreviewPlot(string path)
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="ScottPlot" Version="4.1.30" />
|
<PackageReference Include="ScottPlot" Version="5.0.6-beta" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user