Distribution Pie charts implemented
This commit is contained in:
@@ -12,6 +12,10 @@ class CollectionViewItemMonth: NSCollectionViewItem {
|
||||
|
||||
@IBOutlet var day: NSTextField!
|
||||
@IBOutlet var loss: NSTextField!
|
||||
@IBOutlet var distributionAM: LossDistributionPie!
|
||||
@IBOutlet var distributionPM: LossDistributionPie!
|
||||
|
||||
var distribution: [String] = []
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
@@ -21,4 +25,21 @@ class CollectionViewItemMonth: NSCollectionViewItem {
|
||||
view.layer?.borderWidth = 1.0
|
||||
view.layer?.borderColor = NSColor.clear.cgColor
|
||||
}
|
||||
|
||||
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 distribution {
|
||||
let hour: Int = Int(entry.components(separatedBy: ":")[0])!
|
||||
if hour < 12 {
|
||||
am[hour] += 1
|
||||
} else {
|
||||
pm[hour - 12] += 1
|
||||
}
|
||||
}
|
||||
distributionAM.distribution = am
|
||||
distributionPM.distribution = pm
|
||||
distributionAM.needsDisplay = true
|
||||
distributionPM.needsDisplay = true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,10 @@
|
||||
<objects>
|
||||
<customObject id="-2" userLabel="File's Owner" customClass="CollectionViewItemMonth" customModule="Graphic_Analysis_2" customModuleProvider="target">
|
||||
<connections>
|
||||
<outlet property="day" destination="3aE-Wf-9eZ" id="T7k-f7-IBu"/>
|
||||
<outlet property="distributionAM" destination="B0U-sm-QBD" id="jN5-fA-i8W"/>
|
||||
<outlet property="distributionPM" destination="ftO-kx-Le5" id="Fjl-OH-3tS"/>
|
||||
<outlet property="loss" destination="Ios-8D-sSB" id="RS0-0q-8Bt"/>
|
||||
<outlet property="view" destination="Hz6-mo-xeY" id="0bl-1N-x8E"/>
|
||||
</connections>
|
||||
</customObject>
|
||||
@@ -18,25 +22,16 @@
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<subviews>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" allowsCharacterPickerTouchBarItem="NO" translatesAutoresizingMaskIntoConstraints="NO" id="3aE-Wf-9eZ">
|
||||
<rect key="frame" x="18" y="92" width="24" height="20"/>
|
||||
<rect key="frame" x="18" y="90" width="26" height="22"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="center" title="01" id="hZ1-E9-nbm">
|
||||
<font key="font" metaFont="system" size="16"/>
|
||||
<font key="font" metaFont="system" size="17"/>
|
||||
<color key="textColor" name="controlShadowColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" allowsCharacterPickerTouchBarItem="NO" translatesAutoresizingMaskIntoConstraints="NO" id="bOH-fN-p3a">
|
||||
<rect key="frame" x="18" y="67" width="36" height="17"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Loss:" id="6Hu-ZO-t9e">
|
||||
<font key="font" metaFont="system"/>
|
||||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" allowsCharacterPickerTouchBarItem="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Ios-8D-sSB">
|
||||
<rect key="frame" x="58" y="67" width="59" height="17"/>
|
||||
<rect key="frame" x="58" y="65" width="59" height="17"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="center" id="axa-F2-XeS">
|
||||
<font key="font" metaFont="system"/>
|
||||
@@ -44,12 +39,31 @@
|
||||
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" allowsCharacterPickerTouchBarItem="NO" translatesAutoresizingMaskIntoConstraints="NO" id="bOH-fN-p3a">
|
||||
<rect key="frame" x="18" y="65" width="36" height="17"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Loss:" id="6Hu-ZO-t9e">
|
||||
<font key="font" metaFont="system"/>
|
||||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<customView fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="B0U-sm-QBD" customClass="LossDistributionPie" customModule="Graphic_Analysis_2" customModuleProvider="target">
|
||||
<rect key="frame" x="20" y="20" width="37" height="37"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
</customView>
|
||||
<customView fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="ftO-kx-Le5" customClass="LossDistributionPie" customModule="Graphic_Analysis_2" customModuleProvider="target">
|
||||
<rect key="frame" x="78" y="20" width="37" height="37"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
</customView>
|
||||
</subviews>
|
||||
<point key="canvasLocation" x="138.5" y="169"/>
|
||||
</customView>
|
||||
<collectionViewItem id="0ws-De-Ut2" customClass="CollectionViewItemMonth" customModule="Graphic_Analysis_2" customModuleProvider="target">
|
||||
<connections>
|
||||
<outlet property="day" destination="3aE-Wf-9eZ" id="dB1-dQ-VPe"/>
|
||||
<outlet property="distributionAM" destination="B0U-sm-QBD" id="PYF-qG-EVI"/>
|
||||
<outlet property="distributionPM" destination="ftO-kx-Le5" id="qra-Kr-uWo"/>
|
||||
<outlet property="loss" destination="Ios-8D-sSB" id="Pkz-fU-9Hd"/>
|
||||
<outlet property="view" destination="Hz6-mo-xeY" id="pe3-pf-cYV"/>
|
||||
</connections>
|
||||
|
||||
@@ -30,6 +30,8 @@ extension CollectionViewMonth: NSCollectionViewDataSource {
|
||||
func collectionView(_ itemForRepresentedObjectAtcollectionView: NSCollectionView, itemForRepresentedObjectAt indexPath: IndexPath) -> NSCollectionViewItem {
|
||||
let item = itemForRepresentedObjectAtcollectionView.makeItem(withIdentifier: "CollectionViewItemMonth", for: indexPath)
|
||||
guard let item2 = item as? CollectionViewItemMonth else { return item }
|
||||
item2.distribution = []
|
||||
item2.redrawDistribution()
|
||||
item2.loss.stringValue = ""
|
||||
item2.day.textColor = NSColor.controlShadowColor
|
||||
item2.day.stringValue = "\(indexPath.item + 1)"
|
||||
@@ -37,8 +39,11 @@ extension CollectionViewMonth: NSCollectionViewDataSource {
|
||||
guard let day = days[month!][indexPath.item] else { return item2 }
|
||||
item2.day.textColor = NSColor.black
|
||||
guard let log = day.fileWrappers?["KDLog.txt"] else { return item2 }
|
||||
guard let loss = (String(data: log.regularFileContents!, encoding: .utf8)?.components(separatedBy: "\n").count) else { return item2 }
|
||||
item2.loss.stringValue = "\(loss)"
|
||||
guard var logA = String(data: log.regularFileContents!, encoding: .utf8)?.components(separatedBy: "\n") else { return item2 }
|
||||
logA.removeLast()
|
||||
item2.loss.stringValue = "\(logA.count)"
|
||||
item2.distribution = logA
|
||||
item2.redrawDistribution()
|
||||
return item2
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>2.0</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>157</string>
|
||||
<string>208</string>
|
||||
<key>LSApplicationCategoryType</key>
|
||||
<string>public.app-category.utilities</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
//
|
||||
// LossDistributionPie.swift
|
||||
// Graphic Analysis 2
|
||||
//
|
||||
// Created by Kilian Hofmann on 16.06.17.
|
||||
// Copyright © 2017 Kilian Hofmann. All rights reserved.
|
||||
//
|
||||
|
||||
import Cocoa
|
||||
|
||||
class LossDistributionPie: NSView {
|
||||
|
||||
var distribution: [Int] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
||||
|
||||
override func draw(_ dirtyRect: NSRect) {
|
||||
super.draw(dirtyRect)
|
||||
let center: CGPoint = CGPoint(x: 18.5, y: 18.5)
|
||||
let startAngle: CGFloat = (1/2) * CGFloat.pi
|
||||
let increment: CGFloat = CGFloat.pi / 6
|
||||
|
||||
for i in 0..<12 {
|
||||
let layer: CAShapeLayer = CAShapeLayer()
|
||||
layer.fillColor = CGColor(red: 1, green: 0, blue: 0, alpha: CGFloat(distribution[i]) / 60)
|
||||
layer.strokeColor = NSColor.controlShadowColor.cgColor
|
||||
layer.lineWidth = 0.5
|
||||
layer.frame = dirtyRect
|
||||
let arc: CGMutablePath = CGMutablePath()
|
||||
arc.move(to: center)
|
||||
arc.addArc(center: center, radius: 18, startAngle: startAngle - CGFloat(i)*increment, endAngle: startAngle - CGFloat(i+1)*increment, clockwise: true)
|
||||
arc.closeSubpath()
|
||||
layer.path = arc
|
||||
if self.layer?.sublayers?.count == 12 {
|
||||
self.layer?.replaceSublayer((self.layer?.sublayers?[i])!, with: layer)
|
||||
} else{
|
||||
self.layer?.addSublayer(layer)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,2 +1,2 @@
|
||||
version 2.0
|
||||
build 157
|
||||
build 208
|
||||
|
||||
Reference in New Issue
Block a user