projectstorm / react-diagrams

a super simple, no-nonsense diagramming library written in react that just works
https://projectstorm.cloud/react-diagrams
MIT License
8.45k stars 1.16k forks source link

Label not at correct position while using right-angle links #726

Open agarwalishan opened 3 years ago

agarwalishan commented 3 years ago

When I am using DefaultLinkModel labels appear at correct positions as in the demo but when I am using RightAnglelinkModel labels are getting positioned to top corner probably (0,0) of the canvas. In the below pic labels for both the links appear at same coordinate (they are overlapping). Can someone please tell what could be the reason?

image

agarwalishan commented 3 years ago

@dylanvorster Any updates on this? Could you please fix it I have to use label on right angle links only.

AshishAvesta commented 3 years ago

@agarwalishan @dylanvorster Any updates on this?

maxtsh commented 3 years ago

any updates?

ntquang22298 commented 3 years ago

any updates on this? @dylanvorster or where can i custom it?

Bartel-C8 commented 3 years ago

Maybe same solution applies as described here? https://github.com/projectstorm/react-diagrams/issues/223#issuecomment-544273491

rzfzr commented 2 years ago

I'm also having issues, not solved by #223 image

ladislas14 commented 2 years ago

I still have the same issue. Does anyone have a solution ? @dylanvorster

rzfzr commented 2 years ago

I have not fully solved this, and switched away from using labels, but here is my findings:

  1. Zoom level messes up with label position for me
  2. Size for the diagram elements does also, I was having some other issue where one of the sides of the diagram did some auto routing as if it was on a edge, and the other side didn't, I fixed this by making the diagram span the whole page while showing only a viewport

Messy code as reference, https://github.com/rzfzr/mdd4/blob/main/src/pages/Editor.tsx

ladislas14 commented 2 years ago

I finally manage to find what is going wrong.

It comes from this function

https://github.com/projectstorm/react-diagrams/blob/3060496db0709c37202bca948031cd02ebcc73a7/packages/react-diagrams-core/src/entities/label/LabelWidget.tsx#L40-L64

which is used to determine the labelPosition. However, to calculate the position, it needs the renderedPaths, which is never set in RightAngleWidget due to this line:

https://github.com/projectstorm/react-diagrams/blob/3060496db0709c37202bca948031cd02ebcc73a7/packages/react-diagrams-routing/src/link/RightAngleLinkWidget.tsx#L289

Changing this line to

this.refPaths = paths.map(path => path.props.forwardRef)

solve the issue, but I'm pretty sure that it is not the best way to do it.

Maybe @dylanvorster will have an opinion :)

kosbog commented 1 year ago

Any new updates?

rzfzr commented 1 year ago

@ladislas14's solution did not work for me... I'm also noticing that the label does not move when I move the link..., only the diagram