|
Bogdan Timofte
authored
2 weeks ago
|
1
|
//
|
|
Bogdan Timofte
authored
a week ago
|
2
|
// MeasurementSeriesSheetView.swift
|
|
Bogdan Timofte
authored
2 weeks ago
|
3
|
// USB Meter
|
|
|
4
|
//
|
|
|
5
|
// Created by Bogdan Timofte on 13/04/2020.
|
|
|
6
|
// Copyright © 2020 Bogdan Timofte. All rights reserved.
|
|
|
7
|
//
|
|
|
8
|
|
|
|
9
|
import SwiftUI
|
|
|
10
|
|
|
Bogdan Timofte
authored
a week ago
|
11
|
struct MeasurementSeriesSheetView: View {
|
|
Bogdan Timofte
authored
2 weeks ago
|
12
|
|
|
|
13
|
@EnvironmentObject private var measurements: Measurements
|
|
|
14
|
|
|
|
15
|
@Binding var visibility: Bool
|
|
|
16
|
|
|
|
17
|
var body: some View {
|
|
Bogdan Timofte
authored
a week ago
|
18
|
let seriesPoints = measurements.power.samplePoints
|
|
|
19
|
|
|
Bogdan Timofte
authored
2 weeks ago
|
20
|
NavigationView {
|
|
Bogdan Timofte
authored
2 weeks ago
|
21
|
ScrollView {
|
|
|
22
|
VStack(alignment: .leading, spacing: 14) {
|
|
|
23
|
VStack(alignment: .leading, spacing: 8) {
|
|
Bogdan Timofte
authored
a week ago
|
24
|
Text("Measurement Series")
|
|
Bogdan Timofte
authored
2 weeks ago
|
25
|
.font(.system(.title3, design: .rounded).weight(.bold))
|
|
Bogdan Timofte
authored
a week ago
|
26
|
Text("Buffered measurement series captured from the meter for analysis, charts, and correlations.")
|
|
Bogdan Timofte
authored
2 weeks ago
|
27
|
.font(.footnote)
|
|
|
28
|
.foregroundColor(.secondary)
|
|
|
29
|
}
|
|
|
30
|
.padding(18)
|
|
|
31
|
.meterCard(tint: .blue, fillOpacity: 0.18, strokeOpacity: 0.24)
|
|
|
32
|
|
|
Bogdan Timofte
authored
a week ago
|
33
|
if seriesPoints.isEmpty {
|
|
|
34
|
Text("No measurement samples have been captured yet.")
|
|
Bogdan Timofte
authored
2 weeks ago
|
35
|
.font(.footnote)
|
|
|
36
|
.foregroundColor(.secondary)
|
|
|
37
|
.padding(18)
|
|
|
38
|
.meterCard(tint: .secondary, fillOpacity: 0.14, strokeOpacity: 0.20)
|
|
|
39
|
} else {
|
|
|
40
|
LazyVStack(spacing: 12) {
|
|
Bogdan Timofte
authored
a week ago
|
41
|
ForEach(seriesPoints) { point in
|
|
|
42
|
MeasurementSeriesSampleView(
|
|
Bogdan Timofte
authored
2 weeks ago
|
43
|
power: point,
|
|
|
44
|
voltage: measurements.voltage.points[point.id],
|
|
Bogdan Timofte
authored
19 hours ago
|
45
|
current: measurements.current.points[point.id],
|
|
|
46
|
energy: energyPoint(for: point.timestamp)
|
|
Bogdan Timofte
authored
2 weeks ago
|
47
|
)
|
|
|
48
|
}
|
|
Bogdan Timofte
authored
2 weeks ago
|
49
|
}
|
|
|
50
|
}
|
|
|
51
|
}
|
|
Bogdan Timofte
authored
2 weeks ago
|
52
|
.padding()
|
|
Bogdan Timofte
authored
2 weeks ago
|
53
|
}
|
|
Bogdan Timofte
authored
2 weeks ago
|
54
|
.background(
|
|
|
55
|
LinearGradient(
|
|
|
56
|
colors: [.blue.opacity(0.14), Color.clear],
|
|
|
57
|
startPoint: .topLeading,
|
|
|
58
|
endPoint: .bottomTrailing
|
|
|
59
|
)
|
|
|
60
|
.ignoresSafeArea()
|
|
|
61
|
)
|
|
|
62
|
.navigationBarItems(
|
|
|
63
|
leading: Button("Done") { visibility.toggle() },
|
|
Bogdan Timofte
authored
a week ago
|
64
|
trailing: Button("Reset Series") {
|
|
|
65
|
measurements.resetSeries()
|
|
Bogdan Timofte
authored
2 weeks ago
|
66
|
}
|
|
|
67
|
.foregroundColor(.red)
|
|
|
68
|
)
|
|
Bogdan Timofte
authored
a week ago
|
69
|
.navigationBarTitle("Measurement Series", displayMode: .inline)
|
|
Bogdan Timofte
authored
2 weeks ago
|
70
|
}
|
|
|
71
|
.navigationViewStyle(StackNavigationViewStyle())
|
|
|
72
|
}
|
|
Bogdan Timofte
authored
19 hours ago
|
73
|
|
|
|
74
|
private func energyPoint(for timestamp: Date) -> Measurements.Measurement.Point? {
|
|
|
75
|
measurements.energy.samplePoints.last { $0.timestamp == timestamp }
|
|
|
76
|
}
|
|
Bogdan Timofte
authored
2 weeks ago
|
77
|
}
|