Sources/Orgstar/PlotSheet.swift

36 lines · 997 bytes

 1import AppKit
 2import OrgApp
 3import OrgCore
 4import SwiftUI
 5
 6/// A plotted table: drawn by Swift Charts, or the image gnuplot made.
 7struct PlotSheet: View {
 8    enum Content {
 9        case chart(TablePlot.Plot)
10        case image(URL)
11    }
12
13    let content: Content
14    @Environment(\.dismiss) private var dismiss
15
16    var body: some View {
17        VStack(spacing: 0) {
18            switch content {
19            case .chart(let plot):
20                PlotChart(plot)
21            case .image(let url):
22                if let image = NSImage(contentsOf: url) {
23                    Image(nsImage: image).resizable().scaledToFit().padding()
24                } else {
25                    Text("gnuplot made no image").foregroundStyle(.secondary)
26                }
27            }
28            HStack {
29                Spacer()
30                Button("Done") { dismiss() }.keyboardShortcut(.defaultAction)
31            }
32            .padding(10)
33        }
34        .frame(minWidth: 640, minHeight: 520)
35    }
36}