fix(charts): 修复浮窗层级并平滑切频与曲线移出
This commit is contained in:
@@ -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 }
|
||||
}
|
||||
Reference in New Issue
Block a user