Hello! I was able to get a couple of patterns down for glass in charts; some through views and others with chart-specific protocols.
here's an example .annotation:
extension Charting.Views.Stock.Selection {
struct Annotation: View {
private let low: Double
private let high: Double
private let open: Double
private let close: Double
private let gain: Bool
private var time: String
public init(_ data: Charting.Model.Candle) {
self.low = data.low
self.high = data.high
self.open = data.open
self.close = data.close
self.gain = data.gain
self.time = data.date.formatted(.dateTime.hour().minute().timeZone(.exemplarLocation))
}
@Environment(\.colorScheme) private var colors
var body: some View {
VStack(alignment: .leading) {
Group {
HStack {
Text("Low").font(.caption)
Spacer()
Text(low, format: .currency(code: "USD"))
}
HStack {
Text("High").font(.caption)
Spacer()
Text(high, format: .currency(code: "USD"))
}
Divider()
HStack {
Text("Open").font(.caption)
Spacer()
Text(open, format: .currency(code: "USD"))
}
HStack {
Text("Close").font(.caption)
Spacer()
Text(close, format: .currency(code: "USD"))
}
HStack {
Spacer()
Text(gain ? "+" : "-")
Text(abs(open - close), format: .currency(code: "USD"))
}
Divider()
HStack {
Spacer()
Text(time)
}
}
.foregroundStyle(colors == .dark ? Color.white : Color.black)
}
.padding()
.glassEffect(
.regular.tint(
gain
? Color("Chart-Candle-Green").opacity(0.25)
: Color("Chart-Candle-Red").opacity(0.25)
),
in: RoundedRectangle(cornerRadius: 8, style: .circular)
)
.background(
RoundedRectangle(cornerRadius: 8, style: .circular)
.fill(
.ultraThinMaterial.opacity(0.25)
)
)
.opacity(0.25)
}
}
}
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: