Skip to content

Commit

Permalink
tabbed interface
Browse files Browse the repository at this point in the history
  • Loading branch information
aloneguid committed Jan 9, 2024
1 parent 706cd6e commit e9ce221
Show file tree
Hide file tree
Showing 13 changed files with 216 additions and 201 deletions.
2 changes: 1 addition & 1 deletion src/Parquet.Floor/App.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
Source="avares://Avalonia.Controls.TreeDataGrid/Themes/Fluent.axaml"/>
<actipro:ModernTheme>
<actipro:ModernTheme.Definition>
<generation:ThemeDefinition UserInterfaceDensity="Spacious" />
<generation:ThemeDefinition UserInterfaceDensity="Normal" />
</actipro:ModernTheme.Definition>
</actipro:ModernTheme>
<actipro:ModernTheme Includes="NativeDataGrid"/>
Expand Down
66 changes: 66 additions & 0 deletions src/Parquet.Floor/Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using Parquet.Meta;

namespace Parquet.Floor {
static class Extensions {
public static string ToSimpleString(this LogicalType? lt) {
if(lt == null)
return string.Empty;

if(lt.UUID != null)
return "UUID";

if(lt.STRING != null)
return "STRING";

if(lt.MAP != null)
return "MAP";

if(lt.LIST != null)
return "LIST";

if(lt.ENUM != null)
return "ENUM";

if(lt.DECIMAL != null)
return $"DECIMAL (precision: {lt.DECIMAL.Precision}, scale: {lt.DECIMAL.Scale})";

if(lt.DATE != null)
return $"DATE";

if(lt.TIME != null) {
string unit = lt.TIME.Unit.MICROS != null
? "MICROS"
: lt.TIME.Unit.MILLIS != null
? "MILLIS"
: "NANOS";
return $"TIME (unit: {unit}, isAdjustedToUTC: {lt.TIME.IsAdjustedToUTC})";
}

if(lt.TIMESTAMP != null) {
string unit = lt.TIMESTAMP.Unit.MICROS != null
? "MICROS"
: lt.TIMESTAMP.Unit.MILLIS != null
? "MILLIS"
: "NANOS";
return $"TIMESTAMP (unit: {unit}, isAdjustedToUTC: {lt.TIMESTAMP.IsAdjustedToUTC})";
}

if(lt.INTEGER != null)
return $"INTEGER (bitWidth: {lt.INTEGER.BitWidth}, isSigned: {lt.INTEGER.IsSigned})";

if(lt.UNKNOWN != null)
return "UNKNOWN";

if(lt.JSON != null)
return "JSON";

if(lt.BSON != null)
return "BSON";

if(lt.UUID != null)
return "UUID";

return "?";
}
}
}
6 changes: 3 additions & 3 deletions src/Parquet.Floor/Parquet.Floor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
</ItemGroup>

<ItemGroup>
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0.6" />

<PackageReference Include="ActiproSoftware.Controls.Avalonia" Version="23.1.2" />
<PackageReference Include="ActiproSoftware.Controls.Avalonia.Themes.DataGrid" Version="23.1.2" />
<PackageReference Include="Avalonia.Desktop" Version="11.0.6" />
Expand All @@ -39,9 +42,6 @@
<PackageReference Include="Avalonia.Controls.TreeDataGrid" Version="11.0.2" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.6" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />

<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0.6" />
<PackageReference Include="Projektanker.Icons.Avalonia" Version="9.0.1" />
<PackageReference Include="Projektanker.Icons.Avalonia.FontAwesome" Version="9.0.1" />

Expand Down
29 changes: 14 additions & 15 deletions src/Parquet.Floor/Styles.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,19 @@
<!-- status bar -->

<Style Selector="StackPanel.status-bar">
<Setter Property="Margin" Value="3"/>
</Style>
<Setter Property="Margin" Value="3,0,0,0"/>

<Style Selector="StackPanel.status-bar TextBlock.data">
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="FontSize" Value="15"/>
</Style>
<Style Selector="^ TextBlock.data">
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="FontSize" Value="15"/>
</Style>

<Style Selector="^ TextBlock.sep">
<Setter Property="FontSize" Value="10"/>
<Setter Property="Opacity" Value="0.8"/>
<Setter Property="Padding" Value="9,4,9,0"/>
</Style>

<Style Selector="StackPanel.status-bar TextBlock.sep">
<Setter Property="FontSize" Value="10"/>
<Setter Property="Opacity" Value="0.8"/>
<Setter Property="Padding" Value="9,4,9,0"/>
</Style>


