charts
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map, Observable, shareReplay } from 'rxjs';
|
||||
|
||||
import { ClientService } from '../../services/client.service';
|
||||
|
||||
@@ -13,11 +13,81 @@ export class DashboardComponent {
|
||||
|
||||
|
||||
public clientInfo$: Observable<any>;
|
||||
public chartData$: Observable<any>;
|
||||
|
||||
public chartOptions: any;
|
||||
|
||||
constructor(private clientService: ClientService, private route: ActivatedRoute) {
|
||||
this.clientInfo$ = this.clientService.getClientInfo(this.route.snapshot.params['address']);
|
||||
const address = this.route.snapshot.params['address'];
|
||||
this.clientInfo$ = this.clientService.getClientInfo(address).pipe(
|
||||
shareReplay({ refCount: true, bufferSize: 1 })
|
||||
)
|
||||
|
||||
|
||||
const documentStyle = getComputedStyle(document.documentElement);
|
||||
const textColor = documentStyle.getPropertyValue('--text-color');
|
||||
const textColorSecondary = documentStyle.getPropertyValue('--text-color-secondary');
|
||||
const surfaceBorder = documentStyle.getPropertyValue('--surface-border');
|
||||
|
||||
|
||||
|
||||
this.chartData$ = this.clientInfo$.pipe(
|
||||
map((workerInfo: any) => {
|
||||
|
||||
return {
|
||||
labels: workerInfo.chartData.map((d: any) => d.label),
|
||||
datasets: [
|
||||
{
|
||||
label: address,
|
||||
data: workerInfo.chartData.map((d: any) => d.data),
|
||||
fill: false,
|
||||
backgroundColor: documentStyle.getPropertyValue('--bluegray-700'),
|
||||
borderColor: documentStyle.getPropertyValue('--bluegray-700'),
|
||||
tension: .4
|
||||
}
|
||||
]
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
|
||||
this.chartOptions = {
|
||||
plugins: {
|
||||
legend: {
|
||||
labels: {
|
||||
color: textColor
|
||||
}
|
||||
}
|
||||
},
|
||||
scales: {
|
||||
x: {
|
||||
type: 'time',
|
||||
time: {
|
||||
unit: 'minute', // Set the unit to 'minute'
|
||||
stepSize: 10, // Set the desired interval between labels in minutes
|
||||
|
||||
},
|
||||
ticks: {
|
||||
color: textColorSecondary
|
||||
},
|
||||
grid: {
|
||||
color: surfaceBorder,
|
||||
drawBorder: false
|
||||
}
|
||||
},
|
||||
y: {
|
||||
ticks: {
|
||||
color: textColorSecondary,
|
||||
callback: (value: number) => value + ' GH/s',
|
||||
},
|
||||
grid: {
|
||||
color: surfaceBorder,
|
||||
drawBorder: false
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user