On deactivated event?

Is it possible to detect when a LinkingTool doDeactivate() method has finished if no link has been drawn (i.e. the user has quit drawing the link)?
I’m asking because I want to remove some LinkLabel nodes in case the user quits drawing the link.

I know that a RolledBackTransaction occurs, but from the documentation: “As a general rule, you should not make any changes to the model or any of its data in a listener for any Transaction ChangedEvent.”

Override LinkingTool | GoJS API.

For some reason, I am unable to remove a link label node from the model. This is my code:

  LinkLabelLinkingTool.prototype.doNoLink = function (fromNode, fromPort, toNode, toPort) {

                if (fromNode.category !== 'LinkLabel') return;

                if (fromNode !== null) {

                    let diagram = fromNode.diagram;
                    let model = diagram.model;

                    let targetKey = fromNode.data.key;

                    // need to find the actual link on which the LinkLabel node is located
                    let link = undefined;
                    diagram.links.each(l => {

                        if (l.data !== null && _.some(l.data.labelKeys, k => k === targetKey)) {

                            link = l;

                    model.removeLabelKeyForLinkData(link.data, fromNode.data.key);


The LinkLabel node is still present on the link after it should have been removed. Also, in the console.log - it initially displays an array of 2 elements (which should be correct), but upon expanding, it shows also the node that should have been removed…,

I’ve made a small screen recording to show this, it can be downloaded from here.

Given a Node that Node.isLinkLabel you can get the Link via Node | GoJS API.

It might be easiest to call Diagram.remove on the fromNode.

Unfortunately, I can still see the node that acts as the linkLabel… Should the Link.data.LabelKeys property be equal to [null] when the only linkLabel is removed?

I just tried selecting a link in Links to Links, and then:

var link = myDiagram.selection.first();
var src = link.labelNodes.first();

And sure enough both the label Node on that Link disappeared, along with the Link that I had drawn earlier coming out of that label node.

And a “save” confirmed that that label node had been removed from the Model.nodeDataArray and that its key had been removed from the link data’s “labelKeys” Array.

Hm… strange… I just checked if maybe a new node was being accidentally created, but it doesn’t seem so…
Apart from setting

workspaceDiagram.model.linkLabelKeysProperty = ‘labelKeys’;
Are there any other settings I should have set?

        function LinkLabelLinkingTool() {

        go.Diagram.inherit(LinkLabelLinkingTool, go.LinkingTool);

        LinkLabelLinkingTool.prototype.doNoLink = function (fromNode, fromPort, toNode, toPort) {

            if (fromNode.category !== 'LinkLabel') return;

            if (fromNode !== null) {

                let diagram = fromNode.diagram;

That’s better. But you didn’t read LinkingTool | GoJS API.

By default it assumes that doNoLink doesn’t have any side-effects within the Diagram. So you need to set:

      this.transactionResult = "removed label node";

or to some other string value so that your side-effects aren’t automatically rolled-back, as part of the usual cleanup.

I just noticed I haven’t read the documentation carefully… sorry