added typeaheead and introspetion
This commit is contained in:
@@ -11,23 +11,32 @@ final class SchemaDiagramPrintView: NSView {
|
||||
let diagram: String
|
||||
let entries: [Entry]
|
||||
let links: [Link]
|
||||
let theme: String
|
||||
private let cardWidth: CGFloat = 260
|
||||
private let headerHeight: CGFloat = 34
|
||||
private let rowHeight: CGFloat = 19
|
||||
private let margin: CGFloat = 55
|
||||
private let titleHeight: CGFloat = 76
|
||||
private let navy = NSColor(calibratedRed: 0.12, green: 0.20, blue: 0.34, alpha: 1)
|
||||
private let blue = NSColor(calibratedRed: 0.14, green: 0.38, blue: 0.64, alpha: 1)
|
||||
private let violet = NSColor(calibratedRed: 0.34, green: 0.30, blue: 0.56, alpha: 1)
|
||||
private var blue: NSColor {
|
||||
switch theme {
|
||||
case "Slate": return NSColor(calibratedRed: 0.30, green: 0.38, blue: 0.49, alpha: 1)
|
||||
case "Forest": return NSColor(calibratedRed: 0.16, green: 0.43, blue: 0.36, alpha: 1)
|
||||
case "Plum": return NSColor(calibratedRed: 0.42, green: 0.32, blue: 0.55, alpha: 1)
|
||||
default: return NSColor(calibratedRed: 0.12, green: 0.38, blue: 0.66, alpha: 1)
|
||||
}
|
||||
}
|
||||
private var violet: NSColor { blue.blended(withFraction: 0.25, of: .systemPurple) ?? blue }
|
||||
private let ink = NSColor(calibratedRed: 0.16, green: 0.23, blue: 0.32, alpha: 1)
|
||||
private let muted = NSColor(calibratedRed: 0.43, green: 0.49, blue: 0.57, alpha: 1)
|
||||
private let border = NSColor(calibratedRed: 0.79, green: 0.83, blue: 0.88, alpha: 1)
|
||||
|
||||
init(database: String, diagram: String, entries: [Entry], links: [Link]) {
|
||||
init(database: String, diagram: String, entries: [Entry], links: [Link], theme: String = "Ocean") {
|
||||
self.database = database
|
||||
self.diagram = diagram
|
||||
self.entries = entries
|
||||
self.links = links
|
||||
self.theme = theme
|
||||
let width = max(900, (entries.map { $0.origin.x + 260 }.max() ?? 750) + 110)
|
||||
let height = max(650, (entries.map { $0.origin.y + CGFloat($0.columns.count) * 19 + 46 }.max() ?? 500) + 130)
|
||||
super.init(frame: CGRect(x: 0, y: 0, width: width, height: height))
|
||||
@@ -117,10 +126,15 @@ final class SchemaDiagramPrintView: NSView {
|
||||
let delta: CGFloat = right ? 55 : -55
|
||||
svg += "<path d=\"M \(sx) \(a.midY) C \(sx + delta) \(a.midY), \(ex - delta) \(b.midY), \(ex) \(b.midY)\" fill=\"none\" stroke=\"#6488af\" stroke-width=\"1.7\"/>\n"
|
||||
}
|
||||
let svgBlue = blue.usingColorSpace(.deviceRGB) ?? blue
|
||||
let svgViolet = violet.usingColorSpace(.deviceRGB) ?? violet
|
||||
func hex(_ color: NSColor) -> String {
|
||||
String(format: "#%02X%02X%02X", Int(color.redComponent * 255), Int(color.greenComponent * 255), Int(color.blueComponent * 255))
|
||||
}
|
||||
for entry in entries {
|
||||
let r = cardRect(entry)
|
||||
svg += "<rect x=\"\(r.minX)\" y=\"\(r.minY)\" width=\"\(r.width)\" height=\"\(r.height)\" rx=\"7\" fill=\"white\" stroke=\"#cbd4e0\"/>\n"
|
||||
svg += "<rect x=\"\(r.minX)\" y=\"\(r.minY)\" width=\"\(r.width)\" height=\"34\" fill=\"\(entry.isView ? "#574c8f" : "#2461a3")\"/>\n"
|
||||
svg += "<rect x=\"\(r.minX)\" y=\"\(r.minY)\" width=\"\(r.width)\" height=\"34\" fill=\"\(entry.isView ? hex(svgViolet) : hex(svgBlue))\"/>\n"
|
||||
svg += "<text x=\"\(r.minX + 12)\" y=\"\(r.minY + 23)\" font-family=\"Arial,sans-serif\" font-size=\"12\" font-weight=\"600\" fill=\"white\">\(escape(entry.name))</text>\n"
|
||||
for (index, column) in entry.columns.enumerated() {
|
||||
let y = r.minY + 34 + CGFloat(index) * 19
|
||||
|
||||
Reference in New Issue
Block a user