Skip to content

Commit d851c82

Browse files
committed
chore(): initialite with simple chart
1 parent 8147e70 commit d851c82

4 files changed

Lines changed: 75 additions & 6 deletions

File tree

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"@angular/platform-browser": "19.2.1",
1818
"@angular/platform-browser-dynamic": "19.2.1",
1919
"@angular/router": "19.2.1",
20+
"chart.js": "4.5.0",
2021
"material-icons": "1.13.14",
2122
"rxjs": "7.8.2",
2223
"tslib": "2.8.1",
@@ -28,8 +29,8 @@
2829
"@angular/cli": "19.2.1",
2930
"@angular/compiler-cli": "19.2.1",
3031
"@cypress/schematic": "3.0.0",
31-
"@types/jasmine": "5.1.7",
3232
"@tailwindcss/postcss": "4.0.10",
33+
"@types/jasmine": "5.1.7",
3334
"angular-eslint": "19.2.0",
3435
"cypress": "14.1.0",
3536
"eslint": "9.21.0",

pnpm-lock.yaml

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/app/features/dashboard/dashboard.component.html

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
<mat-card-content>
66
<p>
77
Enter your first and last name to receive data from the result pages from <em>davengo.com</em> for <em>Firmenlauf Leipzig</em>. In the
8-
background, the result pages of the years 2011-2025 are queried and displayed here in summary.
9-
With the exception of 2020 due to the coronavirus pandemic.
8+
background, the result pages of the years 2011-2025 are queried and displayed here in summary. With the exception of 2020 due to the
9+
coronavirus pandemic.
1010
</p>
1111
<form [formGroup]="form" novalidate (ngSubmit)="onSubmit()">
1212
<div class="flex gap-5">
@@ -29,7 +29,7 @@
2929
</form>
3030
<div class="h-1 mb-3">
3131
@if(loading) {
32-
<mat-progress-bar mode="indeterminate"></mat-progress-bar>
32+
<mat-progress-bar mode="indeterminate"></mat-progress-bar>
3333
}
3434
</div>
3535
@if(dataSource) {
@@ -93,3 +93,12 @@
9393
}
9494
</mat-card-content>
9595
</mat-card>
96+
97+
<mat-card class="w-4/5 mx-auto mb-5">
98+
<mat-card-header>
99+
<mat-card-title>Chart data</mat-card-title>
100+
</mat-card-header>
101+
<mat-card-content style="max-height: 400px;">
102+
<canvas id="lineChart" style="width: 100%; height: 400px;"></canvas>
103+
</mat-card-content>
104+
</mat-card>

src/app/features/dashboard/dashboard.component.ts

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
1-
import { Component, type OnInit, inject } from '@angular/core';
1+
import { type AfterViewInit, Component, type OnInit, inject } from '@angular/core';
22
import { FormBuilder, type FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';
33
import { MatButtonModule } from '@angular/material/button';
44
import { MatCardModule } from '@angular/material/card';
55
import { MatFormFieldModule } from '@angular/material/form-field';
66
import { MatInputModule } from '@angular/material/input';
77
import { MatProgressBarModule } from '@angular/material/progress-bar';
88
import { MatTableDataSource, MatTableModule } from '@angular/material/table';
9+
import { Chart, type ChartConfiguration, registerables } from 'chart.js';
910
import type { AppResult } from '../../core/app-result';
1011
import { DavengoService } from '../../core/davengo.service';
1112

13+
Chart.register(...registerables);
14+
1215
@Component({
1316
imports: [MatButtonModule, MatCardModule, MatFormFieldModule, MatInputModule, MatProgressBarModule, MatTableModule, ReactiveFormsModule],
1417
selector: 'dr-dashboard',
1518
templateUrl: './dashboard.component.html',
1619
styleUrls: ['./dashboard.component.css'],
1720
})
18-
export class DashboardComponent implements OnInit {
21+
export class DashboardComponent implements OnInit, AfterViewInit {
1922
private formBuilder = inject(FormBuilder);
2023
private davengoService = inject(DavengoService);
2124

@@ -26,6 +29,34 @@ export class DashboardComponent implements OnInit {
2629
dataSource = new MatTableDataSource<AppResult>();
2730
displayedColumns: string[] = ['year', 'name', 'teamName', 'rank', 'nettoTime'];
2831

32+
lineChart: any;
33+
34+
lineChartConfig: ChartConfiguration = {
35+
type: 'line',
36+
data: {
37+
datasets: [
38+
{
39+
data: [],
40+
label: 'Davengo data',
41+
tension: 0.5
42+
},
43+
],
44+
labels: [],
45+
},
46+
options: {
47+
scales: {
48+
y: {
49+
ticks: {
50+
callback: function (val, index) {
51+
// Hide every 2nd tick label
52+
return `${(Number(val) / 60).toFixed(2)} min`;
53+
},
54+
},
55+
},
56+
},
57+
},
58+
};
59+
2960
ngOnInit(): void {
3061
this.form = this.formBuilder.group({
3162
firstName: ['', Validators.required],
@@ -34,6 +65,10 @@ export class DashboardComponent implements OnInit {
3465
});
3566
}
3667

68+
ngAfterViewInit(): void {
69+
this.lineChart = new Chart('lineChart', this.lineChartConfig);
70+
}
71+
3772
onSubmit(): void {
3873
this.initialSearch = true;
3974
this.loading = true;
@@ -44,6 +79,14 @@ export class DashboardComponent implements OnInit {
4479
.subscribe((appResult) => {
4580
this.dataSource = new MatTableDataSource(appResult);
4681
this.loading = false;
82+
this.lineChartConfig.data.labels = appResult.map((result) => result.year);
83+
this.lineChartConfig.data.datasets[0].data = appResult.map((result) => this.#convertTimeToTimestamp(result.nettoTime));
84+
this.lineChart.update();
4785
});
4886
}
87+
88+
#convertTimeToTimestamp(timeString: string): number {
89+
const [hours, minutes, seconds] = timeString.split(':').map(Number);
90+
return hours * 3600 + minutes * 60 + seconds;
91+
}
4992
}

0 commit comments

Comments
 (0)