Search code examples
draw2d-js

Layout and rotating a shape


Is it possible, to rotate a shape inside another shape with CenterLocator?

var shelvingCode = new draw2d.shape.basic.Label({ text: '1.01' });
myShape.add(this.shelvingCode, new draw2d.layout.locator.CenterLocator());

I tried to use the special command for it.

new draw2d.command.CommandRotate(shelvingCode , (shelvingCode .getRotationAngle() + 90) % 360);

But it seems doesn't work.


Solution

  • I realize this is an old question, but I found this when I was searching to do the same thing and think I figured it out. Thought I might help out anybody else who finds this looking for the same answer :)

    If I understand correctly, you wanted to have the label rotated inside another shape. To do this where you want it rotated 90 degrees more than it is now, you could do

    shelvingCode.rotationAngle = (shelvingCode.getRotationAngle() + 90) % 360;
    

    If you're rotating the label once it's already attached to the parent node, you'll need to put

    shelvingCode.repaint();
    

    so that it updates on the screen.