Reputation: 2606
So I'm wanting to dynamically build a GraphLinksModel in GoJS using addNodeData(nodedata) and addLinkData(linkdata). My issue is that I don't know what the fields of nodedata and linkdata are, other than the fields that are in example code. I can build the Node object and Link object for each of my nodes and links, but addNodeData and addLinkData don't actually want those, they want "nodedata" and "linkdata". When I try to addNodeData(Node) then I get an error.
Here are the descriptions of addNodeData(nodedata) and addLinkData(linkdata). As you can see, it just defines the parameter as an Object, with no hints, other that in the examples about what's supposed to be in it. Any direction or explanation would be appreciated.
Upvotes: 1
Views: 1024
Reputation: 63862
There are no "all", the Node data can contain anything, arbitrarily, but must contain a key
. If no key
is defined, the GoJS model will automatically assign one. In other words, if you add { }
as your node data and look at it, you'll find it is:
{ __gohashid: 1975, key: -5 }
__gohashid
is internal to GoJS and should not be modified or used. They key is unique.
You can change the uniqueness function of the model, and you can even change the keyword for key.
You can read more in the Model overview in the API.
Other than there are a few built in data properties:
category
, which specifies which Node or Link template to use, but the default is ""
and its not necessary to specify.parent
, which specifies the key of the parent Node.Any other properties you find on the Model don't mean anything unless the Diagram's Node and Link templates have data-bindings to those names. For example this template has two data bindings:
// define a simple Node template
myDiagram.nodeTemplate =
$(go.Node, "Auto", // the Shape will go around the TextBlock
$(go.Shape, "RoundedRectangle", { strokeWidth: 0},
// Shape.fill is bound to Node.data.color
new go.Binding("fill", "color")),
$(go.TextBlock,
{ margin: 8 }, // some room around the text
// TextBlock.text is bound to Node.data.key
new go.Binding("text", "key"))
);
If color
exists in the Node data, it will be used as the Shape.fill
in this Node template's Shape.
If key
exists (it has to) in the Node data, it will be used as the TextBlock.text
.
You can see that in action here: http://codepen.io/simonsarris/pen/ORwoLA?editors=1010
Let me know if you think there ought to be additional clarifications and I'll update the answer.
Upvotes: 1
Reputation: 1937
Node data is a JavaScript Object with minimum of the below formats. There can be additional property added to it based on type of object that you use.
{ "id": 1, "text": "TextToDisplay1" }
{ "id": 2, "text": "TextToDisplay2" }
The link data is again a JavaScript Object with the below format
{ "from": 1, "to": 2, "text": "Link above 1 and 2", "curviness": 20 }
'From' attribute of this object will have the From node's Id value and the same is teh case with 'to' attribute, it is 'to' nodes id.
Upvotes: 2