0

Similar to How to add Node data and Link data dynamically in GoJS?, but I want to handle the user adding a link by adding one of my custom objects. In other words, at setup time, I have the following:

   customArray: MyModel[] = getMyLinkArray();
   this.diagram.model.addLinkDataCollection(customArray)

Now when the user goes to add a link, I want to add a link that is derived from a MyModel object I will supply. It should get the gojs properties added in the same way as is done in addLinkDataCollection.

Presumably this means I should intercept a call somewhere, supply my model object, and tell gojs to use that. But I'm not sure what to intercept, how, or even if it is possible.

Can I do that?

Anonymous
  • 23
  • 1
  • 3

1 Answers1

0

Set https://gojs.net/latest/api/symbols/LinkingTool.html#archetypeLinkData to an instance of MyModel with the property values that you want all new link data to have. You can set this when you initialize the Diagram.

  $(go.Diagram, . . .,
    { . . .,
      "linkingTool.archetypeLinkData": new MyModel()
    })

Set https://gojs.net/latest/api/symbols/GraphLinksModel.html#copyLinkDataFunction to a function that takes and returns a copy of MyModel. You will need to set this on each new model that you load.

  var m = go.Model.fromJson(...);
  m.copyLinkDataFunction = function(d) { return ...; };
  myDiagram.model = m;

I do suggest renaming the class to be something like MyLinkModel.

Walter Northwoods
  • 4,061
  • 2
  • 10
  • 16