feat(ui): 实现全卡堆叠趋势与单页资源进程布局

This commit is contained in:
2026-11-15 17:59:52 +08:00
parent 469766892d
commit 99e558625b
37 changed files with 579 additions and 195 deletions
+21 -4
View File
@@ -31,6 +31,7 @@ struct PanelTrendChart: View {
var boundaryDates: Set<Date> = []
var intervals: [TimeInterval] = []
var visibleSeriesCount = 1
var stackOrder: [Int] = []
@State private var retainedScale: Double = 1
@State private var smallSamples = 0
@State private var retainedSecondScale: Double = 1
@@ -45,7 +46,22 @@ struct PanelTrendChart: View {
intervals: intervals.count == dates.count ? intervals : Array(repeating: expectedInterval, count: dates.count),
boundaryDates: boundaryDates)
}
private var maximum: Double { max(1, (first + second + third + fourth).compactMap { $0 }.filter(\.isFinite).max() ?? 1) }
private var renderFrame: PanelCurveFrame {
let raw = inputFrame
guard !stackOrder.isEmpty else { return raw }
return PanelCurveFrame(dates: raw.dates, series: stackOrder.map { index in
raw.series.indices.contains(index) ? raw.series[index] : Array(repeating: nil, count: raw.dates.count)
}, intervals: raw.intervals, boundaryDates: raw.boundaryDates)
}
private var renderColors: [Color] {
let colors = [color, secondColor, thirdColor, fourthColor]
return stackOrder.isEmpty ? colors : stackOrder.map { colors[min(max(0, $0), colors.count - 1)] }
}
private var maximum: Double {
let values = stackOrder.isEmpty ? first + second + third + fourth
: StackedSeries.bands(renderFrame.series, count: dates.count).last?.upper ?? []
return max(1, values.compactMap { $0 }.filter(\.isFinite).max() ?? 1)
}
private var secondMaximum: Double { max(1, second.compactMap { $0 }.filter(\.isFinite).max() ?? 1) }
private var scale: Double { max(0.0001, fixedScale ?? retainedScale) }
private var secondaryScale: Double { max(0.0001, retainedSecondScale) }
@@ -94,10 +110,11 @@ struct PanelTrendChart: View {
var body: some View {
GeometryReader { proxy in
NativePanelCurve(frame: inputFrame, colors: [color, secondColor, thirdColor, fourthColor],
NativePanelCurve(frame: renderFrame, colors: renderColors,
scales: [scale, hasSecondaryScale ? secondaryScale : scale, scale, scale],
maximumGap: max(5, expectedInterval * 2), hoveredIndex: hoveredDate == nil ? nil : index,
visibleSeriesCount: visibleSeriesCount, filledSeriesCount: visibleSeriesCount)
visibleSeriesCount: stackOrder.isEmpty ? visibleSeriesCount : stackOrder.count,
filledSeriesCount: stackOrder.isEmpty ? visibleSeriesCount : stackOrder.count, stacked: !stackOrder.isEmpty)
.contentShape(Rectangle())
.onContinuousHover { phase in
switch phase {
@@ -114,7 +131,7 @@ struct PanelTrendChart: View {
return ChartTooltipPresentation(plot: plot, point: hoverPoint, content: AnyView(tooltip(index: index)))
}
}
.frame(height: ResourceCardMetrics.plotHeight)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.onAppear {
retainedScale = maximum
retainedSecondScale = secondMaximum