-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The sample service will take care of all queries and updates.
- Loading branch information
Showing
17 changed files
with
352 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
frontend/src/app/device-overview/device-overview.component.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
.chart { | ||
width: 80vw; | ||
height: 30vh; | ||
} | ||
|
||
|
||
.chartlegend { | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
} | ||
|
||
.legend svg { | ||
text-align: center; | ||
} | ||
|
||
.allmap { | ||
width: 100%; | ||
height: 50vh; | ||
} |
8 changes: 8 additions & 0 deletions
8
frontend/src/app/device-overview/device-overview.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<div class="chartlegend"> | ||
<div #legend id="legend" class="legend"></div> | ||
<div #chart id="chart" class="chart"></div> | ||
<div>Sist oppdatert {{ samples.lastPoll |date:'YYYY-mm-dd HH:MM'}}</div> | ||
</div> | ||
<div class="allmap"> | ||
<app-device-map-view class="allmap"></app-device-map-view> | ||
</div> |
23 changes: 23 additions & 0 deletions
23
frontend/src/app/device-overview/device-overview.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { DeviceOverviewComponent } from './device-overview.component'; | ||
|
||
describe('DeviceOverviewComponent', () => { | ||
let component: DeviceOverviewComponent; | ||
let fixture: ComponentFixture<DeviceOverviewComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
declarations: [ DeviceOverviewComponent ] | ||
}) | ||
.compileComponents(); | ||
|
||
fixture = TestBed.createComponent(DeviceOverviewComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
95 changes: 95 additions & 0 deletions
95
frontend/src/app/device-overview/device-overview.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { AfterViewInit, Component, ElementRef, OnInit, Renderer2, ViewChild } from '@angular/core'; | ||
import { DeviceSample, SampleService } from '../sample.service'; | ||
import * as d3 from 'd3'; | ||
import * as Plot from '@observablehq/plot'; | ||
|
||
@Component({ | ||
selector: 'app-device-overview', | ||
templateUrl: './device-overview.component.html', | ||
styleUrls: ['./device-overview.component.css'] | ||
}) | ||
export class DeviceOverviewComponent implements OnInit, AfterViewInit { | ||
@ViewChild("chart") chartRef?: ElementRef; | ||
chart?: (SVGElement | HTMLElement); | ||
@ViewChild("legend") legendRef?: ElementRef; | ||
legend?: (SVGElement | HTMLElement); | ||
|
||
constructor( | ||
protected samples: SampleService, | ||
private renderer: Renderer2, | ||
) { } | ||
|
||
ngOnInit(): void { | ||
} | ||
|
||
ngAfterViewInit(): void { | ||
this.showChart(); | ||
} | ||
|
||
showChart(): void { | ||
if (this.chart) { | ||
// Remove the old one if it already exists | ||
this.renderer.removeChild(this.chartRef?.nativeElement, this.chart, false); | ||
} | ||
let data = this.samples.allData(); | ||
|
||
let width = this.chartRef?.nativeElement.offsetWidth; | ||
let max = (d3.max(data, (d: DeviceSample) => (d.ble + d.wifi)) || 1); | ||
const hhmmFormat = d3.timeFormat("%m-%d %H:00") | ||
|
||
this.chart = Plot.plot({ | ||
width: width, | ||
marginLeft: 250, | ||
marginBottom: 100, | ||
x: { | ||
label: "Tid", | ||
tickRotate: -90, | ||
}, | ||
y: { | ||
label: "Enhet", | ||
}, | ||
marks: [ | ||
Plot.cell(data, { | ||
x: d => hhmmFormat(d.time), | ||
y: "name", | ||
fill: (d: DeviceSample) => { | ||
let f = (d.ble + d.wifi); | ||
return f; | ||
}, | ||
}), | ||
Plot.frame() | ||
], | ||
color: { | ||
legend: false, | ||
scheme: "gnbu", | ||
reverse: false, | ||
type: "linear" | ||
}, | ||
style: { | ||
fontFamily: 'sans-serif', | ||
fontSize: '10pt', | ||
background: '#eeeeee', | ||
fill: '#808080', | ||
} | ||
}); | ||
|
||
this.renderer.appendChild(this.chartRef?.nativeElement, this.chart) | ||
|
||
if (!this.legend) { | ||
this.legend = Plot.legend({ | ||
color: { | ||
domain: [0, max], | ||
ticks: 3, | ||
scheme: "gnbu", | ||
reverse: false, | ||
type: "linear" | ||
}, | ||
width: 350, | ||
ticks: 5, | ||
label: "Antall enheter", | ||
style: { background: "#eeeeee" } | ||
},) | ||
this.renderer.appendChild(this.legendRef?.nativeElement, this.legend) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,10 +53,6 @@ | |
vertical-align: middle; | ||
} | ||
|
||
#chart { | ||
display: flex; | ||
} | ||
|
||
#chart svg { | ||
flex: 1 | ||
.chart { | ||
width: 80vw; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.