Linking tool - link gets created and is visible but isn't added to the linkDataArray

Hi,

In working on a project in which you can select different types of links to create between objects. Depending on the type of link and the types of objects you can create a link between two nodes.

The problem is that when the link is created, it isn’t added to the linkDataArray, thus it can’t be saved. Everything else works as it should. Any idea how this could occur?

Thanks,
Tim

How do you specify the different kinds of links? By setting/modifying LinkingTool.archetypeLinkData? That should have worked.

Can you give us a reproducible case of this?

yes i set the LinkingTool.archetypeLinkData.

These are the steps that are taken when selecting the tool:

  • the user selects a link to draw between two nodes.
  • the linkableFrom properties on all nodes will be set to true (default false)
  • the user clicks on a node to draw a link
  • a call will be done to the database to check whether a link can be made between the nodes (this is done for every node), if a link can be made between the nodes, the linkableTo property will be set to true.
  • the user drags a link to another node which can be linked to
  • the new link get displayed with the right template model and works just like every other link, except that it isn’t added to the linkDataArray, also the linkdrawn event is triggered.

Hope you can help,
Tim

Well, I think that the LinkingTool works correctly in all of our samples, so there must be something unusual going on in your app. Have you overridden any methods on LinkingTool?

What value did you set LinkingTool.archetypeLinkData?

So is the user unable to perform this step:

until your app has received the validity information back from your database?

Or do you allow the user to go ahead and (‘optimistically’) do the linking, and you delete it if it later turns out to be invalid?

Do you delete any link data in any code anywhere? Is that code being called for some reason in this situation?

How is the GraphLinksModel.linkDataArray being updated from the database? Might it be deleting a temporary link data object which was (improperly?) being recorded in the database?

Hi Walter,

Thanks for the quick reply:

No i have not, i only set the linkableFrom andLinkable to properties on the nodes to be able to make a link.

An entry from my linktemplateMap, the same that is used for all other links

Yes, the link can only be drawn once all of the requests have been fullfilled, so only valid links can be drawn

No i don’t, deleting a link can only be done with the ‘Del’ button

It’s only set once while loading the model, when a save is done it is only saved to the database, the current model remains unmodified.

When i catch the event thrown in the linkDrawn DiagramEvent and look at the subject it does give me an object, although event.subject.from, event.subject.to, event.subject.data, all give me undefined

Ah, the problem is that LinkingTool.archetypeLinkData should be a model link data object, not a Link.

If you do not supply a plain JavaScript object, GoJS will not know what data to copy and GraphLinksModel.addLinkData.

Yes! that worked out perfectly :).

So don’t set the archetypeLinkData like this:
linkingTool.archetypeLinkData = $(go.Link, $(go.Shape));
but like this
linkingTool.archetypeLinkData = { some_property: 'to_define' };

It’s kinda strange though that the whole operation didn’t thow any error or warnings, but just created the link that i wanted to have, and displayed it without any problems.

anyhoo,
good job troubleshooting :smile:!!
Tim

Yes, that LinkingTool property supports having a Link there so that one can have diagrams that are “unmodeled”. But to avoid confusion we do not document that.

In general we include the term “data” in both property names and method names, to indicate that model data are involved rather than GraphObjects.