Skip to content

Commit 16d72e4

Browse files
authored
fix the getWindowToGraphPosition function (#41)
1 parent 5b408ee commit 16d72e4

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/graph-view-node.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ class GraphViewNode {
455455
switch (event) {
456456
case 'updatePosition': {
457457
nodeView.on('element:pointerup', () => {
458-
var newPos = this._graphView.getWindowToGraphPosition(nodeView.getBBox());
458+
var newPos = this._graphView.getWindowToGraphPosition(nodeView.getBBox(), false);
459459
callback(this.nodeData.id, newPos);
460460
});
461461
break;

src/graph-view.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,17 @@ class GraphView extends JointGraph {
157157
}
158158
}
159159

160-
getWindowToGraphPosition(pos) {
160+
getWindowToGraphPosition(pos, usePaperPosition = true) {
161161
const scale = this._paper.scale().sx;
162162
const translate = this._paper.translate();
163-
const boundingClientRect = this._paper.el.getBoundingClientRect();
163+
if (usePaperPosition) {
164+
const paperPosition = this._paper.el.getBoundingClientRect();
165+
pos.x -= paperPosition.x;
166+
pos.y -= paperPosition.y;
167+
}
164168
return new Vec2(
165-
(-translate.tx / scale) + ((pos.x - boundingClientRect.x) / scale),
166-
(-translate.ty / scale) + ((pos.y - boundingClientRect.y) / scale)
169+
(-translate.tx / scale) + (pos.x / scale),
170+
(-translate.ty / scale) + (pos.y / scale)
167171
);
168172
}
169173

0 commit comments

Comments
 (0)