react-diagrams icon indicating copy to clipboard operation
react-diagrams copied to clipboard

When are generateModel() methods of factories being called?

Open dberardo-com opened this issue 2 years ago • 2 comments

I am trying to implement custom node intialization based on external JSON files, which are passed at runtime.

the idea was to make use of special factories using the generateModel() callback.

I am trying to follow this example: https://github.com/projectstorm/react-diagrams/blob/dd68d1fe671925ba81d8e9e80ae6b3467e2d5c30/diagrams-demo-gallery/demos/demo-custom-node1/SimplePortFactory.ts

adapting it for node factories, but i don't see the generateModel method being called.

Where should this call happen?

Note: i am not initializing the model from a serialized diagram, but always by injecting external JSONs

dberardo-com avatar Oct 05 '21 21:10 dberardo-com

Looking for similar functionality, i.e. being able to load and render diagrams from JSON files (that are probably created offline in backend servers from some other data). It would be great to have such functionality.

KrishnaPG avatar Dec 08 '21 04:12 KrishnaPG

@KrishnaPG for my use case i have managed to set up a system whereby i have 2 different JSON objects as input of a custom Diagram component:

  • Object 1 is used to define custom Node/Link/Port classes, like (type: "custom-node-1", "custom-port-2", etc...) this object is used to define a sort of "default configuration" for the Diagram elements (Models)

  • Object 2 defines the actual list of nodes, ports and links to be used to render the Diagram, and which may override some attributes from the default classes defined by Object 1.

Both objects use a completely customized structure, but then of course the Diagram parses them using the data structure from react-diagrams.

On the surface this approach seems to work, but for now i only use it in Read only mode, because i am using Dagre for automatically position the elements, and this causes some sort of conflict each time the model is deserialized.

If my use case is something you also aim for, then i can share my solution here, but it is indeed a workaround on this issue since it seems to me that the generateModel() callback is only triggered on "deserialize()" and not when the whole Diagram is initialized ... so i could not use it for my purpose

dberardo-com avatar Dec 08 '21 13:12 dberardo-com