From d2b6f539f1f07a51f7168fa46ac2a6790f4fb55f Mon Sep 17 00:00:00 2001 From: Laurent Date: Tue, 6 Aug 2019 18:45:17 +0200 Subject: [PATCH] infography update --- TournamentStats.xcodeproj/project.pbxproj | 24 +++ TournamentStats/AppDelegate.swift | 48 +++--- TournamentStats/Base.lproj/Main.storyboard | 35 ++-- TournamentStats/UI/DataSourceWrapper.swift | 4 +- TournamentStats/UI/UIColor+Extensions.swift | 22 +++ TournamentStats/UI/UIView+Extensions.swift | 10 ++ TournamentStats/UI/components/PieChart.swift | 36 ++++ TournamentStats/UI/components/TableView.swift | 34 ++++ .../UI/components/TitleLabel.swift | 26 +++ .../UI/reports/InfographyView.swift | 162 ++++++++++++++---- .../report/structures/TournamentCounter.swift | 5 + .../utils/ColumnRepresentable.swift | 67 ++++++++ 12 files changed, 407 insertions(+), 66 deletions(-) create mode 100644 TournamentStats/UI/UIColor+Extensions.swift create mode 100644 TournamentStats/UI/components/PieChart.swift create mode 100644 TournamentStats/UI/components/TableView.swift create mode 100644 TournamentStats/UI/components/TitleLabel.swift diff --git a/TournamentStats.xcodeproj/project.pbxproj b/TournamentStats.xcodeproj/project.pbxproj index f8b16ee..7f7b196 100644 --- a/TournamentStats.xcodeproj/project.pbxproj +++ b/TournamentStats.xcodeproj/project.pbxproj @@ -129,6 +129,10 @@ 4DF7614D22A6CC0D004B0EF1 /* NotablePlayers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DF7614C22A6CC0D004B0EF1 /* NotablePlayers.swift */; }; 4DF7614F22A6CF93004B0EF1 /* PlayerResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DF7614E22A6CF93004B0EF1 /* PlayerResult.swift */; }; 4DF7615122A7AECA004B0EF1 /* TournamentRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DF7615022A7AECA004B0EF1 /* TournamentRepresentable.swift */; }; + 4DF78DCE22F9AA3F00C02F73 /* PieChart.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DF78DCD22F9AA3F00C02F73 /* PieChart.swift */; }; + 4DF78DD122F9AADF00C02F73 /* TableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DF78DD022F9AADF00C02F73 /* TableView.swift */; }; + 4DF78DD422F9C85C00C02F73 /* UIColor+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DF78DD322F9C85C00C02F73 /* UIColor+Extensions.swift */; }; + 4DF78DD622F9CE7E00C02F73 /* TitleLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DF78DD522F9CE7E00C02F73 /* TitleLabel.swift */; }; FFE9052C22BB7313006FEFA4 /* event34 in Resources */ = {isa = PBXBuildFile; fileRef = FFE9052922BB7312006FEFA4 /* event34 */; }; FFE9052D22BB7313006FEFA4 /* event41 in Resources */ = {isa = PBXBuildFile; fileRef = FFE9052A22BB7312006FEFA4 /* event41 */; }; FFE9052E22BB7313006FEFA4 /* event40 in Resources */ = {isa = PBXBuildFile; fileRef = FFE9052B22BB7313006FEFA4 /* event40 */; }; @@ -271,6 +275,10 @@ 4DF7614C22A6CC0D004B0EF1 /* NotablePlayers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotablePlayers.swift; sourceTree = ""; }; 4DF7614E22A6CF93004B0EF1 /* PlayerResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerResult.swift; sourceTree = ""; }; 4DF7615022A7AECA004B0EF1 /* TournamentRepresentable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TournamentRepresentable.swift; sourceTree = ""; }; + 4DF78DCD22F9AA3F00C02F73 /* PieChart.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PieChart.swift; sourceTree = ""; }; + 4DF78DD022F9AADF00C02F73 /* TableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableView.swift; sourceTree = ""; }; + 4DF78DD322F9C85C00C02F73 /* UIColor+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIColor+Extensions.swift"; sourceTree = ""; }; + 4DF78DD522F9CE7E00C02F73 /* TitleLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TitleLabel.swift; sourceTree = ""; }; FFE9052922BB7312006FEFA4 /* event34 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = event34; sourceTree = ""; }; FFE9052A22BB7312006FEFA4 /* event41 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = event41; sourceTree = ""; }; FFE9052B22BB7313006FEFA4 /* event40 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = event40; sourceTree = ""; }; @@ -482,6 +490,7 @@ 4DF760C022A561A8004B0EF1 /* UI */ = { isa = PBXGroup; children = ( + 4DF78DCF22F9AA9300C02F73 /* components */, 4D97941222F827A5004A2D7F /* reports */, 4DF7608722A3FB96004B0EF1 /* DetailViewController.swift */, 4DF7608522A3FB96004B0EF1 /* MasterViewController.swift */, @@ -489,6 +498,7 @@ 4D39B6F422F856EF00625E31 /* StackTableCell.xib */, 4D39B6F622F8573900625E31 /* StackTableCell.swift */, 4D39B6F922F85C3400625E31 /* UIView+Extensions.swift */, + 4DF78DD322F9C85C00C02F73 /* UIColor+Extensions.swift */, ); path = UI; sourceTree = ""; @@ -528,6 +538,16 @@ path = structures; sourceTree = ""; }; + 4DF78DCF22F9AA9300C02F73 /* components */ = { + isa = PBXGroup; + children = ( + 4DF78DCD22F9AA3F00C02F73 /* PieChart.swift */, + 4DF78DD022F9AADF00C02F73 /* TableView.swift */, + 4DF78DD522F9CE7E00C02F73 /* TitleLabel.swift */, + ); + path = components; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -745,6 +765,7 @@ buildActionMask = 2147483647; files = ( 4DF7614822A59660004B0EF1 /* ReportGenerator.swift in Sources */, + 4DF78DD422F9C85C00C02F73 /* UIColor+Extensions.swift in Sources */, 4DF760C222A561FF004B0EF1 /* ColumnRepresentable.swift in Sources */, 4DF760B022A47C74004B0EF1 /* RowImporter.swift in Sources */, 4DF7614A22A66675004B0EF1 /* TournamentWinner.swift in Sources */, @@ -752,6 +773,8 @@ 4D39B6F122F829A500625E31 /* InfographyView.swift in Sources */, 4DF760B322A47CAE004B0EF1 /* Realm+Extensions.swift in Sources */, 4DF7608822A3FB96004B0EF1 /* DetailViewController.swift in Sources */, + 4DF78DD122F9AADF00C02F73 /* TableView.swift in Sources */, + 4DF78DD622F9CE7E00C02F73 /* TitleLabel.swift in Sources */, 4DF7615122A7AECA004B0EF1 /* TournamentRepresentable.swift in Sources */, 4DF7608622A3FB96004B0EF1 /* MasterViewController.swift in Sources */, 4DF7608422A3FB96004B0EF1 /* AppDelegate.swift in Sources */, @@ -761,6 +784,7 @@ 4D39B6FC22F8686300625E31 /* CumulatedWins.swift in Sources */, 4DF7614F22A6CF93004B0EF1 /* PlayerResult.swift in Sources */, 4D39B6F722F8573900625E31 /* StackTableCell.swift in Sources */, + 4DF78DCE22F9AA3F00C02F73 /* PieChart.swift in Sources */, 4DF7614622A59407004B0EF1 /* CumulatedResults.swift in Sources */, 4D0F103922C4C1C4005F797A /* ChipCountParser.swift in Sources */, 4D39B6FA22F85C3400625E31 /* UIView+Extensions.swift in Sources */, diff --git a/TournamentStats/AppDelegate.swift b/TournamentStats/AppDelegate.swift index b0365fa..3e80ac3 100644 --- a/TournamentStats/AppDelegate.swift +++ b/TournamentStats/AppDelegate.swift @@ -12,10 +12,10 @@ import Realm @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDelegate { - + var window: UIWindow? - - + + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // UI stuff @@ -40,49 +40,53 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele let d = Date().timeIntervalSince(s) print("reports created in \(d)s") - let infography = InfographyView(frame: CGRect(x: 0, y: 0, width: 1000, height: 1000), generator: generator) - - if let imageData = infography.toImage()?.pngData() { + if let ivc = UIStoryboard(name: "Main", bundle: Bundle.main).instantiateViewController(withIdentifier: "container") as? InfographyViewController { + ivc.generator = generator + ivc.view.frame = CGRect(x: 0, y: 0, width: 1000, height: 1000) - guard let directory = try? FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false) as NSURL else { - return false + if let imageData = ivc.view.toImage()?.pngData() { + + guard let directory = try? FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false) as NSURL else { + return false + } + + do { + try imageData.write(to: directory.appendingPathComponent("infography.png")!) + } catch { + print(error.localizedDescription) + } + } - do { - try imageData.write(to: directory.appendingPathComponent("infography.png")!) - } catch { - print(error.localizedDescription) - } - } return true } - + func applicationWillResignActive(_ application: UIApplication) { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. } - + func applicationDidEnterBackground(_ application: UIApplication) { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. } - + func applicationWillEnterForeground(_ application: UIApplication) { // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. } - + func applicationDidBecomeActive(_ application: UIApplication) { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. } - + func applicationWillTerminate(_ application: UIApplication) { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } - + // MARK: - Split view - + func splitViewController(_ splitViewController: UISplitViewController, collapseSecondary secondaryViewController:UIViewController, onto primaryViewController:UIViewController) -> Bool { guard let secondaryAsNavController = secondaryViewController as? UINavigationController else { return false } guard let topAsDetailController = secondaryAsNavController.topViewController as? DetailViewController else { return false } @@ -92,6 +96,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele } return false } - + } diff --git a/TournamentStats/Base.lproj/Main.storyboard b/TournamentStats/Base.lproj/Main.storyboard index d9e1a32..9df85cf 100644 --- a/TournamentStats/Base.lproj/Main.storyboard +++ b/TournamentStats/Base.lproj/Main.storyboard @@ -1,6 +1,6 @@ - + @@ -15,7 +15,7 @@ - + @@ -31,11 +31,11 @@ - +