anseki / leader-line

Draw a leader line in your web page.
http://anseki.github.io/leader-line/
MIT License
3.03k stars 425 forks source link

Relative Directional Offset from pointAnchor #355

Closed Mochnant closed 2 years ago

Mochnant commented 2 years ago

Is there a way to have a relative offset from an anchor point that is controlled by the direction of the incoming lines?

My usecase is setting a single pointAnchor in the middle of an element and drawing arrows to this pointAnchor from various directions. What happens now is all the arrows lay over each other and it looks bad.

I know I can offset the line but it seems to require an x,y value which doesn't work when I don't know what direction the line is coming from.

What I would like is this:

Thanks for the help and the wonderful library!

anseki commented 2 years ago

Hi @Mochnant, thank you for the comment. Sorry, my English is poor. Do you mean that you want to make blank space between the head of a line and the end point?

Mochnant commented 2 years ago

Yes, you have it exactly. The problem is that I can’t find a way to make it relative to the direction of the line, which is unknown until runtime.

anseki commented 2 years ago

If the lines are straight, you can get the coordinates easily by using Math.cos/sin methods. For example: https://jsfiddle.net/kqzscm7o/ All you need is the getEndPoint function.

Mochnant commented 2 years ago

Thanks for the example, @anseki! Might I suggest this would be a useful feature to add to the core library?

anseki commented 2 years ago

I'm glad if I could help you. :smile: That feature is not added to the LeaderLine because that is not required in many cases and you can do that very easily by using cos/sin methods, any library is not required for that. So, could you close this issue if it was solved?

Mochnant commented 2 years ago

Certainly, and thanks, though by that logic many features of the library could be done in other ways! I think there is a place for convenience in any library, too.