Sources/Orgstar/PlotSheet.swift

6fa43a3d81440242a647c235bf3a7f9fbc11426c
orgstar/Sources/Orgstar/PlotSheet.swift
cmc #+PLOTa81466b635 1 month ago

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}
Keyboard shortcuts

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form