mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 14:26:30 +00:00
better view for class distribution
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
<UserControl x:Class="Azaion.Dataset.Controls.ClassDistribution"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:controls="clr-namespace:Azaion.Dataset.Controls"
|
||||
xmlns:dto="clr-namespace:Azaion.Common.DTO;assembly=Azaion.Common"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="300" d:DesignWidth="400"
|
||||
FontFamily="Segoe UI">
|
||||
<UserControl.Resources>
|
||||
<controls:ProportionToWidthConverter x:Key="ProportionToWidthConverter"/>
|
||||
</UserControl.Resources>
|
||||
<ListView ItemsSource="{Binding Items, RelativeSource={RelativeSource AncestorType=controls:ClassDistribution}}"
|
||||
BorderThickness="0" Background="#FF333333" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
|
||||
<ListView.ItemContainerStyle>
|
||||
<Style TargetType="ListViewItem">
|
||||
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
|
||||
<Setter Property="Focusable" Value="False"/>
|
||||
<Setter Property="Margin" Value="0,1"/>
|
||||
</Style>
|
||||
</ListView.ItemContainerStyle>
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type dto:ClusterDistribution}">
|
||||
<Grid Height="18" x:Name="ItemGrid"> <!-- Give the Grid a name -->
|
||||
<Border HorizontalAlignment="Left" VerticalAlignment="Stretch">
|
||||
<Border.Width>
|
||||
<MultiBinding Converter="{StaticResource ProportionToWidthConverter}">
|
||||
<Binding Path="BarWidth"/>
|
||||
<Binding Path="ActualWidth" ElementName="ItemGrid"/>
|
||||
</MultiBinding>
|
||||
</Border.Width>
|
||||
<Border.Background>
|
||||
<SolidColorBrush Color="{Binding Color}" Opacity="0.5"/>
|
||||
</Border.Background>
|
||||
</Border>
|
||||
<TextBlock Text="{Binding Label}" VerticalAlignment="Center" Margin="5,0,0,0" Foreground="White" FontSize="12"/>
|
||||
<TextBlock Text="{Binding ClassCount}" VerticalAlignment="Center" HorizontalAlignment="Right" Margin="0,0,5,0" Foreground="White" FontSize="12"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
</ListView>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,22 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using Azaion.Common.DTO;
|
||||
|
||||
namespace Azaion.Dataset.Controls;
|
||||
|
||||
public partial class ClassDistribution : UserControl
|
||||
{
|
||||
public static readonly DependencyProperty ItemsProperty =
|
||||
DependencyProperty.Register(nameof(Items), typeof(IEnumerable<ClusterDistribution>), typeof(ClassDistribution), new PropertyMetadata(null));
|
||||
|
||||
public IEnumerable<ClusterDistribution> Items
|
||||
{
|
||||
get => (IEnumerable<ClusterDistribution>)GetValue(ItemsProperty);
|
||||
set => SetValue(ItemsProperty, value);
|
||||
}
|
||||
|
||||
public ClassDistribution()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace Azaion.Dataset.Controls
|
||||
{
|
||||
public class ProportionToWidthConverter : IMultiValueConverter
|
||||
{
|
||||
private const double MinPixelBarWidth = 2.0;
|
||||
|
||||
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (values == null || values.Length < 2 ||
|
||||
!(values[0] is double proportion) ||
|
||||
!(values[1] is double containerActualWidth))
|
||||
return MinPixelBarWidth; // Default or fallback width
|
||||
|
||||
if (containerActualWidth <= 0 || !double.IsFinite(containerActualWidth) || double.IsNaN(containerActualWidth))
|
||||
return MinPixelBarWidth; // Container not ready or invalid
|
||||
|
||||
double calculatedWidth = proportion * containerActualWidth;
|
||||
|
||||
if (proportion >= 0 && calculatedWidth < MinPixelBarWidth)
|
||||
return MinPixelBarWidth;
|
||||
|
||||
return Math.Max(0, calculatedWidth); // Ensure width is not negative
|
||||
}
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user