Expand Down Expand Up @@ -99,6 +100,7 @@
<Setter Property="FontSize" Value="25"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Opacity" Value="0.8"/>
<Setter Property="BorderThickness" Value="0"/>
</Style>

<Style Selector="^ Button:pointerover">
Expand All @@ -115,7 +117,7 @@
<Style Selector="TextBlock.data-cell">
<Setter Property="FontSize" Value="12"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Padding" Value="2"/>
<Setter Property="Padding" Value="5,0,5,0"/>
</Style>

<Style Selector="TextBlock.data-cell-null">
Expand All @@ -142,10 +144,6 @@
<Setter Property="FontWeight" Value="Bold"/>
</Style>

<!-- Thinner expander -->

<!-- todo -->

<!-- raw meta -->
<Style Selector="StackPanel.raw-meta-section StackPanel">
<Setter Property="Margin" Value="4"/>
Expand All @@ -168,6 +166,7 @@

<Style Selector="^ TextBlock">
<Setter Property="Margin" Value="0"/>
<Setter Property="Padding" Value="0"/>
<Setter Property="FontSize" Value="12"/>
</Style>

Expand Down
12 changes: 9 additions & 3 deletions src/Parquet.Floor/ViewModels/DataViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Collections.ObjectModel;
using System.Linq;
using Parquet.Meta;
using Avalonia.Threading;

namespace Parquet.Floor.ViewModels;

