Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent shape positions #487

Closed
fxdave opened this issue Nov 5, 2018 · 6 comments
Closed

Inconsistent shape positions #487

fxdave opened this issue Nov 5, 2018 · 6 comments

Comments

@fxdave
Copy link

fxdave commented Nov 5, 2018

The problem:

Shapes eg. reactangle, circle, ellipse are default to an inconsistent position.
Circles and ellipses are centered, but rectangle is not.

Why is it a problem?

Try to find the absolute position of a random shape's top left corner.
You couldn't because of this.

@lavrton
Copy link
Member

lavrton commented Nov 5, 2018

You are right. That behavior is not consistent. But it is the most convenient to use. To find bounding box of any shape you can use shape.getClientRect().

@lavrton lavrton closed this as completed Nov 5, 2018
@TheGrandmother
Copy link

TheGrandmother commented Jan 9, 2019

Is it possible to move an object by moving it by its client rectangle some how?
Being able to work with a rectangles center coordinates would make life much easier when rotations are involved.

And things are made very confusing as the Transformer rotates an object around its center but changes its position :/

@lavrton
Copy link
Member

lavrton commented Jan 10, 2019

@TheGrandmother

By default position of a rectangle is its top-left corner. So it should be expected that on rotation with Transformer it will change its position too.

If you want to see the center of the rectangle as its position, you need to change its origin with offset.

For more info see: https://konvajs.github.io/docs/posts/Position_vs_Offset.html

const rect = new Konva.Rect({
  x: 100,
  y: 100,
  width: 50,
  height: 50,
  offsetX: 25,
  offsetY: 25,
  fill: 'green'
});
layer.add(rect);


layer.add(new Konva.Transformer({
  node: rect
}))

rect.on('transform', () => {
  console.log(rect.x(), rect.y());
})

https://jsbin.com/xagihujuxa/1/edit?html,js,console,output

@TheGrandmother
Copy link

@lavrton
Thanks for the offset thingy! Had no idea :) But will the offset scale with the scaleX and scaleY?

@lavrton
Copy link
Member

lavrton commented Jan 10, 2019

Try and see how it works.

@TheGrandmother
Copy link

Completely missed the jsbin link. It works perfectly, thanks a lot for the help and sorry for being a top tier wanker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants