61 lines
1.9 KiB
Swift
61 lines
1.9 KiB
Swift
//
|
|
// CollectionViewItemMonth.swift
|
|
// Graphic Analysis 2
|
|
//
|
|
// Created by Kilian Hofmann on 16.06.17.
|
|
// Copyright © 2017 Kilian Hofmann. All rights reserved.
|
|
//
|
|
|
|
import Cocoa
|
|
|
|
class CollectionViewItemMonth: NSCollectionViewItem {
|
|
|
|
@IBOutlet var day: NSTextField!
|
|
@IBOutlet var loss: NSTextField!
|
|
@IBOutlet var distributionAM: LossDistributionPie!
|
|
@IBOutlet var distributionPM: LossDistributionPie!
|
|
@IBOutlet var month: NSTextField!
|
|
|
|
var distribution: [String] = []
|
|
var graph: GraphWindow? = nil
|
|
var dayFW: FileWrapper? = nil
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
view.wantsLayer = true
|
|
view.layer?.backgroundColor = NSColor.white.cgColor
|
|
view.layer?.masksToBounds = true
|
|
view.layer?.borderWidth = 1.0
|
|
view.layer?.borderColor = NSColor.clear.cgColor
|
|
graph = GraphWindow(collectionViewItem: self)
|
|
}
|
|
|
|
func clearDistribution() {
|
|
let am: [Int] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
|
let pm: [Int] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
|
distributionAM.distribution = am
|
|
distributionPM.distribution = pm
|
|
self.distributionAM.needsDisplay = true
|
|
self.distributionPM.needsDisplay = true
|
|
}
|
|
|
|
func redrawDistribution() {
|
|
var am: [Int] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
|
var pm: [Int] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
|
for entry in self.distribution {
|
|
let hour: Int = Int(entry.components(separatedBy: ":")[0])!
|
|
if hour < 12 {
|
|
am[hour] += 1
|
|
} else {
|
|
pm[hour - 12] += 1
|
|
}
|
|
}
|
|
self.distributionAM.distribution = am
|
|
self.distributionPM.distribution = pm
|
|
OperationQueue.main.addOperation {
|
|
self.distributionAM.needsDisplay = true
|
|
self.distributionPM.needsDisplay = true
|
|
}
|
|
}
|
|
}
|