From 55c3bf10488cbc3ffe0bab77098cfa67b38887fe Mon Sep 17 00:00:00 2001 From: "zhanning.bzn" Date: Sat, 5 Oct 2019 17:06:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BD=93=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E7=9A=84=E8=8A=82=E7=82=B9=E4=B8=AD=E5=BF=83=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE=E4=B8=8D=E5=9C=A8=E4=B8=AD=E5=BF=83=E7=82=B9=E6=97=B6?= =?UTF-8?q?delegate=E9=94=99=E4=BD=8D=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- demos/custom-node-card.html | 3 +++ src/behavior/drag-node.js | 31 ++++++++++++++++--------------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/demos/custom-node-card.html b/demos/custom-node-card.html index b2b086da68..9efbb9714a 100644 --- a/demos/custom-node-card.html +++ b/demos/custom-node-card.html @@ -481,6 +481,9 @@ container: 'mountNode', width: 800, height: 600, + modes: { + default: ['drag-node'] + }, defaultNode: { shape: 'card-node' } diff --git a/src/behavior/drag-node.js b/src/behavior/drag-node.js index 61ae278f23..71923ff4d7 100644 --- a/src/behavior/drag-node.js +++ b/src/behavior/drag-node.js @@ -194,29 +194,30 @@ module.exports = { attrs: { width: bbox.width, height: bbox.height, - x: x - bbox.width / 2, - y: y - bbox.height / 2, + x: x + bbox.x, + y: y + bbox.y, ...attrs } }); this.target.set('delegateShape', this.shape); } this.shape.set('capture', false); + } else { + if (this.targets.length > 0) { + const clientX = e.x - this.origin.x + this.originPoint.minX; + const clientY = e.y - this.origin.y + this.originPoint.minY; + this.shape.attr({ + x: clientX, + y: clientY + }); + } else if (this.target) { + this.shape.attr({ + x: x + bbox.x, + y: y + bbox.y + }); + } } - if (this.targets.length > 0) { - const clientX = e.x - this.origin.x + this.originPoint.minX; - const clientY = e.y - this.origin.y + this.originPoint.minY; - this.shape.attr({ - x: clientX, - y: clientY - }); - } else if (this.target) { - this.shape.attr({ - x: x - bbox.width / 2, - y: y - bbox.height / 2 - }); - } this.graph.paint(); }, /**