clock size query params

This commit is contained in:
Mononaut 2023-04-20 05:30:24 +09:00
parent fdb0cf509d
commit 1fccd70379
No known key found for this signature in database
GPG Key ID: A3F058E41374C04E
3 changed files with 22 additions and 12 deletions

View File

@ -25,6 +25,8 @@ export class ClockComponent implements OnInit {
blockStyle; blockStyle;
blockSizerStyle; blockSizerStyle;
wrapperStyle; wrapperStyle;
limitWidth: number;
limitHeight: number;
gradientColors = { gradientColors = {
'': ['#9339f4', '#105fb0'], '': ['#9339f4', '#105fb0'],
@ -40,16 +42,18 @@ export class ClockComponent implements OnInit {
private websocketService: WebsocketService, private websocketService: WebsocketService,
private route: ActivatedRoute, private route: ActivatedRoute,
private cd: ChangeDetectorRef, private cd: ChangeDetectorRef,
) {} ) {
this.route.queryParams.subscribe((params) => {
this.hideStats = params && params.stats === 'false';
this.limitWidth = Number.parseInt(params.width) || null;
this.limitHeight = Number.parseInt(params.height) || null;
});
}
ngOnInit(): void { ngOnInit(): void {
this.resizeCanvas(); this.resizeCanvas();
this.websocketService.want(['blocks']); this.websocketService.want(['blocks']);
this.route.queryParams.subscribe((params) => {
this.hideStats = params && params.stats === 'false';
});
this.blocksSubscription = this.stateService.blocks$ this.blocksSubscription = this.stateService.blocks$
.subscribe(([block]) => { .subscribe(([block]) => {
if (block) { if (block) {
@ -78,9 +82,11 @@ export class ClockComponent implements OnInit {
@HostListener('window:resize', ['$event']) @HostListener('window:resize', ['$event'])
resizeCanvas(): void { resizeCanvas(): void {
this.chainWidth = window.innerWidth; const windowWidth = this.limitWidth || window.innerWidth;
this.chainHeight = Math.max(60, window.innerHeight / 8); const windowHeight = this.limitHeight || window.innerHeight;
this.clockSize = Math.min(800, window.innerWidth, window.innerHeight - (1.4 * this.chainHeight)); this.chainWidth = windowWidth;
this.chainHeight = Math.max(60, windowHeight / 8);
this.clockSize = Math.min(800, windowWidth, windowHeight - (1.4 * this.chainHeight));
const size = Math.ceil(this.clockSize / 75) * 75; const size = Math.ceil(this.clockSize / 75) * 75;
const margin = (this.clockSize - size) / 2; const margin = (this.clockSize - size) / 2;
this.blockSizerStyle = { this.blockSizerStyle = {
@ -90,7 +96,9 @@ export class ClockComponent implements OnInit {
}; };
this.wrapperStyle = { this.wrapperStyle = {
'--clock-width': `${this.clockSize}px`, '--clock-width': `${this.clockSize}px`,
'--chain-height': `${this.chainHeight}px` '--chain-height': `${this.chainHeight}px`,
'width': this.limitWidth ? `${this.limitWidth}px` : undefined,
'height': this.limitHeight ? `${this.limitHeight}px` : undefined,
}; };
this.cd.markForCheck(); this.cd.markForCheck();
} }

View File

@ -1,4 +1,7 @@
<div class="text-center" class="blockchain-wrapper" [class.time-ltr]="timeLtr" [class.ltr-transition]="ltrTransitionEnabled" #container> <div
class="text-center" class="blockchain-wrapper" [class.time-ltr]="timeLtr" #container
[class.ltr-transition]="ltrTransitionEnabled" [style.width]="width + 'px'" [style.height]="height + 'px'"
>
<div class="position-container" [ngClass]="network ? network : ''" [style.top]="(height / 3) + 'px'"> <div class="position-container" [ngClass]="network ? network : ''" [style.top]="(height / 3) + 'px'">
<span> <span>
<div class="blocks-wrapper"> <div class="blocks-wrapper">

View File

@ -21,9 +21,8 @@
.position-container { .position-container {
position: absolute; position: absolute;
left: 0; left: 50%;
top: 0; top: 0;
transform: translateX(50vw);
} }
.black-background { .black-background {