Skip to content

Commit

Permalink
Group position numeric origins (#5143)
Browse files Browse the repository at this point in the history
* fixed positioning

* fixed positioning

* ok tests are ok

* ok tests are ok
  • Loading branch information
asturur authored Aug 5, 2018
1 parent c541a27 commit 133c674
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 35 deletions.
35 changes: 7 additions & 28 deletions src/shapes/group.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,6 @@
this._objects[i].group = this;
}

if (options.originX) {
this.originX = options.originX;
}
if (options.originY) {
this.originY = options.originY;
}

if (!isAlreadyGrouped) {
var center = options && options.centerPoint;
// if coming from svg i do not want to calc bounds.
Expand Down Expand Up @@ -489,7 +482,7 @@
}
}

this.set(this._getBounds(aX, aY, onlyWidthHeight));
this._getBounds(aX, aY, onlyWidthHeight);
},

/**
Expand All @@ -498,28 +491,14 @@
_getBounds: function(aX, aY, onlyWidthHeight) {
var minXY = new fabric.Point(min(aX), min(aY)),
maxXY = new fabric.Point(max(aX), max(aY)),
obj = {
width: (maxXY.x - minXY.x) || 0,
height: (maxXY.y - minXY.y) || 0
};

top = minXY.y || 0, left = minXY.x || 0,
width = (maxXY.x - minXY.x) || 0,
height = (maxXY.y - minXY.y) || 0;
this.width = width;
this.height = height;
if (!onlyWidthHeight) {
obj.left = minXY.x || 0;
obj.top = minXY.y || 0;
if (this.originX === 'center') {
obj.left += obj.width / 2;
}
if (this.originX === 'right') {
obj.left += obj.width;
}
if (this.originY === 'center') {
obj.top += obj.height / 2;
}
if (this.originY === 'bottom') {
obj.top += obj.height;
}
this.setPositionByOrigin({ x: left, y: top }, 'left', 'top');
}
return obj;
},

/* _TO_SVG_START_ */
Expand Down
14 changes: 7 additions & 7 deletions test/unit/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,13 @@
strokeWidth: 0
}];
var expectedObject = {
'version': fabric.version,
'type': 'group',
'left': 50,
'top': 100,
'width': 80,
'height': 60,
'objects': objects
version: fabric.version,
type: 'group',
left: 50,
top: 100,
width: 80,
height: 60,
objects: objects
};
assert.deepEqual(clone, expectedObject);
});
Expand Down

0 comments on commit 133c674

Please sign in to comment.