Skip to content

Commit

Permalink
Ensure stat graphs take up entire width
Browse files Browse the repository at this point in the history
  • Loading branch information
LiamMorrow committed Jun 29, 2024
1 parent 68ced3d commit 3830d9e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
28 changes: 25 additions & 3 deletions LiftLog.Ui/Shared/Presentation/StatGraphCardContent.razor
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@
@implements IDisposable

@inject IThemeProvider ThemeProvider
<div class="flex flex-col gap-2 items-start">
@inject IJSRuntime JSRuntime

<div class="flex flex-col gap-2 items-start" @ref="cardContent" >
@if (ShowTitle)
{

<ItemTitle Title="@(Title)" />
}
@if (IsLoading)
{
<div class="flex flex-col justify-center h-full gap-4 text-on-surface">
<div class="flex flex-col justify-center h-full gap-4 text-on-surface mx-auto">
<div>
<md-circular-progress aria-label="Stats progress" indeterminate four-color></md-circular-progress>
</div>
Expand All @@ -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)
{
Expand Down Expand Up @@ -66,6 +71,12 @@ else

private bool _disposed = false;

private ElementReference cardContent;
private ApexChart<TimeTrackedStatistic> chart = null!;

private string width = "100%";



private ApexChartOptions<TimeTrackedStatistic> options = null!;

Expand Down Expand Up @@ -191,6 +202,17 @@ else
});
}

protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
var cardContentWidth = await JSRuntime.InvokeAsync<double>("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";
Expand Down
4 changes: 4 additions & 0 deletions LiftLog.Ui/wwwroot/app-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 3830d9e

Please sign in to comment.