infography update

master
Laurent 6 years ago
parent d43eb40784
commit d2b6f539f1
  1. 24
      TournamentStats.xcodeproj/project.pbxproj
  2. 8
      TournamentStats/AppDelegate.swift
  3. 35
      TournamentStats/Base.lproj/Main.storyboard
  4. 4
      TournamentStats/UI/DataSourceWrapper.swift
  5. 22
      TournamentStats/UI/UIColor+Extensions.swift
  6. 10
      TournamentStats/UI/UIView+Extensions.swift
  7. 36
      TournamentStats/UI/components/PieChart.swift
  8. 34
      TournamentStats/UI/components/TableView.swift
  9. 26
      TournamentStats/UI/components/TitleLabel.swift
  10. 154
      TournamentStats/UI/reports/InfographyView.swift
  11. 5
      TournamentStats/report/structures/TournamentCounter.swift
  12. 67
      TournamentStats/utils/ColumnRepresentable.swift

@ -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 = "<group>"; };
4DF7614E22A6CF93004B0EF1 /* PlayerResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerResult.swift; sourceTree = "<group>"; };
4DF7615022A7AECA004B0EF1 /* TournamentRepresentable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TournamentRepresentable.swift; sourceTree = "<group>"; };
4DF78DCD22F9AA3F00C02F73 /* PieChart.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PieChart.swift; sourceTree = "<group>"; };
4DF78DD022F9AADF00C02F73 /* TableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableView.swift; sourceTree = "<group>"; };
4DF78DD322F9C85C00C02F73 /* UIColor+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIColor+Extensions.swift"; sourceTree = "<group>"; };
4DF78DD522F9CE7E00C02F73 /* TitleLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TitleLabel.swift; sourceTree = "<group>"; };
FFE9052922BB7312006FEFA4 /* event34 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = event34; sourceTree = "<group>"; };
FFE9052A22BB7312006FEFA4 /* event41 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = event41; sourceTree = "<group>"; };
FFE9052B22BB7313006FEFA4 /* event40 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = event40; sourceTree = "<group>"; };
@ -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 = "<group>";
@ -528,6 +538,16 @@
path = structures;
sourceTree = "<group>";
};
4DF78DCF22F9AA9300C02F73 /* components */ = {
isa = PBXGroup;
children = (
4DF78DCD22F9AA3F00C02F73 /* PieChart.swift */,
4DF78DD022F9AADF00C02F73 /* TableView.swift */,
4DF78DD522F9CE7E00C02F73 /* TitleLabel.swift */,
);
path = components;
sourceTree = "<group>";
};
/* 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 */,

