// // SparkLine.swift // 盯基金 plugin v0.2 // // Pure-SwiftUI port of the design's sparkline for the gold // chart. Handles: // - smooth quadratic curve through points // - filled area under the curve with a vertical gradient // - pulsing "current point" indicator // - dashed midline grid // - empty / 1-point degenerate cases // import SwiftUI struct SparkLine: View { let values: [Double] let lineColor: Color let fillColor: Color let pulseColor: Color var body: some View { GeometryReader { geo in let W = geo.size.width let H = geo.size.height let padX: CGFloat = 8 let padY: CGFloat = 14 ZStack { // dashed midline Path { p in p.move(to: CGPoint(x: 0, y: H / 2)) p.addLine(to: CGPoint(x: W, y: H / 2)) } .stroke( Color.white.opacity(0.04), style: StrokeStyle(lineWidth: 0.5, lineCap: .round, dash: [2, 4]) ) // bail when not enough data if values.count >= 2, let maxV = values.max(), let minV = values.min(), maxV != minV { let xs: (Int) -> CGFloat = { i in padX + (CGFloat(i) / CGFloat(values.count - 1)) * (W - padX * 2) } let ys: (Double) -> CGFloat = { v in let t = (v - minV) / (maxV - minV) return padY + (1 - CGFloat(t)) * (H - padY * 2) } // area fill Path { p in p.move(to: CGPoint(x: xs(0), y: ys(values[0]))) for i in 1..