83 lines
3.4 KiB
Swift
83 lines
3.4 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!
|
|
|
|
override var windowNibName: String! {
|
|
return "GraphWindow"
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
super.init(coder: coder)
|
|
}
|
|
|
|
init(collectionViewItem: CollectionViewItemMonth) {
|
|
super.init(window: nil)
|
|
self.collectionViewItem = collectionViewItem
|
|
}
|
|
|
|
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.
|
|
|
|
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)
|
|
graph.dataLoss = collectionViewItem.distribution
|
|
graph.data = FileOperations.loadUpstream(log: item.regularFileContents! as NSData)!
|
|
let keyString: String = item.filename!.components(separatedBy: " ")[1]
|
|
graph.frequency = Double(keyString.substring(to: keyString.index(keyString.endIndex, offsetBy: -4)))! / 1000000
|
|
let opQueue: OperationQueue = OperationQueue()
|
|
opQueue.addOperation {
|
|
graph.initView()
|
|
}
|
|
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)
|
|
graph.dataLoss = collectionViewItem.distribution
|
|
graph.data = FileOperations.loadDownstream(log: item.regularFileContents! as NSData)!
|
|
let keyString: String = item.filename!.components(separatedBy: " ")[1]
|
|
graph.frequency = Double(keyString.substring(to: keyString.index(keyString.endIndex, offsetBy: -4)))! / 1000000
|
|
let opQueue: OperationQueue = OperationQueue()
|
|
opQueue.addOperation {
|
|
graph.initView()
|
|
}
|
|
numGraphs += 1
|
|
}
|
|
}
|
|
}
|
|
|
|
extension GraphWindow: NSWindowDelegate {
|
|
func windowShouldClose(_ sender: Any) -> Bool {
|
|
collectionViewItem?.isSelected = false
|
|
collectionViewItem?.view.layer?.borderColor = NSColor.clear.cgColor
|
|
return true
|
|
}
|
|
}
|