diff --git a/projects/project-3/frontend/src/app/app.module.ts b/projects/project-3/frontend/src/app/app.module.ts index d73a8f4..3cbe2e4 100644 --- a/projects/project-3/frontend/src/app/app.module.ts +++ b/projects/project-3/frontend/src/app/app.module.ts @@ -26,6 +26,7 @@ import {MatInputModule} from '@angular/material/input'; import {MatTableModule} from '@angular/material/table'; import {AutoRefreshComponent} from './map/auto-refresh/auto-refresh.component'; import {MatSlideToggleModule} from '@angular/material/slide-toggle'; +import {MatCheckboxModule} from '@angular/material/checkbox'; @NgModule({ declarations: [ @@ -57,7 +58,8 @@ import {MatSlideToggleModule} from '@angular/material/slide-toggle'; ReactiveFormsModule, MatInputModule, MatTableModule, - MatSlideToggleModule + MatSlideToggleModule, + MatCheckboxModule ], providers: [], bootstrap: [AppComponent] diff --git a/projects/project-3/frontend/src/app/dashboard/dashboard.component.html b/projects/project-3/frontend/src/app/dashboard/dashboard.component.html index d19a4cf..dd8c780 100644 --- a/projects/project-3/frontend/src/app/dashboard/dashboard.component.html +++ b/projects/project-3/frontend/src/app/dashboard/dashboard.component.html @@ -75,13 +75,22 @@ -
+ + + + - @@ -101,9 +110,19 @@
+ + + station of lend destination{{element.stationName}}
+ + + + - diff --git a/projects/project-3/frontend/src/app/dashboard/dashboard.component.scss b/projects/project-3/frontend/src/app/dashboard/dashboard.component.scss index b0639ea..e5b76b6 100644 --- a/projects/project-3/frontend/src/app/dashboard/dashboard.component.scss +++ b/projects/project-3/frontend/src/app/dashboard/dashboard.component.scss @@ -6,12 +6,9 @@ mat-sidenav-content { flex: 1 1 auto; } -a { - color: #017bfe; -} - .button-back:hover, .button-wiki:hover { background: #086ed2; + } .submit-date { @@ -31,7 +28,7 @@ a { margin-top: 1em; margin-left: 1em; margin-bottom: 1em; - background-image: url('../../assets/bike-point.png'); + background-image: url('../../assets/bike-point-blue.png'); background-size: cover; } diff --git a/projects/project-3/frontend/src/app/dashboard/dashboard.component.ts b/projects/project-3/frontend/src/app/dashboard/dashboard.component.ts index 6b3b689..755f893 100644 --- a/projects/project-3/frontend/src/app/dashboard/dashboard.component.ts +++ b/projects/project-3/frontend/src/app/dashboard/dashboard.component.ts @@ -24,6 +24,8 @@ import { ChartComponent } from 'ng-apexcharts'; import {IMapBikePoint} from '../service/domain/map-bike-point'; +import {SelectionModel} from '@angular/cdk/collections'; +import {MatCheckboxChange} from '@angular/material/checkbox'; export type ChartOptions = { title: ApexTitleSubtitle @@ -54,10 +56,12 @@ export class DashboardComponent implements OnInit { public durationChartOptions: Partial; public timeChartOptions: Partial; public bikePointChartOptions: Partial; - displayedColumnsTo: string[] = ['endStationName', 'number', 'avgDuration']; - displayedColumnsFrom: string[] = ['startStationName', 'number', 'avgDuration']; - stationToSource = new MatTableDataSource(); + displayedColumnsTo: string[] = ['select', 'endStationName', 'number', 'avgDuration']; + displayedColumnsFrom: string[] = ['select', 'startStationName', 'number', 'avgDuration']; + stationToSource = new MatTableDataSource(); + selectionTo = new SelectionModel(true, []); stationFromSource = new MatTableDataSource(); + selectionFrom = new SelectionModel(true, []); station: IDashboardCommonBikePoint; maxStartDate: Date; @@ -67,6 +71,7 @@ export class DashboardComponent implements OnInit { form: FormGroup; bikePoint: IMapBikePoint; + bikePointWithColor = []; constructor( private route: ActivatedRoute, @@ -205,15 +210,15 @@ export class DashboardComponent implements OnInit { } - initDashboard(): void { + async initDashboard(): Promise { const initDate = this.maxEndDate.toISOString().substring(0, 10); this.form.get('daterange').get('start').setValue(initDate); this.form.get('daterange').get('end').setValue(initDate); - this.service.fetchDashboardStationTo(this.station.id, initDate, initDate).then((source) => { + await this.service.fetchDashboardStationTo(this.station.id, initDate, initDate).then((source) => { this.stationToSource = source; this.changeDetectorRefs.detectChanges(); }); - this.service.fetchDashboardStationFrom(this.station.id, initDate, initDate).then((source) => { + await this.service.fetchDashboardStationFrom(this.station.id, initDate, initDate).then((source) => { this.stationFromSource = source; this.changeDetectorRefs.detectChanges(); }); @@ -323,16 +328,16 @@ export class DashboardComponent implements OnInit { text: 'amount of drives', }, }, { - opposite: true, - title: { - text: 'average Duration' - }, + opposite: true, + title: { + text: 'average Duration' + }, labels: { formatter: (val: number): string => { return val + ' min'; } } - }], + }], legend: { horizontalAlign: 'left' }, @@ -495,4 +500,98 @@ export class DashboardComponent implements OnInit { humanizeAvgDuration(avgDuration: number): string { return stht(avgDuration); } + + isToAllSelected(): boolean { + const numSelected = this.selectionTo.selected.length; + const numRows = this.stationToSource.data.length; + return numSelected === numRows; + } + + isFromAllSelected(): boolean { + const numSelected = this.selectionFrom.selected.length; + const numRows = this.stationFromSource.data.length; + return numSelected === numRows; + } + + checkboxLabelTo(row?: any): string { + if (!row) { + return `${this.isToAllSelected() ? 'select' : 'deselect'} all`; + } + return `${this.selectionTo.isSelected(row) ? 'deselect' : 'select'} row ${row.position + 1}`; + } + + checkboxLabelFrom(row?: any): string { + if (!row) { + return `${this.isFromAllSelected() ? 'select' : 'deselect'} all`; + } + return `${this.selectionFrom.isSelected(row) ? 'deselect' : 'select'} row ${row.position + 1}`; + } + + selectRowTo(selection: MatCheckboxChange, row): void { + this.selectionTo.toggle(row); + this.selectionTo.selected.forEach(point => { + if (point.stationId === row.stationId) { + point.color = this.getColorTo(row); + } + this.bikePointWithColor.push(point); + }); + this.map.drawTableStationMarker(this.bikePointWithColor); + } + + selectRowFrom(selection: MatCheckboxChange, row): void { + this.selectionFrom.toggle(row); + this.selectionFrom.selected.forEach(point => { + if (point.stationId === row.stationId) { + point.color = this.getColorFrom(row); + } + this.bikePointWithColor.push(point); + }); + this.map.drawTableStationMarker(this.bikePointWithColor); + } + + getColorTo(value): string { + switch (value.stationName) { + case this.stationToSource[0].stationName: + if (this.stationToSource[0].stationName === this.station.commonName) { + return 'blue'; + } else { + return 'black'; + } + case this.stationToSource[1].stationName: + if (this.stationToSource[1].stationName === this.station.commonName) { + return 'blue'; + } else { + return 'red'; + } + case this.stationToSource[2].stationName: + if (this.stationToSource[2].stationName === this.station.commonName) { + return 'blue'; + } else { + return 'green'; + } + } + } + + getColorFrom(value): string { + switch (value.stationName) { + case this.stationFromSource[0].stationName: + if (this.stationFromSource[0].stationName === this.station.commonName) { + return 'blue'; + } else { + return 'orange'; + } + case this.stationFromSource[1].stationName: + if (this.stationFromSource[1].stationName === this.station.commonName) { + return 'blue'; + } else { + return 'purple'; + } + case this.stationFromSource[2].stationName: + if (this.stationFromSource[2].stationName === this.station.commonName) { + return 'blue'; + } else { + return 'gray'; + } + } + } } diff --git a/projects/project-3/frontend/src/app/map/map.component.ts b/projects/project-3/frontend/src/app/map/map.component.ts index a8435f0..4aaa2ab 100644 --- a/projects/project-3/frontend/src/app/map/map.component.ts +++ b/projects/project-3/frontend/src/app/map/map.component.ts @@ -1,6 +1,5 @@ import {Component, OnInit} from '@angular/core'; import {MapService} from '../service/map.service'; -import {BehaviorSubject, Observable, of, Subject} from 'rxjs'; @Component({ @@ -25,7 +24,7 @@ export class MapComponent implements OnInit { console.log(this.isRefreshActive); } - async initMapView(): Promise { + async initMapView(): Promise { this.service.initMap(51.509865, -0.118092, 14); await this.service.drawStationMarkers(); this.service.drawHeatmap(); diff --git a/projects/project-3/frontend/src/app/service/domain/dashboard-common-bike-point.ts b/projects/project-3/frontend/src/app/service/domain/dashboard-common-bike-point.ts index b47a0bb..3d9508b 100644 --- a/projects/project-3/frontend/src/app/service/domain/dashboard-common-bike-point.ts +++ b/projects/project-3/frontend/src/app/service/domain/dashboard-common-bike-point.ts @@ -1,5 +1,6 @@ export interface IDashboardCommonBikePoint { id?: string; + color?: string; commonName?: string; lat?: number; lon?: number; @@ -10,6 +11,7 @@ export interface IDashboardCommonBikePoint { export class DashboardCommonBikePoint implements IDashboardCommonBikePoint { constructor( public id?: string, + public color?: string, public commonName?: string, public lat?: number, public lon?: number, diff --git a/projects/project-3/frontend/src/app/service/map.service.ts b/projects/project-3/frontend/src/app/service/map.service.ts index 041aef3..186bfba 100644 --- a/projects/project-3/frontend/src/app/service/map.service.ts +++ b/projects/project-3/frontend/src/app/service/map.service.ts @@ -9,8 +9,8 @@ import {IMapBikePoint} from './domain/map-bike-point'; import {Observable, Subject} from 'rxjs'; -const createIcon = L.icon({ - iconUrl: '../../assets/bike-point.png', +const createIcon = color => L.icon({ + iconUrl: `../../assets/bike-point-${color}.png`, iconSize: [45, 45], iconAnchor: [21, 40], popupAnchor: [1, -35] @@ -27,6 +27,9 @@ export class MapService { public miniMap; bikePoints: Array = []; mapOverlays: any = {}; + miniMapMarker: L.layerGroup; + markerLayer = []; + dashBoardMarker = L.marker; constructor( private client: HttpClient, @@ -78,7 +81,7 @@ export class MapService { this.mapOverlays.Bikepoints = markerClusters; this.map.addLayer(markerClusters); for (const station of data) { - const marker = L.marker([station.lat, station.lon], {icon: createIcon}); + const marker = L.marker([station.lat, station.lon], {icon: createIcon('blue')}); markerClusters.addLayer(marker); marker.on('click', e => { e.target.bindPopup(this.popUpService.makeAvailabilityPopUp(station), {maxWidth: 'auto'}) @@ -137,7 +140,20 @@ export class MapService { } public drawDashboardStationMarker(lat: number, lon: number): void { - L.marker([lat, lon], {icon: createIcon}).addTo(this.miniMap); + this.dashBoardMarker = L.marker([lat, lon], {icon: createIcon('blue')}).addTo(this.miniMap); + } + + public drawTableStationMarker(bikePoints: any[]): void { + if (this.markerLayer) { + this.markerLayer.forEach(marker => { + this.miniMap.removeLayer(marker); + }); + } + for (const point of bikePoints) { + const marker = L.marker([point.stationLat, point.stationLon], {icon: createIcon(point.color)}).addTo(this.miniMap); + this.markerLayer.push(marker); + this.miniMap.fitBounds(L.featureGroup([...this.markerLayer, this.dashBoardMarker]).getBounds()); + } } private drawMapControl(): void { diff --git a/projects/project-3/frontend/src/assets/bike-point-black.png b/projects/project-3/frontend/src/assets/bike-point-black.png new file mode 100644 index 0000000..3998fd4 Binary files /dev/null and b/projects/project-3/frontend/src/assets/bike-point-black.png differ diff --git a/projects/project-3/frontend/src/assets/bike-point.png b/projects/project-3/frontend/src/assets/bike-point-blue.png similarity index 100% rename from projects/project-3/frontend/src/assets/bike-point.png rename to projects/project-3/frontend/src/assets/bike-point-blue.png diff --git a/projects/project-3/frontend/src/assets/bike-point-gray.png b/projects/project-3/frontend/src/assets/bike-point-gray.png new file mode 100644 index 0000000..86aa043 Binary files /dev/null and b/projects/project-3/frontend/src/assets/bike-point-gray.png differ diff --git a/projects/project-3/frontend/src/assets/bike-point-green.png b/projects/project-3/frontend/src/assets/bike-point-green.png new file mode 100644 index 0000000..b088769 Binary files /dev/null and b/projects/project-3/frontend/src/assets/bike-point-green.png differ diff --git a/projects/project-3/frontend/src/assets/bike-point-orange.png b/projects/project-3/frontend/src/assets/bike-point-orange.png new file mode 100644 index 0000000..85aa8a8 Binary files /dev/null and b/projects/project-3/frontend/src/assets/bike-point-orange.png differ diff --git a/projects/project-3/frontend/src/assets/bike-point-purple.png b/projects/project-3/frontend/src/assets/bike-point-purple.png new file mode 100644 index 0000000..b0779d5 Binary files /dev/null and b/projects/project-3/frontend/src/assets/bike-point-purple.png differ diff --git a/projects/project-3/frontend/src/assets/bike-point-red.png b/projects/project-3/frontend/src/assets/bike-point-red.png new file mode 100644 index 0000000..636a1e9 Binary files /dev/null and b/projects/project-3/frontend/src/assets/bike-point-red.png differ
+ + + station of lend origin {{element.stationName}}