From 2c9c67e7ae0b3d29e7459d3ff852d907d95d6249 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EA=B0=80=EC=9D=80?= Date: Sun, 6 Nov 2022 19:56:47 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20ChartView=20=EB=88=84=EB=9D=BD=EB=8F=BC?= =?UTF-8?q?=EC=84=9C=20=EB=8B=A4=EC=8B=9C=20=EC=98=AC=EB=A6=BD=EB=8B=88?= =?UTF-8?q?=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2022/Playgrounds/ChartView.swift | 134 +++++++++++++++++++++++++++++ App/LetSwiftApp.swift | 2 +- LetSwift.xcodeproj/project.pbxproj | 8 +- 3 files changed, 139 insertions(+), 5 deletions(-) create mode 100644 2022/Playgrounds/ChartView.swift diff --git a/2022/Playgrounds/ChartView.swift b/2022/Playgrounds/ChartView.swift new file mode 100644 index 00000000..d897d3db --- /dev/null +++ b/2022/Playgrounds/ChartView.swift @@ -0,0 +1,134 @@ +// +// ChartView.swift +// LetSwift +// +// Created by 이가은 on 2022/11/01. +// + +import SwiftUI +import Charts + +struct ChartView: View { + @StateObject var viewModel = ChartViewModel() + + var body: some View { + TabView { + totalChart() + individualChart() + } + .tabViewStyle(PageTabViewStyle()) + .indexViewStyle(PageIndexViewStyle(backgroundDisplayMode: .always)) + } +} + +extension ChartView { + @ViewBuilder + func totalChart() -> some View { + VStack(alignment: .leading) { + if let chartDataList = viewModel.totalChartDataList { + if #available(iOS 16.0, *) { + VStack(alignment: .leading) { + Text("Let’Swift 22 참여자 개발 성향") + .padding(.bottom, 30) + .font(.title) + Chart { + ForEach(chartDataList) { chartData in + if let question = TempChartData.questionList.first(where: { $0.surveyId == chartData.surveyId })?.question, + let answer = TempChartData.getCardCase(answerId: chartData.answerId) + { + BarMark( + x: .value("Category", answer.rawValue), + y: .value("Profit", chartData.count) + ) + .foregroundStyle(by: .value("Product Category", question)) + } + } + } + .frame(height: 500) + } + } else { + Text("iOS 16.0 부터 결과를 확인할 수 있습니다 :)") + } + } else { +#warning("이미지 넣기") + Text("로딩중...") + } + Spacer() + } + .padding(.top, 50) + .padding(.horizontal, 30) + } + @ViewBuilder + func individualChart() -> some View { + ScrollView(showsIndicators: false) { + VStack(alignment: .leading) { + Text("답변 전체 결과 보기") + .padding(.bottom, 30) + .font(.title) + if let chartData = viewModel.chartData { + if #available(iOS 16.0, *) { + ForEach(0..