fix: fix incorrect edge zindex when ends has hight zindex

This commit is contained in:
antv 2024-11-11 16:09:41 +08:00
parent 0ec431f579
commit 624dc794f5
3 changed files with 39 additions and 4 deletions

View File

@ -4,6 +4,7 @@ import type { PathArray } from '@antv/util';
import { isFunction, pick } from '@antv/util';
import type {
BaseElementStyleProps,
Combo,
Edge,
EdgeArrowStyleProps,
EdgeBadgeStyleProps,
@ -216,16 +217,46 @@ export abstract class BaseEdge extends BaseElement<BaseEdgeStyleProps> implement
constructor(options: DisplayObjectConfig<BaseEdgeStyleProps>) {
super(mergeOptions({ style: BaseEdge.defaultStyleProps }, options));
this.updateEdgeZIndex(this.parsedAttributes);
}
protected get sourceNode() {
const { context, sourceNode: source } = this.parsedAttributes;
return context.element!.getElement<Node>(source)!;
return context.element!.getElement<Node | Combo>(source)!;
}
protected get targetNode() {
const { context, targetNode: target } = this.parsedAttributes;
return context.element!.getElement<Node>(target)!;
return context.element!.getElement<Node | Combo>(target)!;
}
protected getEdgeZIndex(attributes: ParsedBaseEdgeStyleProps): number {
const { context } = attributes;
const { sourceNode, targetNode } = this;
const sourceType = context.model.getElementType(sourceNode.id);
const targetType = context.model.getElementType(targetNode.id);
const sourceZIndex = sourceNode.style.zIndex ?? 2;
const targetZIndex = targetNode.style.zIndex ?? 2;
if (sourceType === 'node' && targetType === 'node') {
return Math.min(sourceZIndex, targetZIndex) - 1;
}
if (sourceType === 'combo' && targetType === 'combo') {
return Math.max(sourceZIndex, targetZIndex) + 1;
}
if (sourceType === 'node' && targetType === 'combo') {
return Math.max(sourceZIndex - 1, targetZIndex + 1);
}
return Math.max(sourceZIndex + 1, targetZIndex - 1);
}
protected updateEdgeZIndex(attributes: ParsedBaseEdgeStyleProps): void {
const { zIndex = this.getEdgeZIndex(attributes) } = this.attributes;
if (zIndex !== this.parsedStyle.zIndex) {
this.style.zIndex = zIndex;
}
}
protected getKeyStyle(attributes: ParsedBaseEdgeStyleProps): PathStyleProps {
@ -429,6 +460,11 @@ export abstract class BaseEdge extends BaseElement<BaseEdgeStyleProps> implement
this.drawBadgeShape(attributes, container);
}
public update(attr?: Partial<BaseEdgeStyleProps>): void {
super.update(attr);
this.updateEdgeZIndex(this.parsedAttributes);
}
protected onframe() {
this.drawKeyShape(this.parsedAttributes, this);
this.drawSourceArrow(this.parsedAttributes);

View File

@ -393,7 +393,7 @@ export class ElementController {
this.emit(new ElementLifeCycleEvent(GraphEvent.BEFORE_ELEMENT_CREATE, elementType, datum), context);
if (context.stage === 'expand') {
if (context.stage === 'expand' && elementType === 'node') {
// 如果是展开的元素,需要将其 zIndex 提升至目标元素的上层
const targetZIndex = this.getElementZIndex(context.target!);
if (!style.zIndex || style.zIndex < targetZIndex) style.zIndex = targetZIndex + (style.zIndex ?? 0);

View File

@ -198,7 +198,6 @@ export function create(tokens: ThemeTokens): Theme {
lineWidth: 1,
stroke: edgeColor,
strokeOpacity: 1,
zIndex: 1,
},
state: {
selected: {