fix(design): 按概念图重排面板层级并验证真实组件
This commit is contained in:
@@ -13,35 +13,69 @@ struct PanelTrendChart: View {
|
||||
@State private var smallSamples = 0
|
||||
|
||||
private var maximum: Double { max(1, (first + second).compactMap { $0 }.filter(\.isFinite).max() ?? 1) }
|
||||
private var middleLabel: String {
|
||||
if let fixedScale { return fixedScale == 1 ? "50%" : MetricFormat.bytes(UInt64(max(0, fixedScale / 2))) }
|
||||
return MetricFormat.rate(retainedScale / 2)
|
||||
}
|
||||
var body: some View {
|
||||
VStack(spacing: 2) {
|
||||
HStack {
|
||||
Text(verbatim: scaleLabel ?? (fixedScale == nil ? MetricFormat.rate(retainedScale) : "100%"))
|
||||
Spacer()
|
||||
}.font(.system(size: 9)).foregroundStyle(.secondary)
|
||||
HStack(spacing: 5) {
|
||||
VStack(alignment: .trailing) {
|
||||
Text(verbatim: scaleLabel ?? (fixedScale == nil ? MetricFormat.rate(retainedScale) : "100%"))
|
||||
.lineLimit(1).minimumScaleFactor(0.75)
|
||||
Spacer(minLength: 0)
|
||||
Text(verbatim: middleLabel).lineLimit(1).minimumScaleFactor(0.75)
|
||||
Spacer(minLength: 0)
|
||||
Text(verbatim: "0")
|
||||
}.font(.system(size: 8)).foregroundStyle(.secondary).frame(width: 52, height: 48)
|
||||
Canvas { context, size in
|
||||
var grid = Path()
|
||||
for step in 0...10 {
|
||||
let x = size.width * Double(step) / 10
|
||||
grid.move(to: CGPoint(x: x, y: 0)); grid.addLine(to: CGPoint(x: x, y: size.height))
|
||||
}
|
||||
for step in 0...2 {
|
||||
let y = size.height * Double(step) / 2
|
||||
grid.move(to: CGPoint(x: 0, y: y)); grid.addLine(to: CGPoint(x: size.width, y: y))
|
||||
}
|
||||
context.stroke(grid, with: .color(color.opacity(0.14)), lineWidth: 0.5)
|
||||
guard let begin = dates.first, let end = dates.last, end > begin else { return }
|
||||
let scale = fixedScale ?? retainedScale
|
||||
for (values, tint) in [(first, color), (second, secondColor)] {
|
||||
var path = Path()
|
||||
var connected = false
|
||||
var fill = Path()
|
||||
var runStart: CGPoint?
|
||||
var runEnd: CGPoint?
|
||||
func closeRun() {
|
||||
guard let start = runStart, let end = runEnd else { return }
|
||||
fill.addLine(to: CGPoint(x: end.x, y: size.height))
|
||||
fill.addLine(to: CGPoint(x: start.x, y: size.height)); fill.closeSubpath()
|
||||
runStart = nil; runEnd = nil
|
||||
}
|
||||
for index in dates.indices {
|
||||
guard index < values.count, let value = values[index], value.isFinite else { connected = false; continue }
|
||||
if index > 0 && dates[index].timeIntervalSince(dates[index - 1]) > 5 { connected = false }
|
||||
guard index < values.count, let value = values[index], value.isFinite else { closeRun(); connected = false; continue }
|
||||
if index > 0 && dates[index].timeIntervalSince(dates[index - 1]) > 5 { closeRun(); connected = false }
|
||||
let point = CGPoint(x: size.width * dates[index].timeIntervalSince(begin) / end.timeIntervalSince(begin),
|
||||
y: size.height * (1 - min(1, max(0, value / scale))))
|
||||
if connected { path.addLine(to: point) } else { path.move(to: point) }
|
||||
if connected { path.addLine(to: point); fill.addLine(to: point) }
|
||||
else { path.move(to: point); fill.move(to: point); runStart = point }
|
||||
runEnd = point
|
||||
connected = true
|
||||
}
|
||||
closeRun()
|
||||
context.fill(fill, with: .linearGradient(Gradient(colors: [tint.opacity(0.45), tint.opacity(0.03)]), startPoint: .zero, endPoint: CGPoint(x: 0, y: size.height)))
|
||||
context.stroke(path, with: .color(tint), style: StrokeStyle(lineWidth: 1.5, lineCap: .round))
|
||||
}
|
||||
}.frame(height: 44)
|
||||
}.frame(height: 48)
|
||||
}
|
||||
HStack {
|
||||
if let date = dates.first { Text(date, style: .time) }
|
||||
Spacer()
|
||||
if let date = dates.last { Text(date, style: .time) }
|
||||
}.font(.system(size: 9)).foregroundStyle(.secondary)
|
||||
}.font(.system(size: 9)).foregroundStyle(.secondary).frame(maxWidth: .infinity)
|
||||
}
|
||||
.frame(maxWidth: .infinity)
|
||||
.onAppear { retainedScale = maximum }
|
||||
.onChange(of: dates.last) { _, _ in
|
||||
let target = maximum
|
||||
|
||||
@@ -5,22 +5,26 @@ struct ResourceCard<Content: View>: View {
|
||||
let symbol: String
|
||||
let color: Color
|
||||
let value: String
|
||||
var secondaryValue: String? = nil
|
||||
@ViewBuilder var content: () -> Content
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
HStack {
|
||||
Label(title, systemImage: symbol).font(.system(size: 13, weight: .semibold)).foregroundStyle(color)
|
||||
Spacer(minLength: 6)
|
||||
Text(verbatim: value).font(.system(size: 20, weight: .semibold, design: .rounded)).monospacedDigit()
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Label { Text(title).foregroundStyle(.primary) } icon: {
|
||||
Image(systemName: symbol).foregroundStyle(color)
|
||||
}.font(.system(size: 13, weight: .semibold))
|
||||
HStack(alignment: .firstTextBaseline) {
|
||||
Text(verbatim: value).font(.system(size: 27, weight: .semibold, design: .rounded))
|
||||
.foregroundStyle(color).monospacedDigit().lineLimit(1).minimumScaleFactor(0.8)
|
||||
Spacer(minLength: 4)
|
||||
if let secondaryValue { Text(verbatim: secondaryValue).font(.system(size: 15, weight: .semibold)).foregroundStyle(color).lineLimit(1) }
|
||||
}
|
||||
content()
|
||||
Spacer(minLength: 0)
|
||||
}
|
||||
.font(.system(size: 11))
|
||||
.padding(12)
|
||||
.frame(maxWidth: .infinity, minHeight: 250, alignment: .topLeading)
|
||||
.background(Color("PanelCard"), in: .rect(cornerRadius: 14))
|
||||
.overlay(RoundedRectangle(cornerRadius: 14).strokeBorder(.primary.opacity(0.1)))
|
||||
.padding(10)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
|
||||
.background(Color("PanelCard"), in: .rect(cornerRadius: 10))
|
||||
.overlay(RoundedRectangle(cornerRadius: 10).strokeBorder(.primary.opacity(0.14)))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user