Skip to content

Commit

Permalink
Update navigation and combine charts for comparison reasons
Browse files Browse the repository at this point in the history
  • Loading branch information
atrinh0 committed Feb 27, 2021
1 parent ccb8558 commit 9345e47
Show file tree
Hide file tree
Showing 7 changed files with 239 additions and 153 deletions.
26 changes: 25 additions & 1 deletion covid19/covid19.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
FCA371832529D2C700CD24C3 /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCA371812529D2C700CD24C3 /* Extensions.swift */; };
FCA371872529D34D00CD24C3 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCA371862529D34D00CD24C3 /* Constants.swift */; };
FCA371882529D34D00CD24C3 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCA371862529D34D00CD24C3 /* Constants.swift */; };
FCCACA6525EAC4D100C3E0FF /* WebView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCCACA6425EAC4D100C3E0FF /* WebView.swift */; };
FCCACA6A25EAC52100C3E0FF /* RNumberView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCCACA6925EAC52100C3E0FF /* RNumberView.swift */; };
FCCACA7625EACADA00C3E0FF /* SourceView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCCACA7525EACADA00C3E0FF /* SourceView.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -70,6 +73,9 @@
FC6DCF2C2522816500D38990 /* Launch Screen.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = "Launch Screen.storyboard"; sourceTree = "<group>"; };
FCA371812529D2C700CD24C3 /* Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = "<group>"; };
FCA371862529D34D00CD24C3 /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
FCCACA6425EAC4D100C3E0FF /* WebView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebView.swift; sourceTree = "<group>"; };
FCCACA6925EAC52100C3E0FF /* RNumberView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RNumberView.swift; sourceTree = "<group>"; };
FCCACA7525EACADA00C3E0FF /* SourceView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SourceView.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -117,9 +123,12 @@
FC41008C2520EE0800F931CC /* covid19 */ = {
isa = PBXGroup;
children = (
FCCACA6825EAC50C00C3E0FF /* Views */,
FC41008D2520EE0800F931CC /* covid19App.swift */,
FC41008F2520EE0800F931CC /* ContentView.swift */,
FC41009E2521083B00F931CC /* ViewModel.swift */,
FC41008F2520EE0800F931CC /* ContentView.swift */,
FCCACA6925EAC52100C3E0FF /* RNumberView.swift */,
FCCACA7525EACADA00C3E0FF /* SourceView.swift */,
FC4100912520EE0900F931CC /* Assets.xcassets */,
FC4100962520EE0900F931CC /* Info.plist */,
FC4100932520EE0900F931CC /* Preview Content */,
Expand Down Expand Up @@ -165,6 +174,14 @@
path = Common;
sourceTree = "<group>";
};
FCCACA6825EAC50C00C3E0FF /* Views */ = {
isa = PBXGroup;
children = (
FCCACA6425EAC4D100C3E0FF /* WebView.swift */,
);
path = Views;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -277,10 +294,13 @@
files = (
FCA371822529D2C700CD24C3 /* Extensions.swift in Sources */,
FC4100902520EE0800F931CC /* ContentView.swift in Sources */,
FCCACA6A25EAC52100C3E0FF /* RNumberView.swift in Sources */,
FCCACA7625EACADA00C3E0FF /* SourceView.swift in Sources */,
FC41009F2521083B00F931CC /* ViewModel.swift in Sources */,
FC41008E2520EE0800F931CC /* covid19App.swift in Sources */,
FC6DCF22252269F900D38990 /* Models.swift in Sources */,
FCA371872529D34D00CD24C3 /* Constants.swift in Sources */,
FCCACA6525EAC4D100C3E0FF /* WebView.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -479,6 +499,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
ASSETCATALOG_COMPILER_WIDGET_BACKGROUND_COLOR_NAME = WidgetBackground;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 6DRH5697SN;
INFOPLIST_FILE = CasesWidget/Info.plist;
Expand All @@ -490,6 +511,7 @@
MARKETING_VERSION = 1;
PRODUCT_BUNDLE_IDENTIFIER = com.atrinh.covid.CasesWidget;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SKIP_INSTALL = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
Expand All @@ -501,6 +523,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
ASSETCATALOG_COMPILER_WIDGET_BACKGROUND_COLOR_NAME = WidgetBackground;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 6DRH5697SN;
INFOPLIST_FILE = CasesWidget/Info.plist;
Expand All @@ -512,6 +535,7 @@
MARKETING_VERSION = 1;
PRODUCT_BUNDLE_IDENTIFIER = com.atrinh.covid.CasesWidget;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SKIP_INSTALL = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
Expand Down
256 changes: 117 additions & 139 deletions covid19/covid19/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,158 +14,131 @@ struct ContentView: View {
@State private var locationSelection = Location.uk
@ObservedObject private var viewModel = ViewModel()
@State private var casesChartCount = ChartCount.all
@State private var deathsChartCount = ChartCount.all
@State private var showRelativeChartData = false

let timer = Timer.publish(every: 60, on: .main, in: .common).autoconnect()
private let chartHeight: CGFloat = 175
private let chartHeight: CGFloat = 200

var body: some View {
List {
Section {
HStack() {
Text(locationSelection.rawValue)
.lineLimit(0)
.font(Font.title2.bold())
Spacer()
Picker(selection: $locationSelection, label:
Image(systemName: "chevron.down.circle.fill")
List {
Section {
HStack() {
Text(locationSelection.rawValue)
.lineLimit(0)
.font(Font.title2.bold())
) {
ForEach(Location.allCases) {
Text($0.rawValue)
.tag($0)
Spacer()
Picker(selection: $locationSelection, label:
Image(systemName: "chevron.down.circle.fill")
.font(Font.title2.bold())
) {
ForEach(Location.allCases) {
Text($0.rawValue)
.tag($0)
}
}
}
.onChange(of: locationSelection) { _ in
reloadData()
}
.pickerStyle(MenuPickerStyle())
}
.padding([.vertical])
}
Section {
Text(viewModel.footerText)
.padding([.vertical])
}
Section {
VStack(alignment: .leading, spacing: 10) {
Text("\(locationSelection.flag()) Cases")
.font(Font.title2.bold())
Chart(data: viewModel.casesData.suffix(casesChartCount.numberOfDatapoints()))
.chartStyle(
LineChartStyle(.line, lineColor: .orange, lineWidth: 2)
)
.frame(height: chartHeight)
Picker(selection: $casesChartCount, label:
Text("")
) {
ForEach(ChartCount.allCases) {
Text($0.rawValue)
.tag($0)
.onChange(of: locationSelection) { _ in
reloadData()
}
.pickerStyle(MenuPickerStyle())
}
.pickerStyle(SegmentedPickerStyle())
.padding(.bottom, 5)
VStack(alignment: .leading) {
Text(viewModel.dailyLatestCases)
.font(Font.title2.bold())
.foregroundColor(.orange) +
Text(viewModel.dailyCasesChange)
.font(Font.title2.bold())
.foregroundColor(.gray)
Text("new cases on \(viewModel.latestDate)")
.foregroundColor(.gray)
}
VStack(alignment: .leading) {
Text(viewModel.weeklyLatestCases)
.font(Font.title2.bold())
.foregroundColor(.orange) +
Text(viewModel.weeklyCasesChange)
.font(Font.title2.bold())
.foregroundColor(.gray)
Text("new cases in the last 7 days")
.foregroundColor(.gray)
}
VStack(alignment: .leading) {
Text(viewModel.totalCases)
.font(Font.title2.bold()) +
Text(" total")
.foregroundColor(.gray)
}
.padding([.vertical])
}
.padding(.vertical, 10)
}
Section {
VStack(alignment: .leading, spacing: 10) {
VStack(alignment: .leading) {
Text("\(locationSelection.flag()) Deaths")
.font(Font.title2.bold())
Text("within 28 days of positive test")
.foregroundColor(.gray)
}
Chart(data: viewModel.deathsData.suffix(deathsChartCount.numberOfDatapoints()))
.chartStyle(
LineChartStyle(.line, lineColor: .red, lineWidth: 2)
)
.frame(height: chartHeight)
Picker(selection: $deathsChartCount, label:
Text("")
) {
ForEach(ChartCount.allCases) {
Text($0.rawValue)
.tag($0)
Section {
Text(viewModel.footerText)
.padding([.vertical])
}
Section {
VStack(alignment: .leading, spacing: 10) {
ZStack {
Chart(data: viewModel.casesData.suffix(casesChartCount.numberOfDatapoints()))
.chartStyle(
LineChartStyle(.line, lineColor: .orange, lineWidth: 2)
)
.frame(height: chartHeight)
Chart(data: deathsData)
.chartStyle(
LineChartStyle(.line, lineColor: .red, lineWidth: 2)
)
.frame(height: chartHeight)
}
Picker(selection: $casesChartCount, label:
Text("")
) {
ForEach(ChartCount.allCases) {
Text($0.rawValue)
.tag($0)
}
}
.pickerStyle(SegmentedPickerStyle())
Picker(selection: $showRelativeChartData, label:
Text("")
) {
Text("Relative")
.tag(true)
Text("Emphasised")
.tag(false)
}
.pickerStyle(SegmentedPickerStyle())
.padding(.bottom, 5)
VStack(alignment: .leading) {
Text(viewModel.dailyLatestCases)
.font(Font.title2.bold())
.foregroundColor(.orange) +
Text(viewModel.dailyCasesChange)
.font(Font.title2.bold())
.foregroundColor(.gray)
Text("new cases on \(viewModel.latestDate)")
.foregroundColor(.gray)
}
VStack(alignment: .leading) {
Text(viewModel.weeklyLatestCases)
.font(Font.title2.bold())
.foregroundColor(.orange) +
Text(viewModel.weeklyCasesChange)
.font(Font.title2.bold())
.foregroundColor(.gray)
Text("new cases in the last 7 days")
.foregroundColor(.gray)
}
VStack(alignment: .leading) {
Text(viewModel.totalCases)
.font(Font.title2.bold())
.foregroundColor(.orange) +
Text(" total cases")
.foregroundColor(.gray)
}
VStack(alignment: .leading) {
Text(viewModel.dailyLatestDeaths)
.font(Font.title2.bold())
.foregroundColor(.red) +
Text(viewModel.dailyDeathsChange)
.font(Font.title2.bold())
.foregroundColor(.gray)
Text("new deaths on \(viewModel.latestDate)")
.foregroundColor(.gray)
}
VStack(alignment: .leading) {
Text(viewModel.weeklyLatestDeaths)
.font(Font.title2.bold())
.foregroundColor(.red) +
Text(viewModel.weeklyDeathsChange)
.font(Font.title2.bold())
.foregroundColor(.gray)
Text("new deaths in the last 7 days")
.foregroundColor(.gray)
}
VStack(alignment: .leading) {
Text(viewModel.totalDeaths)
.font(Font.title2.bold())
.foregroundColor(.red) +
Text(" total deaths")
.foregroundColor(.gray)
}
}
.pickerStyle(SegmentedPickerStyle())
.padding(.bottom, 5)
VStack(alignment: .leading) {
Text(viewModel.dailyLatestDeaths)
.font(Font.title2.bold())
.foregroundColor(.red) +
Text(viewModel.dailyDeathsChange)
.font(Font.title2.bold())
.foregroundColor(.gray)
Text("new deaths on \(viewModel.latestDate)")
.foregroundColor(.gray)
}
VStack(alignment: .leading) {
Text(viewModel.weeklyLatestDeaths)
.font(Font.title2.bold())
.foregroundColor(.red) +
Text(viewModel.weeklyDeathsChange)
.font(Font.title2.bold())
.foregroundColor(.gray)
Text("new deaths in the last 7 days")
.foregroundColor(.gray)
}
VStack(alignment: .leading) {
Text(viewModel.totalDeaths)
.font(Font.title2.bold()) +
Text(" total")
.foregroundColor(.gray)
}
}
.padding(.vertical, 10)
}
Section {
Link(destination: Constants.appStoreStory) {
Label("Get the Contact Tracing app", systemImage: "figure.stand.line.dotted.figure.stand")
.padding(.vertical)
.font(Font.body.bold())
}
Link(destination: Constants.rNumberUK) {
Label("R-number and Growth Rate", systemImage: "number")
.padding(.vertical)
.font(Font.body.bold())
}
Link(destination: Constants.sourceGovUK) {
Label("Source: coronavirus.data.gov.uk", systemImage: "link")
.padding(.vertical)
.font(Font.body.bold())
.padding(.vertical, 10)
}
}
}
.listStyle(InsetGroupedListStyle())
.listStyle(InsetGroupedListStyle())
.onAppear {
reloadData()
WidgetCenter.shared.reloadTimelines(ofKind: Constants.widgetName)
Expand Down Expand Up @@ -195,6 +168,11 @@ struct ContentView: View {
viewModel.fetchData(locationSelection, clearData: false)
}
}

private var deathsData: [Double] {
showRelativeChartData ? viewModel.relativeDeathsData.suffix(casesChartCount.numberOfDatapoints()) :
viewModel.rawDeathsData.suffix(casesChartCount.numberOfDatapoints())
}
}

struct ContentView_Previews: PreviewProvider {
Expand Down
Loading

0 comments on commit 9345e47

Please sign in to comment.