diff --git a/Child Labor.xcodeproj/project.pbxproj b/Child Labor.xcodeproj/project.pbxproj index 4942dc6..f393271 100755 --- a/Child Labor.xcodeproj/project.pbxproj +++ b/Child Labor.xcodeproj/project.pbxproj @@ -31,6 +31,7 @@ 1334AC97283BC372000F647E /* CustomExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1334AC96283BC372000F647E /* CustomExtensions.swift */; }; 1334AC992841028D000F647E /* GoodsParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1334AC982841028C000F647E /* GoodsParser.swift */; }; 1334AC9B28410338000F647E /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1334AC9A28410338000F647E /* Constants.swift */; }; + 136829B0286CA84C0083D8E4 /* CustomLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 136829AF286CA84C0083D8E4 /* CustomLabel.swift */; }; 13840007282965170072C737 /* ProportionalChartController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13840006282965160072C737 /* ProportionalChartController.swift */; }; 139AC81D2332509A002420FF /* North_Macedonia-map.png in Resources */ = {isa = PBXBuildFile; fileRef = 139AC8122332509A002420FF /* North_Macedonia-map.png */; }; 139AC81E2332509A002420FF /* Moldova.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 139AC8132332509A002420FF /* Moldova.pdf */; }; @@ -1145,6 +1146,7 @@ 1334AC96283BC372000F647E /* CustomExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomExtensions.swift; sourceTree = ""; }; 1334AC982841028C000F647E /* GoodsParser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GoodsParser.swift; sourceTree = ""; }; 1334AC9A28410338000F647E /* Constants.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = ""; }; + 136829AF286CA84C0083D8E4 /* CustomLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomLabel.swift; sourceTree = ""; }; 13840006282965160072C737 /* ProportionalChartController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProportionalChartController.swift; sourceTree = ""; }; 139AC8122332509A002420FF /* North_Macedonia-map.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "North_Macedonia-map.png"; sourceTree = ""; }; 139AC8132332509A002420FF /* Moldova.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = Moldova.pdf; sourceTree = ""; }; @@ -2279,6 +2281,7 @@ 1334AC772832B76B000F647E /* GoodsChartCollectionCell.swift */, 1334AC782832B76B000F647E /* DataVisualizationTableViewController.swift */, 1334AC792832B76B000F647E /* CirclesLayout.h */, + 136829AF286CA84C0083D8E4 /* CustomLabel.swift */, ); path = charts; sourceTree = SOURCE_ROOT; @@ -4632,6 +4635,7 @@ buildActionMask = 2147483647; files = ( 1334AC97283BC372000F647E /* CustomExtensions.swift in Sources */, + 136829B0286CA84C0083D8E4 /* CustomLabel.swift in Sources */, 83EF03A01B4D944E00C2AECE /* GoodsTableViewController.swift in Sources */, 834D8DA71B4C5EFA001CD795 /* StatisticsTableViewController.swift in Sources */, 1334AC7F2832B76B000F647E /* ProportionalChartViewController.swift in Sources */, diff --git a/Child Labor.xcodeproj/project.xcworkspace/xcuserdata/zolontech.xcuserdatad/UserInterfaceState.xcuserstate b/Child Labor.xcodeproj/project.xcworkspace/xcuserdata/zolontech.xcuserdatad/UserInterfaceState.xcuserstate index f003076..78a7b4a 100644 Binary files a/Child Labor.xcodeproj/project.xcworkspace/xcuserdata/zolontech.xcuserdatad/UserInterfaceState.xcuserstate and b/Child Labor.xcodeproj/project.xcworkspace/xcuserdata/zolontech.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/Child Labor/Base.lproj/Main.storyboard b/Child Labor/Base.lproj/Main.storyboard index a814c4a..cc76408 100755 --- a/Child Labor/Base.lproj/Main.storyboard +++ b/Child Labor/Base.lproj/Main.storyboard @@ -4946,7 +4946,7 @@ Standards - + @@ -5217,14 +5217,14 @@ Standards + + + + + @@ -5880,6 +5885,11 @@ Standards + + + + + diff --git a/Child Labor/PakistanTableViewController.swift b/Child Labor/PakistanTableViewController.swift index fc42203..f947066 100755 --- a/Child Labor/PakistanTableViewController.swift +++ b/Child Labor/PakistanTableViewController.swift @@ -10,12 +10,13 @@ import UIKit class PakistanTableViewController: UITableViewController { - var countryName = "Brazil" - - - + var countryName = "Pakistan" + @IBOutlet weak var agricultureLabel: UILabel! + @IBOutlet weak var industryLabel: UILabel! + @IBOutlet weak var servicesLabel: UILabel! + var analyticsData: [Segment] = [Segment]() override func viewDidLoad() { super.viewDidLoad() @@ -25,7 +26,11 @@ class PakistanTableViewController: UITableViewController { tracker?.set(kGAIScreenName, value: "Pakistan Statistics Screen") tracker?.send(GAIDictionaryBuilder.createAppView().build() as! [AnyHashable: Any]) - + self.readDataFromXML() + self.addTableViewFooter() + } + + func readDataFromXML() { let urlPath = Bundle.main.path(forResource: "countries_2016", ofType: "xml") var contents: NSString? do { @@ -36,15 +41,123 @@ class PakistanTableViewController: UITableViewController { let countriesXML = SWXMLHash.parse(contents! as String) for country in countriesXML["Countries"]["Country"].all { - if country["Name"].element?.text == "Pakistan"{ + if country["Name"].element?.text == "Pakistan" { + let statistics = country["Country_Statistics"] + // Agriculture + if let agriculturePercentage = statistics["Children_Work_Statistics"]["Agriculture"].element { + if agriculturePercentage.text != nil { + if agriculturePercentage.text != "" { + agricultureLabel.text = String(format: "%.1f", (agriculturePercentage.text as NSString).floatValue * 100.0) + "%" + agricultureLabel.textColor = UIColor.black + + if (agriculturePercentage.text as NSString).floatValue > 0 { + let agricultureSector = Segment.init(color: UIColor(red: 108.0/255.0, green: 129.0/255.0, blue: 79.0/255.0, alpha: 1), value: CGFloat((agriculturePercentage.text as NSString).floatValue * 100.0), title : "Agriculture", isFloatType: true) + analyticsData.append(agricultureSector) + } + } + } + if (agriculturePercentage.text == "Unavailable" || agriculturePercentage.text == "unavailable") + { + agricultureLabel.text = "Unavailable" + agricultureLabel.textColor = UIColor.black + } + if agriculturePercentage.text == "N/A" + { + agricultureLabel.text = "N/A" + agricultureLabel.accessibilityLabel = "Not Available" + agricultureLabel.textColor = UIColor.black + } + + } + // Services + if let servicesPercentage = statistics["Children_Work_Statistics"]["Services"].element { + if servicesPercentage.text != nil { + if servicesPercentage.text != "" { + servicesLabel.text = String(format: "%.1f", (servicesPercentage.text as NSString).floatValue * 100.0) + "%" + servicesLabel.textColor = UIColor.black + if (servicesPercentage.text as NSString).floatValue > 0 { + let servicesSector = Segment.init(color: UIColor(red: 57.0/255.0, green: 89.0/255.0, blue: 122.0/255.0, alpha: 1), value: CGFloat((servicesPercentage.text as NSString).floatValue * 100.0), title : "Services", isFloatType: true) + analyticsData.append(servicesSector) + } + } + } + if (servicesPercentage.text == "Unavailable" || servicesPercentage.text == "unavailable") + { + servicesLabel.text = "Unavailable" + servicesLabel.textColor = UIColor.black + } + if servicesPercentage.text == "N/A" + { + servicesLabel.text = "N/A" + servicesLabel.accessibilityLabel = "Not Available" + servicesLabel.textColor = UIColor.black + } + + } + + // Industry + if let industryPercentage = statistics["Children_Work_Statistics"]["Industry"].element { + if industryPercentage.text != nil { + if industryPercentage.text != "" { + industryLabel.text = String(format: "%.1f", (industryPercentage.text as NSString).floatValue * 100.0) + "%" + industryLabel.textColor = UIColor.black + if (industryPercentage.text as NSString).floatValue > 0 { + let industrySector = Segment.init(color: UIColor(red: 218.0/255.0, green: 142.0/255.0, blue: 57.0/255.0, alpha: 1), value: CGFloat((industryPercentage.text as NSString).floatValue * 100.0), title : "Industry", isFloatType: true) + analyticsData.append(industrySector) + } + } + } + if (industryPercentage.text == "Unavailable" || industryPercentage.text == "unavailable") + { + industryLabel.text = "Unavailable" + industryLabel.textColor = UIColor.black + } + if industryPercentage.text == "N/A" + { + industryLabel.text = "N/A" + industryLabel.accessibilityLabel = "Not Available" + industryLabel.textColor = UIColor.black + } + } + if #available(iOS 13.0, *) { + servicesLabel.textColor = .label + agricultureLabel.textColor = .label + industryLabel.textColor = .label + } else { + // Fallback on earlier versions + } + break; } - } } + func addTableViewFooter() { + let customView = UIView(frame: CGRect(x: 0, y: 0, width: self.tableView.frame.width, height: 50)) + customView.backgroundColor = UIColor.clear + let button = UIButton(frame: CGRect(x: 20, y: 0, width: self.tableView.frame.width - 40, height: 50)) + button.setTitleColor(UIColor.black, for: .normal) + button.titleLabel?.font = UIFont.systemFont(ofSize:20) + button.backgroundColor = .lightGray.withAlphaComponent(0.8) + button.layer.cornerRadius = 20 + button.setTitle("Open Analysis", for: .normal) + button.addTarget(self, action: #selector(openWorkingStatics), for: .touchUpInside) + customView.addSubview(button) + self.tableView.tableFooterView = customView + + } + + @objc func openWorkingStatics(_ sender: UIButton!) { + + let viewController = PieChartViewController() + viewController.isFromWorkingStatistics = true + viewController.workingStatistics = analyticsData + viewController.countryName = self.countryName + navigationController?.pushViewController(viewController, animated: true) + } + override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. @@ -53,15 +166,22 @@ class PakistanTableViewController: UITableViewController { // MARK: - Table view data source override func numberOfSections(in tableView: UITableView) -> Int { - // #warning Incomplete implementation, return the number of sections - return 1 + + return 8 } override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - // #warning Incomplete implementation, return the number of rows - return 7 + return (section == 0) ? 0 : 3 } + override func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) { + let header = view as! UITableViewHeaderFooterView + header.textLabel?.textColor = UIColor.gray + } + override func tableView(_ tableView: UITableView, willDisplayFooterView view: UIView, forSection section: Int) { + let header = view as! UITableViewHeaderFooterView + header.textLabel?.textColor = UIColor.gray + } } diff --git a/Child Labor/SomaliaTableViewController.swift b/Child Labor/SomaliaTableViewController.swift index 87ab84b..fb9e24c 100755 --- a/Child Labor/SomaliaTableViewController.swift +++ b/Child Labor/SomaliaTableViewController.swift @@ -10,28 +10,67 @@ import UIKit class SomaliaTableViewController: UITableViewController { - var countryName = "Brazil" - - - - - + var countryName = "Somalia" override func viewDidLoad() { super.viewDidLoad() - - let tracker = GAI.sharedInstance().defaultTracker tracker?.set(kGAIScreenName, value: "Somalia Statistics Screen") tracker?.send(GAIDictionaryBuilder.createAppView().build() as! [AnyHashable: Any]) + self.addTableViewFooter() } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } - - + + func addTableViewFooter() { + let customView = UIView(frame: CGRect(x: 0, y: 0, width: self.tableView.frame.width, height: 50)) + customView.backgroundColor = UIColor.clear + let button = UIButton(frame: CGRect(x: 20, y: 0, width: self.tableView.frame.width - 40, height: 50)) + button.setTitleColor(UIColor.black, for: .normal) + button.titleLabel?.font = UIFont.systemFont(ofSize:20) + button.backgroundColor = .lightGray.withAlphaComponent(0.8) + button.layer.cornerRadius = 20 + button.setTitle("Open Analysis", for: .normal) + button.addTarget(self, action: #selector(openWorkingStatics), for: .touchUpInside) + customView.addSubview(button) + self.tableView.tableFooterView = customView + + } + + @objc func openWorkingStatics(_ sender: UIButton!) { + + let viewController = PieChartViewController() + viewController.isFromWorkingStatistics = true + viewController.workingStatistics = [Segment]() + viewController.countryName = self.countryName + navigationController?.pushViewController(viewController, animated: true) + } + + override func numberOfSections(in tableView: UITableView) -> Int { + + return 8 + } + + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + if (section == 1 || section == 5 || section == 6) { + return 2 + } + return (section == 0) ? 0 : 1 + + } + + override func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) { + let header = view as! UITableViewHeaderFooterView + header.textLabel?.textColor = UIColor.gray + } + + override func tableView(_ tableView: UITableView, willDisplayFooterView view: UIView, forSection section: Int) { + let header = view as! UITableViewHeaderFooterView + header.textLabel?.textColor = UIColor.gray + } } diff --git a/Child Labor/StatisticsTableViewController.swift b/Child Labor/StatisticsTableViewController.swift index 5107b1c..222025e 100755 --- a/Child Labor/StatisticsTableViewController.swift +++ b/Child Labor/StatisticsTableViewController.swift @@ -112,7 +112,7 @@ class StatisticsTableViewController: UITableViewController { agricultureLabel.textColor = UIColor.black if (agriculturePercentage.text as NSString).floatValue > 0 { - let agricultureSector = Segment.init(color: UIColor(red: 57.0/255.0, green: 89.0/255.0, blue: 122.0/255.0, alpha: 1), value: CGFloat((agriculturePercentage.text as NSString).floatValue * 100.0), title : "Agriculture", isFloatType: true) + let agricultureSector = Segment.init(color: UIColor(red: 108.0/255.0, green: 129.0/255.0, blue: 79.0/255.0, alpha: 1), value: CGFloat((agriculturePercentage.text as NSString).floatValue * 100.0), title : "Agriculture", isFloatType: true) analyticsData.append(agricultureSector) } @@ -145,7 +145,7 @@ class StatisticsTableViewController: UITableViewController { servicesLabel.text = String(format: "%.1f", (servicesPercentage.text as NSString).floatValue * 100.0) + "%" servicesLabel.textColor = UIColor.black if (servicesPercentage.text as NSString).floatValue > 0 { - let servicesSector = Segment.init(color: UIColor(red: 108.0/255.0, green: 129.0/255.0, blue: 79.0/255.0, alpha: 1), value: CGFloat((servicesPercentage.text as NSString).floatValue * 100.0), title : "Services", isFloatType: true) + let servicesSector = Segment.init(color: UIColor(red: 57.0/255.0, green: 89.0/255.0, blue: 122.0/255.0, alpha: 1), value: CGFloat((servicesPercentage.text as NSString).floatValue * 100.0), title : "Services", isFloatType: true) analyticsData.append(servicesSector) } } @@ -361,6 +361,14 @@ class StatisticsTableViewController: UITableViewController { return 7 } - + override func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) { + let header = view as! UITableViewHeaderFooterView + header.textLabel?.textColor = UIColor.gray + } + + override func tableView(_ tableView: UITableView, willDisplayFooterView view: UIView, forSection section: Int) { + let header = view as! UITableViewHeaderFooterView + header.textLabel?.textColor = UIColor.gray + } } diff --git a/Child Labor/TanzaniaTableViewController.swift b/Child Labor/TanzaniaTableViewController.swift index 090ffe2..d9befc1 100644 --- a/Child Labor/TanzaniaTableViewController.swift +++ b/Child Labor/TanzaniaTableViewController.swift @@ -9,13 +9,14 @@ import UIKit class TanzaniaTableViewController: UITableViewController { + + var countryName = "Tanzania" - var countryName = "Brazil" - - - - - + @IBOutlet weak var agricultureLabel: UILabel! + @IBOutlet weak var industryLabel: UILabel! + @IBOutlet weak var servicesLabel: UILabel! + var analyticsData: [Segment] = [Segment]() + override func viewDidLoad() { super.viewDidLoad() @@ -25,7 +26,11 @@ class TanzaniaTableViewController: UITableViewController { tracker?.set(kGAIScreenName, value: "Tanzania Statistics Screen") tracker?.send(GAIDictionaryBuilder.createAppView().build() as! [AnyHashable: Any]) - + self.readDataFromXML() + self.addTableViewFooter() + } + + func readDataFromXML() { let urlPath = Bundle.main.path(forResource: "countries_2016", ofType: "xml") var contents: NSString? do { @@ -36,22 +41,146 @@ class TanzaniaTableViewController: UITableViewController { let countriesXML = SWXMLHash.parse(contents! as String) for country in countriesXML["Countries"]["Country"].all { - if country["Name"].element?.text == "Tanzania"{ + if country["Name"].element?.text == "Tanzania" { + + let statistics = country["Country_Statistics"] + // Agriculture + if let agriculturePercentage = statistics["Children_Work_Statistics"]["Agriculture"].element { + if agriculturePercentage.text != nil { + if agriculturePercentage.text != "" { + agricultureLabel.text = String(format: "%.1f", (agriculturePercentage.text as NSString).floatValue * 100.0) + "%" + agricultureLabel.textColor = UIColor.black + + if (agriculturePercentage.text as NSString).floatValue > 0 { + let agricultureSector = Segment.init(color: UIColor(red: 108.0/255.0, green: 129.0/255.0, blue: 79.0/255.0, alpha: 1), value: CGFloat((agriculturePercentage.text as NSString).floatValue * 100.0), title : "Agriculture", isFloatType: true) + analyticsData.append(agricultureSector) + } + } + } + if (agriculturePercentage.text == "Unavailable" || agriculturePercentage.text == "unavailable") + { + agricultureLabel.text = "Unavailable" + agricultureLabel.textColor = UIColor.black + } + if agriculturePercentage.text == "N/A" + { + agricultureLabel.text = "N/A" + agricultureLabel.accessibilityLabel = "Not Available" + agricultureLabel.textColor = UIColor.black + } + + } + // Services + if let servicesPercentage = statistics["Children_Work_Statistics"]["Services"].element { + if servicesPercentage.text != nil { + if servicesPercentage.text != "" { + servicesLabel.text = String(format: "%.1f", (servicesPercentage.text as NSString).floatValue * 100.0) + "%" + servicesLabel.textColor = UIColor.black + if (servicesPercentage.text as NSString).floatValue > 0 { + let servicesSector = Segment.init(color: UIColor(red: 57.0/255.0, green: 89.0/255.0, blue: 122.0/255.0, alpha: 1), value: CGFloat((servicesPercentage.text as NSString).floatValue * 100.0), title : "Services", isFloatType: true) + analyticsData.append(servicesSector) + } + } + } + if (servicesPercentage.text == "Unavailable" || servicesPercentage.text == "unavailable") + { + servicesLabel.text = "Unavailable" + servicesLabel.textColor = UIColor.black + } + if servicesPercentage.text == "N/A" + { + servicesLabel.text = "N/A" + servicesLabel.accessibilityLabel = "Not Available" + servicesLabel.textColor = UIColor.black + } + + } + // Industry + if let industryPercentage = statistics["Children_Work_Statistics"]["Industry"].element { + if industryPercentage.text != nil { + if industryPercentage.text != "" { + industryLabel.text = String(format: "%.1f", (industryPercentage.text as NSString).floatValue * 100.0) + "%" + industryLabel.textColor = UIColor.black + if (industryPercentage.text as NSString).floatValue > 0 { + let industrySector = Segment.init(color: UIColor(red: 218.0/255.0, green: 142.0/255.0, blue: 57.0/255.0, alpha: 1), value: CGFloat((industryPercentage.text as NSString).floatValue * 100.0), title : "Industry", isFloatType: true) + analyticsData.append(industrySector) + } + } + } + if (industryPercentage.text == "Unavailable" || industryPercentage.text == "unavailable") + { + industryLabel.text = "Unavailable" + industryLabel.textColor = UIColor.black + } + if industryPercentage.text == "N/A" + { + industryLabel.text = "N/A" + industryLabel.accessibilityLabel = "Not Available" + industryLabel.textColor = UIColor.black + } + } + if #available(iOS 13.0, *) { + servicesLabel.textColor = .label + agricultureLabel.textColor = .label + industryLabel.textColor = .label + } else { + // Fallback on earlier versions + } + break; } - } } + func addTableViewFooter() { + let customView = UIView(frame: CGRect(x: 0, y: 0, width: self.tableView.frame.width, height: 50)) + customView.backgroundColor = UIColor.clear + let button = UIButton(frame: CGRect(x: 20, y: 0, width: self.tableView.frame.width - 40, height: 50)) + button.setTitleColor(UIColor.black, for: .normal) + button.titleLabel?.font = UIFont.systemFont(ofSize:20) + button.backgroundColor = .lightGray.withAlphaComponent(0.8) + button.layer.cornerRadius = 20 + button.setTitle("Open Analysis", for: .normal) + button.addTarget(self, action: #selector(openWorkingStatics), for: .touchUpInside) + customView.addSubview(button) + self.tableView.tableFooterView = customView + + } + + @objc func openWorkingStatics(_ sender: UIButton!) { + + let viewController = PieChartViewController() + viewController.isFromWorkingStatistics = true + viewController.workingStatistics = analyticsData + viewController.countryName = self.countryName + navigationController?.pushViewController(viewController, animated: true) + } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } + override func numberOfSections(in tableView: UITableView) -> Int { + + return 8 + } + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return (section == 0) ? 0 : 2 + } + + override func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) { + let header = view as! UITableViewHeaderFooterView + header.textLabel?.textColor = UIColor.gray + } + + override func tableView(_ tableView: UITableView, willDisplayFooterView view: UIView, forSection section: Int) { + let header = view as! UITableViewHeaderFooterView + header.textLabel?.textColor = UIColor.gray + } } diff --git a/Child Labor/goods_2016.xml b/Child Labor/goods_2016.xml index ed4333c..79dc192 100644 --- a/Child Labor/goods_2016.xml +++ b/Child Labor/goods_2016.xml @@ -31,7 +31,7 @@ China - + Indo-Pacific No Yes No @@ -305,7 +305,7 @@ China - + Indo-Pacific Yes Yes Yes @@ -333,7 +333,7 @@ Iran - + Middle East and North Africa Yes No No @@ -347,7 +347,7 @@ North Korea - + Indo-Pacific No Yes No @@ -375,7 +375,7 @@ Russia - + Indo-Pacific No Yes No @@ -389,7 +389,7 @@ Vietnam - + Indo-Pacific Yes No No @@ -455,7 +455,7 @@ Iran - + Middle East and North Africa Yes No No @@ -509,7 +509,7 @@ Vietnam - + Indo-Pacific Yes No No @@ -626,7 +626,7 @@ North Korea - + Indo-Pacific No Yes No @@ -698,7 +698,7 @@ China - + Indo-Pacific No Yes No @@ -718,7 +718,7 @@ Turkey - + Middle East and North Africa Yes No No @@ -751,7 +751,7 @@ China - + Indo-Pacific No Yes No @@ -772,7 +772,7 @@ North Korea - + Indo-Pacific No Yes No @@ -1012,7 +1012,7 @@ Vietnam - + Indo-Pacific Yes No No @@ -1114,7 +1114,7 @@ China - + Indo-Pacific Yes Yes Yes @@ -1163,21 +1163,21 @@ Tajikistan - + Indo-Pacific Yes Yes Yes Turkey - + Middle East and North Africa Yes No No Turkmenistan - + Indo-Pacific Yes Yes No @@ -1230,7 +1230,7 @@ Turkey - + Middle East and North Africa Yes No No @@ -1317,14 +1317,14 @@ China - + Indo-Pacific Yes Yes Yes Malaysia - + Indo-Pacific No Yes No @@ -1383,7 +1383,7 @@ China - + Indo-Pacific Yes Yes No @@ -1438,7 +1438,7 @@ China - + Indo-Pacific No Yes No @@ -1487,7 +1487,7 @@ Taiwan - + Indo-Pacific No Yes No @@ -1508,7 +1508,7 @@ Vietnam - + Indo-Pacific Yes No No @@ -1568,7 +1568,7 @@ China - + Indo-Pacific No Yes No @@ -1582,14 +1582,14 @@ Turkey - + Middle East and North Africa Yes No No Vietnam - + Indo-Pacific Yes No No @@ -1628,14 +1628,14 @@ Turkey - + Middle East and North Africa Yes No No Vietnam - + Indo-Pacific Yes No No @@ -1702,7 +1702,7 @@ China - + Indo-Pacific No Yes No @@ -1716,7 +1716,7 @@ Malaysia - + Indo-Pacific No Yes No @@ -1737,14 +1737,14 @@ Turkey - + Middle East and North Africa Yes No No Vietnam - + Indo-Pacific Yes Yes Yes @@ -1810,7 +1810,7 @@ China - + Indo-Pacific No Yes No @@ -1948,7 +1948,7 @@ North Korea - + Indo-Pacific No Yes No @@ -1976,7 +1976,7 @@ Sudan - + Sub-Saharan Africa Yes No No @@ -2004,7 +2004,7 @@ Venezuela - + Latin America and the Caribbean No Yes No @@ -2117,7 +2117,7 @@ China - + Indo-Pacific No Yes No @@ -2130,7 +2130,7 @@ Turkey - + Middle East and North Africa Yes No No @@ -2183,7 +2183,7 @@ North Korea - + Indo-Pacific No Yes No @@ -2262,7 +2262,7 @@ Vietnam - + Indo-Pacific Yes No No @@ -2455,7 +2455,7 @@ China - + Indo-Pacific No Yes No @@ -2488,7 +2488,7 @@ Malaysia - + Indo-Pacific Yes Yes No @@ -2568,7 +2568,7 @@ Turkey - + Middle East and North Africa Yes No No @@ -2581,7 +2581,7 @@ Vietnam - + Indo-Pacific Yes No No @@ -2620,7 +2620,7 @@ China - + Indo-Pacific No Yes No @@ -2681,7 +2681,7 @@ Russia - + Indo-Pacific Yes Yes Yes @@ -2748,7 +2748,7 @@ Turkey - + Middle East and North Africa Yes No No @@ -2830,7 +2830,7 @@ Vietnam - + Indo-Pacific Yes No No @@ -2878,7 +2878,7 @@ Vietnam - + Indo-Pacific Yes No No @@ -2891,7 +2891,7 @@ Malaysia - + Indo-Pacific No Yes No @@ -3290,7 +3290,7 @@ Turkey - + Middle East and North Africa Yes No No @@ -3422,7 +3422,7 @@ Vietnam - + Indo-Pacific Yes No No @@ -3542,7 +3542,7 @@ Vietnam - + Indo-Pacific Yes No No @@ -3582,21 +3582,21 @@ China - + Indo-Pacific Yes Yes No North Korea - + Indo-Pacific No Yes No Vietnam - + Indo-Pacific Yes No No @@ -3622,7 +3622,7 @@ China - + Indo-Pacific No Yes No @@ -3669,7 +3669,7 @@ North Korea - + Indo-Pacific No Yes No @@ -3683,14 +3683,14 @@ Russia - + Indo-Pacific No Yes No Vietnam - + Indo-Pacific Yes No No @@ -3834,7 +3834,7 @@ Vietnam - + Indo-Pacific Yes No No @@ -3861,7 +3861,7 @@ China - + Indo-Pacific No Yes No @@ -3908,7 +3908,7 @@ China - + Indo-Pacific Yes Yes Yes diff --git a/charts/CircularSliceView.swift b/charts/CircularSliceView.swift index 38709fc..13efff9 100644 --- a/charts/CircularSliceView.swift +++ b/charts/CircularSliceView.swift @@ -27,7 +27,7 @@ class CircularSliceView: UIView { } private var totalValue: CGFloat = 1; - private var labels: [UILabel] = [] + private var labels: [CustomLabel] = [] @@ -96,7 +96,7 @@ class CircularSliceView: UIView { var diff = segments.count - labels.count; if diff >= 0 { for _ in 0 ..< diff { - let lbl = UILabel() + let lbl = CustomLabel() lbl.numberOfLines = 0 lbl.adjustsFontSizeToFitWidth = true self.addSubview(lbl) @@ -106,7 +106,7 @@ class CircularSliceView: UIView { // loop until diff is 0 // while diff != 0 { - var lbl: UILabel! + var lbl: CustomLabel! // if there is no more labels to remove // break the loop if labels.count <= 0 { @@ -133,7 +133,7 @@ class CircularSliceView: UIView { func layoutLabels() { let anglePI2 = CGFloat.pi * 2 let center = CGPoint.init(x: bounds.size.width / 2, y: bounds.size.height / 2) - let radius = min(bounds.size.width / 2, bounds.size.height / 2) / 2 + let radius = min(bounds.size.width / 1.3, bounds.size.height / 2) / 1.3 var currentAngle: CGFloat = 0; let iRange = 0 ..< labels.count diff --git a/charts/CustomLabel.swift b/charts/CustomLabel.swift new file mode 100644 index 0000000..7f1b910 --- /dev/null +++ b/charts/CustomLabel.swift @@ -0,0 +1,16 @@ +// +// CustomLabel.swift +// Child Labor +// +// Created by Zolon Tech on 29/06/22. +// Copyright © 2022 U.S. Department of Labor. All rights reserved. +// + +import Foundation +class CustomLabel: UILabel { + + override func drawText(in rect: CGRect) { + let insets = UIEdgeInsets.init(top: 0, left: 0, bottom: 0, right: 0) + super.drawText(in: UIEdgeInsetsInsetRect(rect, insets)) + } +} diff --git a/charts/DataVisualizationTableViewController.swift b/charts/DataVisualizationTableViewController.swift index 369b833..0d425da 100644 --- a/charts/DataVisualizationTableViewController.swift +++ b/charts/DataVisualizationTableViewController.swift @@ -3,7 +3,7 @@ import UIKit enum ChartTypes: String, CaseIterable { - case proportionalChart = "Most common goods produced with exploited labor" + //case proportionalChart = "Most common goods produced with exploited labor" case goodsBySector = "Goods By Sector" case goodsByRegion = "Goods By Region" } @@ -90,9 +90,9 @@ extension DataVisualizationTableViewController { let chartType = ChartTypes.allCases[indexPath.row] switch chartType { - case .proportionalChart: - vc = ProportionalChartViewController.loadFromNib() - break +// case .proportionalChart: +// vc = ProportionalChartViewController.loadFromNib() +// break case .goodsBySector: vc = PieChartViewController(chartType: .goodsSectorType) break diff --git a/charts/GoodsChartCollectionCell.swift b/charts/GoodsChartCollectionCell.swift index 38824a4..36624d2 100644 --- a/charts/GoodsChartCollectionCell.swift +++ b/charts/GoodsChartCollectionCell.swift @@ -35,6 +35,11 @@ class GoodsChartCollectionCell: UICollectionViewCell { self.titleLabel.text = cellData.title self.backgroundColor = cellData.color self.layer.cornerRadius = self.frame.size.width / 2; + if #available(iOS 13.0, *) { + if (self.traitCollection.userInterfaceStyle == .dark) { + self.titleLabel.textColor = .black + } + } } } diff --git a/charts/PieChartViewController.swift b/charts/PieChartViewController.swift index 30493b9..be9a4a1 100644 --- a/charts/PieChartViewController.swift +++ b/charts/PieChartViewController.swift @@ -38,6 +38,7 @@ class PieChartViewController: UIViewController { @IBOutlet weak var colorCodesCollectionView : UICollectionView! @IBOutlet weak var segmentHeightConstraint: NSLayoutConstraint! @IBOutlet weak var collectionViewHeightConstraint: NSLayoutConstraint! + @IBOutlet weak var centerCircularView : UIView! var isFromWorkingStatistics: Bool = false var countryName: String = "" @@ -83,19 +84,25 @@ class PieChartViewController: UIViewController { self.goodsSegments.isHidden = true self.segmentHeightConstraint.constant = 0 } + self.centerCircularView.layer.cornerRadius = 55 } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) if isFromWorkingStatistics { - self.title = "Working Statistics" + self.title = "Working Children Statistics" self.countryTitleLabel.text = "No Data Available" + if #available(iOS 12.0, *) { + if (self.traitCollection.userInterfaceStyle == .dark) { + self.countryTitleLabel.textColor = .white + } + } self.countryTitleLabel.frame = CGRect(x: 0, y: self.view.frame.height/2 , width: self.view.frame.width, height: 40) self.countryTitleLabel.center = self.view.center if self.workingStatistics?.count ?? 0 > 0 { self.countryTitleLabel.text = "\(countryName) Statistics" circularPieView.segments = self.workingStatistics ?? [Segment]() - self.countryTitleLabel.frame = CGRect(x: 0, y: circularPieView.frame.minY - 30 , width: self.view.frame.width, height: 40) + self.countryTitleLabel.frame = CGRect(x: 0, y: circularPieView.frame.minY - 10 , width: self.view.frame.width, height: 40) } self.view.addSubview(self.countryTitleLabel) @@ -109,8 +116,14 @@ class PieChartViewController: UIViewController { if isFromWorkingStatistics { self.colorCodesCollectionView.layer.borderColor = UIColor.clear.cgColor self.colorCodesCollectionView.layer.borderWidth = 0 + } else { + if #available(iOS 12.0, *) { + if (self.traitCollection.userInterfaceStyle == .dark) { + self.colorCodesCollectionView.backgroundColor = .black + self.colorCodesCollectionView.layer.borderColor = UIColor.white.cgColor + } + } } - self.colorCodesCollectionView.register(UICollectionViewCell.self, forCellWithReuseIdentifier: "DefaultCollectionCell") self.colorCodesCollectionView.register(UINib(nibName:"CustomColorCodeCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "CustomColorCodeCollectionViewCell") } @@ -261,6 +274,17 @@ extension PieChartViewController: UICollectionViewDelegate, UICollectionViewData let color = isFromWorkingStatistics ? self.workingStatistics?[indexPath.item].color : countryRegionArray[indexPath.item].color colorCell.lblTitle.text = title colorCell.colorCodeLbl.backgroundColor = color + if isFromWorkingStatistics { + colorCell.lblTitle.textColor = .black + } else { + if #available(iOS 12.0, *) { + if (self.traitCollection.userInterfaceStyle == .dark) { + colorCell.lblTitle.textColor = .white + } + } else { + colorCell.lblTitle.textColor = .black + } + } return colorCell } diff --git a/charts/PieChartViewController.xib b/charts/PieChartViewController.xib index fc60357..70343dc 100644 --- a/charts/PieChartViewController.xib +++ b/charts/PieChartViewController.xib @@ -11,10 +11,12 @@ + + - + @@ -25,7 +27,21 @@ + + + + + + + + + + + + + + @@ -42,7 +58,7 @@ - + @@ -64,7 +80,7 @@ - +