|
|
|
|
@ -53,16 +53,18 @@ struct StatsView: View { |
|
|
|
|
|
|
|
|
|
var body: some View { |
|
|
|
|
|
|
|
|
|
VStack() { |
|
|
|
|
|
|
|
|
|
if self.model.isComputing { |
|
|
|
|
ProgressView() |
|
|
|
|
.progressViewStyle(CircularProgressViewStyle()) |
|
|
|
|
} else { |
|
|
|
|
VStack(alignment: .leading) { |
|
|
|
|
ForEach(self.model.statValues) { statValue in |
|
|
|
|
StatGraphView(statValue: statValue) |
|
|
|
|
// .padding(.vertical) |
|
|
|
|
Section { |
|
|
|
|
VStack() { |
|
|
|
|
|
|
|
|
|
if self.model.isComputing { |
|
|
|
|
ProgressView() |
|
|
|
|
.progressViewStyle(CircularProgressViewStyle()) |
|
|
|
|
} else { |
|
|
|
|
VStack(alignment: .leading) { |
|
|
|
|
ForEach(self.model.statValues) { statValue in |
|
|
|
|
StatGraphView(statValue: statValue, timeFrame: self.timeFrame) |
|
|
|
|
// .padding(.vertical) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -93,6 +95,7 @@ struct StatView: View { |
|
|
|
|
struct StatGraphView: View { |
|
|
|
|
|
|
|
|
|
var statValue: StatValue |
|
|
|
|
var timeFrame: TimeFrame |
|
|
|
|
|
|
|
|
|
var body: some View { |
|
|
|
|
VStack { |
|
|
|
|
@ -102,24 +105,35 @@ struct StatGraphView: View { |
|
|
|
|
Text(self.statValue.formattedValue) |
|
|
|
|
// .font(.system(.title, weight: .bold)) |
|
|
|
|
} |
|
|
|
|
Chart(self.statValue.records) { point in |
|
|
|
|
Chart(self.statValue.chartPoint(timeFrame: self.timeFrame)) { point in |
|
|
|
|
|
|
|
|
|
let stat: Stat = self.statValue.stat |
|
|
|
|
|
|
|
|
|
switch stat { |
|
|
|
|
case .count, .totalDuration: |
|
|
|
|
BarMark(x: .value("date", point.date, unit: .day), |
|
|
|
|
BarMark(x: .value("date", point.index), |
|
|
|
|
y: .value("value", point.value.doubleValue)) |
|
|
|
|
default: |
|
|
|
|
LineMark(x: .value("date", point.date, unit: .day), |
|
|
|
|
LineMark(x: .value("date", point.index), |
|
|
|
|
y: .value("value", point.value.doubleValue)) |
|
|
|
|
} |
|
|
|
|
}.frame(height: 300.0) |
|
|
|
|
}.frame(height: 200.0) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
struct StatGraphView_Previews: PreviewProvider { |
|
|
|
|
|
|
|
|
|
static let points: [Point] = [Point(date: Date(), value: 1), |
|
|
|
|
Point(date: Date(), value: 1), |
|
|
|
|
Point(date: Date(timeIntervalSince1970: 100000), value: 1)] |
|
|
|
|
|
|
|
|
|
static var previews: some View { |
|
|
|
|
StatGraphView(statValue: StatValue(stat: .count, value: NSDecimalNumber(integerLiteral: 3), points: points), timeFrame: .all) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
struct StatView_Previews: PreviewProvider { |
|
|
|
|
static var previews: some View { |
|
|
|
|
StatView(statValue: StatValue(stat: .count, value: NSDecimalNumber(integerLiteral: 3))) |
|
|
|
|
|