Prettify main view, add temperature history
This commit is contained in:
@@ -14,6 +14,12 @@ struct DeviceInfoView: View {
|
||||
private let storageWarnBytes = 500
|
||||
|
||||
let info: DeviceInfo
|
||||
|
||||
@Binding
|
||||
var isPresented: Bool
|
||||
|
||||
@Binding
|
||||
var updateToggle: Bool
|
||||
|
||||
private var runTimeString: String {
|
||||
let number = info.numberOfSecondsRunning
|
||||
@@ -97,6 +103,16 @@ struct DeviceInfoView: View {
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 5) {
|
||||
HStack {
|
||||
Text("Device Info").font(.title2).bold()
|
||||
Spacer()
|
||||
Button(action: { isPresented = false }) {
|
||||
Image(systemSymbol: .xmarkCircleFill)
|
||||
.foregroundColor(.gray)
|
||||
.font(.system(size: 26))
|
||||
}
|
||||
}
|
||||
.padding(.bottom)
|
||||
VStack(alignment: .leading, spacing: 5) {
|
||||
Text("Recording")
|
||||
.font(.headline)
|
||||
@@ -159,8 +175,11 @@ struct DeviceInfoView: View {
|
||||
|
||||
struct DeviceInfoView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
DeviceInfoView(info: .mock)
|
||||
.previewLayout(.fixed(width: 375, height: 500))
|
||||
DeviceInfoView(
|
||||
info: .mock,
|
||||
isPresented: .constant(true),
|
||||
updateToggle: .constant(true))
|
||||
.previewLayout(.fixed(width: 375, height: 600))
|
||||
}
|
||||
}
|
||||
|
||||
|
58
TempTrack/Views/TemperatureHistoryChart.swift
Normal file
58
TempTrack/Views/TemperatureHistoryChart.swift
Normal file
@@ -0,0 +1,58 @@
|
||||
import SwiftUI
|
||||
import Charts
|
||||
|
||||
struct TemperatureHistoryChart: View {
|
||||
|
||||
let points: [TemperatureMeasurement]
|
||||
|
||||
let upperTempLimit = 40.0
|
||||
let lowerTempLimit = -20.0
|
||||
|
||||
let pastDateLimit = -3600
|
||||
let futureDateLimit = 0
|
||||
|
||||
var body: some View {
|
||||
Chart {
|
||||
ForEach(points) { point in
|
||||
if let s = point.sensor0.optionalValue {
|
||||
LineMark(
|
||||
x: .value("Date", point.secondsAgo),
|
||||
y: .value("Temperature", s))
|
||||
.foregroundStyle(Color.red)
|
||||
}
|
||||
if let s = point.sensor1.optionalValue {
|
||||
LineMark(
|
||||
x: .value("Date", point.secondsAgo),
|
||||
y: .value("Temperature", s))
|
||||
.foregroundStyle(by: .value("Type", "Sensor 1"))
|
||||
}
|
||||
}
|
||||
}
|
||||
.chartXScale(domain: pastDateLimit...futureDateLimit)
|
||||
.chartYScale(domain: lowerTempLimit...upperTempLimit)
|
||||
.chartXAxis(.hidden)
|
||||
.chartLegend(.hidden)
|
||||
.chartYAxis {
|
||||
AxisMarks(position: .trailing, values: .automatic) { value in
|
||||
AxisValueLabel(multiLabelAlignment: .trailing) {
|
||||
if let intValue = value.as(Int.self) {
|
||||
Text("\(intValue) km")
|
||||
.font(.system(size: 10))
|
||||
.foregroundColor(.white)
|
||||
}
|
||||
}
|
||||
}
|
||||
//AxisMarks(position: .trailing, stroke: StrokeStyle(lineWidth: 0))
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
}
|
||||
|
||||
struct TemperatureHistoryChart_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
TemperatureHistoryChart(
|
||||
points: TemperatureMeasurement.mockData)
|
||||
.previewLayout(.fixed(width: 350, height: 150))
|
||||
.background(.gray)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user