From 3830d9ee64fc66106b43d85e83003c2cd9095a69 Mon Sep 17 00:00:00 2001 From: Li Date: Sat, 29 Jun 2024 20:07:49 +1000 Subject: [PATCH] Ensure stat graphs take up entire width --- .../Presentation/StatGraphCardContent.razor | 28 +++++++++++++++++-- LiftLog.Ui/wwwroot/app-utils.js | 4 +++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/LiftLog.Ui/Shared/Presentation/StatGraphCardContent.razor b/LiftLog.Ui/Shared/Presentation/StatGraphCardContent.razor index 37808c03..2b4d376f 100644 --- a/LiftLog.Ui/Shared/Presentation/StatGraphCardContent.razor +++ b/LiftLog.Ui/Shared/Presentation/StatGraphCardContent.razor @@ -6,7 +6,9 @@ @implements IDisposable @inject IThemeProvider ThemeProvider -
+@inject IJSRuntime JSRuntime + +
@if (ShowTitle) { @@ -14,7 +16,7 @@ } @if (IsLoading) { -
+
@@ -29,7 +31,10 @@ else TItem="TimeTrackedStatistic" Title="" Options="options" - XAxisType="XAxisType.Datetime"> + Width="@width" + Height="230" + XAxisType="XAxisType.Datetime" + @ref="chart"> @foreach(var statistics in Statistics) { @@ -66,6 +71,12 @@ else private bool _disposed = false; + private ElementReference cardContent; + private ApexChart chart = null!; + + private string width = "100%"; + + private ApexChartOptions options = null!; @@ -191,6 +202,17 @@ else }); } + protected override async Task OnAfterRenderAsync(bool firstRender) + { + if (firstRender) + { + var cardContentWidth = await JSRuntime.InvokeAsync("AppUtils.getWidth", cardContent); + width = $"{cardContentWidth}px"; + await InvokeAsync(StateHasChanged); + } + await base.OnAfterRenderAsync(firstRender); + } + private string GetColorString(uint color) => "#" + color.ToString("X").Substring(2, 6); private string WeightSuffix => UseImperial ? " lbs" : " kg"; diff --git a/LiftLog.Ui/wwwroot/app-utils.js b/LiftLog.Ui/wwwroot/app-utils.js index 3b8fd348..c0ba8eb9 100644 --- a/LiftLog.Ui/wwwroot/app-utils.js +++ b/LiftLog.Ui/wwwroot/app-utils.js @@ -62,6 +62,10 @@ AppUtils.getValue = function (element) { return element.value; } +AppUtils.getWidth = function (element) { + return element?.offsetWidth ?? 0; +} + AppUtils.isOpen = function (element) { return element.open;