add last chart: burrow-time to dashboard

This commit is contained in:
Tim Herbst 2020-12-26 16:27:08 +01:00
parent f64fe65ed6
commit 945642db5a

View File

@ -28,7 +28,7 @@ export type ChartOptions = {
chart: ApexChart; chart: ApexChart;
dataLabels: ApexDataLabels; dataLabels: ApexDataLabels;
plotOptions: ApexPlotOptions; plotOptions: ApexPlotOptions;
yaxis: ApexYAxis; yaxis: ApexYAxis | ApexYAxis[];
xaxis: ApexXAxis; xaxis: ApexXAxis;
fill: ApexFill; fill: ApexFill;
tooltip: ApexTooltip; tooltip: ApexTooltip;
@ -37,6 +37,8 @@ export type ChartOptions = {
noData: ApexNoData; noData: ApexNoData;
}; };
const chartHeight = 450;
@Component({ @Component({
selector: 'app-dashboard', selector: 'app-dashboard',
templateUrl: './dashboard.component.html', templateUrl: './dashboard.component.html',
@ -46,6 +48,7 @@ export type ChartOptions = {
export class DashboardComponent implements OnInit { export class DashboardComponent implements OnInit {
@ViewChild('Station-Dashboard-Borrow-Duration') chart: ChartComponent; @ViewChild('Station-Dashboard-Borrow-Duration') chart: ChartComponent;
public durationChartOptions: Partial<ChartOptions>; public durationChartOptions: Partial<ChartOptions>;
public timeChartOptions: Partial<ChartOptions>;
displayedColumnsTo: string[] = ['endStationName', 'number', 'avgDuration']; displayedColumnsTo: string[] = ['endStationName', 'number', 'avgDuration'];
displayedColumnsFrom: string[] = ['startStationName', 'number', 'avgDuration']; displayedColumnsFrom: string[] = ['startStationName', 'number', 'avgDuration'];
stationToSource = new MatTableDataSource<any>(); stationToSource = new MatTableDataSource<any>();
@ -68,11 +71,18 @@ export class DashboardComponent implements OnInit {
private fb: FormBuilder private fb: FormBuilder
) { ) {
this.durationChartOptions = { this.durationChartOptions = {
title: { series: [],
text: 'test', chart: {
align: 'left', type: 'bar'
margin: 10
}, },
dataLabels: {
enabled: false
},
noData: {
text: 'Loading...'
}
};
this.timeChartOptions = {
series: [], series: [],
chart: { chart: {
type: 'bar' type: 'bar'
@ -112,7 +122,7 @@ export class DashboardComponent implements OnInit {
this.stationFromSource = source; this.stationFromSource = source;
this.changeDetectorRefs.detectChanges(); this.changeDetectorRefs.detectChanges();
}); });
this.service.fetch_dashboard_station_duration(this.station.id, initDate, initDate).then((source) => { this.service.fetch_dashboard_station_charts(this.station.id, initDate, initDate, 'duration').then((source) => {
const numbers = []; const numbers = [];
const minutesGroup = []; const minutesGroup = [];
source.forEach(value => { source.forEach(value => {
@ -123,12 +133,12 @@ export class DashboardComponent implements OnInit {
series: [ series: [
{ {
name: 'amount of drives for given borrow duration', name: 'amount of drives for given borrow duration',
data: [...numbers] data: numbers
} }
], ],
chart: { chart: {
type: 'bar', type: 'bar',
height: 400 height: chartHeight
}, },
plotOptions: { plotOptions: {
bar: { bar: {
@ -146,7 +156,7 @@ export class DashboardComponent implements OnInit {
colors: ['transparent'] colors: ['transparent']
}, },
xaxis: { xaxis: {
categories: [...minutesGroup], categories: minutesGroup,
labels: { labels: {
formatter: value => { formatter: value => {
return value + ' min'; return value + ' min';
@ -163,6 +173,64 @@ export class DashboardComponent implements OnInit {
} }
}; };
}); });
this.service.fetch_dashboard_station_charts(this.station.id, initDate, initDate, 'time').then((source) => {
const timeFrame = [];
const numbers = [];
const avgDuration = [];
source.forEach(value => {
timeFrame.push(value.timeFrame);
numbers.push(value.number);
avgDuration.push(value.avgDuration);
});
this.timeChartOptions = {
series: [
{
name: 'amount of drives',
type: 'bar',
data: numbers
},
{
name: 'avgDuration',
type: 'line',
data: avgDuration
}
],
chart: {
type: 'line',
height: chartHeight,
zoom: {
enabled: true
}
},
dataLabels: {
enabled: false
},
stroke: {
curve: 'straight'
},
xaxis: {
categories: timeFrame,
tickAmount: 24
},
yaxis: [{
title: {
text: 'number of drives',
},
}, {
opposite: true,
title: {
text: 'avgDuration'
}
}],
legend: {
horizontalAlign: 'left'
},
fill: {
opacity: 1
}
};
});
this.map.draw_dashboard_map(this.station.lat, this.station.lon, 17); this.map.draw_dashboard_map(this.station.lat, this.station.lon, 17);
this.map.draw_dashboard_station_marker(this.station.lat, this.station.lon); this.map.draw_dashboard_station_marker(this.station.lat, this.station.lon);
} }
@ -170,15 +238,28 @@ export class DashboardComponent implements OnInit {
onSubmit(): void { onSubmit(): void {
this.actualStartDate = this.form.get('daterange').value.start; this.actualStartDate = this.form.get('daterange').value.start;
this.actualEndDate = this.form.get('daterange').value.end; this.actualEndDate = this.form.get('daterange').value.end;
this.service.fetch_dashboard_station_to(this.station.id, this.actualStartDate.toISOString().substring(0, 10), this.actualEndDate.toISOString().substring(0, 10)).then((source) => { this.service.fetch_dashboard_station_to(
this.station.id,
this.actualStartDate.toISOString().substring(0, 10),
this.actualEndDate.toISOString().substring(0, 10)
).then((source) => {
this.stationToSource = source; this.stationToSource = source;
this.changeDetectorRefs.detectChanges(); this.changeDetectorRefs.detectChanges();
}); });
this.service.fetch_dashboard_station_from(this.station.id, this.actualStartDate.toISOString().substring(0, 10), this.actualEndDate.toISOString().substring(0, 10)).then((source) => { this.service.fetch_dashboard_station_from(
this.station.id,
this.actualStartDate.toISOString().substring(0, 10),
this.actualEndDate.toISOString().substring(0, 10)
).then((source) => {
this.stationFromSource = source; this.stationFromSource = source;
this.changeDetectorRefs.detectChanges(); this.changeDetectorRefs.detectChanges();
}); });
this.service.fetch_dashboard_station_duration(this.station.id, this.actualStartDate.toISOString().substring(0, 10), this.actualEndDate.toISOString().substring(0, 10)).then((source) => { this.service.fetch_dashboard_station_charts(
this.station.id,
this.actualStartDate.toISOString().substring(0, 10),
this.actualEndDate.toISOString().substring(0, 10),
'duration'
).then((source) => {
const numbers = []; const numbers = [];
const minutesGroup = []; const minutesGroup = [];
source.forEach(value => { source.forEach(value => {
@ -189,12 +270,12 @@ export class DashboardComponent implements OnInit {
series: [ series: [
{ {
name: 'borrow-duration', name: 'borrow-duration',
data: [...numbers] data: numbers
} }
], ],
chart: { chart: {
type: 'bar', type: 'bar',
height: 450 height: chartHeight
}, },
plotOptions: { plotOptions: {
bar: { bar: {
@ -212,7 +293,12 @@ export class DashboardComponent implements OnInit {
colors: ['transparent'] colors: ['transparent']
}, },
xaxis: { xaxis: {
categories: [...minutesGroup] categories: minutesGroup,
labels: {
formatter: value => {
return value + ' min';
}
}
}, },
yaxis: { yaxis: {
title: { title: {
@ -224,5 +310,67 @@ export class DashboardComponent implements OnInit {
} }
}; };
}); });
this.service.fetch_dashboard_station_charts(
this.station.id,
this.actualStartDate.toISOString().substring(0, 10),
this.actualEndDate.toISOString().substring(0, 10),
'time'
).then((source) => {
const timeFrame = [];
const numbers = [];
const avgDuration = [];
source.forEach(value => {
timeFrame.push(value.timeFrame);
numbers.push(value.number);
avgDuration.push(value.avgDuration);
});
this.timeChartOptions = {
series: [
{
name: 'amount of drives',
type: 'bar',
data: numbers
},
{
name: 'avgDuration',
type: 'line',
data: avgDuration
}
],
chart: {
type: 'line',
height: chartHeight,
zoom: {
enabled: true
}
},
dataLabels: {
enabled: false
},
stroke: {
curve: 'straight'
},
xaxis: {
categories: timeFrame,
tickAmount: 24
},
yaxis: [{
title: {
text: 'number of drives',
},
}, {
opposite: true,
title: {
text: 'avgDuration'
}
}],
legend: {
horizontalAlign: 'left'
},
fill: {
opacity: 1
}
};
});
} }
} }