Page Index Toggle Pages: [1] 2  Send TopicPrint
Hot Topic (More than 10 Replies) Control points are not set when node is moved along with attached label (Read 822 times)
Kannan Thirumal
Senior Member
****
Offline


I Love Mind Fusion Diagram
:-)

Posts: 284
Location: Bangalore, India
Joined: Jan 18th, 2019
Control points are not set when node is moved along with attached label
Nov 4th, 2024 at 12:32pm
Print Post  
Hi,

I've created two nodes (Node-1, Node-2) and created a link between those two nodes. There are four control points in that link.

First I moved the Node-2 to a different location. Point 1, 2, and 3 got modified except the Point 0.

Then I moved the Node-2 along with the attached label (by selecting both node and label using ctrl key). Now, only the Point 3 got set.

May I know why the other points are not updated in this case?

Please check the attached screen shots where the control points are console logged (in Event.nodeModified).

Regards,
Kannan
  
Back to top
 
IP Logged
 
Kannan Thirumal
Senior Member
****
Offline


I Love Mind Fusion Diagram
:-)

Posts: 284
Location: Bangalore, India
Joined: Jan 18th, 2019
Re: Control points are not set when node is moved along with attached label
Reply #1 - Nov 4th, 2024 at 12:37pm
Print Post  
Hi,

I've attached the screen shots.

Regards,
Kannan
  

Link.zip ( 973 KB | 26 Downloads )
Back to top
 
IP Logged
 
Kannan Thirumal
Senior Member
****
Offline


I Love Mind Fusion Diagram
:-)

Posts: 284
Location: Bangalore, India
Joined: Jan 18th, 2019
Re: Control points are not set when node is moved along with attached label
Reply #2 - Nov 4th, 2024 at 12:38pm
Print Post  
Hi,

I've attached the sample code to simulate the issue.

Regards,
Kannan
  

Sample-Diagram.zip ( 569 KB | 40 Downloads )
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3343
Joined: Oct 19th, 2005
Re: Control points are not set when node is moved along with attached label
Reply #3 - Nov 5th, 2024 at 9:27am
Print Post  
Hi,

I can see nothing wrong by dragging the nodes in your test project, nor in screenshots. If you want link segment to keep horizontal / vertical directions during drag operation, switch link.shape to Cascading. Or let me know what you are referring to exactly.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Kannan Thirumal
Senior Member
****
Offline


I Love Mind Fusion Diagram
:-)

Posts: 284
Location: Bangalore, India
Joined: Jan 18th, 2019
Re: Control points are not set when node is moved along with attached label
Reply #4 - Nov 5th, 2024 at 10:16am
Print Post  
Hi Slavcho,

First, I moved the node by dragging the node. Second, I moved the node by dragging the node along with the attached label. In both the scenarios, the moved location is same. But the values of the control points are different. I've console logged those points in the sample app whose screen shot is attached with this.

Regards,
Kannan
  

Moved_Element_with_Attached_Label.png ( 863 KB | 26 Downloads )
Moved_Element_with_Attached_Label.png
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3343
Joined: Oct 19th, 2005
Re: Control points are not set when node is moved along with attached label
Reply #5 - Nov 6th, 2024 at 7:02am
Print Post  
The link routes are obviously the same in both screenshots. The end point has a few pixels difference because the node from left screenshot is placed further to the left than one from right screenshot (you will see it's closer to the grid line if you zoom in enough). The printed coordinates of middle points differ a lot because you print them before auto-router runs I guess.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Kannan Thirumal
Senior Member
****
Offline


I Love Mind Fusion Diagram
:-)

Posts: 284
Location: Bangalore, India
Joined: Jan 18th, 2019
Re: Control points are not set when node is moved along with attached label
Reply #6 - Nov 6th, 2024 at 7:10am
Print Post  
Hi Slavcho,

Yes, the UI control points and printed ones are different. I've taken those control points of the link in the Event.linkModified like this,

this.diagram.addEventListener(Event.linkModified, this.handleLinkModified);

this.handleLinkModified = function (sender: any, args: LinkEventArgs) {

var link = args.getLink() as any;

if (link) {
ths.consoleLinkPoints(link, "On Modify: ");
}
}

private consoleLinkPoints(link: any, message: string) {

console.log(message)

var points = link.getControlPoints();

for (var i = 0; i < points.length; i++) {
var point = points[i];
console.log("Point " + i + ": " + point.x + ", " + point.y);
}
}

Please check the attached sample code (in the previous post) to reproduce the issue.

We are storing these points in the database. When loading the diagram, the link and the control points are created based on this stored data. So, the loaded link is totally different from the one created in the ui before. May I know how to fix this issue?

Regards,
Kannan
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3343
Joined: Oct 19th, 2005
Re: Control points are not set when node is moved along with attached label
Reply #7 - Nov 6th, 2024 at 11:32am
Print Post  
Hi Kannan,

nodeModified event only indicates that user moves / resizes a node, and does not guarantee processing of auto-routed links has completed. We have LinkRouted event on other platforms that would give you access to the final auto-route coordinates, but it's not available in JavaScript version yet. We'll have in mind adding it for upcoming release.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Kannan Thirumal
Senior Member
****
Offline


I Love Mind Fusion Diagram
:-)

Posts: 284
Location: Bangalore, India
Joined: Jan 18th, 2019
Re: Control points are not set when node is moved along with attached label
Reply #8 - Nov 6th, 2024 at 11:39am
Print Post  
Hi Slavcho,

Oh sad, what is the workaround?

As I said, we need to save these control points of the link to the database so that it can be used to render the same diagram when reopened.

But, I wonder, how it works when only the node is moved? It is not working when node is moved along with the attached label (by selecting both the node and label by ctrl key pressed).

Regards,
Kannan
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3343
Joined: Oct 19th, 2005
Re: Control points are not set when node is moved along with attached label
Reply #9 - Nov 6th, 2024 at 7:56pm
Print Post  
Hi Kannan,

This build raises linkRouted event whenever auto-router is triggered -

https://mindfusion.eu/_beta/jsdiag45.zip

You could as well get the new coordinates with some delay from your several event handlers. E.g. call requestAnimationFrame from them, and the callback should run after the diagram processes current mouse up message, with all routes already calculated.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Kannan Thirumal
Senior Member
****
Offline


I Love Mind Fusion Diagram
:-)

Posts: 284
Location: Bangalore, India
Joined: Jan 18th, 2019
Re: Control points are not set when node is moved along with attached label
Reply #10 - Nov 7th, 2024 at 11:33am
Print Post  
Hi Slavcho,

Below is the existing code,

this.handleNodeModified = function (sender: any, args: any) {

  var node = args.getNode();

  var link = node.incomingLinks[0];
  if (link) {
    ths.consoleLinkPoints(link, "On Node Modify: ");
  }
}

Below is the modified code based on the suggestion from you,

    this.handleNodeModified = function (sender: any, args: any) {

      window.requestAnimationFrame(function () {
        var node = args.getNode();

        var link = node.incomingLinks[0];
        if (link) {
          ths.consoleLinkPoints(link, "On Node Modify: ");
        }
      });

I've used requestAnimationFrame to fix this issue. Is this correct? Also, is there any drawback in this approach? Thank you!

Regards,
Kannan
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3343
Joined: Oct 19th, 2005
Re: Control points are not set when node is moved along with attached label
Reply #11 - Nov 7th, 2024 at 12:46pm
Print Post  
Hi Kannan,

The linkRouted event would notify you for everything that triggers auto-routing, while with your approach you might miss some links. E.g. modifying a node recalculates routes of all links in the vicinity, and not just the ones connected to it, so looping over incomingLinks and outgoingLinks could miss some changed coordinates. Nearby links are re-routed also when users draw new nodes. If your company is too cheap to upgrade to current version, I guess it would be best to loop over all links when closing the diagram, and send their latest coordinates to the database.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Kannan Thirumal
Senior Member
****
Offline


I Love Mind Fusion Diagram
:-)

Posts: 284
Location: Bangalore, India
Joined: Jan 18th, 2019
Re: Control points are not set when node is moved along with attached label
Reply #12 - Nov 7th, 2024 at 1:27pm
Print Post  
Hi Slavcho,

We have subscribed to the Event.linkModified and doing the same in that event handler like this,

this.diagram.addEventListener(Event.linkModified, this.handleLinkModified);

    this.handleLinkModified = function (sender: any, args: LinkEventArgs) {

      window.requestAnimationFrame(function () {
        var link = args.getLink() as any;

        if (link) {
          ths.consoleLinkPoints(link, "On Link Modify: ");
        }
      });
    }

So, the other links in the vicinity should be handled here. I hope, this should be fine?

We are updating the diagram-library package through npm and we are using the latest version which is 3.5.7. Do you have any idea to update this package with linkRouted changes ?  Smiley

Regards,
Kannan
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3343
Joined: Oct 19th, 2005
Re: Control points are not set when node is moved along with attached label
Reply #13 - Nov 8th, 2024 at 6:44am
Print Post  
Hi Kannan,

That is 4-5 years old now. We have moved our libraries to a @mindfusion npm scope, the diagram is here -

https://www.npmjs.com/package/@mindfusion/diagramming

linkModified is raised only when user drags link's control point directly and won't fire for changes done by router. You might be able to detect changes done by automatic layouts and routers by replacing DiagramLink.prototype.updateFromPoints method with your own function, and updating database from it.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Kannan Thirumal
Senior Member
****
Offline


I Love Mind Fusion Diagram
:-)

Posts: 284
Location: Bangalore, India
Joined: Jan 18th, 2019
Re: Control points are not set when node is moved along with attached label
Reply #14 - Nov 8th, 2024 at 12:39pm
Print Post  
Hi Slavcho,

I tried to fix this issue using updateFromPoints . I added the below code,

        this.updateFromPoints2 = DiagramLink.prototype.updateFromPoints;
        var ths = this;
        DiagramLink.prototype.updateFromPoints = function () {
          ths.consoleLinkPoints(this, "On updateFromPoints");
          ths.updateFromPoints2();
        };

But I got the below error when the diagram loads,

app.component.ts:239 ERROR TypeError: this[b(...)] is not a function
    at AppComponent.updateFromPoints [as updateFromPoints2] (MindFusion.Diagramming.js:6:547285)
    at DiagramLink.updateFromPoints (app.component.ts:249:15)
    at arv.<computed>.validateParams (MindFusion.Diagramming.js:6:549870)
    at new arv.<computed> (MindFusion.Diagramming.js:6:524338)
    at aEN.<computed>.<computed> [as createDiagramLink] (MindFusion.Diagramming.js:6:616897)
    at AppComponent.createDiagramLink2 (app.component.ts:382:26)
    at AppComponent.drawDiagram2 (app.component.ts:362:10)
    at xhr.onload [as __zone_symbol__ON_PROPERTYload] (app.component.ts:256:14)
    at XMLHttpRequest.wrapFn (zone.js:755:39)
    at _ZoneDelegate.invokeTask (zone.js:402:31)

Am I doing anything wrong? If so, please correct me.

Regards,
Kannan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: [1] 2 
Send TopicPrint