new tests
This commit is contained in:
+251
-1050
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,25 @@
|
||||
import Foundation
|
||||
import CoreGraphics
|
||||
|
||||
/// Pure schema-diagram operations shared by the UI and XCTest suite.
|
||||
enum DiagramLogic {
|
||||
static func selectedObjects(_ requested: Set<String>, available: [String]) -> Set<String> {
|
||||
requested.intersection(Set(available))
|
||||
}
|
||||
|
||||
static func arrangedPositions(_ names: [String]) -> [String: CGPoint] {
|
||||
let countPerRow = max(1, Int(ceil(sqrt(Double(max(1, names.count))))))
|
||||
var positions: [String: CGPoint] = [:]
|
||||
for (index, name) in names.enumerated() {
|
||||
positions[name] = CGPoint(x: CGFloat(index % countPerRow) * 290 + 30,
|
||||
y: CGFloat(index / countPerRow) * 300 + 30)
|
||||
}
|
||||
return positions
|
||||
}
|
||||
|
||||
static func translatedPosition(_ origin: CGPoint, translation: CGSize, zoom: CGFloat) -> CGPoint {
|
||||
let scale = max(zoom, 0.1)
|
||||
return CGPoint(x: origin.x + translation.width / scale,
|
||||
y: origin.y + translation.height / scale)
|
||||
}
|
||||
}
|
||||
@@ -355,7 +355,7 @@ struct DBSynSchemaDiagramView: View {
|
||||
// previous implementation only saved the checkboxes, leaving the diagram
|
||||
// scrolled to stale positions after None / All / individual selections.
|
||||
private func updateIncludedObjects(_ updated: Set<String>) {
|
||||
let valid = updated.intersection(Set(allObjects))
|
||||
let valid = DiagramLogic.selectedObjects(updated, available: allObjects)
|
||||
guard valid != includedObjects else { return }
|
||||
includedObjects = valid
|
||||
if let selectedObject, !valid.contains(selectedObject) {
|
||||
@@ -371,11 +371,7 @@ struct DBSynSchemaDiagramView: View {
|
||||
|
||||
private func arrange() {
|
||||
let names = allObjects.filter { includedObjects.contains($0) }
|
||||
let countPerRow = max(1, Int(ceil(sqrt(Double(max(1, names.count))))))
|
||||
for (index, name) in names.enumerated() {
|
||||
positions[name] = CGPoint(x: CGFloat(index % countPerRow) * 290 + 30,
|
||||
y: CGFloat(index / countPerRow) * 300 + 30)
|
||||
}
|
||||
positions.merge(DiagramLogic.arrangedPositions(names)) { _, latest in latest }
|
||||
}
|
||||
private func loadCatalog() {
|
||||
let stored = UserDefaults.standard.stringArray(forKey: catalogKey) ?? ["Main"]
|
||||
|
||||
Reference in New Issue
Block a user