Expand All @@ -30,18 +31,23 @@ public partial class DataViewModel : ViewModelBase {
public DataViewModel() {
#if DEBUG
if(Design.IsDesignMode) {
Data = DesignData.Data;
File = new FileViewModel {
Schema = DesignData.Schema,
RowCount = 1012,
RowGroupCount = 3,
CreatedBy = "Parquet.Floor",
};
Data = DesignData.Data;
}
#endif
}

public async Task InitReaderAsync(Stream fileStream) {
public async Task InitReaderAsync(FileViewModel? file, Stream fileStream) {
ParquetSerializer.UntypedResult fd = await ParquetSerializer.DeserializeAsync(fileStream);
Data = fd.Data;

Dispatcher.UIThread.Invoke(() => {
File = file;
Data = fd.Data;
});
}
}
63 changes: 3 additions & 60 deletions src/Parquet.Floor/ViewModels/FieldModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ public FieldModel(Field field) {

public string? FieldId => Field.SchemaElement?.FieldId?.ToString();

public string? LogicalType => FormatLogicalType();
public string? LogicalType => Field.SchemaElement?.LogicalType?.ToSimpleString();

public string DefinitionLevel => Field.MaxDefinitionLevel.ToString();

public string RepetitionLevel => Field.MaxRepetitionLevel.ToString();

public bool IsExpanded { get; set; } = true;

public List<FieldModel> Children => Field switch {
StructField sf => sf.Fields.Select(f => new FieldModel(f)).ToList(),
MapField mf => new List<FieldModel> {
Expand All @@ -62,63 +64,4 @@ public FieldModel(Field field) {
return "unknown";
}
}

private string FormatLogicalType() {

LogicalType? lt = Field.SchemaElement?.LogicalType;

if(lt == null)
return string.Empty;

if(lt.UUID != null)
return "UUID";

if(lt.STRING != null)
return "STRING";

if(lt.MAP != null)
return "MAP";

if(lt.LIST != null)
return "LIST";

if(lt.ENUM != null)
return "ENUM";

if(lt.DECIMAL != null)
return $"DECIMAL (precision: {lt.DECIMAL.Precision}, scale: {lt.DECIMAL.Scale})";

if(lt.DATE != null)
return $"DATE";

if(lt.TIME != null) {
string unit = lt.TIME.Unit.MICROS != null
? "MICROS"
: lt.TIME.Unit.MILLIS != null
? "MILLIS"
: "NANOS";
return $"TIME (unit: {unit}, isAdjustedToUTC: {lt.TIME.IsAdjustedToUTC})";
}

if(lt.TIMESTAMP != null)
return "TIMESTAMP";

if(lt.INTEGER != null)
return $"INTEGER (bitWidth: {lt.INTEGER.BitWidth}, isSigned: {lt.INTEGER.IsSigned})";

if(lt.UNKNOWN != null)
return "UNKNOWN";

if(lt.JSON != null)
return "JSON";

if(lt.BSON != null)
return "BSON";

if(lt.UUID != null)
return "UUID";

return "?";
}

}
3 changes: 1 addition & 2 deletions src/Parquet.Floor/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ private async Task LoadAsync(Stream fileStream) {
};
}
Schema.InitSchema(File.Schema);
Data.File = File;
await Data.InitReaderAsync(_fileStream);
await Data.InitReaderAsync(File, _fileStream);

} catch(Exception ex) {
HasError = true;
Expand Down
2 changes: 1 addition & 1 deletion src/Parquet.Floor/ViewModels/SchemaViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void InitSchema(ParquetSchema? schema) {
Columns = {
new HierarchicalExpanderColumn<FieldModel>(
new TextColumn<FieldModel, string>("Name", x => x.Name),
x => x.Children),
x => x.Children, isExpandedSelector: x => x.IsExpanded),
//new TextColumn<FieldModel, string>("Num children", x => x.NumChildren),
new TextColumn<FieldModel, string>("Type", x => x.Type),
new TextColumn<FieldModel, string>("Converted type", x => x.ConvertedType),
Expand Down
45 changes: 18 additions & 27 deletions src/Parquet.Floor/Views/DataView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,29 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="clr-namespace:Parquet.Floor.ViewModels"
xmlns:pqs="clr-namespace:Parquet.Schema;assembly=Parquet"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
xmlns:i="https://github.com/projektanker/icons.avalonia"
mc:Ignorable="d" d:DesignWidth="400" d:DesignHeight="450"
x:Class="Parquet.Floor.Views.DataView"
x:DataType="vm:DataViewModel">
<Design.DataContext>
<vm:DataViewModel />
</Design.DataContext>

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>

<DataGrid AutoGenerateColumns="False" x:Name="grid"
CanUserSortColumns="True"
CanUserResizeColumns="True"
CanUserReorderColumns="True"
GridLinesVisibility="Horizontal"
IsReadOnly="True"
ItemsSource="{Binding Data}">
</DataGrid>

<StackPanel Orientation="Horizontal" Grid.Row="1" Classes="status-bar">
<TextBlock Text="{Binding File.RowCount}" Classes="data" ToolTip.Tip="Total row count"/>
<TextBlock Text="|" Classes="sep"/>
<TextBlock Text="{Binding File.RowGroupCount}" Classes="data" ToolTip.Tip="Row group count"/>
<TextBlock Text="|" Classes="sep"/>
<TextBlock Text="{Binding File.CreatedBy}" Classes="data"
FontSize="10" Padding="0,4,0,0"
FontStyle="Italic"
ToolTip.Tip="Creator of this file"/>
</StackPanel>
</Grid>
<DataGrid x:Name="grid"
AutoGenerateColumns="False"
CanUserSortColumns="True"
CanUserResizeColumns="True"
CanUserReorderColumns="True"
GridLinesVisibility="Horizontal"
IsReadOnly="True"
ItemsSource="{Binding Data}"
CellPointerPressed="DataGrid_CellPointerPressed">
<DataGrid.Columns>
<DataGridTextColumn Header="First Name" Width="*"
Binding="{Binding [id]}"/>
<DataGridTextColumn Header="Last Name" Width="*"
Binding="{Binding [name]}" />
</DataGrid.Columns>
</DataGrid>

</UserControl>
9 changes: 7 additions & 2 deletions src/Parquet.Floor/Views/DataView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Avalonia.Data;
using Avalonia.Threading;
using Parquet.Floor.ViewModels;
using Parquet.Floor.Views.Templates;
using Parquet.Schema;

namespace Parquet.Floor.Views {
Expand All @@ -19,7 +20,7 @@ public DataView() {

protected override void OnDataContextChanged(EventArgs e) {

if(ViewModel != null) {
if(ViewModel != null) {
ViewModel.PropertyChanged += ViewModel_PropertyChanged;
}

Expand All @@ -33,6 +34,7 @@ protected override void OnDataContextChanged(EventArgs e) {
? null
: schema.Fields.Select(f => new DataGridTemplateColumn {
Header = f.Name,
HeaderTemplate = new DataViewHeaderTemplate(f),
CellTemplate = new DataViewCellTemplate(f)
}).Cast<DataGridColumn>().ToList();
}
Expand All @@ -54,9 +56,12 @@ private void ViewModel_PropertyChanged(object? sender, PropertyChangedEventArgs
grid.Columns.Add(c);
}
}
}
}
});
}

private void DataGrid_CellPointerPressed(object? sender, Avalonia.Controls.DataGridCellPointerPressedEventArgs e) {
grid.SelectedItem = null;
}
}
}
Loading

0 comments on commit e9ce221

Please sign in to comment.