fix(charts): 修复浮窗层级并平滑切频与曲线移出

This commit is contained in:
2026-11-03 12:07:01 +08:00
parent 36b8e32af3
commit 7ef92d9c21
17 changed files with 271 additions and 59 deletions
+13
View File
@@ -30,5 +30,18 @@ struct ResourceCard<Content: View>: View {
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
.modifier(PanelCardBackground(radius: 10))
.overlay(RoundedRectangle(cornerRadius: 10).strokeBorder(.primary.opacity(0.14)))
.overlayPreferenceValue(ChartTooltipPreference.self) { tooltip in
GeometryReader { proxy in
if let tooltip {
let plot = proxy[tooltip.plot]
ChartTooltipLayer(point: CGPoint(x: plot.minX + tooltip.point.x, y: plot.minY + tooltip.point.y)) {
tooltip.content.fixedSize(horizontal: false, vertical: true)
}
.frame(width: proxy.size.width, height: proxy.size.height)
}
}
.allowsHitTesting(false)
.accessibilityHidden(true)
}
}
}
@@ -0,0 +1,31 @@
import SwiftUI
import AppKit
/// Within-window blending blurs the chart and labels below the card's root overlay.
struct TooltipMaterialBackground: View {
@Environment(\.accessibilityReduceTransparency) private var reduceTransparency
var body: some View {
Group {
if reduceTransparency { Color(nsColor: .windowBackgroundColor) }
else {
WithinWindowMaterial()
.overlay(Color("PanelTooltip").opacity(0.12))
}
}.clipShape(.rect(cornerRadius: 7))
}
}
private struct WithinWindowMaterial: NSViewRepresentable {
func makeNSView(context: Context) -> NSVisualEffectView {
let view = PassthroughVisualEffectView()
view.material = .popover
view.blendingMode = .withinWindow
view.state = .active
return view
}
func updateNSView(_ view: NSVisualEffectView, context: Context) {}
}
private final class PassthroughVisualEffectView: NSVisualEffectView {
override func hitTest(_ point: NSPoint) -> NSView? { nil }
}