Link points interop with GoDiagram

Hi, I’m currently working on re-implementing our tool using GoJS. In the past we have used GoDiagram and in our GoDiagram implementation, we stored the points for links excluding the first and last point, since these could be derived from the position of the objects the link is connecting to.

In our GoJS implementation, if I don’t set the start and end point, the link appears to be unconnected at both ends. So I need to add those points. Links have a getRealPoint method, but I imagine the only time I can call that method is once the diagram is loaded. Is there a good event to hook into to call this method and set up my links? I have tried doing this after a 1/2 second timeout which is working but seems a little fragile and causes a small flicker.

Alternatively is there a way to tell GoJS to use sensible defaults for the start and end point, based on the location of the nodes and ports the link goes to? That way I can set up the points in my model data which should be more reliable.

Assuming your Link has all of the points it needs except the first and the last one, this code should work in most situations where there are 4 or more points normally in the Link, as would be the case with orthogonal links:
 function addEndPoints(link) {<br /> var pts = link.points.copy();<br /> var start = link.getLinkPointFromPoint(link.fromNode, link.fromPort, link.fromPort.getDocumentPoint(go.Spot.Center), pts.elt(0), true);<br /> var end = link.getLinkPointFromPoint(link.toNode, link.toPort, link.toPort.getDocumentPoint(go.Spot.Center), pts.elt(pts.length - 1), false);<br /> pts.insertAt(0, start);<br /> pts.add(end);<br /> link.points = pts;<br /> }
I suggest you do this to each abbreviated Link in an “InitialLayoutCompleted” DiagramEvent listener.


Thanks, I will give that a go

It’s almost working. Our documents contain multiple diagrams (but we only show one at once) so we re-use a single instance of go.Diagram. It seems that InitialLayoutCompleted only gets triggered on the very first load of the diagram, not when we change between diagrams. I call diagram.clear() then reset all the model data, should I be doing this differently to ensure the event gets triggered? Should I recreate the go.Diagram object?

Re-creating your Diagram would work, but re-using your Diagram is commonplace.

No, to load a new diagram, just set Diagram.model. All of the samples demonstrate this in functions named “load”. There are also “save” functions for those samples that support that too.

Sorry for the slow reply, I got diverted onto some other work. It looks like your suggestion did the trick. I can now edit in our web client and open in the desktop version and edit in the desktop and open in the web with all links in their correct place. Thanks!

That’s great!