|
|
|
|
@ -7,6 +7,7 @@ |
|
|
|
|
|
|
|
|
|
import SwiftUI |
|
|
|
|
import CoreData |
|
|
|
|
import Charts |
|
|
|
|
|
|
|
|
|
class StatModel: ObservableObject { |
|
|
|
|
|
|
|
|
|
@ -59,11 +60,11 @@ struct StatsView: View { |
|
|
|
|
} else { |
|
|
|
|
VStack(alignment: .leading) { |
|
|
|
|
ForEach(self.model.statValues) { statValue in |
|
|
|
|
StatView(name: statValue.stat.localizedName, value: statValue.formattedValue).padding(.vertical) |
|
|
|
|
StatGraphView(statValue: statValue) |
|
|
|
|
// .padding(.vertical) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
Spacer() |
|
|
|
|
} |
|
|
|
|
.onAppear() { |
|
|
|
|
self.model.compute(activity: self.activity, filter: self.filter) |
|
|
|
|
@ -75,13 +76,43 @@ struct StatsView: View { |
|
|
|
|
|
|
|
|
|
struct StatView: View { |
|
|
|
|
|
|
|
|
|
var name: String |
|
|
|
|
var value: String |
|
|
|
|
var statValue: StatValue |
|
|
|
|
|
|
|
|
|
var body: some View { |
|
|
|
|
VStack(alignment: .leading) { |
|
|
|
|
Text(self.name.uppercased()).font(.footnote) |
|
|
|
|
Text(self.value).font(.system(.title, weight: .bold)) |
|
|
|
|
Text(self.statValue.stat.localizedName.uppercased()) |
|
|
|
|
.font(.footnote) |
|
|
|
|
Text(self.statValue.formattedValue) |
|
|
|
|
.font(.system(.title, weight: .bold)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
struct StatGraphView: View { |
|
|
|
|
|
|
|
|
|
var statValue: StatValue |
|
|
|
|
|
|
|
|
|
var body: some View { |
|
|
|
|
VStack { |
|
|
|
|
HStack { |
|
|
|
|
Text(self.statValue.stat.localizedName.uppercased()) |
|
|
|
|
// .font(.footnote) |
|
|
|
|
Text(self.statValue.formattedValue) |
|
|
|
|
// .font(.system(.title, weight: .bold)) |
|
|
|
|
} |
|
|
|
|
Chart(self.statValue.records) { point in |
|
|
|
|
|
|
|
|
|
let stat: Stat = self.statValue.stat |
|
|
|
|
switch stat { |
|
|
|
|
case .count, .totalDuration: |
|
|
|
|
BarMark(x: .value("name", point.date, unit: .month), |
|
|
|
|
y: .value("value", point.value.doubleValue)) |
|
|
|
|
default: |
|
|
|
|
LineMark(x: .value("name", point.date, unit: .month), |
|
|
|
|
y: .value("value", point.value.doubleValue)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -89,7 +120,7 @@ struct StatView: View { |
|
|
|
|
|
|
|
|
|
struct StatView_Previews: PreviewProvider { |
|
|
|
|
static var previews: some View { |
|
|
|
|
StatView(name: "Duration", value: "3") |
|
|
|
|
StatView(statValue: StatValue(stat: .count, value: NSDecimalNumber(integerLiteral: 3))) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|