start of chart component

This commit is contained in:
Jesse Lucas
2020-03-29 16:51:12 -04:00
parent ad2902b3ee
commit 82f5706350
10 changed files with 131 additions and 27 deletions
+2
View File
@@ -21,6 +21,7 @@ import { environment } from '../environments/environment';
import { DashboardComponent } from './dashboard/dashboard.component';
import { MatCardModule } from '@angular/material/card';
import { FlexLayoutModule } from '@angular/flex-layout';
import { DonutChartComponent } from './donut-chart/donut-chart.component';
@NgModule({
declarations: [
@@ -30,6 +31,7 @@ import { FlexLayoutModule } from '@angular/flex-layout';
DeviceListComponent,
StatusToggleComponent,
DashboardComponent,
DonutChartComponent,
],
imports: [
BrowserModule,
+6 -2
View File
@@ -6,13 +6,17 @@
<div gdArea="folders">
<mat-card>
<mat-card-title>Folders</mat-card-title>
<mat-card-content></mat-card-content>
<mat-card-content>
<app-donut-chart [elementID]="foldersChart"></app-donut-chart>
</mat-card-content>
</mat-card>
</div>
<div gdArea="devices">
<mat-card>
<mat-card-title>Devices</mat-card-title>
<mat-card-content></mat-card-content>
<mat-card-content>
<app-donut-chart [elementID]="devicesChart"></app-donut-chart>
</mat-card-content>
</mat-card>
</div>
<app-status-list gdArea="status-list"></app-status-list>
+3
View File
@@ -7,6 +7,9 @@ import { SystemConfigService } from '../system-config.service';
styleUrls: ['./dashboard.component.scss']
})
export class DashboardComponent {
foldersChart = 'foldersChart';
devicesChart = 'devicesChart';
constructor(private systemConfigService: SystemConfigService) { }
ngOnInit() {
@@ -0,0 +1 @@
<canvas id={{elementID}} width="200%" height="100%"></canvas>
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { DonutChartComponent } from './donut-chart.component';
describe('DonutChartComponent', () => {
let component: DonutChartComponent;
let fixture: ComponentFixture<DonutChartComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ DonutChartComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(DonutChartComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,48 @@
import { Component, OnInit, AfterViewInit, Input } from '@angular/core';
import { Chart } from 'chart.js'
import { flatMap } from 'rxjs/operators';
@Component({
selector: 'app-donut-chart',
templateUrl: './donut-chart.component.html',
styleUrls: ['./donut-chart.component.scss']
})
export class DonutChartComponent implements OnInit {
@Input() elementID: string;
private canvas: any;
private ctx: any;
constructor() { }
ngOnInit(): void {
}
ngAfterViewInit(): void {
console.log("elementID?", this.elementID)
this.canvas = document.getElementById(this.elementID);
this.ctx = this.canvas.getContext('2d');
const myChart = new Chart(this.ctx, {
type: 'doughnut',
data: {
labels: ["Up to Date", "Syncing", "Waiting to Sync", "Out of Sync", "Failed Items"],
datasets: [{
data: [1, 2, 3, 0, 0],
backgroundColor: [
'#56C568',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)'
],
borderWidth: 1
}]
},
options: {
responsive: false,
display: false,
legend: {
display: false
}
}
});
}
}
+13 -22
View File
@@ -24,7 +24,7 @@ export class SystemConfigService {
private systemConfigUrl = environment.production ? apiURL + 'rest/system/config' : 'api/config';
private httpOptions;
private checkInterval: number = 200;
private checkInterval: number = 500;
constructor(private http: HttpClient, private cookieService: CookieService) {
this.httpOptions = { headers: new HttpHeaders(this.cookieService.getCSRFHeader()) };
@@ -52,19 +52,11 @@ export class SystemConfigService {
observer.next(this.folders);
} else {
// create timer to keep checking for folders
let check = (): Boolean => {
if (this.folders) {
observer.next(this.folders);
return true;
}
return false;
}
let t = setInterval(() => {
if (check())
if (check(this.folders))
clearInterval(t);
observer.next(this.folders);
}, this.checkInterval);
check(); // try right away
}
});
return folderObservable;
@@ -75,22 +67,21 @@ export class SystemConfigService {
if (this.folders) {
observer.next(this.devices);
} else {
// create timer to keep checking for devices
let check = (): Boolean => {
if (this.devices) {
observer.next(this.devices);
return true;
}
return false;
}
let t = setInterval(() => {
if (check())
if (check(this.devices)) {
clearInterval(t);
observer.next(this.devices);
}
}, this.checkInterval);
check() // try right away
}
});
return deviceObserverable;
}
}
const check = (target: any): Boolean => {
if (target) {
return true;
}
return false;
}