feat(memory): 增加内存分类历史趋势曲线
This commit is contained in:
@@ -14,9 +14,11 @@ struct PanelTrendChart: View {
|
||||
let first: [Double?]
|
||||
var second: [Double?] = []
|
||||
var third: [Double?] = []
|
||||
var fourth: [Double?] = []
|
||||
let color: Color
|
||||
var secondColor: Color = .orange
|
||||
var thirdColor: Color = .purple
|
||||
var fourthColor: Color = .yellow
|
||||
var fixedScale: Double? = 1
|
||||
var scaleLabel: String?
|
||||
var secondSeriesUsesAutonomousScale = false
|
||||
@@ -25,6 +27,7 @@ struct PanelTrendChart: View {
|
||||
var firstLabel: LocalizedStringKey = "panel.total"
|
||||
var secondLabel: LocalizedStringKey = "network.upload"
|
||||
var thirdLabel: LocalizedStringKey = "cpu.system"
|
||||
var fourthLabel: LocalizedStringKey = "memory.compressed"
|
||||
var expectedInterval: TimeInterval = 2
|
||||
var boundaryDates: Set<Date> = []
|
||||
var intervals: [TimeInterval] = []
|
||||
@@ -43,11 +46,11 @@ struct PanelTrendChart: View {
|
||||
@State private var displayedFrame: PanelCurveFrame?
|
||||
|
||||
private var inputFrame: PanelCurveFrame {
|
||||
PanelCurveFrame(dates: dates, series: [first, second, third],
|
||||
PanelCurveFrame(dates: dates, series: [first, second, third, fourth],
|
||||
intervals: intervals.count == dates.count ? intervals : Array(repeating: expectedInterval, count: dates.count),
|
||||
boundaryDates: boundaryDates)
|
||||
}
|
||||
private var maximum: Double { max(1, (first + second + third).compactMap { $0 }.filter(\.isFinite).max() ?? 1) }
|
||||
private var maximum: Double { max(1, (first + second + third + fourth).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) }
|
||||
@@ -95,6 +98,7 @@ struct PanelTrendChart: View {
|
||||
tooltipRow(firstLabel, values: first, tint: color, index: index)
|
||||
if !second.isEmpty { tooltipRow(secondLabel, values: second, tint: secondColor, format: secondValueFormat, index: index) }
|
||||
if !third.isEmpty { tooltipRow(thirdLabel, values: third, tint: thirdColor, index: index) }
|
||||
if !fourth.isEmpty { tooltipRow(fourthLabel, values: fourth, tint: fourthColor, index: index) }
|
||||
}
|
||||
.font(.system(size: 10)).padding(8)
|
||||
.background { TooltipMaterialBackground() }
|
||||
@@ -108,6 +112,7 @@ struct PanelTrendChart: View {
|
||||
legend(firstLabel, values: first, tint: color)
|
||||
if !second.isEmpty { legend(secondLabel, values: second, tint: secondColor, format: secondValueFormat) }
|
||||
if !third.isEmpty { legend(thirdLabel, values: third, tint: thirdColor) }
|
||||
if !fourth.isEmpty { legend(fourthLabel, values: fourth, tint: fourthColor) }
|
||||
Spacer(minLength: 0)
|
||||
}.frame(height: 14)
|
||||
HStack(spacing: 5) {
|
||||
@@ -121,8 +126,8 @@ struct PanelTrendChart: View {
|
||||
.lineLimit(1).minimumScaleFactor(0.6).frame(width: fixedScale == 1 ? 28 : 47, height: plotHeight)
|
||||
GeometryReader { proxy in
|
||||
ZStack(alignment: .topLeading) {
|
||||
PanelCurveCanvas(frame: displayedFrame ?? inputFrame, colors: [color, secondColor, thirdColor],
|
||||
scales: [scale, hasSecondaryScale ? secondaryScale : scale, hasSecondaryScale ? secondaryScale : scale],
|
||||
PanelCurveCanvas(frame: displayedFrame ?? inputFrame, colors: [color, secondColor, thirdColor, fourthColor],
|
||||
scales: [scale, hasSecondaryScale ? secondaryScale : scale, hasSecondaryScale ? secondaryScale : scale, scale],
|
||||
maximumGap: max(5, expectedInterval * 2),
|
||||
targetBegin: (lastFrame ?? inputFrame).dates.first, targetEnd: (lastFrame ?? inputFrame).dates.last,
|
||||
previousBegin: previousBegin, previousEnd: previousEnd, progress: progress)
|
||||
@@ -131,11 +136,11 @@ struct PanelTrendChart: View {
|
||||
Path { path in
|
||||
path.move(to: CGPoint(x: x, y: 0)); path.addLine(to: CGPoint(x: x, y: proxy.size.height))
|
||||
}.stroke(.primary.opacity(0.45), style: StrokeStyle(lineWidth: 1, dash: [3, 2]))
|
||||
ForEach(0..<3, id: \.self) { series in
|
||||
let values = [first, second, third][series]
|
||||
ForEach(0..<4, id: \.self) { series in
|
||||
let values = [first, second, third, fourth][series]
|
||||
if index < values.count, let value = values[index], value.isFinite {
|
||||
let seriesScale = [scale, hasSecondaryScale ? secondaryScale : scale, hasSecondaryScale ? secondaryScale : scale][series]
|
||||
Circle().fill([color, secondColor, thirdColor][series]).frame(width: 5, height: 5)
|
||||
let seriesScale = [scale, hasSecondaryScale ? secondaryScale : scale, hasSecondaryScale ? secondaryScale : scale, scale][series]
|
||||
Circle().fill([color, secondColor, thirdColor, fourthColor][series]).frame(width: 5, height: 5)
|
||||
.position(x: x, y: proxy.size.height * (1 - min(1, max(0, value / seriesScale))))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user