Files
MLBApp/mlbTVOS/Views/Components/DiamondView.swift
Trey t b5daddefd3 Add UI redesign: design system, dashboard density, game intelligence, feed tab, league leaders
Phase 1 - Design System: DesignSystem.swift (typography, colors, spacing
constants) and DataPanel.swift (reusable panel container with 3 densities
and optional team accent bar).

Phase 2 - Dashboard Density: LiveSituationBar (compact strip of all live
games with scores/innings/outs), MiniLinescoreView (R-H-E footer for game
cards), DiamondView (visual baseball diamond with runners and count).
Dashboard shows live situation bar when games are active. Game cards now
display mini linescore for live/final games.

Phase 3 - Game Center Intelligence: WinProbabilityChartView (full-game
line chart using Swift Charts with area fills), PitchArsenalView (pitch
type distribution with velocity bars). GameCenterViewModel now stores
full WP history array instead of just latest values.

Phase 4 - Feed Tab: MLBWebDataService (fetches league leaders from Stats
API, news headlines, transactions), FeedViewModel, FeedView with
reverse-chronological feed items. FeedItemView with colored edge bars
by category. Added 5th "Feed" tab to both tvOS and iOS.

Phase 5 - Intel Tab: LeaderboardView (top-5 stat cards with headshots),
integrated into LeagueCenterView. Renamed tabs: Games->Today,
League->Intel. LeagueCenterViewModel now fetches league leaders.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 13:12:09 -05:00

121 lines
4.2 KiB
Swift

import SwiftUI
/// Visual baseball diamond showing base runners, count, and outs
struct DiamondView: View {
var onFirst: Bool = false
var onSecond: Bool = false
var onThird: Bool = false
var balls: Int = 0
var strikes: Int = 0
var outs: Int = 0
var body: some View {
HStack(spacing: diamondCountGap) {
// Diamond
ZStack {
// Diamond shape outline
diamondPath
.stroke(DS.Colors.textQuaternary, lineWidth: 1.5)
// Base markers
baseMarker(at: firstBasePos, occupied: onFirst)
baseMarker(at: secondBasePos, occupied: onSecond)
baseMarker(at: thirdBasePos, occupied: onThird)
baseMarker(at: homePos, occupied: false, isHome: true)
}
.frame(width: diamondSize, height: diamondSize)
// Count + Outs
VStack(alignment: .leading, spacing: countSpacing) {
HStack(spacing: 3) {
Text("B").dataLabelStyle()
ForEach(0..<4, id: \.self) { i in
Circle()
.fill(i < balls ? DS.Colors.positive : DS.Colors.textQuaternary)
.frame(width: dotSize, height: dotSize)
}
}
HStack(spacing: 3) {
Text("S").dataLabelStyle()
ForEach(0..<3, id: \.self) { i in
Circle()
.fill(i < strikes ? DS.Colors.live : DS.Colors.textQuaternary)
.frame(width: dotSize, height: dotSize)
}
}
HStack(spacing: 3) {
Text("O").dataLabelStyle()
ForEach(0..<3, id: \.self) { i in
Circle()
.fill(i < outs ? DS.Colors.warning : DS.Colors.textQuaternary)
.frame(width: dotSize, height: dotSize)
}
}
}
}
}
// MARK: - Diamond geometry
private var diamondPath: Path {
let s = diamondSize
let mid = s / 2
let inset: CGFloat = baseSize / 2 + 2
var path = Path()
path.move(to: CGPoint(x: mid, y: inset)) // 2nd base (top)
path.addLine(to: CGPoint(x: s - inset, y: mid)) // 1st base (right)
path.addLine(to: CGPoint(x: mid, y: s - inset)) // Home (bottom)
path.addLine(to: CGPoint(x: inset, y: mid)) // 3rd base (left)
path.closeSubpath()
return path
}
private var firstBasePos: CGPoint {
CGPoint(x: diamondSize - baseSize / 2 - 2, y: diamondSize / 2)
}
private var secondBasePos: CGPoint {
CGPoint(x: diamondSize / 2, y: baseSize / 2 + 2)
}
private var thirdBasePos: CGPoint {
CGPoint(x: baseSize / 2 + 2, y: diamondSize / 2)
}
private var homePos: CGPoint {
CGPoint(x: diamondSize / 2, y: diamondSize - baseSize / 2 - 2)
}
@ViewBuilder
private func baseMarker(at position: CGPoint, occupied: Bool, isHome: Bool = false) -> some View {
Group {
if isHome {
// Home plate: small pentagon-like shape
Circle()
.fill(DS.Colors.textQuaternary)
.frame(width: baseSize * 0.7, height: baseSize * 0.7)
} else {
// Base: rotated square
Rectangle()
.fill(occupied ? DS.Colors.interactive : DS.Colors.textQuaternary)
.frame(width: baseSize, height: baseSize)
.rotationEffect(.degrees(45))
}
}
.position(position)
}
// MARK: - Platform sizing
#if os(tvOS)
private var diamondSize: CGFloat { 60 }
private var baseSize: CGFloat { 12 }
private var dotSize: CGFloat { 9 }
private var countSpacing: CGFloat { 5 }
private var diamondCountGap: CGFloat { 14 }
#else
private var diamondSize: CGFloat { 44 }
private var baseSize: CGFloat { 9 }
private var dotSize: CGFloat { 7 }
private var countSpacing: CGFloat { 3 }
private var diamondCountGap: CGFloat { 10 }
#endif
}