Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

makeUniqueKeyFunction is not called for first node of a template #19

Closed
FritzHerbers opened this issue Apr 25, 2016 · 3 comments
Closed
Labels
question; belongs in forum This isn't an issue with GoJS, so doesn't belong here -- post at https://forum.nwoods.com/c/gojs/11

Comments

@FritzHerbers
Copy link

FritzHerbers commented Apr 25, 2016

We adapted load() from the workflow sample to generate unique UUIDs (similar to stateChartIncremental sample).

  function load() {
      var model = go.Model.fromJson(document.getElementById("mySavedModel").value);

      model.makeUniqueKeyFunction = function (model, data) {
          var uuid = new UUID(4).format(); //pure-uuid
          data.uuid = uuid;
          return uuid;
      };

      model.makeUniqueLinkKeyFunction = function (model, data) {
          var uuid = new UUID(4).format(); //pure-uuid
          data.uuid = uuid;
          return uuid;
      };

      myDiagram.model = model;
  }

Now we noticed that for the first node of a specific template the function is never called.

For the stateChartIncremental this would mean that the additional data.id for every first node of a specific template when taken from a palette would not be set.

{ "class": "go.GraphLinksModel",
  "linkFromPortIdProperty": "fromPort",
  "linkToPortIdProperty": "toPort",
  "nodeDataArray": [ 
{"category":"Start", "text":"Start", "key":-1, "loc":"-380 -280"},
{"category":"Start", "text":"Start", "key":"addc329b-6e0e-4867-b257-895cf7284731", "loc":"-40 -180", "uuid":"addc329b-6e0e-4867-b257-895cf7284731"},
{"category":"Comment", "text":"Comment", "key":-8, "loc":"-180 120"},
{"category":"Comment", "text":"Comment", "key":"92b4479c-ee2e-4a1c-afdd-3fb111be6382", "loc":"120 100", "uuid":"92b4479c-ee2e-4a1c-afdd-3fb111be6382"}
 ],
  "linkDataArray": []}

Did some further testing:
It seems to be dependent on the nodeKeyProperty. When set the function is called.

When adding to the model

  "nodeKeyProperty": "uuid",
  "linkKeyProperty": "uuid",
{ "class": "go.GraphLinksModel",
  "nodeKeyProperty": "uuid",
  "linkKeyProperty": "uuid",
  "linkFromPortIdProperty": "fromPort",
  "linkToPortIdProperty": "toPort",
  "nodeDataArray": [ 
{"category":"Start", "text":"Start", "key":-1, "loc":"-300 -180", "uuid":"a7d3e978-5042-4da5-95af-464eb4c9c420"},
{"category":"RunClass", "text":"RunClass ...", "key":-2, "loc":"-300 40", "uuid":"fac335a8-34ec-49e9-a1c7-e9f2f6966e70"},
{"category":"Start", "text":"Start", "key":-1, "loc":"120 -180", "uuid":"fcf834e2-e7da-45d7-83a7-9695f4a66214"},
{"category":"RunClass", "text":"RunClass ...", "key":-2, "loc":"160 40", "uuid":"fbd7798a-117b-4ded-8c1e-d9eb989cc769"}
 ],
  "linkDataArray": [ 
{"from":"a7d3e978-5042-4da5-95af-464eb4c9c420", "to":"fac335a8-34ec-49e9-a1c7-e9f2f6966e70", "fromPort":"B", "toPort":"T", "uuid":"793d60d4-e5f3-4146-aac9-d235a6d18859", "points":[-300,-140,-300,-130,-300,-60,-300,-60,-300,10,-300,20]},
{"from":"fcf834e2-e7da-45d7-83a7-9695f4a66214", "to":"fbd7798a-117b-4ded-8c1e-d9eb989cc769", "fromPort":"B", "toPort":"L", "uuid":"d04e2a90-0646-457e-9315-c6edf40884ce", "points":[120,-140,120,-130,120,-59,50,-59,50,40,60,40]}
 ]}

the function gets called, but it is unclear why there is also a "key" saved, which is even not unique.

@WalterNorthwoods
Copy link
Contributor

It sounds like your new node data object already has a key property declared on it. Search for "key" in your sources.

When loading a node data object, if the key is not undefined and is already unique, it is kept and the Model.makeUniqueKeyFunction should not be called. After all, if you are loading data that already has keys defined, you would not want to replace them with new keys, thereby losing information from the model.

Note how everything seemed to work well once you used a different Model.nodeKeyProperty name. That is because none of the node data objects already had values for that property.

@WalterNorthwoods
Copy link
Contributor

By the way, the Model.makeUniqueKeyFunction does not need to modify the data object. This should also work:

model.makeUniqueKeyFunction = function() { return new UUID(4).format(); };

@simonsarris
Copy link
Collaborator

simonsarris commented Apr 29, 2016

Going to close out this issue. Please contact us (email - gojs (at) nwoods.com, or at our forum) if support related. Or you can open a new issue if you still believe there is a bug.

@WalterNorthwoods WalterNorthwoods added the question; belongs in forum This isn't an issue with GoJS, so doesn't belong here -- post at https://forum.nwoods.com/c/gojs/11 label Oct 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question; belongs in forum This isn't an issue with GoJS, so doesn't belong here -- post at https://forum.nwoods.com/c/gojs/11
Projects
None yet
Development

No branches or pull requests

3 participants