React-diagrams: More complex examples / docs / guides

Created on 4 Mar 2017  路  6Comments  路  Source: projectstorm/react-diagrams

A project is look very good.
I have to create something more like on you first images. Different types of ports and nodes.
What the best way to extend default ones?

Most helpful comment

My $0.02, since I've been called in:

Basically, what's core to understanding the lib (and feel free to correct me @dylanvorster, I'm still kinda learning it :D) is this:

  1. If you're familiar with MVC, it's kind of like that, with all the Widget classes being the View layer and Models are, sliiightly contrary to their name, something in-between actual Models and Controllers, depending on how you want to play it. @dylanvorster seems particularly keen on giving you the freedom to make the call which of the two do you want them to be.
  2. DiagramEngine is the main thing running the show, with its DiagramModel (which is baked in, you can access it via getDiagramModel() or just substitute your own. This is where you'll add factories that are what binds models and widgets together.
  3. Factories, by default work like this: your node models (nodels, if you will?) each have a nodeType (which is a string). DiagramModel uses that type to pick which factory to use. Then, when you add a new node to the model, it's gonna use the factory's generateReactWidget method to actually deliver the widget. Do note, so as not to make my mistake, that multiple nodels can have the same type, with the logic dedicated to deciding which widget to pick might be delegated elsewhere: to the factory, or where have you.
  4. Don't sweat factories too much. Just get a good base going (e.g. by taking my advice above and not making too many specialized ones), and the majority of work you'll be doing with the lib will be in nodels and widgets anyway.

Apologies if the above is _too_ ranting and chaotic, I've scarcely had any sleep last night :D

Anyway, if you have any questions, don't hesitate to ask them, @gen4sp (or anyone i suppose) :)

All 6 comments

the best way to learn how to create your own nodes is to take a look at the default folder. I do plan to make guides and docs, I just don't have too much time at the moment. But more to the point: the best way would be to create your own NodeModel (like MyNewNodeModel extends NodeModel) and then to register a WidgetFactory that knows how to render that type. I will provide a 'demo3' folder now that shows how to create custom nodes and models. In the mean time, please check out https://github.com/mwozniczak/adventure-weave by @mwozniczak who has been pushing me for quite a few of these things (thanks @mwozniczak for all the support thus far :) ). I am also willing to help on bitter if you need some assistance :)

I just added a demo3 folder which shows a more complex example on how to really extend this library as intended, it created a diamond node, that has 4 inputs at each corner.

Awesome, thanks!

My $0.02, since I've been called in:

Basically, what's core to understanding the lib (and feel free to correct me @dylanvorster, I'm still kinda learning it :D) is this:

  1. If you're familiar with MVC, it's kind of like that, with all the Widget classes being the View layer and Models are, sliiightly contrary to their name, something in-between actual Models and Controllers, depending on how you want to play it. @dylanvorster seems particularly keen on giving you the freedom to make the call which of the two do you want them to be.
  2. DiagramEngine is the main thing running the show, with its DiagramModel (which is baked in, you can access it via getDiagramModel() or just substitute your own. This is where you'll add factories that are what binds models and widgets together.
  3. Factories, by default work like this: your node models (nodels, if you will?) each have a nodeType (which is a string). DiagramModel uses that type to pick which factory to use. Then, when you add a new node to the model, it's gonna use the factory's generateReactWidget method to actually deliver the widget. Do note, so as not to make my mistake, that multiple nodels can have the same type, with the logic dedicated to deciding which widget to pick might be delegated elsewhere: to the factory, or where have you.
  4. Don't sweat factories too much. Just get a good base going (e.g. by taking my advice above and not making too many specialized ones), and the majority of work you'll be doing with the lib will be in nodels and widgets anyway.

Apologies if the above is _too_ ranting and chaotic, I've scarcely had any sleep last night :D

Anyway, if you have any questions, don't hesitate to ask them, @gen4sp (or anyone i suppose) :)

I kind of one to pin this until I can get some guides going o_o

Well, by all means :D

Was this page helpful?
0 / 5 - 0 ratings

Related issues

abhijitnandy2011 picture abhijitnandy2011  路  3Comments

quangas picture quangas  路  3Comments

affanshahid picture affanshahid  路  3Comments

schecter22107 picture schecter22107  路  3Comments

kmannislands picture kmannislands  路  3Comments