Skip to content

Commit 577db01

Browse files
author
Manuela Paula Ritter
committed
improve duedate positioning
1 parent 3c33183 commit 577db01

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

src/app/matrix/canvas/canvas.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class CanvasComponent implements OnInit {
1616
maxDate = new Date();
1717

1818
constructor(public readonly store: Store<AppState>) {
19-
this.maxDate = new Date(this.maxDate.setMonth(this.maxDate.getMonth() - 1));
19+
this.maxDate = new Date(this.maxDate.setMonth(this.maxDate.getMonth() + 1));
2020
}
2121

2222
ngOnInit(): void {

src/app/matrix/x-position.pipe.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,27 @@ import { Pipe, PipeTransform } from '@angular/core';
44
export class XPositionPipe implements PipeTransform {
55
transform(xValue: Date, maxDate: Date): string {
66
// | > maxDate ------------- < maxDate | <- today
7+
// | 100 --------------------------- 0 |
8+
// 100 = maxDate - today
9+
// 0 = today
710
const today = new Date().getTime();
811
const maxDateTime = maxDate.getTime();
9-
const maxDiff = maxDateTime - today;
10-
const diff = maxDateTime - xValue.getTime();
11-
const ratio = diff / maxDiff;
12-
return ratio * 94 + '%';
12+
const value = xValue.getTime();
13+
let ratio: number;
14+
if (value < today) {
15+
ratio = 0;
16+
} else if (value > maxDateTime) {
17+
ratio = 1;
18+
} else {
19+
ratio = (value - today) / (maxDateTime - today);
20+
}
21+
22+
console.log(ratio);
23+
24+
ratio = Math.max(ratio, 0);
25+
ratio = Math.min(ratio, 1);
26+
27+
console.log(ratio);
28+
return (1 - ratio) * 94 + '%';
1329
}
1430
}

0 commit comments

Comments
 (0)