Skip to content

Commit

Permalink
fix mouse x,y calculations when diagram is in scrolled element
Browse files Browse the repository at this point in the history
  • Loading branch information
gwenaelp committed Mar 23, 2023
1 parent 5400fbf commit b219278
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/components/Diagram.vue
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,8 @@ const generateId = () => {
const getAbsoluteXY = (element) => {
var viewportElement = document.documentElement;
var box = element.getBoundingClientRect();
var scrollLeft = viewportElement.scrollLeft;
var scrollTop = viewportElement.scrollTop;
var x = box.left + scrollLeft;
var y = box.top + scrollTop;
var x = box.left;
var y = box.top;
return { x, y };
}
Expand Down Expand Up @@ -285,7 +283,7 @@ export default {
let rootelt = document.getElementById('svgroot2');
let rec = document.getElementById('viewport');
let point = rootelt.createSVGPoint();
let rooteltPosition = getAbsoluteXY(rootelt);
let rooteltPosition = getAbsoluteXY(this.$el);
point.x = x - rooteltPosition.x;
point.y = y - rooteltPosition.y;
let ctm = rec.getCTM().inverse();
Expand Down Expand Up @@ -373,16 +371,16 @@ export default {
if (!this.editable) return;
const links = this.model._model.links;
this.mouseX = pos.x;
this.mouseY = pos.y;
const bbox = this.$el.getBoundingClientRect();
this.mouseX = pos.clientX;
this.mouseY = pos.clientY;
this.viewportMousePos = this.convertXYtoViewPort(pos.x, pos.y);
if (this.mode === 'move') {
if (this.draggedItem) {
const index = this.draggedItem.index;
const type = this.draggedItem.type;
let coords = this.convertXYtoViewPort(this.mouseX, this.mouseY);
coords.x = snapToGrip(coords.x, this.gridSnap) - this.gridSnap / 2;
coords.y = snapToGrip(coords.y, this.gridSnap);
Expand Down

0 comments on commit b219278

Please sign in to comment.