-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBarGraphViews.swift
More file actions
176 lines (136 loc) · 4.25 KB
/
BarGraphViews.swift
File metadata and controls
176 lines (136 loc) · 4.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
//
// BarGraphViews.swift
// InductionApp
//
// Created by Ben Altschuler on 5/19/20.
// Copyright © 2020 Ben Altschuler. All rights reserved.
//
import Foundation
import SwiftUI
enum SectionName: Int, CaseIterable, Hashable, Identifiable {
case overall = 0
case reading
case english
case math
case science
var name: String {
return "\(self)".capitalized
}
var id: SectionName {self}
}
enum Days: String, CaseIterable, Hashable, Identifiable {
// case CSE
// case POW
// case KOL
//
// case KID
// case IK
// case CS
//
// case IES
// case Alg
// case Geom
// case Func
// case Modeling
// case NQ
//
// case IOD
// case SI
// case EM
case ACT1 = "02-05-20"
case ACT2 = "05-05-20"
//case ACT3
var shortName: String {
return self.rawValue
}
var id: Days {self}
}
struct BarContentView: View {
@State var pickerSelectedItem = 0
@State var data: [(dayPart: SectionName, caloriesByDay: [(day:Days, calories:Int)])] =
[
(
SectionName.overall,
[
(Days.ACT1, 26),
(Days.ACT2, 27),
//(Days.ACT3, 36)
]
),
(
SectionName.reading,
[
(Days.ACT1, 25),
(Days.ACT2, 24),
//(Days.ACT3, 35)
]
),
(
SectionName.english,
[
(Days.ACT1, 28),
(Days.ACT2, 25),
//(Days.ACT3, 36)
]
),
(
SectionName.math,
[
(Days.ACT1, 31),
(Days.ACT2, 26),
//(Days.ACT3, 36)
]
),
(
SectionName.science,
[
(Days.ACT1, 21),
(Days.ACT2, 35),
//(Days.ACT3, 36)
]
)
]
var body: some View {
ZStack {
VStack {
Text("Quick Data")
.foregroundColor(Color("lightBlue"))
.font(.system(size: 34))
.fontWeight(.heavy)
Picker(selection: $pickerSelectedItem.animation(), label: Text("")) {
ForEach(SectionName.allCases) { dp in
Text(dp.name).tag(dp.rawValue)
}
}.pickerStyle(SegmentedPickerStyle())
.padding(.horizontal, 24)
.animation(.default)
HStack (spacing: 10) {
ForEach(0..<self.data[pickerSelectedItem].caloriesByDay.count, id: \.self)
{ i in
BarView(
value: self.data[self.pickerSelectedItem].caloriesByDay[i].calories,
label: self.data[self.pickerSelectedItem].caloriesByDay[i].day.shortName
)
}
}.padding(.top, 24)
.animation(.default)
}//vs
}//zs
}
}
struct BarView: View {
var value: Int
var label: String
var body: some View {
VStack {
ZStack(alignment: .bottom) {
Capsule().frame(width: 30, height: 216)
.foregroundColor(Color("lightBlue"))
Capsule().frame(width: 30, height: CGFloat(value*6))
.foregroundColor( Color("salmon"))
}
Text(label)
.padding(.top,8)
}
}
}