diff options
| author | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-07-04 17:06:28 +0200 |
|---|---|---|
| committer | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-07-04 17:06:28 +0200 |
| commit | c843d34f56c207abcf4b93e424125eea2dc601e0 (patch) | |
| tree | 415dc2d9be4be31e290e1dd1dedb0b630c5e8fc6 /Map/Data | |
| parent | ed10ac191df473c92c4fec495aafa7f569d108c8 (diff) | |
Upgrade to Swift 6
Diffstat (limited to 'Map/Data')
| -rw-r--r-- | Map/Data/Debouncer.swift | 35 | ||||
| -rw-r--r-- | Map/Data/MapDocument.swift | 18 | ||||
| -rw-r--r-- | Map/Data/Stage.swift | 209 |
3 files changed, 50 insertions, 212 deletions
diff --git a/Map/Data/Debouncer.swift b/Map/Data/Debouncer.swift new file mode 100644 index 0000000..8d40e99 --- /dev/null +++ b/Map/Data/Debouncer.swift @@ -0,0 +1,35 @@ +// Copyright (C) 2024 Rubén Beltrán del Río + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see https://map.tranquil.systems. +import Foundation + +class Debouncer { + + // MARK: - Properties + private let queue = DispatchQueue.global(qos: .utility) + private var workItem = DispatchWorkItem(block: {}) + private var interval: TimeInterval + + // MARK: - Initializer + init(seconds: TimeInterval) { + self.interval = seconds + } + + // MARK: - Debouncing function + func debounce(action: @escaping (() -> Void)) { + workItem.cancel() + workItem = DispatchWorkItem(block: { action() }) + queue.asyncAfter(deadline: .now() + interval, execute: workItem) + } +} diff --git a/Map/Data/MapDocument.swift b/Map/Data/MapDocument.swift index 1b43efb..3c6d352 100644 --- a/Map/Data/MapDocument.swift +++ b/Map/Data/MapDocument.swift @@ -16,7 +16,7 @@ import SwiftUI import UniformTypeIdentifiers extension UTType { - static var exampleText: UTType { + static var wmap: UTType { UTType(importedAs: "systems.tranquil.map.wmap") } } @@ -24,11 +24,23 @@ extension UTType { struct MapDocument: FileDocument { var text: String - init(text: String = "Hello, world!") { + init( + text: String = """ + Anchor (60, 5) [x] + Node A (78, 23) + Node B (40, 30) [square] + Node C (65, 70) + + Anchor -> Node A + Anchor -> Node B + Node A -> Node C + Node B -> Node C + """ + ) { self.text = text } - static var readableContentTypes: [UTType] { [.exampleText] } + static var readableContentTypes: [UTType] { [.wmap] } init(configuration: ReadConfiguration) throws { guard let data = configuration.file.regularFileContents, diff --git a/Map/Data/Stage.swift b/Map/Data/Stage.swift deleted file mode 100644 index 4f737a1..0000000 --- a/Map/Data/Stage.swift +++ /dev/null @@ -1,209 +0,0 @@ -// Copyright (C) 2024 Rubén Beltrán del Río - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see https://map.tranquil.systems. -struct Stage { - let i: String - let ii: String - let iii: String - let iv: String - - static func stages(_ type: StageType) -> Stage { - switch type { - case .general: - return Stage( - i: "Genesis", ii: "Custom", iii: "Product (+rental)", iv: "Commodity (+utility)") - case .practice: - return Stage( - i: "Novel", ii: "Emerging", iii: "Good", iv: "Best") - case .data: - return Stage( - i: "Unmodelled", ii: "Divergent", iii: "Convergent", iv: "Modelled") - case .knowledge: - return Stage( - i: "Concept", ii: "Hypothesis", iii: "Theory", iv: "Accepted") - case .ubiquity: - return Stage( - i: "Rare", ii: "Slowly Increasing", iii: "Rapidly Increasing", - iv: "Widespread in the applicable market / ecosystem") - case .certainty: - return Stage( - i: "Poorly Understood / exploring the unknown", - ii: "Rapid Increase In Learning / discovery becomes refining", - iii: "Rapid increase in use / increasing fit for purpose", - iv: "Commonly understood (in terms of use)") - case .publicationTypes: - return Stage( - i: - "Describe the wonder of the thing / the discovery of some marvel / a new land / an unknown frontier", - ii: - "Focused on build / construct / awareness and learning / many models of explanation / no accepted forms / a wild west", - iii: - "Maintenance / operations / installation / comparison between competing forms / feature analysis", - iv: "Focused on use / increasingly an accepted, almost invisible component") - case .market: - return Stage( - i: "Undefined Market", - ii: "Forming Market / an array of competing forms and models of understanding", - iii: "Growing Market / consolidation to a few competing but more accepted forms", - iv: "Mature Market / stabilised to an accepted form") - case .knowledgeManagement: - return Stage( - i: "Uncertain", ii: "Learning on use / focused on testing prediction", - iii: "Learning on operation / using prediction / verification", iv: "Known / accepted") - case .marketPerception: - return Stage( - i: "Chaotic (non-linear) / domain of the \"crazy\"", ii: "Domain of \"experts\"", - iii: "Increasing expectation of use / domain of \"professionals\"", - iv: "Ordered (appearance of being linear) / trivial / formula to be applied") - case .userPerception: - return Stage( - i: "Different / confusing / exciting / surprising / dangerous", - ii: "Leading edge / emerging / unceirtanty over results", - iii: "Increasingly common / disappointed if not used or available / feeling left behind", - iv: "Standard / expected / feeling of shock if not used") - case .perceptionInIndustry: - return Stage( - i: "Future source of competitive advantage / unpredictable / unknown", - ii: "Seen as a scompetitive advantage / a differential / ROI / case examples", - iii: "Advantage through implementation / features / this model is better than that", - iv: "Cost of doing business / accepted / specific defined models") - case .focusOfValue: - return Stage( - i: "High future worth but immediate investment", - ii: "Seeking ways to profit and a ROI / seeking confirmation of value", - iii: - "High profitability per unit / a valuable model / a feeling of understanding / focus on exploitation", - iv: - "High volume / reducing margin / important but invisible / an essential component of something more complex" - ) - case .understanding: - return Stage( - i: "Poorly Understood / unpredictable", - ii: "Increasing understanding / development of measures", - iii: "Increasing education / constant refinement of needs / measures", - iv: "Believed to be well defined / stable / measurable") - case .comparison: - return Stage( - i: "Constantly changing / a differential / unstable", - ii: "Learning from others / testing the water / some evidential support", - iii: "Competing models / feature difference / evidential support", - iv: "Essential / any advantage is operational / accepted norm") - case .failure: - return Stage( - i: "High / tolerated / assumed to be wrong", - ii: "Moderate / unsurprising if wrong but disappointed", - iii: - "Not tolerated / focus on constant improvement / assumed to be in the right direction / resistance to changing the model", - iv: "Surprised by failure / focus on operational efficiency") - case .marketAction: - return Stage( - i: "Gambling / driven by gut", ii: "Exploring a \"found\" value", - iii: "Market analysis / listening to customers", iv: "Metric driven / build what is needed") - case .efficiency: - return Stage( - i: "Reducing the cost of change (experimentation)", ii: "Reducing cost of waste (Learning)", - iii: "Reducing cost of waste (Learning)", iv: "Reducing cost of deviation (Volume)") - case .decisionDrivers: - return Stage( - i: "Heritage / culture", ii: "Analyses & synthesis", iii: "Analyses & synthesis", - iv: "Previous Experience") - case .behavior: - return Stage( - i: "Uncertain when to use", ii: "Learning when to use", iii: "Learning through use", - iv: "Known / common usage") - } - } - - static func title(_ type: StageType) -> String { - switch type { - case .general: - return "Activities" - case .practice: - return "Practice" - case .data: - return "Data" - case .knowledge: - return "Knowledge" - case .ubiquity: - return "Ubiquity" - case .certainty: - return "Certainty" - case .publicationTypes: - return "Publication Types" - case .market: - return "Market" - case .knowledgeManagement: - return "Knowledge Management" - case .marketPerception: - return "Market Perception" - case .userPerception: - return "User Perception" - case .perceptionInIndustry: - return "Perception In Industry" - case .focusOfValue: - return "Focus Of Value" - case .understanding: - return "Understanding" - case .comparison: - return "Comparison" - case .failure: - return "Failure" - case .marketAction: - return "Market Action" - case .efficiency: - return "Efficiency" - case .decisionDrivers: - return "Decision Drivers" - case .behavior: - return "Behavior" - } - } -} - -enum StageType: String, CaseIterable, Identifiable { - case general - case practice - case data - case knowledge - - case ubiquity - case certainty - case publicationTypes - - case market - case knowledgeManagement - case marketPerception - case userPerception - case perceptionInIndustry - case focusOfValue - case understanding - case comparison - case failure - case marketAction - case efficiency - case decisionDrivers - - case behavior - - var id: String { self.rawValue } - - static let types: [StageType] = [.general, .practice, .data, .knowledge] - static let characteristics: [StageType] = [.ubiquity, .certainty, .publicationTypes] - static let properties: [StageType] = [ - .market, .knowledgeManagement, .marketPerception, .userPerception, - .perceptionInIndustry, .focusOfValue, .understanding, .comparison, .failure, - .marketAction, .efficiency, .decisionDrivers, - ] - static let custom: [StageType] = [.behavior] -} |