From b4a353dc7023e8f9e14744463c845c039b03665a Mon Sep 17 00:00:00 2001 From: leondt1 Date: Tue, 21 May 2024 11:26:18 +0800 Subject: [PATCH] fix: get wrong anchor when a node is invisible --- packages/x6/src/registry/node-anchor/bbox.ts | 11 ++++++++--- packages/x6/src/registry/node-anchor/middle-side.ts | 6 +++++- packages/x6/src/registry/node-anchor/orth.ts | 4 +++- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/packages/x6/src/registry/node-anchor/bbox.ts b/packages/x6/src/registry/node-anchor/bbox.ts index b344a7c3a09..6e9d87d5d8a 100644 --- a/packages/x6/src/registry/node-anchor/bbox.ts +++ b/packages/x6/src/registry/node-anchor/bbox.ts @@ -35,9 +35,14 @@ function createBBoxAnchor( | 'bottomRight', ): NodeAnchor.Definition { return function (view, magnet, ref, options: BBoxEndpointOptions = {}) { - const bbox = options.rotate - ? view.getUnrotatedBBoxOfElement(magnet) - : view.getBBoxOfElement(magnet) + let bbox + if (view.cell.visible) { + bbox = options.rotate + ? view.getUnrotatedBBoxOfElement(magnet) + : view.getBBoxOfElement(magnet) + } else { + bbox = view.cell.getBBox() + } const result = bbox[method] result.x += NumberExt.normalizePercentage(options.dx, bbox.width) diff --git a/packages/x6/src/registry/node-anchor/middle-side.ts b/packages/x6/src/registry/node-anchor/middle-side.ts index 02e4bf74f78..fd219811b23 100644 --- a/packages/x6/src/registry/node-anchor/middle-side.ts +++ b/packages/x6/src/registry/node-anchor/middle-side.ts @@ -20,7 +20,11 @@ const middleSide: NodeAnchor.ResolvedDefinition = center = node.getBBox().getCenter() angle = node.getAngle() } else { - bbox = view.getBBoxOfElement(magnet) + if (node.visible) { + bbox = view.getBBoxOfElement(magnet) + } else { + bbox = view.cell.getBBox() + } } const padding = options.padding diff --git a/packages/x6/src/registry/node-anchor/orth.ts b/packages/x6/src/registry/node-anchor/orth.ts index bf73a60c349..1aa3c21c6a2 100644 --- a/packages/x6/src/registry/node-anchor/orth.ts +++ b/packages/x6/src/registry/node-anchor/orth.ts @@ -9,7 +9,9 @@ export interface OrthEndpointOptions extends ResolveOptions { const orthogonal: NodeAnchor.ResolvedDefinition = function (view, magnet, refPoint, options) { const angle = Angle.normalize(view.cell.getAngle()) - const bbox = view.getBBoxOfElement(magnet) + const bbox = view.cell.visible + ? view.getBBoxOfElement(magnet) + : view.cell.getBBox() const result = bbox.getCenter() const topLeft = bbox.getTopLeft() const bottomRight = bbox.getBottomRight()