@ -40,9 +40,11 @@ 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 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)
if let imageData = infography.toImage()?.pngData() {
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
@ -56,6 +58,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele
}
}
return true
}

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="H1p-Uh-vWS">
<device id="ipad9_7" orientation="portrait">
<device id="retina5_9" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
@ -15,7 +15,7 @@
<objects>
<navigationController title="Master" id="RMx-3f-FxP" sceneMemberID="viewController">
<navigationBar key="navigationBar" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" id="Pmd-2v-anx">
<rect key="frame" x="0.0" y="20" width="320" height="50"/>
<rect key="frame" x="0.0" y="44" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<connections>
@ -31,11 +31,11 @@
<objects>
<viewController title="Detail" id="JEX-9P-axG" customClass="DetailViewController" customModule="TournamentStats" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="svH-Pt-448">
<rect key="frame" x="0.0" y="0.0" width="768" height="1024"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="812"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleToFill" text="Detail view content goes here" textAlignment="center" lineBreakMode="tailTruncation" minimumFontSize="10" translatesAutoresizingMaskIntoConstraints="NO" id="0XM-y9-sOw">
<rect key="frame" x="20" y="502" width="728" height="20.5"/>
<rect key="frame" x="20" y="395.66666666666669" width="335" height="20.666666666666686"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
@ -79,26 +79,26 @@
<objects>
<tableViewController title="Master" clearsSelectionOnViewWillAppear="NO" id="7bK-jq-Zjz" customClass="MasterViewController" customModule="TournamentStats" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" id="r7i-6Z-zg0">
<rect key="frame" x="0.0" y="0.0" width="320" height="1024"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="812"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<prototypes>
<tableViewCell contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="Cell" textLabel="Arm-wq-HPj" detailTextLabel="HdP-BR-LBd" style="IBUITableViewCellStyleValue1" id="WCw-Qf-5nD">
<rect key="frame" x="0.0" y="28" width="320" height="44"/>
<rect key="frame" x="0.0" y="28" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="WCw-Qf-5nD" id="37f-cq-3Eg">
<rect key="frame" x="0.0" y="0.0" width="320" height="43.5"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="43.666666666666664"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="left" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="Arm-wq-HPj">
<rect key="frame" x="16" y="12" width="33.5" height="20.5"/>
<rect key="frame" x="16.000000000000004" y="11.999999999999998" width="33.333333333333336" height="20.333333333333332"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="highlightedColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</label>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Detail" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="HdP-BR-LBd">
<rect key="frame" x="260" y="12" width="44" height="20.5"/>
<rect key="frame" x="315" y="11.999999999999998" width="44" height="20.333333333333332"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
@ -129,7 +129,7 @@
<objects>
<navigationController id="vC3-pB-5Vb" sceneMemberID="viewController">
<navigationBar key="navigationBar" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" id="DjV-YW-jjY">
<rect key="frame" x="0.0" y="20" width="768" height="50"/>
<rect key="frame" x="0.0" y="44" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<connections>
@ -140,6 +140,21 @@
</objects>
<point key="canvasLocation" x="-45" y="129"/>
</scene>
<!--Infography View Controller-->
<scene sceneID="e9y-X1-vaX">
<objects>
<placeholder placeholderIdentifier="IBFirstResponder" id="yr4-1K-87y" userLabel="First Responder" sceneMemberID="firstResponder"/>
<viewController storyboardIdentifier="container" id="mxo-2c-VBS" customClass="InfographyViewController" customModule="TournamentStats" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="Eky-dM-hcs">
<rect key="frame" x="0.0" y="0.0" width="375" height="812"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<viewLayoutGuide key="safeArea" id="sco-HF-vLG"/>
</view>
</viewController>
</objects>
<point key="canvasLocation" x="-879" y="638"/>
</scene>
</scenes>
<inferredMetricsTieBreakers>
<segue reference="6S0-TO-JiA"/>

