Files
pokerfreak/mac/Sources/Cockpit/FormatVergleich.swift
T
mmintelandClaude Opus 5.5 83a31b3831 Mac-App: "Was spielen" mit Tischen je Format, "Formate im Vergleich"
A card per format with its table count under the plan tiles (unmeasured
formats are marked), the table tile shows the sum. Results show bb/100
per format with its 95 % span on a shared axis and the verdict, Practice
and Live separately.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 10:43:23 +01:00

85 lines
3.9 KiB
Swift

import CockpitKern
import SwiftUI
/// Welches Format läuft am besten: bb/100 je Format mit 95-%-Spanne als Balken auf einer
/// gemeinsamen Achse, darüber das Urteil - nur wenn die Spannen es tragen.
struct FormatVergleich: View {
var kurven: Kurven?
var body: some View {
let zeilen = kurven?.jeFormat ?? []
if !zeilen.isEmpty {
VStack(alignment: .leading, spacing: 8) {
HStack(alignment: .firstTextBaseline) {
Text("Formate im Vergleich").font(.caption.weight(.semibold)).foregroundStyle(.secondary)
Spacer()
Text("bb/100 · 95 %").font(.caption2).foregroundStyle(.tertiary)
}
if let u = kurven?.bestesFormat { urteil(u) }
let achse = Self.achse(zeilen)
ForEach(zeilen) { z in
FormatBalken(zeile: z, achse: achse)
}
}
.padding(10)
.background(.white.opacity(0.05), in: RoundedRectangle(cornerRadius: 14))
}
}
private func urteil(_ u: FormatUrteil) -> some View {
let sieger = u.format.flatMap(SpielFormat.init(rawValue:))
return VStack(alignment: .leading, spacing: 1) {
Label(sieger.map { "\($0.name) liegt vorn" } ?? "Noch kein Urteil",
systemImage: sieger == nil ? "hourglass" : "rosette")
.font(.callout.weight(.semibold))
.foregroundStyle(sieger == nil ? Color.secondary : .green)
Text(u.grund).font(.caption2).foregroundStyle(.tertiary).fixedSize(horizontal: false, vertical: true)
}
}
/// Gemeinsame Achse über alle Spannen und Werte, mit der Null darin.
static func achse(_ z: [FormatZeile]) -> ClosedRange<Double> {
let werte: [Double] = z.flatMap { [$0.unten, $0.oben, $0.bb100].compactMap { $0 } } + [0.0]
let lo = werte.min() ?? -1, hi = werte.max() ?? 1
return lo == hi ? (lo - 1)...(hi + 1) : lo...hi
}
}
private struct FormatBalken: View {
var zeile: FormatZeile
var achse: ClosedRange<Double>
private var format: SpielFormat? { SpielFormat(rawValue: zeile.format) }
var body: some View {
VStack(alignment: .leading, spacing: 3) {
HStack(spacing: 6) {
Image(systemName: format?.symbol ?? "questionmark.circle").font(.caption).foregroundStyle(.secondary).frame(width: 16)
Text(zeile.name).font(.caption.weight(.semibold))
Text("\(zeile.haende) Hände").font(.caption2).foregroundStyle(.tertiary)
Spacer()
Text(Format.vorzeichen(zeile.bb100, stellen: 1)).font(.caption.weight(.semibold).monospacedDigit())
.foregroundStyle(Farben.ergebnis(zeile.bb100))
}
GeometryReader { g in
let x = { (v: Double) in g.size.width * (v - achse.lowerBound) / (achse.upperBound - achse.lowerBound) }
ZStack(alignment: .leading) {
Capsule().fill(.quaternary).frame(height: 4)
Rectangle().fill(.secondary.opacity(0.6)).frame(width: 1, height: 12).offset(x: x(0))
if let u = zeile.unten, let o = zeile.oben {
Capsule().fill(Farben.ergebnis(zeile.bb100).opacity(0.35))
.frame(width: max(2, x(o) - x(u)), height: 8).offset(x: x(u))
}
if let b = zeile.bb100 {
Circle().fill(Farben.ergebnis(b)).frame(width: 8, height: 8).offset(x: x(b) - 4)
}
}
.frame(maxHeight: .infinity)
}
.frame(height: 12)
.help(zeile.unten.map { u in "95 %: \(Format.zahl(u, stellen: 0)) bis \(Format.zahl(zeile.oben, stellen: 0)) bb/100" }
?? "zu wenig Hände für eine Spanne")
}
}
}