Newer Older
72 lines | 2.743kb
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],
45
                                    current: measurements.current.points[point.id]
46
                                )
47
                            }
Bogdan Timofte authored 2 weeks ago
48
                        }
49
                    }
50
                }
Bogdan Timofte authored 2 weeks ago
51
                .padding()
Bogdan Timofte authored 2 weeks ago
52
            }
Bogdan Timofte authored 2 weeks ago
53
            .background(
54
                LinearGradient(
55
                    colors: [.blue.opacity(0.14), Color.clear],
56
                    startPoint: .topLeading,
57
                    endPoint: .bottomTrailing
58
                )
59
                .ignoresSafeArea()
60
            )
61
            .navigationBarItems(
62
                leading: Button("Done") { visibility.toggle() },
Bogdan Timofte authored a week ago
63
                trailing: Button("Reset Series") {
64
                    measurements.resetSeries()
Bogdan Timofte authored 2 weeks ago
65
                }
66
                .foregroundColor(.red)
67
            )
Bogdan Timofte authored a week ago
68
            .navigationBarTitle("Measurement Series", displayMode: .inline)
Bogdan Timofte authored 2 weeks ago
69
        }
70
        .navigationViewStyle(StackNavigationViewStyle())
71
    }
72
}