Help SOS: Bounding Box is messing up with group.addWithUpdate() when scaled #10233
Unanswered
kartiksolanki
asked this question in
Q&A
Replies: 1 comment
-
please make examples editable if you want other people to get engaged and help you |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have fabricjs canvas with arrow like this:
addArrow() {
const centerCanvas = this.getZoomedCenter();
const arrowLength = 100;
const arrowHeadSize = 15;
const arrId = 123;
}
On mouse:down event, I am make the selection of that arrow group like this:
enableArrowAdjustment (obj) {
this.canvas.setActiveObject(obj);
let selection = this.canvas.getActiveObject();
selection.set({
hasBorders: true,
hasControls: true,
lockScalingFlip: true,
lockRotation: false,
centeredRotation: true,
cornerStyle: 'circle',
transparentCorners: false,
borderOpacityWhenMoving: 1,
cornerSize: 7,
padding: 10,
cornerStrokeColor: '#FFF',
cornerColor: '#FFF',
borderColor: '#FFF',
hoverCursor:'default',
centeredScaling: false,
editingBorderColor: '#92949c'
}).setControlsVisibility({
mtr: true, mt: false, mb: false, ml: true, mr: false, bl: false, br: false, tl: false, tr: false
});
this.canvas.renderAll();
}
Now when i try to scale the arrow group, I am scaling only arrowBody and unscaling the arrowHead like this:
var group = this.canvas.getActiveObject();
var arrowHead = group.getObjects()[1];
var groupScaleX = group.scaleX;
var groupScaleY = group.scaleY;
arrowHead.set({
scaleX: 1 / groupScaleX,
scaleY: 1 / groupScaleY
}).setCoords();
group.set({
shapeScaleX: groupScaleX,
shapeScaleY: groupScaleY
}).setCoords();
//Update the group (messes up the bounding box when rotated)
group.addWithUpdate();
this.canvas.renderAll();
this.detailObserver(group);
While this scaling works flawlessly and it scales only the arrow body but when i rotate my arrow group, and then try to scale the arrow body, the bounding box i turning into square and it skews the arrow instead of scaling arrow body.
Any idea what am i doing wrong?
Beta Was this translation helpful? Give feedback.
All reactions