projectstorm / react-diagrams

a super simple, no-nonsense diagramming library written in react that just works
https://projectstorm.cloud/react-diagrams
MIT License
8.46k stars 1.16k forks source link

When are generateModel() methods of factories being called? #890

Open dberardo-com opened 2 years ago

dberardo-com commented 2 years ago

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

KrishnaPG commented 2 years ago

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.

dberardo-com commented 2 years ago

@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:

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