131 lines
5.1 KiB
Swift
131 lines
5.1 KiB
Swift
//
|
|
// GraphWindow.swift
|
|
// Graphic Analysis 2
|
|
//
|
|
// Created by Kilian Hofmann on 17.06.17.
|
|
// Copyright © 2017 Kilian Hofmann. All rights reserved.
|
|
//
|
|
|
|
import Cocoa
|
|
|
|
class GraphWindow: NSWindowController {
|
|
|
|
var collectionViewItem: CollectionViewItemMonth!
|
|
@IBOutlet var scrollView: NSScrollView!
|
|
@IBOutlet var indicator1: NSProgressIndicator!
|
|
@IBOutlet var indicator2: NSProgressIndicator!
|
|
@IBOutlet var indicator3: NSProgressIndicator!
|
|
@IBOutlet var indicator4: NSProgressIndicator!
|
|
var indicators: [NSProgressIndicator]!
|
|
|
|
let loadingQueue1: OperationQueue = OperationQueue()
|
|
let loadingQueue2: OperationQueue = OperationQueue()
|
|
let loadingQueue3: OperationQueue = OperationQueue()
|
|
let loadingQueue4: OperationQueue = OperationQueue()
|
|
|
|
override var windowNibName: NSNib.Name? {
|
|
return NSNib.Name(rawValue: "GraphWindow")
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
super.init(coder: coder)
|
|
}
|
|
|
|
init(collectionViewItem: CollectionViewItemMonth) {
|
|
super.init(window: nil)
|
|
self.collectionViewItem = collectionViewItem
|
|
loadingQueue1.maxConcurrentOperationCount = 1
|
|
loadingQueue2.maxConcurrentOperationCount = 1
|
|
loadingQueue3.maxConcurrentOperationCount = 1
|
|
loadingQueue4.maxConcurrentOperationCount = 1
|
|
}
|
|
|
|
override func windowDidLoad() {
|
|
super.windowDidLoad()
|
|
// Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
|
|
|
|
indicators = [indicator1, indicator2, indicator3, indicator4]
|
|
|
|
var upstreamFiles: [FileWrapper] = []
|
|
var downstreamFiles: [FileWrapper] = []
|
|
guard collectionViewItem.dayFW != nil else { return }
|
|
for file in (collectionViewItem.dayFW?.fileWrappers)! {
|
|
if file.key.contains("Upstream") {
|
|
upstreamFiles.append(file.value)
|
|
} else if file.key.contains("Downstream") {
|
|
downstreamFiles.append(file.value)
|
|
}
|
|
}
|
|
|
|
let content: FlippedView = FlippedView(frame: NSMakeRect(0, 0, CGFloat(FrequencyGraph.maxGraphSize), CGFloat(((upstreamFiles.count + downstreamFiles.count) * FrequencyGraph.graphSizeWithSeparator)-1)))
|
|
|
|
scrollView.documentView = content
|
|
|
|
var numGraphs: Int = 0
|
|
for item in upstreamFiles {
|
|
let graph: FrequencyGraph = FrequencyGraph(upstream: true, frame: NSMakeRect(0, CGFloat(numGraphs * FrequencyGraph.graphSizeWithSeparator), CGFloat(FrequencyGraph.maxGraphSize), CGFloat(FrequencyGraph.graphSize)), superview: content, indicator: indicators[numGraphs%4])
|
|
graph.dataLoss = collectionViewItem.distribution
|
|
|
|
switch numGraphs%4 {
|
|
case 0:
|
|
loadingQueue1.addOperation(GraphLoadOperation(graph: graph, item: item, downstream: false))
|
|
case 1:
|
|
loadingQueue2.addOperation(GraphLoadOperation(graph: graph, item: item, downstream: false))
|
|
case 2:
|
|
loadingQueue3.addOperation(GraphLoadOperation(graph: graph, item: item, downstream: false))
|
|
case 3:
|
|
loadingQueue4.addOperation(GraphLoadOperation(graph: graph, item: item, downstream: false))
|
|
default:
|
|
NSLog("Mathematics broke today :/")
|
|
exit(-1)
|
|
}
|
|
numGraphs += 1
|
|
}
|
|
for item in downstreamFiles {
|
|
let graph: FrequencyGraph = FrequencyGraph(upstream: false, frame: NSMakeRect(0, CGFloat(numGraphs * FrequencyGraph.graphSizeWithSeparator), CGFloat(FrequencyGraph.maxGraphSize), CGFloat(FrequencyGraph.graphSize)), superview: content, indicator: indicators[numGraphs%4])
|
|
graph.dataLoss = collectionViewItem.distribution
|
|
switch numGraphs%4 {
|
|
case 0:
|
|
loadingQueue1.addOperation(GraphLoadOperation(graph: graph, item: item, downstream: true))
|
|
case 1:
|
|
loadingQueue2.addOperation(GraphLoadOperation(graph: graph, item: item, downstream: true))
|
|
case 2:
|
|
loadingQueue3.addOperation(GraphLoadOperation(graph: graph, item: item, downstream: true))
|
|
case 3:
|
|
loadingQueue4.addOperation(GraphLoadOperation(graph: graph, item: item, downstream: true))
|
|
default:
|
|
NSLog("Mathematics broke today :/")
|
|
exit(-1)
|
|
}
|
|
numGraphs += 1
|
|
}
|
|
}
|
|
}
|
|
|
|
extension GraphWindow: NSWindowDelegate {
|
|
func windowShouldClose(_ sender: NSWindow) -> Bool {
|
|
for op in loadingQueue1.operations {
|
|
if !op.isFinished {
|
|
return false
|
|
}
|
|
}
|
|
for op in loadingQueue2.operations {
|
|
if !op.isFinished {
|
|
return false
|
|
}
|
|
}
|
|
for op in loadingQueue3.operations {
|
|
if !op.isFinished {
|
|
return false
|
|
}
|
|
}
|
|
for op in loadingQueue4.operations {
|
|
if !op.isFinished {
|
|
return false
|
|
}
|
|
}
|
|
collectionViewItem.collectionView?.deselectAll(self)
|
|
return true
|
|
}
|
|
}
|