-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
link far end aligns with the mouse pointer position #469
link far end aligns with the mouse pointer position #469
Conversation
@dylanvorster running |
a1f0d5b
to
a3ca75d
Compare
@@ -56,6 +60,9 @@ export class DragNewLinkState extends AbstractDisplacementState<DiagramEngine> { | |||
this.link.setSourcePort(this.port); | |||
this.engine.getModel().addLink(this.link); | |||
this.port.reportPosition(); | |||
|
|||
// save the mouse position for further precision in calculating the link's far-end point | |||
this.startingPoint = new Point(event.event.clientX, event.event.clientY); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The AbstractDisplacementState already contains this data in the abstract class :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The AbstractDisplacementState already contains this data in the abstract class :)
that's brilliant!
I'm going to update the PR, thank you for the tip ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dylanvorster MR updated! ;)
67a3227
to
ea6130d
Compare
Ok I've better looked into it (and I apologise I haven't done it before) @mathiasbaldissera is right, apparently it works most of the time: but sometimes it doesn't: I can't really understand why and I'll try to figure out as soon as possible... any suggestion @dylanvorster ? |
@antonioru Using the initialXRelative and initialYRelative less the canvas offset worked to me const pos = this.port.getPosition()
const linkNextPosX =
pos.x + (this.initialXRelative - this.engine.getModel().getOffsetX() - pos.x) + event.virtualDisplacementX
const linkNextPosY =
pos.y + (this.initialYRelative - this.engine.getModel().getOffsetY() - pos.y) + event.virtualDisplacementY
this.link.getLastPoint().setPosition(linkNextPosX, linkNextPosY) |
It doesn't work for me, it doesn't show the link at all |
3b70531
to
6dd0677
Compare
@mathiasbaldissera @dylanvorster Ok, I've updated the PR by using the relative coordinates (initialXRelative, initialYRelative) instead of the absolute ones (initialX, initialY) and it works for be every time now. Please Mathias let me know if you find any other problem. The code I've updated is the following:
I hope it helps :) Thank you guys, you've been really helpful |
If u use only the relative coordinates, and move the canvas (generating an offsetX and offsetY to the canvas) it'll bug, did u try it? |
I see your point, so the engine offset must be taken into account as well ... |
this seems to finally work even when you move the canvas :)
|
I'll try it at the afternoon (now i'ts 11:12 here :v) |
hehe, take your time mate, I'll update the PR in the meanwhile :) |
@antonioru 1 question. How did you exactly run the demos? Every time I try to run i got erros, and I need to test the changes into my own projects (I didn't find you on Facebook to ask this question hehehe :v) |
i think it's all reported into the doc somewhere |
I really forgot to run the |
It work perfectly now ;) |
So it just needs to be merged :)) Thank you @mathiasbaldissera, you really helped me out |
what a journey xD |
Checklist
yarn run pretty
What?
The
DragNewLinkState.fireMouseMoved
method was not taking into account the click starting position when dragging a new link, it just assumes it's the same point (x,y) of the link port. Sometimes, especially with big ports, it causes a slight mismatch between the link far end point and the mouse position as reported in the issue #467How?
I saved the mouse starting position within the
DragNewLinkState
class itself.Feel good image:
(Add your own one below :])