Skip to content

Commit

Permalink
🎨 Add vertical grid bars on charts, and try to improve the UI memory …
Browse files Browse the repository at this point in the history
…usage.

Memory seems to leaks from the sensor chart refreshes, but it somehow does not seem to come from C# objects directly. Quite mysterious for now.
  • Loading branch information
hexawyz committed Apr 23, 2024
1 parent f4571c1 commit 29d0457
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
34 changes: 31 additions & 3 deletions Exo.Settings.Ui/Controls/LineChart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,40 @@ public Brush MinMaxLineStroke
public LineChart()
{
_seriesDataChanged = OnSeriesDataChanged;

Loading += OnLoading;
Loaded += OnLoaded;
Unloaded += OnUnloaded;
SizeChanged += OnSizeChanged;
}

private void OnSizeChanged(object sender, SizeChangedEventArgs e)
{
RefreshChart();
}

private void OnLoading(FrameworkElement sender, object args)
{
if (Series is { } series) series.Changed += _seriesDataChanged;
}

private void OnLoaded(object sender, RoutedEventArgs e) => RefreshChart();

private void OnUnloaded(object sender, RoutedEventArgs e)
{
if (Series is { } series) series.Changed -= _seriesDataChanged;
}

private static void OnSeriesChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) => ((LineChart)d).OnSeriesChanged(e);

private void OnSeriesChanged(DependencyPropertyChangedEventArgs e)
{
if (e.OldValue is ITimeSeries old) old.Changed -= _seriesDataChanged;
if (e.NewValue is ITimeSeries @new) @new.Changed += _seriesDataChanged;
RefreshChart();
if (IsLoaded)
{
if (e.NewValue is ITimeSeries @new) @new.Changed += _seriesDataChanged;
RefreshChart();
}
}

private static void OnScaleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) => ((LineChart)d).OnScaleChanged(e);
Expand Down Expand Up @@ -167,10 +192,13 @@ private void AttachParts()

private void RefreshChart()
{
if (Series is null)
if (Series is null || ActualHeight == 0 || ActualWidth == 0)
{
if (_strokePath is { }) _strokePath.Data = null;
if (_fillPath is { }) _fillPath.Data = null;
if (_horizontalGridLinesPath is { }) _horizontalGridLinesPath.Data = null;
if (_verticalGridLinesPath is { }) _verticalGridLinesPath.Data = null;
if (_minMaxLinesPath is { }) _minMaxLinesPath.Data = null;
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion Exo.Settings.Ui/Controls/LineChart.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
BorderThickness="{TemplateBinding BorderThickness}">
<Grid x:Name="PART_LayoutGrid">
<Path x:Name="PART_HorizontalGridLinesPath" Stroke="{TemplateBinding HorizontalGridStroke}" />
<Path x:Name="PART_VerticalGridLinesPath" Stroke="{TemplateBinding HorizontalGridStroke}" />
<Path x:Name="PART_VerticalGridLinesPath" Stroke="{TemplateBinding VerticalGridStroke}" />
<Path x:Name="PART_FillPath" Fill="{TemplateBinding AreaFill}" Opacity="{TemplateBinding AreaOpacity}" />
<Path x:Name="PART_StrokePath" Stroke="{TemplateBinding Stroke}" StrokeThickness="{TemplateBinding StrokeThickness}" StrokeLineJoin="{TemplateBinding StrokeLineJoin}" />
<Path x:Name="PART_MinMaxLinesPath" Stroke="{TemplateBinding MinMaxLineStroke}" />
Expand Down
3 changes: 2 additions & 1 deletion Exo.Settings.Ui/Exo.Settings.Ui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<PublishSingleFile>false</PublishSingleFile>
<ApplicationIcon>..\exo-icon.ico</ApplicationIcon>
<DefineConstants>$(DefineConstants);DISABLE_XAML_GENERATED_MAIN</DefineConstants>
<ServerGarbageCollection>false</ServerGarbageCollection>
</PropertyGroup>
<ItemGroup>
<None Remove="Controls\LineChart.xaml" />
Expand Down Expand Up @@ -49,7 +50,7 @@
<PackageReference Include="CommunityToolkit.WinUI.Converters" Version="8.1.240328-rc" />
<PackageReference Include="Grpc.Net.Client" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240311000" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240404000" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.3233" />
<PackageReference Include="protobuf-net.Grpc" Version="1.1.1" />
<Manifest Include="$(ApplicationManifest)" />
Expand Down
1 change: 1 addition & 0 deletions Exo.Settings.Ui/SensorsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
BorderBrush="{StaticResource ControlStrongStrokeColorDefaultBrush}"
BorderThickness="1"
HorizontalGridStroke="{ThemeResource AccentAcrylicBackgroundFillColorDefaultBrush}"
VerticalGridStroke="{ThemeResource AccentAcrylicBackgroundFillColorDefaultBrush}"
ScaleYMinimum="{Binding ScaleMinimumValue, Mode=OneWay}"
ScaleYMaximum="{Binding ScaleMaximumValue, Mode=OneWay}" />
<TextBlock
Expand Down

0 comments on commit 29d0457

Please sign in to comment.