Skip to content

Commit 5acfbe1

Browse files
committed
Add hover view when mousing over Estimated Compression size that shows all the database results for each compression algorithm
1 parent 0c4a82c commit 5acfbe1

File tree

5 files changed

+187
-12
lines changed

5 files changed

+187
-12
lines changed

CompactGUI/Components/Converters/IValueConverters.vb

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,63 @@ Public Class WindowScalingConverter : Implements IValueConverter
151151
Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, culture As CultureInfo) As Object Implements IValueConverter.ConvertBack
152152
Throw New NotImplementedException()
153153
End Function
154-
End Class
154+
End Class
155+
156+
157+
Public Class WikiCompressionLevelAbbreviatedConverter : Implements IValueConverter
158+
159+
Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As CultureInfo) As Object Implements IValueConverter.Convert
160+
Dim clvl = CType(value, Integer)
161+
Select Case clvl
162+
Case 0 : Return "X4"
163+
Case 1 : Return "X8"
164+
Case 2 : Return "X16"
165+
Case 3 : Return "LZX"
166+
End Select
167+
End Function
168+
169+
Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, culture As CultureInfo) As Object Implements IValueConverter.ConvertBack
170+
Throw New NotImplementedException()
171+
End Function
172+
End Class
173+
174+
175+
Public Class RatioConverter : Implements IMultiValueConverter
176+
177+
Public Function Convert(values As Object(), targetType As Type, parameter As Object, culture As CultureInfo) As Object Implements IMultiValueConverter.Convert
178+
If values.Length <> 2 Then
179+
Throw New ArgumentException("Two values should be provided.")
180+
End If
181+
182+
Dim afterBytes As Long
183+
Dim beforeBytes As Long
184+
185+
If Not Long.TryParse(values(0).ToString(), afterBytes) OrElse Not Long.TryParse(values(1).ToString(), beforeBytes) Then
186+
Throw New ArgumentException("Both values should be of type double.")
187+
End If
188+
189+
Dim ratio = Math.Round((1 - afterBytes / beforeBytes) * 100, 0)
190+
191+
Return $"{ratio}%"
192+
End Function
193+
194+
Public Function ConvertBack(value As Object, targetTypes As Type(), parameter As Object, culture As CultureInfo) As Object() Implements IMultiValueConverter.ConvertBack
195+
Throw New NotImplementedException("ConvertBack is not implemented.")
196+
End Function
197+
198+
End Class
199+
200+
201+
Public Class NonZeroToVisConverter : Implements IValueConverter
202+
203+
Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As CultureInfo) As Object Implements IValueConverter.Convert
204+
Dim clvl = CType(value, Integer)
205+
If clvl = 0 Then Return Visibility.Collapsed
206+
207+
Return Visibility.Visible
208+
End Function
209+
210+
Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, culture As CultureInfo) As Object Implements IValueConverter.ConvertBack
211+
Throw New NotImplementedException()
212+
End Function
213+
End Class

CompactGUI/Models/SharedObjects.vb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11

2+
Imports System.Collections.ObjectModel
3+
24
Imports Microsoft.Toolkit.Mvvm.ComponentModel
35
''' <summary>
46
''' Shared objects between multiple code regions
@@ -15,6 +17,7 @@ Public Class ActiveFolder : Inherits ObservableObject
1517
Public Property CompressedBytes As Long
1618
Public Property SelectedCompressionMode = 0
1719
Public Property CompressionConfidence = -1
20+
Public Property WikiCompressionResults As New ObservableCollection(Of CompressionResult)
1821

1922
Public Property IsFreshlyCompressed As Boolean = False
2023

@@ -68,12 +71,12 @@ End Class
6871

6972

7073
' Used to hold compression results from parsed existing wiki file (above)
71-
Public Class CompressionResult
74+
Public Class CompressionResult : Inherits ObservableObject
7275

73-
Public CompType As Integer
74-
Public BeforeBytes As Long
75-
Public AfterBytes As Long
76-
Public TotalResults As Integer
76+
Public Property CompType As Integer
77+
Public Property BeforeBytes As Long
78+
Public Property AfterBytes As Long
79+
Public Property TotalResults As Integer
7780

7881
End Class
7982

CompactGUI/Models/WikiHandler.vb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Public Class WikiHandler
2828

2929
End Function
3030

31-
Shared Async Function ParseData(appid As Integer) As Task(Of (estimatedRatio As Decimal, confidence As Integer, poorlyCompressedList As Dictionary(Of String, Integer)))
31+
Shared Async Function ParseData(appid As Integer) As Task(Of (estimatedRatio As Decimal, confidence As Integer, poorlyCompressedList As Dictionary(Of String, Integer), compressionResults As List(Of CompressionResult)))
3232

3333
Dim JSONFile As IO.FileInfo = New IO.FileInfo(filePath)
3434
If Not JSONFile.Exists Then Return Nothing
@@ -46,11 +46,13 @@ Public Class WikiHandler
4646
estimatedRatio += ratio * compressionResult.TotalResults
4747
Next
4848

