From efa9fa57130f20d10bf282bc7715b55db94a636a Mon Sep 17 00:00:00 2001 From: realhsb Date: Sun, 28 Apr 2024 18:55:35 +0900 Subject: [PATCH 01/14] =?UTF-8?q?feat:=20DailyReport=20=EB=B7=B0=20?= =?UTF-8?q?=EB=B0=8F=20=EB=B7=B0=EB=AA=A8=EB=8D=B8=20=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RollTheDice.xcodeproj/project.pbxproj | 8 ++++ .../View/Report/Daily/DailyReportModel.swift | 35 ++++++++++++++++++ .../Report/Daily/DailyReportViewModel.swift | 37 +++++++++++++++++++ 3 files changed, 80 insertions(+) create mode 100644 iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyReportModel.swift create mode 100644 iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyReportViewModel.swift diff --git a/iOS/RollTheDice/RollTheDice.xcodeproj/project.pbxproj b/iOS/RollTheDice/RollTheDice.xcodeproj/project.pbxproj index 9c887cb2..fdde27bb 100644 --- a/iOS/RollTheDice/RollTheDice.xcodeproj/project.pbxproj +++ b/iOS/RollTheDice/RollTheDice.xcodeproj/project.pbxproj @@ -28,6 +28,8 @@ 6C454A822B9DAFA3006FD9D0 /* Path.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C454A812B9DAFA3006FD9D0 /* Path.swift */; }; 6C454A842B9DAFCB006FD9D0 /* PathType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C454A832B9DAFCB006FD9D0 /* PathType.swift */; }; 6C454A882B9DB6C2006FD9D0 /* CustomNavigationBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C454A872B9DB6C2006FD9D0 /* CustomNavigationBar.swift */; }; + 6C4F7BAB2BDE50C600ED01DA /* DailyReportModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C4F7BAA2BDE50C600ED01DA /* DailyReportModel.swift */; }; + 6C4F7BAD2BDE510900ED01DA /* DailyReportViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C4F7BAC2BDE510900ED01DA /* DailyReportViewModel.swift */; }; 6C77048C2B722686001B17CB /* MainTabView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C77048B2B722686001B17CB /* MainTabView.swift */; }; 6C77048F2B7229B1001B17CB /* NewsListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C77048E2B7229B1001B17CB /* NewsListView.swift */; }; 6C7704992B722A20001B17CB /* MainTabViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C7704982B722A20001B17CB /* MainTabViewModel.swift */; }; @@ -98,6 +100,8 @@ 6C454A812B9DAFA3006FD9D0 /* Path.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Path.swift; sourceTree = ""; }; 6C454A832B9DAFCB006FD9D0 /* PathType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PathType.swift; sourceTree = ""; }; 6C454A872B9DB6C2006FD9D0 /* CustomNavigationBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomNavigationBar.swift; sourceTree = ""; }; + 6C4F7BAA2BDE50C600ED01DA /* DailyReportModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DailyReportModel.swift; sourceTree = ""; }; + 6C4F7BAC2BDE510900ED01DA /* DailyReportViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DailyReportViewModel.swift; sourceTree = ""; }; 6C77048B2B722686001B17CB /* MainTabView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainTabView.swift; sourceTree = ""; }; 6C77048E2B7229B1001B17CB /* NewsListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewsListView.swift; sourceTree = ""; }; 6C7704982B722A20001B17CB /* MainTabViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainTabViewModel.swift; sourceTree = ""; }; @@ -444,6 +448,8 @@ 6CE103112BD56AF700498AA4 /* Daily */ = { isa = PBXGroup; children = ( + 6C4F7BAA2BDE50C600ED01DA /* DailyReportModel.swift */, + 6C4F7BAC2BDE510900ED01DA /* DailyReportViewModel.swift */, 6CE103122BD56B1200498AA4 /* DailyReportView.swift */, 6CE103142BD56CA800498AA4 /* DailyBarChartView.swift */, ); @@ -643,6 +649,7 @@ 6C3237AE2B7C382E00B699AB /* NewsViewModel.swift in Sources */, 6C77048F2B7229B1001B17CB /* NewsListView.swift in Sources */, 357666132BBD54AA002C226A /* SplashView.swift in Sources */, + 6C4F7BAD2BDE510900ED01DA /* DailyReportViewModel.swift in Sources */, 6C3237A72B7C37E500B699AB /* BookmarkListViewModel.swift in Sources */, 6C454A822B9DAFA3006FD9D0 /* Path.swift in Sources */, 6C94799E2BD3C00C00D5AEEB /* Image.swift in Sources */, @@ -658,6 +665,7 @@ 6C32379F2B7C376D00B699AB /* Bookmark.swift in Sources */, 6C454A7E2B9DAA3F006FD9D0 /* SignUpFinishView.swift in Sources */, 6C7704A12B722CEB001B17CB /* ProfileView.swift in Sources */, + 6C4F7BAB2BDE50C600ED01DA /* DailyReportModel.swift in Sources */, 6C3237B72B7C434600B699AB /* ChatType.swift in Sources */, 6CE103152BD56CA800498AA4 /* DailyBarChartView.swift in Sources */, 6CE2AC122BD43FB900416A02 /* SignInView.swift in Sources */, diff --git a/iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyReportModel.swift b/iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyReportModel.swift new file mode 100644 index 00000000..a7a30e44 --- /dev/null +++ b/iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyReportModel.swift @@ -0,0 +1,35 @@ +// +// DailyReportModel.swift +// RollTheDice +// +// Created by Subeen on 4/28/24. +// + +import Foundation +import SwiftUI + +struct DailyReport: Hashable, Identifiable { + let id = UUID() + let dateStr: String // DateFormatter로 변환 + let views: Int + + var date: Date { + // TODO: Format Style 사용해서 String -> Date 생성하기 +// let strategy = Date.ParseStrategy(format: "\(month: .twoDigits)년 \(month: .twoDigits)월 \(day: .defaultDigits)", timeZone: TimeZone(abbreviation: "CDT")!) + + let dateFormatter = DateFormatter() + dateFormatter.dateFormat = "yyyy년 MM월 dd일" + + let convertedDate = dateFormatter.date(from: dateStr)! + + return convertedDate + } + + init( + dateStr: String, + views: Int + ) { + self.dateStr = dateStr + self.views = views + } +} diff --git a/iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyReportViewModel.swift b/iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyReportViewModel.swift new file mode 100644 index 00000000..aebf139c --- /dev/null +++ b/iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyReportViewModel.swift @@ -0,0 +1,37 @@ +// +// DailyReportViewModel.swift +// RollTheDice +// +// Created by Subeen on 4/28/24. +// + +import Foundation + +class DailyReportViewModel: ObservableObject{ + @Published var dailyViews: [DailyReport] + + /// 일주일 평균 조회수 + var averageView: String { + var aver = 0.0 + + for daily in dailyViews { + aver += Double(daily.views) + } + + return String(format: "%.1f", aver / 7) + } + + init( + dailyViews: [DailyReport] = [ + .init(dateStr: "2024년 1월 1일", views: 32), + .init(dateStr: "2024년 1월 2일", views: 2), + .init(dateStr: "2024년 1월 3일", views: 300), + .init(dateStr: "2024년 1월 4일", views: 999), + .init(dateStr: "2024년 1월 5일", views: 12), + .init(dateStr: "2024년 1월 6일", views: 1), + .init(dateStr: "2024년 1월 7일", views: 99), + ] + ) { + self.dailyViews = dailyViews + } +} From fe3923dc40905446c2d759c7092323bc5d02003a Mon Sep 17 00:00:00 2001 From: realhsb Date: Sun, 28 Apr 2024 18:55:57 +0900 Subject: [PATCH 02/14] =?UTF-8?q?design:=20=EC=9D=BC=EC=9D=BC=20=ED=86=B5?= =?UTF-8?q?=EA=B3=84=20=EB=B7=B0=20UI=20=EC=88=98=EC=A0=95=20=EB=B0=8F=20?= =?UTF-8?q?=EB=B7=B0=EB=AA=A8=EB=8D=B8=20=EC=97=B0=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../View/Report/Daily/DailyBarChartView.swift | 92 ++++++------------- .../View/Report/Daily/DailyReportView.swift | 5 +- 2 files changed, 29 insertions(+), 68 deletions(-) diff --git a/iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyBarChartView.swift b/iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyBarChartView.swift index 62b7b0e4..c8f8f312 100644 --- a/iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyBarChartView.swift +++ b/iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyBarChartView.swift @@ -11,21 +11,26 @@ import Charts struct DailyBarChartView: View { + @StateObject var dailyViewModel: DailyReportViewModel + @State var selectedDay: Date? @State var selectedView: Int? - var previews: [DailyViews] = [ - .init(dateStr: "1월 1일", views: 32), - .init(dateStr: "1월 2일", views: 2), - .init(dateStr: "1월 3일", views: 300), - .init(dateStr: "1월 4일", views: 999), - .init(dateStr: "1월 5일", views: 12), - .init(dateStr: "1월 6일", views: 1), - .init(dateStr: "1월 7일", views: 99), - ] + + var dateToView: Int? { + if let selectedDay { + for preview in dailyViewModel.dailyViews { + print("\(preview.date.formatted()), \(selectedDay.formatted(date: .long, time: .omitted))") + if preview.date.formatted(date: .long, time: .omitted) == selectedDay.formatted(date: .long, time: .omitted) { + return preview.views + } + } + } + return nil + } // TODO: 평균 기사 개수 구하는 함수 작성 - var avg: Double = 99.9 +// var avg: Double = 99.9 var body: some View { VStack(alignment: .leading) { @@ -35,7 +40,7 @@ struct DailyBarChartView: View { .foregroundStyle(.gray04) .font(.pretendardBold12) HStack { - Text("\(avg)") + Text(dailyViewModel.averageView) .foregroundStyle(.basicWhite) .font(.pretendardBold40) Text("기사") @@ -47,19 +52,19 @@ struct DailyBarChartView: View { } Chart{ - ForEach(previews) { day in + ForEach(dailyViewModel.dailyViews) { day in BarMark( - x: .value("Day", day.date, unit: .day), + x: .value("Day", day.date, unit: .weekdayOrdinal), y: .value("Views", day.views) ) .foregroundStyle(.orange) } - if let selectedView = selectedView { + if let selectedDay = selectedDay { + RuleMark( -// x: .value("Day", selectedDay!) - y: .value("Views", selectedView) + x: .value("Day", selectedDay, unit: .day) ) .annotation( position: .top, @@ -69,67 +74,22 @@ struct DailyBarChartView: View { y: .disabled ) ) { -// Text("\(previews[selectedDay])") - Text("\(selectedView)") + + Text("\(dateToView ?? -1)") } + .foregroundStyle(.basicWhite) } } - - .padding(.horizontal, 20) .chartXAxis { - AxisMarks(values: .stride(by: .day)) + AxisMarks(values: .automatic(desiredCount: 7)) } -// .chartYAxis { -// AxisMarks(preset: .extended, position: .leading) -// } .chartYAxis(.hidden) .chartXSelection(value: $selectedDay) - .chartYSelection(value: $selectedView) -// .chartOverlay { proxy in -// GeometryReader { geometry in -// Rectangle().fill(.clear).contentShape(Rectangle()) -// .onTapGesture { value in -//// let posX = -// } -// .gesture( -// DragGesture() -// .onChanged { value in -// let origin = geometry[proxy.plotFrame!].origin -// let location = CGPoint( -// x: value.location.x - origin.x, -// y: value.location.y - origin.y -// ) -// -// selectedDay = proxy.value(atX: location.x, as: Date.self)! -// let (date, view) = proxy.value(at: location, as: (Date, Int).self)! -// print("Location \(date), \(view)") -// } -// ) -// -// } -// } } .frame(width: 440, height: 300) } } - -struct DailyViews: Identifiable { - let id = UUID() - let dateStr: String // DateFormatter로 변환 - let views: Int - - var date: Date { - let dateFormatter = DateFormatter() - dateFormatter.dateFormat = "MM월 dd일" - - let convertedDate = dateFormatter.date(from: dateStr)! - - return convertedDate - } -} - - #Preview { - DailyBarChartView() + DailyBarChartView(dailyViewModel: DailyReportViewModel()) } diff --git a/iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyReportView.swift b/iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyReportView.swift index 3bbf9246..1e3eebaf 100644 --- a/iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyReportView.swift +++ b/iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyReportView.swift @@ -14,7 +14,7 @@ struct DailyReportView: View { Color.backgroundDark.ignoresSafeArea(.all) VStack { -// CustomNavigationBar(title: "요일별 뉴스 관람 개수 통계", isDisplayLeadingBtn: true, leadingItems: [(Image(.chevronLeft), {})]) + CustomNavigationBar( isDisplayLeadingBtn: true, leadingItems: [(Image(.chevronLeft), {})]) Spacer() @@ -38,7 +38,8 @@ struct DailyReportView: View { .stroke(.basicWhite, lineWidth: /*@START_MENU_TOKEN@*/1.0/*@END_MENU_TOKEN@*/) .background(.gray07) .overlay { - DailyBarChartView() + DailyBarChartView(dailyViewModel: DailyReportViewModel()) + } } From c48c61af33d269d168809e6f66640e702b82ecef Mon Sep 17 00:00:00 2001 From: realhsb Date: Sun, 28 Apr 2024 19:20:07 +0900 Subject: [PATCH 03/14] =?UTF-8?q?feat:=20=EC=9D=BC=EC=9D=BC=20=ED=86=B5?= =?UTF-8?q?=EA=B3=84=20=EC=83=81=EC=84=B8=20=EC=A1=B0=ED=9A=8C=EC=88=98=20?= =?UTF-8?q?=ED=8C=9D=EC=97=85=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../View/Report/Daily/DailyBarChartView.swift | 58 +++++++++++++------ .../View/Report/Daily/DailyReportView.swift | 4 +- 2 files changed, 41 insertions(+), 21 deletions(-) diff --git a/iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyBarChartView.swift b/iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyBarChartView.swift index c8f8f312..83b22bd6 100644 --- a/iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyBarChartView.swift +++ b/iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyBarChartView.swift @@ -17,21 +17,18 @@ struct DailyBarChartView: View { @State var selectedView: Int? - var dateToView: Int? { + var dateToValue: (date: Date, views: Int)? { if let selectedDay { for preview in dailyViewModel.dailyViews { print("\(preview.date.formatted()), \(selectedDay.formatted(date: .long, time: .omitted))") if preview.date.formatted(date: .long, time: .omitted) == selectedDay.formatted(date: .long, time: .omitted) { - return preview.views + return (selectedDay, preview.views) } } } return nil } - // TODO: 평균 기사 개수 구하는 함수 작성 -// var avg: Double = 99.9 - var body: some View { VStack(alignment: .leading) { HStack { @@ -51,6 +48,9 @@ struct DailyBarChartView: View { Spacer() } + Spacer() + .frame(height: 100) + Chart{ ForEach(dailyViewModel.dailyViews) { day in BarMark( @@ -62,22 +62,23 @@ struct DailyBarChartView: View { } if let selectedDay = selectedDay { + if dateToValue != nil { - RuleMark( - x: .value("Day", selectedDay, unit: .day) - ) - .annotation( - position: .top, - alignment: .leading, - overflowResolution: .init( - x: .fit(to: .chart), - y: .disabled + RuleMark( + x: .value("Day", selectedDay, unit: .day) ) - ) { - - Text("\(dateToView ?? -1)") + .annotation( + position: .top, + alignment: .centerLastTextBaseline, + overflowResolution: .init( + x: .fit(to: .chart), + y: .disabled + ) + ) { + popoverView + } + .foregroundStyle(.basicWhite) } - .foregroundStyle(.basicWhite) } } .chartXAxis { @@ -86,7 +87,26 @@ struct DailyBarChartView: View { .chartYAxis(.hidden) .chartXSelection(value: $selectedDay) } - .frame(width: 440, height: 300) + } + + @ViewBuilder + var popoverView: some View { + VStack(alignment: .center) { + Text("\(dateToValue?.date.formatted(date: .numeric, time: .omitted) ?? "")") + .font(.pretendardRegular14) + Text("\(dateToValue?.views ?? 0)") + .font(.pretendardBold32) + + } + .padding(10) + .background(.gray06) + .clipShape( + RoundedRectangle(cornerRadius: 8) + ) + .overlay { + RoundedRectangle(cornerRadius: 8) + .stroke(.gray05, lineWidth: 1.0) + } } } diff --git a/iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyReportView.swift b/iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyReportView.swift index 1e3eebaf..b6b44bc7 100644 --- a/iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyReportView.swift +++ b/iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyReportView.swift @@ -20,7 +20,7 @@ struct DailyReportView: View { HStack { statisticsView - reportView + reportView } .frame(height: 500) .padding(.horizontal, 110) @@ -39,7 +39,7 @@ struct DailyReportView: View { .background(.gray07) .overlay { DailyBarChartView(dailyViewModel: DailyReportViewModel()) - + .padding(50) } } From fa3e8cc07d9e0d9206a9643510dfaeb449268553 Mon Sep 17 00:00:00 2001 From: realhsb Date: Sun, 28 Apr 2024 20:30:28 +0900 Subject: [PATCH 04/14] =?UTF-8?q?design:=20=ED=8C=8C=EC=9D=B4=EC=B0=A8?= =?UTF-8?q?=ED=8A=B8=EC=9A=A9=20Color=20Assets=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ColorAssets.xcassets/Report/Contents.json | 6 +++ .../Report/reportCyan.colorset/Contents.json | 38 +++++++++++++++++++ .../Report/reportGreen.colorset/Contents.json | 38 +++++++++++++++++++ .../Report/reportPink.colorset/Contents.json | 38 +++++++++++++++++++ .../reportPurple.colorset/Contents.json | 38 +++++++++++++++++++ .../reportYellow.colorset/Contents.json | 38 +++++++++++++++++++ 6 files changed, 196 insertions(+) create mode 100644 iOS/RollTheDice/RollTheDice/Resources/ColorAssets.xcassets/Report/Contents.json create mode 100644 iOS/RollTheDice/RollTheDice/Resources/ColorAssets.xcassets/Report/reportCyan.colorset/Contents.json create mode 100644 iOS/RollTheDice/RollTheDice/Resources/ColorAssets.xcassets/Report/reportGreen.colorset/Contents.json create mode 100644 iOS/RollTheDice/RollTheDice/Resources/ColorAssets.xcassets/Report/reportPink.colorset/Contents.json create mode 100644 iOS/RollTheDice/RollTheDice/Resources/ColorAssets.xcassets/Report/reportPurple.colorset/Contents.json create mode 100644 iOS/RollTheDice/RollTheDice/Resources/ColorAssets.xcassets/Report/reportYellow.colorset/Contents.json diff --git a/iOS/RollTheDice/RollTheDice/Resources/ColorAssets.xcassets/Report/Contents.json b/iOS/RollTheDice/RollTheDice/Resources/ColorAssets.xcassets/Report/Contents.json new file mode 100644 index 00000000..73c00596 --- /dev/null +++ b/iOS/RollTheDice/RollTheDice/Resources/ColorAssets.xcassets/Report/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/iOS/RollTheDice/RollTheDice/Resources/ColorAssets.xcassets/Report/reportCyan.colorset/Contents.json b/iOS/RollTheDice/RollTheDice/Resources/ColorAssets.xcassets/Report/reportCyan.colorset/Contents.json new file mode 100644 index 00000000..37a19a22 --- /dev/null +++ b/iOS/RollTheDice/RollTheDice/Resources/ColorAssets.xcassets/Report/reportCyan.colorset/Contents.json @@ -0,0 +1,38 @@ +{ + "colors" : [ + { + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "0xD8", + "green" : "0xD0", + "red" : "0x23" + } + }, + "idiom" : "universal" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "dark" + } + ], + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "0xD8", + "green" : "0xD0", + "red" : "0x23" + } + }, + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/iOS/RollTheDice/RollTheDice/Resources/ColorAssets.xcassets/Report/reportGreen.colorset/Contents.json b/iOS/RollTheDice/RollTheDice/Resources/ColorAssets.xcassets/Report/reportGreen.colorset/Contents.json new file mode 100644 index 00000000..0aeb53c7 --- /dev/null +++ b/iOS/RollTheDice/RollTheDice/Resources/ColorAssets.xcassets/Report/reportGreen.colorset/Contents.json @@ -0,0 +1,38 @@ +{ + "colors" : [ + { + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "0x00", + "green" : "0xDE", + "red" : "0x6F" + } + }, + "idiom" : "universal" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "dark" + } + ], + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "0x00", + "green" : "0xDE", + "red" : "0x6F" + } + }, + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/iOS/RollTheDice/RollTheDice/Resources/ColorAssets.xcassets/Report/reportPink.colorset/Contents.json b/iOS/RollTheDice/RollTheDice/Resources/ColorAssets.xcassets/Report/reportPink.colorset/Contents.json new file mode 100644 index 00000000..67f870da --- /dev/null +++ b/iOS/RollTheDice/RollTheDice/Resources/ColorAssets.xcassets/Report/reportPink.colorset/Contents.json @@ -0,0 +1,38 @@ +{ + "colors" : [ + { + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "0x73", + "green" : "0x47", + "red" : "0xF8" + } + }, + "idiom" : "universal" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "dark" + } + ], + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "0x73", + "green" : "0x47", + "red" : "0xF8" + } + }, + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/iOS/RollTheDice/RollTheDice/Resources/ColorAssets.xcassets/Report/reportPurple.colorset/Contents.json b/iOS/RollTheDice/RollTheDice/Resources/ColorAssets.xcassets/Report/reportPurple.colorset/Contents.json new file mode 100644 index 00000000..fb5a073e --- /dev/null +++ b/iOS/RollTheDice/RollTheDice/Resources/ColorAssets.xcassets/Report/reportPurple.colorset/Contents.json @@ -0,0 +1,38 @@ +{ + "colors" : [ + { + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "0xFF", + "green" : "0x2B", + "red" : "0xC8" + } + }, + "idiom" : "universal" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "dark" + } + ], + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "0xFF", + "green" : "0x2B", + "red" : "0xC8" + } + }, + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/iOS/RollTheDice/RollTheDice/Resources/ColorAssets.xcassets/Report/reportYellow.colorset/Contents.json b/iOS/RollTheDice/RollTheDice/Resources/ColorAssets.xcassets/Report/reportYellow.colorset/Contents.json new file mode 100644 index 00000000..d6fb2665 --- /dev/null +++ b/iOS/RollTheDice/RollTheDice/Resources/ColorAssets.xcassets/Report/reportYellow.colorset/Contents.json @@ -0,0 +1,38 @@ +{ + "colors" : [ + { + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "0x17", + "green" : "0xCC", + "red" : "0xFF" + } + }, + "idiom" : "universal" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "dark" + } + ], + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "0x17", + "green" : "0xCC", + "red" : "0xFF" + } + }, + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} From ae8c3174769e79af75b5d11f9b947df63e217df7 Mon Sep 17 00:00:00 2001 From: realhsb Date: Sun, 28 Apr 2024 20:32:04 +0900 Subject: [PATCH 05/14] =?UTF-8?q?chore:=20NewsType=20=ED=8C=8C=EC=9D=BC=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RollTheDice.xcodeproj/project.pbxproj | 12 +++++ .../Source/Model/Report/NewsType.swift | 52 +++++++++++++++++++ .../View/Report/Type/TypeReportModel.swift | 22 ++++---- 3 files changed, 77 insertions(+), 9 deletions(-) create mode 100644 iOS/RollTheDice/RollTheDice/Source/Model/Report/NewsType.swift diff --git a/iOS/RollTheDice/RollTheDice.xcodeproj/project.pbxproj b/iOS/RollTheDice/RollTheDice.xcodeproj/project.pbxproj index fdde27bb..2b922267 100644 --- a/iOS/RollTheDice/RollTheDice.xcodeproj/project.pbxproj +++ b/iOS/RollTheDice/RollTheDice.xcodeproj/project.pbxproj @@ -21,6 +21,7 @@ 6C3237B22B7C385000B699AB /* NewsListViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C3237B12B7C385000B699AB /* NewsListViewModel.swift */; }; 6C3237B52B7C433D00B699AB /* ChatTypeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C3237B42B7C433D00B699AB /* ChatTypeView.swift */; }; 6C3237B72B7C434600B699AB /* ChatType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C3237B62B7C434600B699AB /* ChatType.swift */; }; + 6C41B8D22BDE696200274FA4 /* NewsType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C41B8D12BDE696200274FA4 /* NewsType.swift */; }; 6C454A782B9DA657006FD9D0 /* SignUpQuestionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C454A772B9DA657006FD9D0 /* SignUpQuestionView.swift */; }; 6C454A7A2B9DA67C006FD9D0 /* SignUpViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C454A792B9DA67C006FD9D0 /* SignUpViewModel.swift */; }; 6C454A7C2B9DA71C006FD9D0 /* SignUpView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C454A7B2B9DA71C006FD9D0 /* SignUpView.swift */; }; @@ -93,6 +94,7 @@ 6C3237B12B7C385000B699AB /* NewsListViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewsListViewModel.swift; sourceTree = ""; }; 6C3237B42B7C433D00B699AB /* ChatTypeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatTypeView.swift; sourceTree = ""; }; 6C3237B62B7C434600B699AB /* ChatType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatType.swift; sourceTree = ""; }; + 6C41B8D12BDE696200274FA4 /* NewsType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewsType.swift; sourceTree = ""; }; 6C454A772B9DA657006FD9D0 /* SignUpQuestionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignUpQuestionView.swift; sourceTree = ""; }; 6C454A792B9DA67C006FD9D0 /* SignUpViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignUpViewModel.swift; sourceTree = ""; }; 6C454A7B2B9DA71C006FD9D0 /* SignUpView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignUpView.swift; sourceTree = ""; }; @@ -206,6 +208,14 @@ path = ChatType; sourceTree = ""; }; + 6C41B8D02BDE695A00274FA4 /* Report */ = { + isa = PBXGroup; + children = ( + 6C41B8D12BDE696200274FA4 /* NewsType.swift */, + ); + path = Report; + sourceTree = ""; + }; 6C454A762B9DA62C006FD9D0 /* SignUp */ = { isa = PBXGroup; children = ( @@ -220,6 +230,7 @@ 6C454A7F2B9DAF21006FD9D0 /* Model */ = { isa = PBXGroup; children = ( + 6C41B8D02BDE695A00274FA4 /* Report */, 6C454A802B9DAF9F006FD9D0 /* Path */, ); path = Model; @@ -639,6 +650,7 @@ 6CF130AD2BAB0C4400A437B6 /* AuthenticationViewModel.swift in Sources */, 6CDB29F92BAA07350081037B /* GPTChat.swift in Sources */, 6CDB29FD2BAA07FD0081037B /* GPTChatView.swift in Sources */, + 6C41B8D22BDE696200274FA4 /* NewsType.swift in Sources */, 357666102BBD4BF6002C226A /* ReportListView.swift in Sources */, 6C3237A12B7C377600B699AB /* BookmarkViewModel.swift in Sources */, 6C3237AC2B7C382200B699AB /* News.swift in Sources */, diff --git a/iOS/RollTheDice/RollTheDice/Source/Model/Report/NewsType.swift b/iOS/RollTheDice/RollTheDice/Source/Model/Report/NewsType.swift new file mode 100644 index 00000000..99deabbe --- /dev/null +++ b/iOS/RollTheDice/RollTheDice/Source/Model/Report/NewsType.swift @@ -0,0 +1,52 @@ +// +// NewsReport.swift +// RollTheDice +// +// Created by Subeen on 4/28/24. +// + +import Foundation +import SwiftUI + +enum NewsType { + case politics // 정치 + case economy // 경제 + case society // 사회 + case living // 생활/문화 + case world // 세계 + case science // IT/과학 + + var desciption: String { + switch self { + case .politics: + "정치" + case .economy: + "경제" + case .society: + "사회" + case .living: + "생활/문화" + case .world: + "세계" + case .science: + "IT/과학" + } + } + + var color: SwiftUI.Color { + switch self { + case .politics: + Color.reportCyan + case .economy: + Color.reportGreen + case .society: + Color.reportPurple + case .living: + Color.reportYellow + case .world: + Color.primary01 + case .science: + Color.reportPink + } + } +} diff --git a/iOS/RollTheDice/RollTheDice/Source/View/Report/Type/TypeReportModel.swift b/iOS/RollTheDice/RollTheDice/Source/View/Report/Type/TypeReportModel.swift index e429c173..ead8dbd6 100644 --- a/iOS/RollTheDice/RollTheDice/Source/View/Report/Type/TypeReportModel.swift +++ b/iOS/RollTheDice/RollTheDice/Source/View/Report/Type/TypeReportModel.swift @@ -7,15 +7,19 @@ import Foundation -struct TypeReport { - var typeReportList: [[NewsType : Double]] +struct TypeReportList { + var reportList: [TypeReport] } -enum NewsType { - case politics // 정치 - case economy // 경제 - case society // 사회 - case living // 생활/문화 - case world // 세계 - case science // IT/과학 +struct TypeReport: Hashable, Identifiable { + var id = UUID() + var typeReportList: NewsType + var view: Int + + // case politics // 정치 + // case economy // 경제 + // case society // 사회 + // case living // 생활/문화 + // case world // 세계 + // case science // IT/과학 } From d7dfef40b1bc7abb50a719e220f436f376688693 Mon Sep 17 00:00:00 2001 From: realhsb Date: Sun, 28 Apr 2024 20:33:15 +0900 Subject: [PATCH 06/14] =?UTF-8?q?chore:=20=EB=B3=80=EC=88=98=EB=AA=85=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../View/Report/Daily/DailyBarChartView.swift | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyBarChartView.swift b/iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyBarChartView.swift index 83b22bd6..124f4634 100644 --- a/iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyBarChartView.swift +++ b/iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyBarChartView.swift @@ -17,10 +17,9 @@ struct DailyBarChartView: View { @State var selectedView: Int? - var dateToValue: (date: Date, views: Int)? { + var selectedValue: (date: Date, views: Int)? { if let selectedDay { for preview in dailyViewModel.dailyViews { - print("\(preview.date.formatted()), \(selectedDay.formatted(date: .long, time: .omitted))") if preview.date.formatted(date: .long, time: .omitted) == selectedDay.formatted(date: .long, time: .omitted) { return (selectedDay, preview.views) } @@ -58,15 +57,20 @@ struct DailyBarChartView: View { y: .value("Views", day.views) ) - .foregroundStyle(.orange) + .cornerRadius(8) + .foregroundStyle(.primary01.gradient) +// .foregroundStyle(selectedValue?.date.formatted(date: .abbreviated, time: .omitted) == selectedDay?.formatted(date: .abbreviated, time: .omitted) ? .orange : .blue) + //TODO: 바 선택 / 미선택에 따른 막대 투명도 조절 + .opacity(selectedValue?.date == nil || selectedValue?.date.formatted(date: .numeric, time: .omitted) == selectedDay?.formatted(date: .numeric, time: .omitted) ? 1 : 0.5) } if let selectedDay = selectedDay { - if dateToValue != nil { + if selectedValue != nil { RuleMark( x: .value("Day", selectedDay, unit: .day) ) + .zIndex(-1) .annotation( position: .top, alignment: .centerLastTextBaseline, @@ -92,14 +96,14 @@ struct DailyBarChartView: View { @ViewBuilder var popoverView: some View { VStack(alignment: .center) { - Text("\(dateToValue?.date.formatted(date: .numeric, time: .omitted) ?? "")") + Text("\(selectedValue?.date.formatted(date: .numeric, time: .omitted) ?? "")") .font(.pretendardRegular14) - Text("\(dateToValue?.views ?? 0)") - .font(.pretendardBold32) + Text("\(selectedValue?.views ?? 0)") + .font(.pretendardBold24) } .padding(10) - .background(.gray06) + .background(.gray06.gradient) .clipShape( RoundedRectangle(cornerRadius: 8) ) From 92ff4a993ac14679b57f02d6ad0ab24bffabe4a7 Mon Sep 17 00:00:00 2001 From: realhsb Date: Sun, 28 Apr 2024 20:37:33 +0900 Subject: [PATCH 07/14] =?UTF-8?q?chore:=20Report=20=EB=AA=A8=EB=8D=B8=20?= =?UTF-8?q?=EB=B0=8F=20=EB=B7=B0=EB=AA=A8=EB=8D=B8=20=EA=B5=AC=EC=A1=B0?= =?UTF-8?q?=EC=B2=B4=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../View/Report/Daily/DailyBarChartView.swift | 4 +-- .../View/Report/Daily/DailyReportModel.swift | 12 +++------ .../Report/Daily/DailyReportViewModel.swift | 26 ++++++++++--------- .../Report/Type/TypeReportViewModel.swift | 24 ++++++++++------- 4 files changed, 35 insertions(+), 31 deletions(-) diff --git a/iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyBarChartView.swift b/iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyBarChartView.swift index 124f4634..58ac3055 100644 --- a/iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyBarChartView.swift +++ b/iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyBarChartView.swift @@ -19,7 +19,7 @@ struct DailyBarChartView: View { var selectedValue: (date: Date, views: Int)? { if let selectedDay { - for preview in dailyViewModel.dailyViews { + for preview in dailyViewModel.dailyReportList.reportList { if preview.date.formatted(date: .long, time: .omitted) == selectedDay.formatted(date: .long, time: .omitted) { return (selectedDay, preview.views) } @@ -51,7 +51,7 @@ struct DailyBarChartView: View { .frame(height: 100) Chart{ - ForEach(dailyViewModel.dailyViews) { day in + ForEach(dailyViewModel.dailyReportList.reportList) { day in BarMark( x: .value("Day", day.date, unit: .weekdayOrdinal), y: .value("Views", day.views) diff --git a/iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyReportModel.swift b/iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyReportModel.swift index a7a30e44..9a5051cc 100644 --- a/iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyReportModel.swift +++ b/iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyReportModel.swift @@ -8,6 +8,10 @@ import Foundation import SwiftUI +struct DailyReportList: Hashable { + var reportList: [DailyReport] +} + struct DailyReport: Hashable, Identifiable { let id = UUID() let dateStr: String // DateFormatter로 변환 @@ -24,12 +28,4 @@ struct DailyReport: Hashable, Identifiable { return convertedDate } - - init( - dateStr: String, - views: Int - ) { - self.dateStr = dateStr - self.views = views - } } diff --git a/iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyReportViewModel.swift b/iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyReportViewModel.swift index aebf139c..344ca3bb 100644 --- a/iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyReportViewModel.swift +++ b/iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyReportViewModel.swift @@ -8,13 +8,13 @@ import Foundation class DailyReportViewModel: ObservableObject{ - @Published var dailyViews: [DailyReport] + @Published var dailyReportList: DailyReportList /// 일주일 평균 조회수 var averageView: String { var aver = 0.0 - for daily in dailyViews { + for daily in dailyReportList.reportList { aver += Double(daily.views) } @@ -22,16 +22,18 @@ class DailyReportViewModel: ObservableObject{ } init( - dailyViews: [DailyReport] = [ - .init(dateStr: "2024년 1월 1일", views: 32), - .init(dateStr: "2024년 1월 2일", views: 2), - .init(dateStr: "2024년 1월 3일", views: 300), - .init(dateStr: "2024년 1월 4일", views: 999), - .init(dateStr: "2024년 1월 5일", views: 12), - .init(dateStr: "2024년 1월 6일", views: 1), - .init(dateStr: "2024년 1월 7일", views: 99), - ] + dailyReportList: DailyReportList = .init( + reportList: + [.init(dateStr: "2024년 1월 1일", views: 32), + .init(dateStr: "2024년 1월 2일", views: 2), + .init(dateStr: "2024년 1월 3일", views: 300), + .init(dateStr: "2024년 1월 4일", views: 999), + .init(dateStr: "2024년 1월 5일", views: 12), + .init(dateStr: "2024년 1월 6일", views: 1), + .init(dateStr: "2024년 1월 7일", views: 99), + ] + ) ) { - self.dailyViews = dailyViews + self.dailyReportList = dailyReportList } } diff --git a/iOS/RollTheDice/RollTheDice/Source/View/Report/Type/TypeReportViewModel.swift b/iOS/RollTheDice/RollTheDice/Source/View/Report/Type/TypeReportViewModel.swift index 6c77c825..987ac463 100644 --- a/iOS/RollTheDice/RollTheDice/Source/View/Report/Type/TypeReportViewModel.swift +++ b/iOS/RollTheDice/RollTheDice/Source/View/Report/Type/TypeReportViewModel.swift @@ -8,20 +8,26 @@ import Foundation class TypeReportViewModel: ObservableObject { - @Published var typeReportList: TypeReport + + @Published var typeReportList: TypeReportList init( - typeReportList: TypeReport = .init( - typeReportList: [ - [NewsType.economy : 10.0], - [NewsType.living : 20.0], - [NewsType.politics : 30.0], - [NewsType.science : 5.0], - [NewsType.society : 5.0], - [NewsType.world : 30.0], + typeReportList: TypeReportList = .init( + reportList: [ + .init(typeReportList: .economy, view: 10), + .init(typeReportList: .living, view: 20), + .init(typeReportList: .politics, view: 30), + .init(typeReportList: .science, view: 5), + .init(typeReportList: .society, view: 5), + .init(typeReportList: .world, view: 30) ] ) ) { self.typeReportList = typeReportList } + + // 비율이 낮은순으로 정렬 (파이 차트에서 반시계방향으로 그래프 차지) + var sortedList: [TypeReport] { + return typeReportList.reportList.sorted { $0.view < $1.view } + } } From 7ccb5e0c2f26d091418e78215dfa92e6762f8a4d Mon Sep 17 00:00:00 2001 From: realhsb Date: Sun, 28 Apr 2024 20:37:57 +0900 Subject: [PATCH 08/14] =?UTF-8?q?feat:=20Report=20Navigation=20Path=20?= =?UTF-8?q?=EC=97=B0=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Source/View/Report/Daily/DailyReportView.swift | 6 +++++- .../Source/View/Report/Type/TypeReportView.swift | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyReportView.swift b/iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyReportView.swift index b6b44bc7..ed73c2ad 100644 --- a/iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyReportView.swift +++ b/iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyReportView.swift @@ -9,12 +9,16 @@ import SwiftUI struct DailyReportView: View { + + @EnvironmentObject var pathModel: PathModel + var body: some View { ZStack { Color.backgroundDark.ignoresSafeArea(.all) VStack { - CustomNavigationBar( isDisplayLeadingBtn: true, leadingItems: [(Image(.chevronLeft), {})]) + /// 내비게이션 뒤로가기 + CustomNavigationBar(isDisplayLeadingBtn: true, leadingItems: [(Image(.chevronLeft), {pathModel.paths.popLast()})]) Spacer() diff --git a/iOS/RollTheDice/RollTheDice/Source/View/Report/Type/TypeReportView.swift b/iOS/RollTheDice/RollTheDice/Source/View/Report/Type/TypeReportView.swift index edb012e1..3b8d3d27 100644 --- a/iOS/RollTheDice/RollTheDice/Source/View/Report/Type/TypeReportView.swift +++ b/iOS/RollTheDice/RollTheDice/Source/View/Report/Type/TypeReportView.swift @@ -8,12 +8,15 @@ import SwiftUI struct TypeReportView: View { + + @EnvironmentObject var pathModel: PathModel + var body: some View { ZStack { Color.backgroundDark.ignoresSafeArea(.all) VStack { -// CustomNavigationBar(title: "분야별 레포트", isDisplayLeadingBtn: true, leadingItems: [(Image(.chevronLeft), {})]) + CustomNavigationBar(isDisplayLeadingBtn: true, leadingItems: [(Image(.chevronLeft), {pathModel.paths.popLast()})]) Spacer() From 2d7695f83ffaa8af9f2c75957199c09a02d25972 Mon Sep 17 00:00:00 2001 From: realhsb Date: Sun, 28 Apr 2024 20:55:10 +0900 Subject: [PATCH 09/14] =?UTF-8?q?chore:=20TypeReport=20=EB=B3=80=EC=88=98?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../View/Report/Type/TypeReportModel.swift | 4 ++-- .../Report/Type/TypeReportViewModel.swift | 22 +++++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/iOS/RollTheDice/RollTheDice/Source/View/Report/Type/TypeReportModel.swift b/iOS/RollTheDice/RollTheDice/Source/View/Report/Type/TypeReportModel.swift index ead8dbd6..1c35be6e 100644 --- a/iOS/RollTheDice/RollTheDice/Source/View/Report/Type/TypeReportModel.swift +++ b/iOS/RollTheDice/RollTheDice/Source/View/Report/Type/TypeReportModel.swift @@ -7,13 +7,13 @@ import Foundation -struct TypeReportList { +struct TypeReportList: Hashable { var reportList: [TypeReport] } struct TypeReport: Hashable, Identifiable { var id = UUID() - var typeReportList: NewsType + var newsType: NewsType var view: Int // case politics // 정치 diff --git a/iOS/RollTheDice/RollTheDice/Source/View/Report/Type/TypeReportViewModel.swift b/iOS/RollTheDice/RollTheDice/Source/View/Report/Type/TypeReportViewModel.swift index 987ac463..d23bce97 100644 --- a/iOS/RollTheDice/RollTheDice/Source/View/Report/Type/TypeReportViewModel.swift +++ b/iOS/RollTheDice/RollTheDice/Source/View/Report/Type/TypeReportViewModel.swift @@ -9,25 +9,25 @@ import Foundation class TypeReportViewModel: ObservableObject { - @Published var typeReportList: TypeReportList + @Published var reportList: TypeReportList init( - typeReportList: TypeReportList = .init( + reportList: TypeReportList = .init( reportList: [ - .init(typeReportList: .economy, view: 10), - .init(typeReportList: .living, view: 20), - .init(typeReportList: .politics, view: 30), - .init(typeReportList: .science, view: 5), - .init(typeReportList: .society, view: 5), - .init(typeReportList: .world, view: 30) + .init(newsType: .economy, view: 10), + .init(newsType: .living, view: 20), + .init(newsType: .politics, view: 30), + .init(newsType: .science, view: 5), + .init(newsType: .society, view: 5), + .init(newsType: .world, view: 30) ] ) ) { - self.typeReportList = typeReportList + self.reportList = reportList } - // 비율이 낮은순으로 정렬 (파이 차트에서 반시계방향으로 그래프 차지) + // 비율이 낮은 순으로 정렬 (파이 차트에서 반시계방향으로 그래프 차지) var sortedList: [TypeReport] { - return typeReportList.reportList.sorted { $0.view < $1.view } + return reportList.reportList.sorted { $0.view > $1.view } } } From e1c01ee08930c332fdaf344c9af15ddc0b487500 Mon Sep 17 00:00:00 2001 From: realhsb Date: Sun, 28 Apr 2024 20:55:30 +0900 Subject: [PATCH 10/14] =?UTF-8?q?feat:=20Pie=20Chart=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RollTheDice.xcodeproj/project.pbxproj | 4 +++ .../View/Report/Type/TypePieChartView.swift | 30 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 iOS/RollTheDice/RollTheDice/Source/View/Report/Type/TypePieChartView.swift diff --git a/iOS/RollTheDice/RollTheDice.xcodeproj/project.pbxproj b/iOS/RollTheDice/RollTheDice.xcodeproj/project.pbxproj index 2b922267..f1ca2bac 100644 --- a/iOS/RollTheDice/RollTheDice.xcodeproj/project.pbxproj +++ b/iOS/RollTheDice/RollTheDice.xcodeproj/project.pbxproj @@ -22,6 +22,7 @@ 6C3237B52B7C433D00B699AB /* ChatTypeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C3237B42B7C433D00B699AB /* ChatTypeView.swift */; }; 6C3237B72B7C434600B699AB /* ChatType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C3237B62B7C434600B699AB /* ChatType.swift */; }; 6C41B8D22BDE696200274FA4 /* NewsType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C41B8D12BDE696200274FA4 /* NewsType.swift */; }; + 6C41B8D42BDE6D2500274FA4 /* TypePieChartView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C41B8D32BDE6D2500274FA4 /* TypePieChartView.swift */; }; 6C454A782B9DA657006FD9D0 /* SignUpQuestionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C454A772B9DA657006FD9D0 /* SignUpQuestionView.swift */; }; 6C454A7A2B9DA67C006FD9D0 /* SignUpViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C454A792B9DA67C006FD9D0 /* SignUpViewModel.swift */; }; 6C454A7C2B9DA71C006FD9D0 /* SignUpView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C454A7B2B9DA71C006FD9D0 /* SignUpView.swift */; }; @@ -95,6 +96,7 @@ 6C3237B42B7C433D00B699AB /* ChatTypeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatTypeView.swift; sourceTree = ""; }; 6C3237B62B7C434600B699AB /* ChatType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatType.swift; sourceTree = ""; }; 6C41B8D12BDE696200274FA4 /* NewsType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewsType.swift; sourceTree = ""; }; + 6C41B8D32BDE6D2500274FA4 /* TypePieChartView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypePieChartView.swift; sourceTree = ""; }; 6C454A772B9DA657006FD9D0 /* SignUpQuestionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignUpQuestionView.swift; sourceTree = ""; }; 6C454A792B9DA67C006FD9D0 /* SignUpViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignUpViewModel.swift; sourceTree = ""; }; 6C454A7B2B9DA71C006FD9D0 /* SignUpView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignUpView.swift; sourceTree = ""; }; @@ -450,6 +452,7 @@ isa = PBXGroup; children = ( 6CE1030B2BD56A4000498AA4 /* TypeReportView.swift */, + 6C41B8D32BDE6D2500274FA4 /* TypePieChartView.swift */, 6CE1030D2BD56A5200498AA4 /* TypeReportModel.swift */, 6CE1030F2BD56A5B00498AA4 /* TypeReportViewModel.swift */, ); @@ -652,6 +655,7 @@ 6CDB29FD2BAA07FD0081037B /* GPTChatView.swift in Sources */, 6C41B8D22BDE696200274FA4 /* NewsType.swift in Sources */, 357666102BBD4BF6002C226A /* ReportListView.swift in Sources */, + 6C41B8D42BDE6D2500274FA4 /* TypePieChartView.swift in Sources */, 6C3237A12B7C377600B699AB /* BookmarkViewModel.swift in Sources */, 6C3237AC2B7C382200B699AB /* News.swift in Sources */, 6CE1030E2BD56A5200498AA4 /* TypeReportModel.swift in Sources */, diff --git a/iOS/RollTheDice/RollTheDice/Source/View/Report/Type/TypePieChartView.swift b/iOS/RollTheDice/RollTheDice/Source/View/Report/Type/TypePieChartView.swift new file mode 100644 index 00000000..5c667532 --- /dev/null +++ b/iOS/RollTheDice/RollTheDice/Source/View/Report/Type/TypePieChartView.swift @@ -0,0 +1,30 @@ +// +// TypePieChartView.swift +// RollTheDice +// +// Created by Subeen on 4/28/24. +// + +import SwiftUI +import Charts + +struct TypePieChartView: View { + + @StateObject var reportViewModel: TypeReportViewModel + + var body: some View { + Chart(reportViewModel.sortedList) { report in + SectorMark( + angle: .value("Views", report.view), + innerRadius: .ratio(0.618), + angularInset: 2.0 + ) + .cornerRadius(8) + .foregroundStyle(report.newsType.color) + } + } +} + +#Preview { + TypePieChartView(reportViewModel: TypeReportViewModel()) +} From 0b79061abec135e524992c154361ef171d07ef4d Mon Sep 17 00:00:00 2001 From: realhsb Date: Sun, 28 Apr 2024 21:06:18 +0900 Subject: [PATCH 11/14] =?UTF-8?q?feat:=20Pie=20Chart=20=EA=B0=80=EC=9A=B4?= =?UTF-8?q?=EB=8D=B0=EC=97=90=20=EB=A7=8E=EC=9D=B4=20=EB=B3=B8=20=EB=B6=84?= =?UTF-8?q?=EC=95=BC=20=ED=85=8D=EC=8A=A4=ED=8A=B8=20=EB=B0=B0=EC=B9=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../View/Report/Type/TypePieChartView.swift | 23 ++++++++++++++++++- .../View/Report/Type/TypeReportView.swift | 4 ++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/iOS/RollTheDice/RollTheDice/Source/View/Report/Type/TypePieChartView.swift b/iOS/RollTheDice/RollTheDice/Source/View/Report/Type/TypePieChartView.swift index 5c667532..9ff50a82 100644 --- a/iOS/RollTheDice/RollTheDice/Source/View/Report/Type/TypePieChartView.swift +++ b/iOS/RollTheDice/RollTheDice/Source/View/Report/Type/TypePieChartView.swift @@ -12,16 +12,37 @@ struct TypePieChartView: View { @StateObject var reportViewModel: TypeReportViewModel + var mostViewed: NewsType { + return reportViewModel.sortedList.first!.newsType + } + var body: some View { Chart(reportViewModel.sortedList) { report in SectorMark( angle: .value("Views", report.view), - innerRadius: .ratio(0.618), + innerRadius: .ratio(0.7), angularInset: 2.0 ) .cornerRadius(8) .foregroundStyle(report.newsType.color) } + /// pie chart의 가운데 문구 + .chartBackground { chartProxy in + GeometryReader { geometry in + let frame = geometry[chartProxy.plotFrame!] + + VStack { + Text("많이 본 분야") + .foregroundStyle(.gray05) + .font(.pretendardRegular14) + Text(mostViewed.desciption) + .foregroundStyle(.gray01) + .font(.pretendardBold24) + } + .position(x: frame.midX, y: frame.midY) + } + } + .padding(100) } } diff --git a/iOS/RollTheDice/RollTheDice/Source/View/Report/Type/TypeReportView.swift b/iOS/RollTheDice/RollTheDice/Source/View/Report/Type/TypeReportView.swift index 3b8d3d27..3f37a170 100644 --- a/iOS/RollTheDice/RollTheDice/Source/View/Report/Type/TypeReportView.swift +++ b/iOS/RollTheDice/RollTheDice/Source/View/Report/Type/TypeReportView.swift @@ -34,9 +34,13 @@ struct TypeReportView: View { } var statisticsView: some View { + RoundedRectangle(cornerRadius: 16) .stroke(.basicWhite, lineWidth: /*@START_MENU_TOKEN@*/1.0/*@END_MENU_TOKEN@*/) .background(.gray07) + .overlay { + TypePieChartView(reportViewModel: TypeReportViewModel()) + } } // TODO : 배치 바꾸기!! From d63e7b82c03e232a9124d833621f96d9bd0a66ff Mon Sep 17 00:00:00 2001 From: realhsb Date: Sun, 28 Apr 2024 21:37:34 +0900 Subject: [PATCH 12/14] =?UTF-8?q?chore:=20Report=20View=EC=97=90=EC=84=9C?= =?UTF-8?q?=20=EB=82=B4=EB=B9=84=EA=B2=8C=EC=9D=B4=EC=85=98=20=EB=B2=84?= =?UTF-8?q?=ED=8A=BC=20=EC=88=A8=EA=B9=80=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RollTheDice/Source/View/Report/Daily/DailyReportView.swift | 2 +- .../RollTheDice/Source/View/Report/Type/TypeReportView.swift | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyReportView.swift b/iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyReportView.swift index ed73c2ad..20b5db78 100644 --- a/iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyReportView.swift +++ b/iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyReportView.swift @@ -31,8 +31,8 @@ struct DailyReportView: View { Spacer() } - } + .navigationBarBackButtonHidden() } diff --git a/iOS/RollTheDice/RollTheDice/Source/View/Report/Type/TypeReportView.swift b/iOS/RollTheDice/RollTheDice/Source/View/Report/Type/TypeReportView.swift index 3f37a170..5f33b3bf 100644 --- a/iOS/RollTheDice/RollTheDice/Source/View/Report/Type/TypeReportView.swift +++ b/iOS/RollTheDice/RollTheDice/Source/View/Report/Type/TypeReportView.swift @@ -31,6 +31,7 @@ struct TypeReportView: View { } } + .navigationBarBackButtonHidden() } var statisticsView: some View { From 95897a3af50b357b004544b5bbcbcbf542d180e9 Mon Sep 17 00:00:00 2001 From: realhsb Date: Sun, 28 Apr 2024 21:38:42 +0900 Subject: [PATCH 13/14] =?UTF-8?q?feat:=20=ED=86=B5=EA=B3=84=20=ED=83=AD?= =?UTF-8?q?=EB=B7=B0=20UI=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Source/View/Report/ReportListView.swift | 54 +++++++++---------- 1 file changed, 25 insertions(+), 29 deletions(-) diff --git a/iOS/RollTheDice/RollTheDice/Source/View/Report/ReportListView.swift b/iOS/RollTheDice/RollTheDice/Source/View/Report/ReportListView.swift index 0f298953..57cc844b 100644 --- a/iOS/RollTheDice/RollTheDice/Source/View/Report/ReportListView.swift +++ b/iOS/RollTheDice/RollTheDice/Source/View/Report/ReportListView.swift @@ -10,6 +10,7 @@ import SwiftUI struct ReportListView: View { + @EnvironmentObject var pathModel: PathModel @State private var selectedSegment = 0 var body: some View { @@ -17,39 +18,34 @@ struct ReportListView: View { Color.backgroundDark .ignoresSafeArea(.all) - VStack { - HStack(spacing: 0) { - ForEach(0 ..< 2) { index in - Text(index == 0 ? "분야별 레포트" : "일별 레포트") - .bold() - .font(.system(size: 30)) - .frame(maxWidth: .infinity) - .padding() - .foregroundColor(selectedSegment == index ? .white : .primary01) - .background(selectedSegment == index ? Color.primary01 : .clear) - .cornerRadius(10) - .onTapGesture { - selectedSegment = index - } - .tag(index) - } + HStack { + Button { + pathModel.paths.append(.typeReportView) + } label: { + RoundedRectangle(cornerRadius: 8) + .stroke(.gray01, lineWidth: /*@START_MENU_TOKEN@*/1.0/*@END_MENU_TOKEN@*/) + .background(.gray07) + .overlay { + TypePieChartView(reportViewModel: TypeReportViewModel(), isPreview: true) + } + .frame(width: 400, height: 400) + } - .padding(.leading, 200) - .padding(.trailing, 200) - .padding(.top,10) - Spacer() - - if selectedSegment == 0 { - TypeReportView() - } else if selectedSegment == 1 { - DailyReportView() + Button { + pathModel.paths.append(.dailyReportView) + } label: { + RoundedRectangle(cornerRadius: 8) + .stroke(.gray01, lineWidth: /*@START_MENU_TOKEN@*/1.0/*@END_MENU_TOKEN@*/) + .background(.gray07) + .overlay { + DailyBarChartView(dailyViewModel: DailyReportViewModel(), isPreview: true) + .frame(height: 200) + } + .frame(width: 400, height: 400) + } - - - Spacer() } - .padding() } From 92902fdd6d8629d9b9ec177fe556d8738f11fa00 Mon Sep 17 00:00:00 2001 From: realhsb Date: Sun, 28 Apr 2024 21:39:10 +0900 Subject: [PATCH 14/14] =?UTF-8?q?feat:=20=ED=94=84=EB=A6=AC=EB=B7=B0=20?= =?UTF-8?q?=EB=AA=A8=EB=93=9C=EC=97=90=20=EB=94=B0=EB=A5=B8=20chart=20?= =?UTF-8?q?=ED=98=95=ED=83=9C=20=EB=B6=84=EA=B8=B0=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../View/Report/Daily/DailyBarChartView.swift | 68 +++++++++++-------- .../View/Report/Type/TypePieChartView.swift | 22 +++--- 2 files changed, 52 insertions(+), 38 deletions(-) diff --git a/iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyBarChartView.swift b/iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyBarChartView.swift index 58ac3055..f1b36734 100644 --- a/iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyBarChartView.swift +++ b/iOS/RollTheDice/RollTheDice/Source/View/Report/Daily/DailyBarChartView.swift @@ -16,6 +16,8 @@ struct DailyBarChartView: View { @State var selectedDay: Date? @State var selectedView: Int? + var isPreview: Bool = false + var selectedValue: (date: Date, views: Int)? { if let selectedDay { @@ -30,25 +32,29 @@ struct DailyBarChartView: View { var body: some View { VStack(alignment: .leading) { - HStack { - VStack(alignment: .leading) { - Text("이번주 평균") - .foregroundStyle(.gray04) - .font(.pretendardBold12) - HStack { - Text(dailyViewModel.averageView) - .foregroundStyle(.basicWhite) - .font(.pretendardBold40) - Text("기사") + if !isPreview { + HStack { + VStack(alignment: .leading) { + Text("이번주 평균") .foregroundStyle(.gray04) .font(.pretendardBold12) + HStack { + Text(dailyViewModel.averageView) + .foregroundStyle(.basicWhite) + .font(.pretendardBold40) + Text("기사") + .foregroundStyle(.gray04) + .font(.pretendardBold12) + } } + Spacer() } + Spacer() + .frame(height: 100) } - Spacer() - .frame(height: 100) + Chart{ ForEach(dailyViewModel.dailyReportList.reportList) { day in @@ -59,32 +65,36 @@ struct DailyBarChartView: View { ) .cornerRadius(8) .foregroundStyle(.primary01.gradient) -// .foregroundStyle(selectedValue?.date.formatted(date: .abbreviated, time: .omitted) == selectedDay?.formatted(date: .abbreviated, time: .omitted) ? .orange : .blue) + //TODO: 바 선택 / 미선택에 따른 막대 투명도 조절 .opacity(selectedValue?.date == nil || selectedValue?.date.formatted(date: .numeric, time: .omitted) == selectedDay?.formatted(date: .numeric, time: .omitted) ? 1 : 0.5) } - if let selectedDay = selectedDay { - if selectedValue != nil { - - RuleMark( - x: .value("Day", selectedDay, unit: .day) - ) - .zIndex(-1) - .annotation( - position: .top, - alignment: .centerLastTextBaseline, - overflowResolution: .init( - x: .fit(to: .chart), - y: .disabled + if !isPreview { + if let selectedDay = selectedDay { + if selectedValue != nil { + + RuleMark( + x: .value("Day", selectedDay, unit: .day) ) - ) { - popoverView + .zIndex(-1) + .annotation( + position: .top, + alignment: .centerLastTextBaseline, + overflowResolution: .init( + x: .fit(to: .chart), + y: .disabled + ) + ) { + popoverView + } + .foregroundStyle(.basicWhite) } - .foregroundStyle(.basicWhite) } } } + .padding(isPreview ? 50 : 0) + .chartXAxis(isPreview ? .hidden : .visible) .chartXAxis { AxisMarks(values: .automatic(desiredCount: 7)) } diff --git a/iOS/RollTheDice/RollTheDice/Source/View/Report/Type/TypePieChartView.swift b/iOS/RollTheDice/RollTheDice/Source/View/Report/Type/TypePieChartView.swift index 9ff50a82..bbd26054 100644 --- a/iOS/RollTheDice/RollTheDice/Source/View/Report/Type/TypePieChartView.swift +++ b/iOS/RollTheDice/RollTheDice/Source/View/Report/Type/TypePieChartView.swift @@ -12,6 +12,8 @@ struct TypePieChartView: View { @StateObject var reportViewModel: TypeReportViewModel + var isPreview: Bool = false + var mostViewed: NewsType { return reportViewModel.sortedList.first!.newsType } @@ -24,22 +26,24 @@ struct TypePieChartView: View { angularInset: 2.0 ) .cornerRadius(8) - .foregroundStyle(report.newsType.color) + .foregroundStyle(report.newsType.color.gradient) } /// pie chart의 가운데 문구 .chartBackground { chartProxy in GeometryReader { geometry in let frame = geometry[chartProxy.plotFrame!] - VStack { - Text("많이 본 분야") - .foregroundStyle(.gray05) - .font(.pretendardRegular14) - Text(mostViewed.desciption) - .foregroundStyle(.gray01) - .font(.pretendardBold24) + if !isPreview { + VStack { + Text("많이 본 분야") + .foregroundStyle(.gray05) + .font(.pretendardRegular14) + Text(mostViewed.desciption) + .foregroundStyle(.gray01) + .font(.pretendardBold24) + } + .position(x: frame.midX, y: frame.midY) } - .position(x: frame.midX, y: frame.midY) } } .padding(100)