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

How to bind PortWidget with PortModel

Open sjw441500 opened this issue 7 years ago • 5 comments

Hi dylanvorster, Thank you a lot for creating such an awesome project. Recently I got some problems on binding PortWidget with PortModel.Here is the scenario in detail.I use version 5.2.1. I create a data list in the NodeModel and each data item has a corresponding port.They will show in the node in one column.I add PortModel using addPort() and generate PortWidget in NodeWidget.For some reason I need to sort or reorder the data list where the port position should also change.But the port order will mess up then.For example,I have a list [data1,data2,data3,...] and data1 has a port connected to other node.After reorder,the list becomes [data2,data1,data3] and now the data2 is connected which should still be data1.I think this may because I only change the PortWidget order but the PortModel order somehow does not change at all.I just wonder if I can bind widget with model in somewhere,maybe in PortFactory? I will appreciate it if anyone can help me with this.

sjw441500 avatar Sep 17 '19 17:09 sjw441500

Widget is rendered representation of model, if you order of elements should be changed it must be done in the model not in the widget

alex-enchi avatar Sep 17 '19 18:09 alex-enchi

Widget is rendered representation of model, if you order of elements should be changed it must be done in the model not in the widget

Thank you a lot for your reply.Basically I change the element order in model.I just want to bind each data element with one specific port so that it can always be linked to no matter how the order changes.

sjw441500 avatar Sep 18 '19 15:09 sjw441500

I haven't used v5 but I do recall an issue on here that might be related. Someone had an issue that when deleting a port in a set of of ports, the links were no longer pointing to the correct port. The issue there was that although the data in the model was correct (portA linked to portB with linkC) the actual rendered link had not been updated and it appeared to be wrong. Simply refreshing/redrawing the diagram would show the correct links.

It might be that your issue could be related. You might need to refresh/redraw the diagram if you aren't doing it after the reordering.

David-Melo avatar Sep 18 '19 20:09 David-Melo

I haven't used v5 but I do recall an issue on here that might be related. Someone had an issue that when deleting a port in a set of of ports, the links were no longer pointing to the correct port. The issue there was that although the data in the model was correct (portA linked to portB with linkC) the actual rendered link had not been updated and it appeared to be wrong. Simply refreshing/redrawing the diagram would show the correct links.

It might be that your issue could be related. You might need to refresh/redraw the diagram if you aren't doing it after the reordering.

Thank you for your suggestion.I tried redraw it using engine.setDiagramModel,engine.repaintCanvas(),and forceUpdate my node widget,and the Link was still linked to the wrong port.

sjw441500 avatar Sep 20 '19 19:09 sjw441500

@sjw441500 Did you apply a key={somePortId} to the widget in your port output? If react cannot identify which port actually changed it could create the effect you are describing?

Irrelon avatar Jun 29 '20 14:06 Irrelon