49+
workingGame.CompressionResults.Sort(Function(x, y) x.CompType.CompareTo(y.CompType))
50+
4951
'TODO: Adjust this return to account for selected level of aggressiveness in settings
5052
'Dim poorlyCompressedExt = workingGame.PoorlyCompressedExtensions.Where(Function(k) k.Value > 100).Select(Function(k) k.Key)
5153

5254
estimatedRatio /= totaldataPoints
53-
Return (estimatedRatio, workingGame.Confidence, workingGame.PoorlyCompressedExtensions)
55+
Return (estimatedRatio, workingGame.Confidence, workingGame.PoorlyCompressedExtensions, workingGame.CompressionResults)
5456

5557
End Function
5658

CompactGUI/ViewModels/MainViewModel.vb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,10 @@ Public Class MainViewModel : Inherits ObservableObject
208208
'TODO: Modify the 100 cutoff based on level of aggressiveness selected by user in settings
209209
ActiveFolder.WikiPoorlyCompressedFiles = res.poorlyCompressedList.Where(Function(k) k.Value > 100 AndAlso k.Key <> "").Select(Function(k) k.Key).ToList
210210
ActiveFolder.CompressionConfidence = res.confidence
211+
For Each item In res.compressionResults
212+
ActiveFolder.WikiCompressionResults.Add(item)
213+
Next
214+
211215
Return CLng(ActiveFolder.UncompressedBytes * res.estimatedRatio)
212216

213217
End Function

CompactGUI/Views/MainWindow.xaml

Lines changed: 111 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@
2424
<local:CompressionLevelAbbreviatedConverter x:Key="CompressionLevelAbbreviatedConverter"/>
2525
<local:ConfidenceIntToColorConverter x:Key="ConfidenceIntToColorConverter"/>
2626
<local:ConfidenceIntToStringConverter x:Key="ConfidenceIntToStringConverter"/>
27+
<local:WikiCompressionLevelAbbreviatedConverter x:Key="WikiCompressionLevelAbbreviatedConverter" />
28+
<local:RatioConverter x:Key="RatioConverter" />
29+
<local:NonZeroToVisConverter x:Key="NonZeroToVisConverter" />
2730

28-
</ResourceDictionary>
31+
</ResourceDictionary>
2932

3033
</Window.Resources>
3134

@@ -790,11 +793,115 @@
790793
<TextBlock x:Name="LeftLabel" Text="current size" FontFamily="Segoe UI Semibold" FontSize="17" Foreground="#BAC2CA" HorizontalAlignment="Center"/>
791794
</StackPanel>
792795

