Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Add chart for body weight

Roland Geiderd7c025f354e2
diff --git a/angular/package-lock.json b/angular/package-lock.json
index d17476b10..909a761fa 100644
--- a/angular/package-lock.json
+++ b/angular/package-lock.json
@@ -1,6 +1,6 @@
{
- "name": "angular",
- "version": "0.0.0",
+ "name": "wger-angular",
+ "version": "0.0.1",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@@ -323,6 +323,23 @@
"tslib": "^2.1.0"
}
},
+ "@angular/cdk": {
+ "version": "12.0.6",
+ "resolved": "https://registry.npmjs.org/@angular/cdk/-/cdk-12.0.6.tgz",
+ "integrity": "sha512-GroS6U9u2GhZmm26XQ/YjKEtJvawI0p25eANi7mPg0pDvvi18Q+inJHE5TvCP8Xnw4Vd27oWv8k7OSm/UQOrAA==",
+ "requires": {
+ "parse5": "^5.0.0",
+ "tslib": "^2.1.0"
+ },
+ "dependencies": {
+ "parse5": {
+ "version": "5.1.1",
+ "resolved": "https://registry.npmjs.org/parse5/-/parse5-5.1.1.tgz",
+ "integrity": "sha512-ugq4DFI0Ptb+WWjAdOK16+u/nHfiIrcE+sh8kZMaM0WllQKLI9rOUq6c2b7cwPkXdzfQESqvoqK6ug7U/Yyzug==",
+ "optional": true
+ }
+ }
+ },
"@angular/cli": {
"version": "12.0.2",
"resolved": "https://registry.npmjs.org/@angular/cli/-/cli-12.0.2.tgz",
@@ -1916,6 +1933,26 @@
"jsonc-parser": "3.0.0"
}
},
+ "@swimlane/ngx-charts": {
+ "version": "18.0.1",
+ "resolved": "https://registry.npmjs.org/@swimlane/ngx-charts/-/ngx-charts-18.0.1.tgz",
+ "integrity": "sha512-yTSKIPyzcrR13wUnJf5K4cem+nrYhfKeywdipLM+7/qgJiLcs7HFRvcUhCTp3jQl2K+y8a6OWJAAmS8azcAshg==",
+ "requires": {
+ "@types/d3-shape": "^2.0.0",
+ "d3-array": "^2.9.1",
+ "d3-brush": "^2.1.0",
+ "d3-color": "^2.0.0",
+ "d3-format": "^2.0.0",
+ "d3-hierarchy": "^2.0.0",
+ "d3-interpolate": "^2.0.1",
+ "d3-scale": "^3.2.3",
+ "d3-selection": "^2.0.0",
+ "d3-shape": "^2.0.0",
+ "d3-time-format": "^3.0.0",
+ "d3-transition": "^2.0.0",
+ "tslib": "^2.0.0"
+ }
+ },
"@tootallnate/once": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/@tootallnate/once/-/once-1.1.2.tgz",
@@ -1946,6 +1983,19 @@
"integrity": "sha512-C7srjHiVG3Ey1nR6d511dtDkCEjxuN9W1HWAEjGq8kpcwmNM6JJkpC0xvabM7BXTG2wDq8Eu33iH9aQKa7IvLQ==",
"dev": true
},
+ "@types/d3-path": {
+ "version": "2.0.1",
+ "resolved": "https://registry.npmjs.org/@types/d3-path/-/d3-path-2.0.1.tgz",
+ "integrity": "sha512-6K8LaFlztlhZO7mwsZg7ClRsdLg3FJRzIIi6SZXDWmmSJc2x8dd2VkESbLXdk3p8cuvz71f36S0y8Zv2AxqvQw=="
+ },
+ "@types/d3-shape": {
+ "version": "2.1.2",
+ "resolved": "https://registry.npmjs.org/@types/d3-shape/-/d3-shape-2.1.2.tgz",
+ "integrity": "sha512-LeRBMzX30vohbkES3YEjXDKjOuP1QVJbvzIk9VaI2+wZaEyzar7cJckJNeHTCPSIVbDGE0SiIf46UkCygFz8DQ==",
+ "requires": {
+ "@types/d3-path": "^2"
+ }
+ },
"@types/eslint": {
"version": "7.2.12",
"resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-7.2.12.tgz",
@@ -4179,6 +4229,131 @@
"integrity": "sha1-XQKkaFCt8bSjF5RqOSj8y1v9BCU=",
"dev": true
},
+ "d3-array": {
+ "version": "2.12.1",
+ "resolved": "https://registry.npmjs.org/d3-array/-/d3-array-2.12.1.tgz",
+ "integrity": "sha512-B0ErZK/66mHtEsR1TkPEEkwdy+WDesimkM5gpZr5Dsg54BiTA5RXtYW5qTLIAcekaS9xfZrzBLF/OAkB3Qn1YQ==",
+ "requires": {
+ "internmap": "^1.0.0"
+ }
+ },
+ "d3-brush": {
+ "version": "2.1.0",
+ "resolved": "https://registry.npmjs.org/d3-brush/-/d3-brush-2.1.0.tgz",
+ "integrity": "sha512-cHLLAFatBATyIKqZOkk/mDHUbzne2B3ZwxkzMHvFTCZCmLaXDpZRihQSn8UNXTkGD/3lb/W2sQz0etAftmHMJQ==",
+ "requires": {
+ "d3-dispatch": "1 - 2",
+ "d3-drag": "2",
+ "d3-interpolate": "1 - 2",
+ "d3-selection": "2",
+ "d3-transition": "2"
+ }
+ },
+ "d3-color": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/d3-color/-/d3-color-2.0.0.tgz",
+ "integrity": "sha512-SPXi0TSKPD4g9tw0NMZFnR95XVgUZiBH+uUTqQuDu1OsE2zomHU7ho0FISciaPvosimixwHFl3WHLGabv6dDgQ=="
+ },
+ "d3-dispatch": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/d3-dispatch/-/d3-dispatch-2.0.0.tgz",
+ "integrity": "sha512-S/m2VsXI7gAti2pBoLClFFTMOO1HTtT0j99AuXLoGFKO6deHDdnv6ZGTxSTTUTgO1zVcv82fCOtDjYK4EECmWA=="
+ },
+ "d3-drag": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/d3-drag/-/d3-drag-2.0.0.tgz",
+ "integrity": "sha512-g9y9WbMnF5uqB9qKqwIIa/921RYWzlUDv9Jl1/yONQwxbOfszAWTCm8u7HOTgJgRDXiRZN56cHT9pd24dmXs8w==",
+ "requires": {
+ "d3-dispatch": "1 - 2",
+ "d3-selection": "2"
+ }
+ },
+ "d3-ease": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/d3-ease/-/d3-ease-2.0.0.tgz",
+ "integrity": "sha512-68/n9JWarxXkOWMshcT5IcjbB+agblQUaIsbnXmrzejn2O82n3p2A9R2zEB9HIEFWKFwPAEDDN8gR0VdSAyyAQ=="
+ },
+ "d3-format": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/d3-format/-/d3-format-2.0.0.tgz",
+ "integrity": "sha512-Ab3S6XuE/Q+flY96HXT0jOXcM4EAClYFnRGY5zsjRGNy6qCYrQsMffs7cV5Q9xejb35zxW5hf/guKw34kvIKsA=="
+ },
+ "d3-hierarchy": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/d3-hierarchy/-/d3-hierarchy-2.0.0.tgz",
+ "integrity": "sha512-SwIdqM3HxQX2214EG9GTjgmCc/mbSx4mQBn+DuEETubhOw6/U3fmnji4uCVrmzOydMHSO1nZle5gh6HB/wdOzw=="
+ },
+ "d3-interpolate": {
+ "version": "2.0.1",
+ "resolved": "https://registry.npmjs.org/d3-interpolate/-/d3-interpolate-2.0.1.tgz",
+ "integrity": "sha512-c5UhwwTs/yybcmTpAVqwSFl6vrQ8JZJoT5F7xNFK9pymv5C0Ymcc9/LIJHtYIggg/yS9YHw8i8O8tgb9pupjeQ==",
+ "requires": {
+ "d3-color": "1 - 2"
+ }
+ },
+ "d3-path": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/d3-path/-/d3-path-2.0.0.tgz",
+ "integrity": "sha512-ZwZQxKhBnv9yHaiWd6ZU4x5BtCQ7pXszEV9CU6kRgwIQVQGLMv1oiL4M+MK/n79sYzsj+gcgpPQSctJUsLN7fA=="
+ },
+ "d3-scale": {
+ "version": "3.3.0",
+ "resolved": "https://registry.npmjs.org/d3-scale/-/d3-scale-3.3.0.tgz",
+ "integrity": "sha512-1JGp44NQCt5d1g+Yy+GeOnZP7xHo0ii8zsQp6PGzd+C1/dl0KGsp9A7Mxwp+1D1o4unbTTxVdU/ZOIEBoeZPbQ==",
+ "requires": {
+ "d3-array": "^2.3.0",
+ "d3-format": "1 - 2",
+ "d3-interpolate": "1.2.0 - 2",
+ "d3-time": "^2.1.1",
+ "d3-time-format": "2 - 3"
+ }
+ },
+ "d3-selection": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/d3-selection/-/d3-selection-2.0.0.tgz",
+ "integrity": "sha512-XoGGqhLUN/W14NmaqcO/bb1nqjDAw5WtSYb2X8wiuQWvSZUsUVYsOSkOybUrNvcBjaywBdYPy03eXHMXjk9nZA=="
+ },
+ "d3-shape": {
+ "version": "2.1.0",
+ "resolved": "https://registry.npmjs.org/d3-shape/-/d3-shape-2.1.0.tgz",
+ "integrity": "sha512-PnjUqfM2PpskbSLTJvAzp2Wv4CZsnAgTfcVRTwW03QR3MkXF8Uo7B1y/lWkAsmbKwuecto++4NlsYcvYpXpTHA==",
+ "requires": {
+ "d3-path": "1 - 2"
+ }
+ },
+ "d3-time": {
+ "version": "2.1.1",
+ "resolved": "https://registry.npmjs.org/d3-time/-/d3-time-2.1.1.tgz",
+ "integrity": "sha512-/eIQe/eR4kCQwq7yxi7z4c6qEXf2IYGcjoWB5OOQy4Tq9Uv39/947qlDcN2TLkiTzQWzvnsuYPB9TrWaNfipKQ==",
+ "requires": {
+ "d3-array": "2"
+ }
+ },
+ "d3-time-format": {
+ "version": "3.0.0",
+ "resolved": "https://registry.npmjs.org/d3-time-format/-/d3-time-format-3.0.0.tgz",
+ "integrity": "sha512-UXJh6EKsHBTjopVqZBhFysQcoXSv/5yLONZvkQ5Kk3qbwiUYkdX17Xa1PT6U1ZWXGGfB1ey5L8dKMlFq2DO0Ag==",
+ "requires": {
+ "d3-time": "1 - 2"
+ }
+ },
+ "d3-timer": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/d3-timer/-/d3-timer-2.0.0.tgz",
+ "integrity": "sha512-TO4VLh0/420Y/9dO3+f9abDEFYeCUr2WZRlxJvbp4HPTQcSylXNiL6yZa9FIUvV1yRiFufl1bszTCLDqv9PWNA=="
+ },
+ "d3-transition": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/d3-transition/-/d3-transition-2.0.0.tgz",
+ "integrity": "sha512-42ltAGgJesfQE3u9LuuBHNbGrI/AJjNL2OAUdclE70UE6Vy239GCBEYD38uBPoLeNsOhFStGpPI0BAOV+HMxog==",
+ "requires": {
+ "d3-color": "1 - 2",
+ "d3-dispatch": "1 - 2",
+ "d3-ease": "1 - 2",
+ "d3-interpolate": "1 - 2",
+ "d3-timer": "1 - 2"
+ }
+ },
"dashdash": {
"version": "1.14.1",
"resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz",
@@ -6335,6 +6510,11 @@
"ipaddr.js": "^1.9.0"
}
},
+ "internmap": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/internmap/-/internmap-1.0.1.tgz",
+ "integrity": "sha512-lDB5YccMydFBtasVtxnZ3MRBHuaoE8GKsppq+EchKL2U4nK/DmEpPHNH8MZe5HkMtpSiTSOZwfN0tzYjO/lJEw=="
+ },
"ip": {
"version": "1.1.5",
"resolved": "https://registry.npmjs.org/ip/-/ip-1.1.5.tgz",
diff --git a/angular/package.json b/angular/package.json
index 3de08ecf9..8f6bbcad5 100644
--- a/angular/package.json
+++ b/angular/package.json
@@ -15,10 +15,12 @@
"@angular/common": "~12.0.2",
"@angular/compiler": "~12.0.2",
"@angular/core": "~12.0.2",
+ "@angular/cdk": "~12.0.2",
"@angular/forms": "~12.0.2",
"@angular/platform-browser": "~12.0.2",
"@angular/platform-browser-dynamic": "~12.0.2",
"@angular/router": "~12.0.2",
+ "@swimlane/ngx-charts": "^18.0.1",
"rxjs": "~6.6.0",
"tslib": "^2.0.0",
"zone.js": "~0.11.4"
diff --git a/angular/src/app/app.module.ts b/angular/src/app/app.module.ts
index e1d724227..8f2959267 100644
--- a/angular/src/app/app.module.ts
+++ b/angular/src/app/app.module.ts
@@ -20,6 +20,8 @@ import {HttpClientModule} from '@angular/common/http';
import {NgModule} from '@angular/core';
import {ReactiveFormsModule} from '@angular/forms';
import {BrowserModule} from '@angular/platform-browser';
+import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
+import {NgxChartsModule} from '@swimlane/ngx-charts';
import {AppComponent} from './app.component';
import {ExerciseDetailComponent} from './exercise/exercise-detail/exercise-detail.component';
@@ -28,6 +30,8 @@ import { ExerciseEditComponent } from './exercise/exercise-edit/exercise-edit.co
import {ExerciseService} from './exercise/exercise.service';
import {WeightListComponent} from './weight/weight-list/weight-list.component';
import { WeightDetailComponent } from './weight/weight-detail/weight-detail.component';
+import { WeightEditComponent } from './weight/weight-edit/weight-edit.component';
+import { WeightChartComponent } from './weight/weight-chart/weight-chart.component';
@NgModule({
declarations: [
@@ -37,12 +41,16 @@ import { WeightDetailComponent } from './weight/weight-detail/weight-detail.comp
ExerciseEditComponent,
WeightListComponent,
- WeightDetailComponent
+ WeightDetailComponent,
+ WeightEditComponent,
+ WeightChartComponent
],
imports: [
BrowserModule,
HttpClientModule,
- ReactiveFormsModule
+ ReactiveFormsModule,
+ NgxChartsModule,
+ BrowserAnimationsModule
],
providers: [ExerciseService],
bootstrap: [AppComponent]
diff --git a/angular/src/app/weight/models/weight.model.ts b/angular/src/app/weight/models/weight.model.ts
index 80532bb8b..c6dce428e 100644
--- a/angular/src/app/weight/models/weight.model.ts
+++ b/angular/src/app/weight/models/weight.model.ts
@@ -34,7 +34,7 @@ export class WeightEntry {
export class WeightAdapter implements Adapter<WeightEntry> {
fromJson(item: any): WeightEntry {
return new WeightEntry(
- item.date,
+ new Date(item.date),
item.weight,
item.id,
);
diff --git a/angular/src/app/weight/weight-chart/weight-chart.component.css b/angular/src/app/weight/weight-chart/weight-chart.component.css
new file mode 100644
index 000000000..e69de29bb
diff --git a/angular/src/app/weight/weight-chart/weight-chart.component.html b/angular/src/app/weight/weight-chart/weight-chart.component.html
new file mode 100644
index 000000000..1a5411df2
--- /dev/null
+++ b/angular/src/app/weight/weight-chart/weight-chart.component.html
@@ -0,0 +1,18 @@
+
+<ngx-charts-line-chart
+ [view]="view"
+ [scheme]="colorScheme"
+ [legend]="legend"
+ [showXAxisLabel]="showXAxisLabel"
+ [showYAxisLabel]="showYAxisLabel"
+ [xAxis]="xAxis"
+ [yAxis]="yAxis"
+
+ [timeline]="timeline"
+ [results]="data"
+ [autoScale]="autoScale"
+ (select)="onSelect($event)"
+ (activate)="onActivate($event)"
+ (deactivate)="onDeactivate($event)"
+>
+</ngx-charts-line-chart>
diff --git a/angular/src/app/weight/weight-chart/weight-chart.component.spec.ts b/angular/src/app/weight/weight-chart/weight-chart.component.spec.ts
new file mode 100644
index 000000000..5253f0b1d
--- /dev/null
+++ b/angular/src/app/weight/weight-chart/weight-chart.component.spec.ts
@@ -0,0 +1,25 @@
+import { ComponentFixture, TestBed } from '@angular/core/testing';
+
+import { WeightChartComponent } from './weight-chart.component';
+
+describe('WeightChartComponent', () => {
+ let component: WeightChartComponent;
+ let fixture: ComponentFixture<WeightChartComponent>;
+
+ beforeEach(async () => {
+ await TestBed.configureTestingModule({
+ declarations: [ WeightChartComponent ]
+ })
+ .compileComponents();
+ });
+
+ beforeEach(() => {
+ fixture = TestBed.createComponent(WeightChartComponent);
+ component = fixture.componentInstance;
+ fixture.detectChanges();
+ });
+
+ it('should create', () => {
+ expect(component).toBeTruthy();
+ });
+});
diff --git a/angular/src/app/weight/weight-chart/weight-chart.component.ts b/angular/src/app/weight/weight-chart/weight-chart.component.ts
new file mode 100644
index 000000000..84da3b42d
--- /dev/null
+++ b/angular/src/app/weight/weight-chart/weight-chart.component.ts
@@ -0,0 +1,62 @@
+import {Component, OnInit} from '@angular/core';
+import {WeightService} from '../weight.service';
+
+@Component({
+ selector: 'app-weight-chart',
+ templateUrl: './weight-chart.component.html',
+ styleUrls: ['./weight-chart.component.css']
+})
+export class WeightChartComponent implements OnInit {
+
+ view: [number, number] = [700, 300];
+
+ // options
+ legend: boolean = false;
+ showLabels: boolean = true;
+ animations: boolean = true;
+ xAxis: boolean = true;
+ yAxis: boolean = true;
+ showYAxisLabel: boolean = false;
+ showXAxisLabel: boolean = false;
+ //xAxisLabel: string = 'Date';
+ //yAxisLabel: string = 'Weight';
+ timeline: boolean = true;
+ autoScale = true;
+
+ colorScheme = {
+ domain: ['#266dd3', '#E44D25', '#CFC0BB', '#7aa3e5', '#a8385d', '#aae3f5']
+ };
+
+ data : any
+
+
+ constructor(private service: WeightService) {
+ }
+
+ async ngOnInit(): Promise<void> {
+ await this.service.loadWeightEntries();
+ const out: {name: Date, value: number}[] = this.service.entries.map(entry => {
+ return {name: entry.date, value: entry.weight};
+ });
+ console.log(out);
+ this.data = [{
+ name: 'Weight',
+ series: out
+ }];
+
+ }
+
+
+ onSelect(data: any): void {
+ console.log('Item clicked', JSON.parse(JSON.stringify(data)));
+ }
+
+ onActivate(data: any): void {
+ console.log('Activate', JSON.parse(JSON.stringify(data)));
+ }
+
+ onDeactivate(data: any): void {
+ console.log('Deactivate', JSON.parse(JSON.stringify(data)));
+ }
+
+}
diff --git a/angular/src/app/weight/weight-detail/weight-detail.component.html b/angular/src/app/weight/weight-detail/weight-detail.component.html
index ae6fffde7..f7a3403fa 100644
--- a/angular/src/app/weight/weight-detail/weight-detail.component.html
+++ b/angular/src/app/weight/weight-detail/weight-detail.component.html
@@ -5,7 +5,7 @@
<button class="btn btn-primary" (click)="toggleForm()">Edit</button>
<div *ngIf="!showForm">
- {{entry.date}} - {{entry.weight}}
+ {{entry.date | date:'shortDate'}} - {{entry.weight}}
</div>
<app-weight-edit *ngIf="showForm" [weight]="entry"></app-weight-edit>
</li>
diff --git a/angular/src/app/weight/weight-edit/weight-edit.component.ts b/angular/src/app/weight/weight-edit/weight-edit.component.ts
index b46f51b46..31da2da97 100644
--- a/angular/src/app/weight/weight-edit/weight-edit.component.ts
+++ b/angular/src/app/weight/weight-edit/weight-edit.component.ts
@@ -31,7 +31,7 @@ export class WeightEditComponent implements OnInit {
private initForm() {
this.group = this.formBuilder.group({
- date: [this.weight!.date, Validators.required],
+ date: [this.weight!.date.toISOString().split('T')[0], Validators.required],
weight: [
this.weight!.weight,
[Validators.required, Validators.min(30), Validators.max(300)],
diff --git a/angular/src/app/weight/weight-list/weight-list.component.html b/angular/src/app/weight/weight-list/weight-list.component.html
index 21161a395..daf8d9bd5 100644
--- a/angular/src/app/weight/weight-list/weight-list.component.html
+++ b/angular/src/app/weight/weight-list/weight-list.component.html
@@ -1,8 +1,19 @@
+<div class="row">
+ <div class="col-12">
+ <app-weight-chart></app-weight-chart>
+ </div>
+</div>
+
+
+<div class="row">
+ <div class="col-12">
<ul *ngFor="let entry of weightEntries"
class="list-group">
<app-weight-detail [entry]="entry"></app-weight-detail>
</ul>
+</div>
+</div>
<button class="btn btn-primary" (click)="toggleForm()">Add entry</button>
<app-weight-edit *ngIf="showForm"></app-weight-edit>
diff --git a/angular/src/app/weight/weight.service.ts b/angular/src/app/weight/weight.service.ts
index adc7cea3b..5d8ff4b8f 100644
--- a/angular/src/app/weight/weight.service.ts
+++ b/angular/src/app/weight/weight.service.ts
@@ -32,6 +32,7 @@ export class WeightService {
return this.entries;
}
+
/**
* Updates an existing weight entry
*