-
Notifications
You must be signed in to change notification settings - Fork 1
Add lap timer UI controls page #554
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bracyw
wants to merge
21
commits into
develop
Choose a base branch
from
547-lap-timer-ui-controls
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
21452c8
#547 - add lap timer UI controls page
bracyw 0ac6a13
Merge branch 'develop' of github.com:Northeastern-Electric-Racing/Arg…
bracyw 5ba5ebe
#547 migrate DataTypeEnum to topic.utils
bracyw 06d4210
#547 remove unused code and dead declarations
bracyw 8593aa1
#547 apply prettier formatting
bracyw 6f565a3
#547 add OnPush change detection and remove explicit standalone
bracyw 8ea5492
Merge remote-tracking branch 'origin/develop' into 547-lap-timer-ui-c…
TheJeffreyKuo 53296ab
lap timer ui cleanup and local persistence
TheJeffreyKuo a94c131
Merge branch 'develop' into 547-lap-timer-ui-controls
TheJeffreyKuo 7781263
clean up
TheJeffreyKuo f2e6e1a
#547 - merge develop
TheJeffreyKuo 89f2164
remove redundant catch
TheJeffreyKuo 0421b8a
gauge-stat component
TheJeffreyKuo 097751a
fill lap-timer tile components to their grid cells
TheJeffreyKuo 9a2bc2d
fix session rename input binding to editingName signal
TheJeffreyKuo 663d647
prevent duplicate telemetry subs on restart after reset/pause
TheJeffreyKuo eded127
prevent SOC carry-over between sessions
TheJeffreyKuo 2aa20b9
trim sessions-panel CSS
TheJeffreyKuo 833a40c
remove dead lap-timer api stub and duplicate downloadAsFile util
TheJeffreyKuo df09641
Merge branch 'develop' into 547-lap-timer-ui-controls
TheJeffreyKuo 113530c
fix speed gauge by rendering SVG arc instead of ApexCharts
TheJeffreyKuo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
angular-client/src/components/gauge-stat/gauge-stat.component.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| .gauge-stat { | ||
| display: flex; | ||
| align-items: baseline; | ||
| justify-content: center; | ||
| gap: 4px; | ||
| padding: 8px 0; | ||
| } | ||
| .gauge-value { | ||
| font-family: var(--font-family); | ||
| font-variant-numeric: tabular-nums; | ||
| font-size: var(--font-size-xxl); | ||
| font-weight: 700; | ||
| color: var(--color-text-primary); | ||
| } | ||
| .gauge-unit { | ||
| font-size: var(--font-size-sm); | ||
| color: var(--color-text-secondary); | ||
| } |
4 changes: 4 additions & 0 deletions
4
angular-client/src/components/gauge-stat/gauge-stat.component.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| <div class="gauge-stat"> | ||
| <span class="gauge-value" [style.color]="color()">{{ value() | number: digitsInfo() }}</span> | ||
| <span class="gauge-unit">{{ unit() }}</span> | ||
| </div> |
19 changes: 19 additions & 0 deletions
19
angular-client/src/components/gauge-stat/gauge-stat.component.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { ChangeDetectionStrategy, Component, computed, input } from '@angular/core'; | ||
| import { DecimalPipe } from '@angular/common'; | ||
|
|
||
| @Component({ | ||
| selector: 'gauge-stat', | ||
| templateUrl: './gauge-stat.component.html', | ||
| styleUrl: './gauge-stat.component.css', | ||
| changeDetection: ChangeDetectionStrategy.OnPush, | ||
| imports: [DecimalPipe] | ||
| }) | ||
| export class GaugeStatComponent { | ||
| value = input.required<number>(); | ||
| unit = input<string>(''); | ||
| /** Optional color for the value; falls back to CSS default when empty. */ | ||
| color = input<string>(''); | ||
| precision = input<number>(0); | ||
|
|
||
| digitsInfo = computed(() => `1.0-${this.precision()}`); | ||
| } |
31 changes: 29 additions & 2 deletions
31
angular-client/src/components/half-gauge/half-gauge.component.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,32 @@ | ||
| .gauge-container { | ||
| position: relative; | ||
| display: flex; | ||
| align-items: center; | ||
| background-color: #2c2c2c; | ||
| border-radius: 10px; | ||
| justify-content: center; | ||
| width: 100%; | ||
| height: 100%; | ||
| } | ||
|
|
||
| .gauge-svg { | ||
| width: 100%; | ||
| height: 100%; | ||
| } | ||
|
|
||
| .gauge-track { | ||
| stroke: #1d1d1d; | ||
| } | ||
|
|
||
| .gauge-arc { | ||
| /* Smooth the arc between value updates without re-rendering the chart. */ | ||
| transition: stroke-dashoffset 0.1s linear; | ||
| } | ||
|
|
||
| .gauge-value { | ||
| position: absolute; | ||
| bottom: 12%; | ||
| left: 50%; | ||
| transform: translateX(-50%); | ||
| font-weight: 300; | ||
| color: #fafafa; | ||
| pointer-events: none; | ||
| } |
25 changes: 15 additions & 10 deletions
25
angular-client/src/components/half-gauge/half-gauge.component.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,16 @@ | ||
| <div class="gauge-container" [ngStyle]="{ width: widthpx, height: heightpx }"> | ||
| <apx-chart | ||
| [series]="chartOptions.series" | ||
| [colors]="chartOptions.colors" | ||
| [stroke]="chartOptions.stroke" | ||
| [chart]="chartOptions.chart" | ||
| [plotOptions]="chartOptions.plotOptions" | ||
| [labels]="chartOptions.labels" | ||
| [fill]="chartOptions.fill" | ||
| /> | ||
| <div class="gauge-container"> | ||
| <svg class="gauge-svg" [attr.viewBox]="viewBox()" preserveAspectRatio="xMidYMid meet"> | ||
| <path class="gauge-track" [attr.d]="arcPath()" [attr.stroke-width]="stroke()" fill="none" stroke-linecap="round" /> | ||
| <path | ||
| class="gauge-arc" | ||
| [attr.d]="arcPath()" | ||
| [attr.stroke]="color()" | ||
| [attr.stroke-width]="stroke()" | ||
| [attr.stroke-dasharray]="arcLength()" | ||
| [attr.stroke-dashoffset]="dashOffset()" | ||
| fill="none" | ||
| stroke-linecap="butt" | ||
| /> | ||
| </svg> | ||
| <span class="gauge-value" [style.font-size.px]="fontSizePx()">{{ label() }}</span> | ||
| </div> |
133 changes: 42 additions & 91 deletions
133
angular-client/src/components/half-gauge/half-gauge.component.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,99 +1,50 @@ | ||
| import { Component, Input, OnInit } from '@angular/core'; | ||
|
|
||
| import { ApexNonAxisChartSeries, ApexPlotOptions, ApexChart, ApexFill, NgApexchartsModule } from 'ng-apexcharts'; | ||
| import { NgStyle } from '@angular/common'; | ||
|
|
||
| export type ChartOptions = { | ||
| series: ApexNonAxisChartSeries; | ||
| chart: ApexChart; | ||
| labels: string[]; | ||
| plotOptions: ApexPlotOptions; | ||
| fill: ApexFill; | ||
| }; | ||
| import { ChangeDetectionStrategy, Component, computed, input } from '@angular/core'; | ||
|
|
||
| @Component({ | ||
| selector: 'half-gauge', | ||
| templateUrl: 'half-gauge.component.html', | ||
| styleUrls: ['half-gauge.component.css'], | ||
| standalone: true, | ||
| imports: [NgStyle, NgApexchartsModule] | ||
| templateUrl: './half-gauge.component.html', | ||
| styleUrls: ['./half-gauge.component.css'], | ||
| changeDetection: ChangeDetectionStrategy.OnPush | ||
| }) | ||
| export default class HalfGaugeComponent implements OnInit { | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| public chartOptions!: Partial<ChartOptions> | any; | ||
| @Input() current: number = 50; | ||
| @Input() min: number = 0; | ||
| @Input() max: number = 100; | ||
| @Input() unit: string = 'm/s'; | ||
| @Input() color: string = '#ff0000'; | ||
| @Input() size: number = 200; | ||
| export default class HalfGaugeComponent { | ||
| current = input<number>(50); | ||
| min = input<number>(0); | ||
| max = input<number>(100); | ||
| unit = input<string>('m/s'); | ||
| color = input<string>('#ff0000'); | ||
| size = input<number>(200); | ||
|
|
||
| // Stroke thickness as a fraction of width, matching the old radialBar look. | ||
| private readonly strokeWidth = computed(() => this.size() * 0.1); | ||
| private readonly radius = computed(() => (this.size() - this.strokeWidth()) / 2); | ||
| // Baseline y of the semicircle (its flat edge sits at the bottom). | ||
| private readonly centerY = computed(() => this.radius() + this.strokeWidth() / 2); | ||
|
|
||
| protected readonly stroke = computed(() => this.strokeWidth()); | ||
| // Half-circle footprint: width = size, height = size / 2 (matches the old gauge). | ||
| protected readonly heightPx = computed(() => this.size() / 2); | ||
| protected readonly fontSizePx = computed(() => this.size() / 10); | ||
| protected readonly viewBox = computed(() => `0 0 ${this.size()} ${this.heightPx()}`); | ||
|
|
||
| widthpx: string = '200px'; | ||
| heightpx: string = '200px'; | ||
| paddingTop: string = '20px'; | ||
| label: string = 'm/s'; | ||
| percentage: number = 50; | ||
| fontsize: string = '50px'; | ||
| // Top semicircle from the left edge to the right edge. | ||
| protected readonly arcPath = computed(() => { | ||
| const s = this.strokeWidth() / 2; | ||
| const cy = this.centerY(); | ||
| return `M ${s} ${cy} A ${this.radius()} ${this.radius()} 0 0 1 ${this.size() - s} ${cy}`; | ||
| }); | ||
| protected readonly arcLength = computed(() => Math.PI * this.radius()); | ||
|
|
||
| ngOnInit() { | ||
| this.widthpx = this.size + 'px'; | ||
| this.heightpx = this.size * 0.5 + 'px'; | ||
| this.paddingTop = ''; | ||
| this.label = this.current + this.unit; | ||
| this.percentage = ((this.current - this.min) / (this.max - this.min)) * 100; | ||
| this.fontsize = this.size / 10 + 'px'; | ||
| protected readonly percentage = computed(() => { | ||
| const pct = ((this.current() - this.min()) / (this.max() - this.min())) * 100; | ||
| return Math.max(0, Math.min(100, pct)); | ||
| }); | ||
|
|
||
| // The only value that changes per tick: a single attribute on one <path>. | ||
| protected readonly dashOffset = computed(() => this.arcLength() * (1 - this.percentage() / 100)); | ||
|
|
||
| protected readonly label = computed(() => formatGaugeValue(this.current()) + this.unit()); | ||
| } | ||
|
|
||
| // apex radial charts are hard coded to work with percentages, so converting to percentage to | ||
| // accurately represent min and max in chart and then using actual value and unit as label | ||
| this.chartOptions = { | ||
| series: [this.percentage], | ||
| chart: { | ||
| type: 'radialBar', | ||
| foreColor: '#eeeeee', // text color | ||
| redrawOnParentResize: true, | ||
| offsetY: -100 | ||
| }, | ||
| plotOptions: { | ||
| radialBar: { | ||
| startAngle: -90, | ||
| endAngle: 90, | ||
| offsetY: 100, | ||
| hollow: { | ||
| margin: 10, | ||
| size: '60%' | ||
| }, | ||
| track: { | ||
| background: '#1d1d1d', | ||
| strokeWidth: '97%', | ||
| margin: 5, // margin is in pixels | ||
| dropShadow: { | ||
| enabled: false, | ||
| top: 2, | ||
| left: 0, | ||
| opacity: 0, | ||
| blur: 2 | ||
| } | ||
| }, | ||
| dataLabels: { | ||
| name: { | ||
| show: true, | ||
| color: '#fafafa', | ||
| fontSize: this.fontsize, | ||
| fontFamily: undefined, | ||
| fontWeight: 300, | ||
| offsetY: -5 | ||
| }, | ||
| value: { | ||
| show: false | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| fill: { | ||
| type: 'solid', | ||
| colors: [this.color] | ||
| }, | ||
| labels: [this.label] | ||
| }; | ||
| } | ||
| function formatGaugeValue(n: number): string { | ||
| return (Math.round(n * 100) / 100).toFixed(2); | ||
| } |
12 changes: 12 additions & 0 deletions
12
angular-client/src/pages/lap-timer-page/lap-timer-page.component.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| .page-grid { | ||
| margin: 0 16px; | ||
| } | ||
|
|
||
| .gauge-wrap { | ||
| display: flex; | ||
| justify-content: center; | ||
| align-items: center; | ||
| height: 100%; | ||
| width: 100%; | ||
| overflow: hidden; | ||
| } |
42 changes: 42 additions & 0 deletions
42
angular-client/src/pages/lap-timer-page/lap-timer-page.component.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| <div class="page-grid"> | ||
| <p-toast position="top-right" /> | ||
| <p-confirmDialog /> | ||
|
|
||
| <mat-grid-list cols="6" gutterSize="15px" rowHeight="1.5rem"> | ||
| <mat-grid-tile [colspan]="6" [rowspan]="8"> | ||
| <sessions-panel /> | ||
| </mat-grid-tile> | ||
|
|
||
| <mat-grid-tile [colspan]="3" [rowspan]="9"> | ||
| <timer-hero /> | ||
| </mat-grid-tile> | ||
|
|
||
| <mat-grid-tile [colspan]="1" [rowspan]="9"> | ||
| <session-summary /> | ||
| </mat-grid-tile> | ||
|
|
||
| <mat-grid-tile [colspan]="2" [rowspan]="5"> | ||
| <info-background svgIcon="speed" title="Speed" style="width: 100%; height: 100%"> | ||
| <div class="gauge-wrap"> | ||
| <half-gauge [current]="liveSpeed()" [max]="100" [min]="0" unit="mph" [color]="speedGaugeColor()" [size]="320" /> | ||
| </div> | ||
| </info-background> | ||
| </mat-grid-tile> | ||
|
|
||
| <mat-grid-tile [colspan]="1" [rowspan]="4"> | ||
| <info-background title="Battery" style="width: 100%; height: 100%"> | ||
| <gauge-stat [value]="liveSoc()" unit="%" [color]="socColor()" /> | ||
| </info-background> | ||
| </mat-grid-tile> | ||
|
|
||
| <mat-grid-tile [colspan]="1" [rowspan]="4"> | ||
| <info-background title="Motor" style="width: 100%; height: 100%"> | ||
| <gauge-stat [value]="liveMotorTemp()" unit="°C" [color]="motorTempColor()" /> | ||
| </info-background> | ||
| </mat-grid-tile> | ||
|
|
||
| <mat-grid-tile [colspan]="6" [rowspan]="22"> | ||
| <laps-table /> | ||
| </mat-grid-tile> | ||
| </mat-grid-list> | ||
| </div> | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.