Giter Site home page Giter Site logo

Comments (4)

simonsarris avatar simonsarris commented on May 1, 2024

Generally, if you have two models that need to interact, you will want to set properties like makeUniqueKeyFunction and nodeKeyProperty on both of them, though there may be exceptions.

Why is the variable key for the first node not 1001?

When adding new node data, GoJS does this:

If the data.key does not exist, generate one, calling makeUniqueKeyFunction

Else, the node data has a data.key, so use that key.

Unless the key is already in the map, then call makeUniqueKeyFunction

The first node to be copied over from the palette has a key assigned (by the palette) so the "Else" is true. It does not need to call makeUniqueKeyFunction to ensure uniqueness.

The second node to be copied over from the palette has the same key assigned, so "Else" is true again, but this time the "Unless" clause is also true. Duplicate keys are not acceptable, so it calls makeUniqueKeyFunction to ensure uniqueness.

These rules are important, because if you wanted to add new nodes (perhaps from a loaded source) that have keys defined already, you would not want to destroy that data.

You could also set the makeUniqueKeyFunction on the Palette's model, so that it doesn't use its default.

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

Because you are copying data from myPalette.model, and the data looks like this:

{text: "???", figure: "Diamond", key: -3, loc: "0 110"}

So the data is copied over faithfully. Then, a key is added to that data, since it has none (since you declared the nodeKeyProperty to be "uuid" instead of "key")

GoJS will not destroy the "key" node data (or any node data), and the "key" was present in the palette, when you copy it to another model.

You could avoid that by setting nodeKeyProperty on both the Palette and the Diagram models.

from gojs.

simonsarris avatar simonsarris commented on May 1, 2024

Just so we are on the same page, when you are copying data from the palette, such as:

{"text":"???", "figure":"Diamond", "key":-3, "loc":"-121.875 -131"}

You really want to copy this instead:

{"text":"???", "figure":"Diamond", "loc":"-121.875 -131"} // no key

So that the Diagram Model is forced to make its own new key every time. Is that correct?

from gojs.

WalterNorthwoods avatar WalterNorthwoods commented on May 1, 2024

Another possibility is to leave the use of "key" as the Model.nodeKeyProperty in the Palette, and to continue to use "uuid" as the Model.nodeKeyProperty in the main Diagram, and to add this DiagramEvent listener:

            . . . ,
            "ExternalObjectsDropped": function(e) {
              e.diagram.nodes.each(function(n) {
                n.data.key = undefined;
              });
            },

from gojs.

FritzHerbers avatar FritzHerbers commented on May 1, 2024

Thx for the clarification and pointing to the existence of a generated key for the nodes in the palette diagram, which is copied over to the diagram.

I successfully used your last proposal. thx again.

from gojs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.