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

ParallelMidpointLocator doesn't rotate figures inside the label #255

Open
ittayd opened this issue Jan 12, 2025 · 3 comments
Open

ParallelMidpointLocator doesn't rotate figures inside the label #255

ittayd opened this issue Jan 12, 2025 · 3 comments

Comments

@ittayd
Copy link

ittayd commented Jan 12, 2025

If I have a label and I add another figure to it. The label is rotated by the locator. But, the figure inside it remains in place (or, more likely, the locator associated with it, places it according to the old label placement).

I think that in general, the best approach is for each figure to have a local coordinate space and then child figures are placed in this space and to draw them globally, any matrix that applies to the figure is applied to them as well (and recursively if that figure is inside another)

@ittayd
Copy link
Author

ittayd commented Jan 13, 2025

I did this which rotates the figures:

if (!draw2d.Figure.injected) {
  let prev = draw2d.Figure.prototype.setRotationAngle
  draw2d.Figure.inject({
    setRotationAngle: function(angle) {
console.log('rotating', this)
      const ret = prev.apply(this, [angle])
      this.children.each((i, e) =>  e.figure.setRotationAngle(angle))
      return ret
    },
  })

draw2d.Figure.injected = true
}

But in my case, the locator is LeftLocator which uses setPosition which is absolute. Seems like there should be an applyConsiderRotation method (taken from PortLocator) that all locators use instead of setPosition.

@ittayd
Copy link
Author

ittayd commented Jan 13, 2025

I tried to use applyConsiderRotation instead of setPosition in LeftLocator. It doesn't work. The reason is that it calculates the offset according to the parent's bounding box that is in absolute space.

@ittayd
Copy link
Author

ittayd commented Jan 14, 2025

I ended up creating these patches to LeftLocator and TopLocator. I achieved them using trial & error, and they work only for a 90 angle rotation.

LeftLocator:

 relocate: function (index, target) {
       const parent = target.getParent();
       if (parent.getRotationAngle() == 90) {
         const boundingBox = parent.getBoundingBox()
         let targetBoundingBox = target.getBoundingBox()

         target.setPosition(boundingBox.w / 2 - (targetBoundingBox.w / 2), -(boundingBox.w/2 + 2))
         //target.repaint()
         return;
       }
       return originals.leftRelocate.apply(this, [index, target])
}

TopLocator:

relocate: function (index, target) {
       const parent = target.getParent();
       if (parent.getRotationAngle() == 90) {
         const boundingBox = parent.getBoundingBox()
         let targetBoundingBox = target.getBoundingBox()

         target.setPosition(-(targetBoundingBox.w/2 - boundingBox.w/2) -  targetBoundingBox.h/2 - 4, 0)
         //target.repaint()
         return;
       }
       return originals.bottomRelocate.apply(this, [index, target])
}

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

1 participant