793-
<StackPanel Orientation="Vertical" Grid.Column="3" HorizontalAlignment="Center" VerticalAlignment="Center">
794-
<TextBlock Text="{Binding ActiveFolder.CompressedBytes, Converter={StaticResource BytesToReadableConverter}}" d:Text="29.7 GB" FontFamily="Segoe UI Semibold" FontSize="31" Foreground="White" HorizontalAlignment="Center"/>
795-
<TextBlock x:Name="RightLabel" Text="estimated size" FontFamily="Segoe UI Semibold" FontSize="17" Foreground="#BAC2CA" HorizontalAlignment="Center"/>
796+
<StackPanel Orientation="Vertical" Grid.Column="3" HorizontalAlignment="Center" VerticalAlignment="Center" Cursor="Help">
797+
<TextBlock Text="{Binding ActiveFolder.CompressedBytes, Converter={StaticResource BytesToReadableConverter}}" d:Text="29.7 GB" FontFamily="Segoe UI Semibold" FontSize="31" Foreground="White" HorizontalAlignment="Center"/>
798+
<TextBlock x:Name="RightLabel" Text="estimated size" FontFamily="Segoe UI Semibold" FontSize="17" Foreground="#BAC2CA" HorizontalAlignment="Center"/>
799+
<StackPanel.ToolTip>
800+
<ToolTip Visibility="{Binding ActiveFolder.WikiCompressionResults.Count, Converter={StaticResource NonZeroToVisConverter}}" >
801+
<ToolTip.Resources>
802+
<Style TargetType="ToolTip">
803+
<Setter Property="ContentTemplate">
804+
<Setter.Value>
805+
<DataTemplate>
806+
<Border BorderBrush="Gray" Padding="10"
807+
BorderThickness="1" Background="White" CornerRadius="5">
808+
809+
<ContentPresenter Content="{Binding}" />
810+
</Border>
811+
</DataTemplate>
812+
</Setter.Value>
813+
</Setter>
814+
<Setter Property="MaxWidth"
815+
Value="400" />
816+
<Setter Property="Width"
817+
Value="400" />
818+
<Setter Property="Background"
819+
Value="Transparent" />
820+
<Setter Property="BorderThickness"
821+
Value="0" />
822+
</Style>
823+
824+
</ToolTip.Resources>
825+
<Grid >
826+
<Grid.RowDefinitions>
827+
<RowDefinition Height="30" />
828+
<RowDefinition Height="auto" />
829+
</Grid.RowDefinitions>
830+
831+
<StackPanel VerticalAlignment="Center" Orientation="Horizontal"
832+
Grid.Row="0">
833+
834+
<TextBlock Text="Algorithm" FontFamily="Segoe UI " FontSize="13" Foreground="#4A4A4A" Width="110" Margin="10,0" />
835+
<TextBlock Text="Before" TextAlignment="Right" FontFamily="Segoe UI " FontSize="13" Foreground="#4A4A4A" Width="60"/>
836+
<TextBlock Text="After" TextAlignment="Right" FontFamily="Segoe UI " FontSize="13" Foreground="#4A4A4A" Width="80"/>
837+
<TextBlock Text="%Saved" TextAlignment="Right" FontFamily="Segoe UI " FontSize="13" Foreground="#4A4A4A" Width="80"/>
838+
</StackPanel>
839+
840+
<ListView Grid.Row="1" ItemsSource="{Binding ActiveFolder.WikiCompressionResults}"
841+
HorizontalAlignment="Left" HorizontalContentAlignment="Left"
842+
Background="Transparent"
843+
BorderThickness="0"
844+
Foreground="White"
845+
FontFamily="Segoe UI"
846+
FontSize="13"
847+
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
848+
ScrollViewer.VerticalScrollBarVisibility="Disabled">
849+
<ListView.ItemTemplate>
850+
<DataTemplate>
851+
852+
<StackPanel >
853+
<StackPanel Orientation="Horizontal">
854+
<Grid Margin="0,0,40,0" Height="30" >
855+
856+
<Grid.ColumnDefinitions>
857+
<ColumnDefinition Width="50" />
858+
<ColumnDefinition Width="auto" />
859+
</Grid.ColumnDefinitions>
860+
861+
<Border Grid.Column="0"
862+
Grid.ColumnSpan="2"
863+
CornerRadius="4"
864+
Background="#C03f4758" Margin="0" Padding="0" />
865+
866+
<TextBlock VerticalAlignment="Center" Grid.Column="0" Text="{Binding CompType, Converter={StaticResource WikiCompressionLevelAbbreviatedConverter}}" Margin="7,0,5,0" FontFamily="Segoe UI Semibold" FontSize="14" Foreground="White"/>
867+
868+
<Border Grid.Column="1" CornerRadius="4" Width="30"
869+
HorizontalAlignment="Center" Margin="0,0,-1,0"
870+
Background="#3f4758" Padding="2,0">
871+
<TextBlock VerticalAlignment="Center" Text="{Binding TotalResults}"
872+
TextAlignment="Center" Foreground="White"
873+
FontFamily="Segoe UI Semibold"
874+
Padding="0,2,0,0" FontSize="12"/>
875+
</Border>
876+
877+
878+
</Grid>
796879

880+
881+
<TextBlock VerticalAlignment="Center" Text="{Binding BeforeBytes, Converter={StaticResource BytesToReadableConverter}}" TextAlignment="Right" Width="60" Margin="0,0,10,0"/>
882+
<TextBlock VerticalAlignment="Center" Text="{Binding AfterBytes, Converter={StaticResource BytesToReadableConverter}}" TextAlignment="Right" Width="70" Margin="0,0,10,0"/>
883+
<TextBlock VerticalAlignment="Center" TextAlignment="Right" Width="70" Margin="0,0,10,0">
884+
<TextBlock.Text>
885+
<MultiBinding Converter="{StaticResource RatioConverter}">
886+
<Binding Path="AfterBytes" />
887+
<Binding Path="BeforeBytes" />
888+
</MultiBinding>
889+
</TextBlock.Text>
890+
</TextBlock>
891+
</StackPanel>
797892
</StackPanel>
893+
</DataTemplate>
894+
</ListView.ItemTemplate>
895+
</ListView>
896+
897+
</Grid>
898+
</ToolTip>
899+
900+
901+
902+
903+
</StackPanel.ToolTip>
904+
</StackPanel>
798905
<Grid Margin="0,3,0,0" x:Name="Confidence" Grid.Column="3" Grid.Row="1" Grid.ColumnSpan="1" HorizontalAlignment="Center" Width="110">
799906
<TextBlock HorizontalAlignment="Left" Text="confidence" FontFamily="Segoe UI " FontSize="13" Foreground="#50BAC2CA" />
800907
<TextBlock HorizontalAlignment="Right" Text="{Binding ActiveFolder.CompressionConfidence, Converter={StaticResource ConfidenceIntToStringConverter}}" FontFamily="Segoe UI SemiBold" FontSize="13" Foreground="{Binding ActiveFolder.CompressionConfidence, Converter={StaticResource ConfidenceIntToColorConverter}}" />

0 commit comments

Comments
 (0)