@ -42,8 +42,8 @@ class DataSourceWrapper<T : ColumnRepresentable> : NSObject, UITableViewDataSour
columns.forEach { value in
let label: UILabel = UILabel(frame: CGRect(x: 0, y: 0, width: 50, height: 30))
label.textColor = UIColor.black
label.backgroundColor = UIColor.white
label.textColor = UIColor.white
label.backgroundColor = UIColor.clear
label.text = value
label.font = font
cell.stackView.addArrangedSubview(label)

@ -0,0 +1,22 @@
//
// UIColor+Extensions.swift
// TournamentStats
//
// Created by Laurent Morvillier on 06/08/2019.
// Copyright © 2019 Stax River. All rights reserved.
//
import Foundation
import UIKit
extension UIColor {
convenience init(red: CGFloat, green: CGFloat, blue: CGFloat) {
self.init(red: red/255.0, green: green/255.0, blue: blue/255.0, alpha: 1.0)
}
convenience init(r red: CGFloat, g green: CGFloat, b blue: CGFloat, a alpha: CGFloat) {
self.init(red: red/255.0, green: green/255.0, blue: blue/255.0, alpha: alpha)
}
}

@ -26,6 +26,16 @@ extension UIView {
// MARK: - Constraints
public func defineConstraints(width: CGFloat? = nil, height: CGFloat? = nil) {
self.translatesAutoresizingMaskIntoConstraints = false
if let width = width {
self.widthAnchor.constraint(equalToConstant: width).isActive = true
}
if let height = height {
self.heightAnchor.constraint(equalToConstant: height).isActive = true
}
}
@objc public func addMaxConstraints(view: UIView) {
view.translatesAutoresizingMaskIntoConstraints = false

@ -0,0 +1,36 @@
//
// PieChart.swift
// TournamentStats
//
// Created by Laurent Morvillier on 06/08/2019.
// Copyright © 2019 Stax River. All rights reserved.
//
import Foundation
import Charts
class PieChart : PieChartView {
override init(frame: CGRect) {
super.init(frame: frame)
self.holeColor = UIColor.clear
self.usePercentValuesEnabled = true
self.legend.textColor = UIColor.white
self.legend.font = UIFont.systemFont(ofSize: 16.0)
self.legend.orientation = .vertical
// self.legend.form = .square
// self.legend.neededHeight = 320.0
// self.legend.neededWidth = 300.0
self.legend.maxSizePercent = 0.2
self.legend.verticalAlignment = .center
// self.legend.horizontalAlignment = .left
self.holeRadiusPercent = 0.2
self.drawEntryLabelsEnabled = false
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}

@ -0,0 +1,34 @@
//
// TableView.swift
// TournamentStats
//
// Created by Laurent Morvillier on 06/08/2019.
// Copyright © 2019 Stax River. All rights reserved.
//
import Foundation
import UIKit
class TableView<T : ColumnRepresentable> : UITableView {
var wrapper: DataSourceWrapper<T>
init(data: [T], frame: CGRect, style: UITableView.Style) {
self.wrapper = DataSourceWrapper(array: data)
super.init(frame: frame, style: style)
self.register(UINib(nibName: "StackTableCell", bundle: Bundle.main), forCellReuseIdentifier: "Cell")
self.backgroundColor = UIColor.clear
self.dataSource = self.wrapper
self.delegate = self.wrapper
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}

@ -0,0 +1,26 @@
//
// TitleLabel.swift
// TournamentStats
//
// Created by Laurent Morvillier on 06/08/2019.
// Copyright © 2019 Stax River. All rights reserved.
//
import Foundation
import UIKit
class TitleLabel : UILabel {
init(frame: CGRect, text: String) {
super.init(frame: frame)
self.textColor = UIColor.white
self.text = text
self.textAlignment = .center
self.font = UIFont.boldSystemFont(ofSize: 16.0)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}

@ -8,46 +8,144 @@
import Foundation
import UIKit
import Charts
class InfographyView : UIView {
class InfographyViewController : UIViewController {
var references: [UITableViewDataSource] = []
var generator: ReportGenerator?
init(frame: CGRect, generator: ReportGenerator) {
super.init(frame: frame)
self.backgroundColor = UIColor.white
override func viewDidLayoutSubviews() {
let table1 = UITableView(frame: CGRect(x: 0, y: 0, width: 500, height: 500), style: .grouped)
table1.register(UINib(nibName: "StackTableCell", bundle: Bundle.main), forCellReuseIdentifier: "Cell")
table1.backgroundColor = UIColor.clear
let ds = DataSourceWrapper(array: generator.biggestWinners)
table1.dataSource = ds
table1.delegate = ds
self.references.append(ds)
super.viewDidLayoutSubviews()
let table2 = UITableView(frame: CGRect(x: 500, y: 0, width: 500, height: 500), style: .grouped)
table2.register(UINib(nibName: "StackTableCell", bundle: Bundle.main), forCellReuseIdentifier: "Cell")
table2.backgroundColor = UIColor.clear
let ds2 = DataSourceWrapper(array: generator.mostWins)
table2.dataSource = ds2
table2.delegate = ds2
self.references.append(ds2)
let gradient: CAGradientLayer = CAGradientLayer()
let startColor = UIColor(red: 23/255, green: 72/255, blue: 61/255, alpha: 1)
let endColor = UIColor(red: 47/255, green: 149/255, blue: 126/255, alpha: 1)
gradient.colors = [startColor.cgColor, endColor.cgColor]
gradient.locations = [0.2 , 1.0]
gradient.startPoint = CGPoint(x: 0.0, y: 0.0)
gradient.endPoint = CGPoint(x: 1.0, y: 1.0)
gradient.frame = self.view.bounds
self.view.layer.insertSublayer(gradient, at: 0)
}
override func viewDidLoad() {
guard let generator = self.generator else {
return
}
let table1 = TableView(data: generator.biggestWinners, frame: CGRect.zero, style: .grouped)
table1.defineConstraints(width: 500, height: 500)
let table2 = TableView(data: generator.mostWins, frame: CGRect.zero, style: .grouped)
table2.defineConstraints(width: 500, height: 500)
let hstack1: UIStackView = UIStackView(arrangedSubviews: [table1, table2])
hstack1.distribution = .fill
hstack1.backgroundColor = UIColor.green
hstack1.defineConstraints(width: 1000, height: 300.0)
hstack1.distribution = .equalSpacing
hstack1.spacing = 8.0
hstack1.axis = .horizontal
hstack1.alignment = .top
let title1 = TitleLabel(frame: CGRect.zero, text: "Buy-in distribution")
let title2 = TitleLabel(frame: CGRect.zero, text: "First prizes distribution")
let title3 = TitleLabel(frame: CGRect.zero, text: "Prizepool distribution")
let hstack2a: UIStackView = UIStackView(arrangedSubviews: [title1, title2, title3])
hstack2a.defineConstraints(width: 1000)
hstack2a.distribution = .fillEqually
hstack2a.axis = .horizontal
hstack2a.alignment = .top
let buyinDistribPie = PieChart(frame: CGRect.zero)
buyinDistribPie.data = generator.tournamentBuyinDistribution.pieChartData
buyinDistribPie.defineConstraints(height: 300)
let firstPrizeDistributionPie = PieChart(frame: CGRect.zero)
firstPrizeDistributionPie.data = generator.firstPrizeDistribution.pieChartData
firstPrizeDistributionPie.defineConstraints(height: 300)
let prizepoolDistribPie = PieChart(frame: CGRect.zero)
prizepoolDistribPie.data = generator.tournamentPrizepoolDistribution.pieChartData
prizepoolDistribPie.defineConstraints(height: 300)
let vstack: UIStackView = UIStackView(arrangedSubviews: [hstack1])
hstack1.backgroundColor = UIColor.blue
let hstack2: UIStackView = UIStackView(arrangedSubviews: [buyinDistribPie, firstPrizeDistributionPie, prizepoolDistribPie])
hstack2.defineConstraints(width: 1000, height: 350.0)
hstack2.distribution = .fillEqually
hstack2.axis = .horizontal
hstack2.alignment = .top
let mainTitle = UILabel()
mainTitle.textColor = UIColor.white
mainTitle.font = UIFont.boldSystemFont(ofSize: 64.0)
mainTitle.textAlignment = .center
mainTitle.text = "2019 WSOP"
let vstack: UIStackView = UIStackView(arrangedSubviews: [mainTitle, hstack1, hstack2a, hstack2])
vstack.axis = .vertical
self.addSubview(vstack)
self.addMaxConstraints(view: vstack)
vstack.distribution = .equalCentering
vstack.alignment = .center
vstack.spacing = 10.0
self.view.addSubview(vstack)
}
vstack.translatesAutoresizingMaskIntoConstraints = false
vstack.leadingAnchor.constraint(equalTo: self.view.leadingAnchor, constant: 16.0).isActive = true
vstack.trailingAnchor.constraint(equalTo: self.view.trailingAnchor, constant: -16.0).isActive = true
vstack.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor, constant: 16.0).isActive = true
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
//class InfographyView : UIView {
//
// var references: [UITableViewDataSource] = []
//
// init(frame: CGRect, generator: ReportGenerator) {
// super.init(frame: frame)
// self.backgroundColor = UIColor.lightGray
//
// let table1 = TableView(data: generator.biggestWinners, frame: CGRect.zero, style: .grouped)
// table1.defineConstraints(width: 500, height: 500)
//
// let table2 = TableView(data: generator.mostWins, frame: CGRect.zero, style: .grouped)
// table2.defineConstraints(width: 500, height: 500)
//
// let pieChart = PieChartView(frame: CGRect.zero)
// pieChart.data = generator.tournamentBuyinDistribution.pieChartData
// pieChart.defineConstraints(width: 300, height: 300)
//
// let hstack1: UIStackView = UIStackView(arrangedSubviews: [table1, table2])
// hstack1.defineConstraints(width: 1000, height: 500)
// hstack1.distribution = .fill
// hstack1.axis = .horizontal
// hstack1.alignment = .top
// hstack1.backgroundColor = UIColor.red
//
// let hstack2: UIStackView = UIStackView(arrangedSubviews: [pieChart])
// hstack2.defineConstraints(width: 1000, height: 300)
// hstack2.distribution = .fill
// hstack2.axis = .horizontal
// hstack2.alignment = .top
// hstack2.backgroundColor = UIColor.green
//
// let vstack: UIStackView = UIStackView(arrangedSubviews: [hstack1, hstack2])
// vstack.axis = .vertical
// vstack.distribution = .fill
// vstack.alignment = .leading
// vstack.backgroundColor = UIColor.blue
// self.addSubview(vstack)
// self.addMaxConstraints(view: vstack)
//
// }
//
// required init?(coder aDecoder: NSCoder) {
// fatalError("init(coder:) has not been implemented")
// }
//
//}

@ -7,6 +7,7 @@
//
import Foundation
import Charts
class DistributionCounter : HTMLRepresentable {
@ -32,6 +33,10 @@ class DistributionCounter : HTMLRepresentable {
return strings
}
var pieChartDataEntry: PieChartDataEntry {
return PieChartDataEntry(value: Double(self.counter), label: name)
}
// static func htmlHeaders() -> String {
// var strings: [String] = []
// strings.append("Tournament")

@ -7,10 +7,77 @@
//
import Foundation
import Charts
extension UIColor {
static var paGreen: UIColor {
return UIColor(red: 0/255, green: 255/255, blue: 196/255, alpha: 1)
}
static var paColor1: UIColor {
return UIColor(red: 125/255, green: 155/255, blue: 255/255, alpha: 1)
}
static var paColor2: UIColor {
return UIColor(red: 255/255, green: 125/255, blue: 196/255, alpha: 1)
}
}
public protocol ColumnRepresentable {
static func headers() -> [String]
func colums() -> [String]
var chartDataEntry: ChartDataEntry { get }
var pieChartDataEntry: PieChartDataEntry { get }
}
extension ColumnRepresentable {
var chartDataEntry: ChartDataEntry {
return ChartDataEntry(x: 0, y: 0)
}
var pieChartDataEntry: PieChartDataEntry {
return PieChartDataEntry(value: 0.0)
}
}
class PercentageFormatter : IValueFormatter {
var numberFormatter: NumberFormatter = NumberFormatter()
init() {
self.numberFormatter.maximumFractionDigits = 0
}
func stringForValue(_ value: Double, entry: ChartDataEntry, dataSetIndex: Int, viewPortHandler: ViewPortHandler?) -> String {
return self.numberFormatter.string(from: NSNumber(value: value)) ?? ""
}
}
extension Array where Element : ColumnRepresentable {
var pieChartData: PieChartData {
var dataEntries: [ChartDataEntry] = []
self.forEach { representable in
dataEntries.append(representable.pieChartDataEntry)
}
let dataSet = PieChartDataSet(entries: dataEntries, label: "")
dataSet.entryLabelFont = UIFont.boldSystemFont(ofSize: 18.0)
dataSet.colors = [UIColor.paGreen, UIColor.paColor1, UIColor.paColor2]
dataSet.valueFormatter = PercentageFormatter()
return PieChartData(dataSet: dataSet)
}
var chartData: ChartData {
var dataEntries: [ChartDataEntry] = []
self.forEach { representable in
dataEntries.append(representable.chartDataEntry)
}
let dataSet = ChartDataSet(entries: dataEntries)
return ChartData(dataSet: dataSet)
}
}
public protocol HTMLRepresentable : ColumnRepresentable {

Loading…
Cancel
Save