Link Disconnect

Hello everyone,

I need a help.
How to handle link disconnected event?
Maybe I think it is impossible am I right?

What do you mean by disconnect?

You can handle deleted objects with DiagramEvents: DiagramEvent | GoJS API

or similarly with the “LinkRelinked” Diagram event.

Dear Simon,

Thank you for reply,
I want to know opposite event of “LinkDrawn”.
I mean when we delete 2 nodes connection.

There is no event that is the opposite of the “LinkDrawn” DiagramEvent. Links can be removed for several reasons in several manners.

The “LinkDrawn” DiagramEvent is raised when the user has successfully drawn a new link by the LinkingTool. Perhaps the closest to the opposite of that would be the “SelectionDeleted” DiagramEvent when the user had selected that Link. However, if the user deletes a Node, all Links connecting with that Node will be removed as well.

A more reliable way to find out when a link has been removed is to implement a ModelChanged listener. To get a log of all Model changes, you can try:

myDiagram.addModelChangedListener(e => console.log(e.toString()))

When the user deletes a node, that might produce results such as:

*  StartedTransaction:  Delete 
!mChangedEvent.Remove linkDataArray:  GraphLinksModel  old: [object Object] 0 
!mChangedEvent.Remove linkDataArray:  GraphLinksModel  old: [object Object] 1 
!mChangedEvent.Remove nodeDataArray:  GraphLinksModel  old: Beta 1 
*  CommittingTransaction:  Delete 
*  CommittedTransaction:  Delete

Note how there are two cases of removing a link data object from the GraphLinksModel.linkDataArray.

So perhaps you can get what you want by:

myDiagram.addModelChangedListener(function(e) {
    if (e.change === go.ChangedEvent.Remove && e.propertyName === "linkDataArray") {

Note that that won’t handle removals due to undo or redo. I don’t know if you care about that.

See also the Update Demo, Update Demo GoJS Sample, which goes into these matters in more detail.

Thank you Dear Walter

I solved my problem according to your advise.
Great solution.

Hi @walter: What do you suggest if one cares about undo/redo?

This section of the Introduction shows two examples similar to your requirement: GoJS Changed Events -- Northwoods Software