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

How to pass data from widget to node?

Open sedulka opened this issue 7 years ago • 8 comments

I have trouble with passing data from widget to node. I have textfield in my widget and I need to pass the text that is inputed to the node so that that text appears there while user prints text. I used demo and just added this features. Is it possible to pass data from there to the node?

sedulka avatar Jul 15 '19 08:07 sedulka

I did it by implementing my own NodeFactory. I think DiamondNode demo (Demo 3) should demonstrate this. Anyways I can post an example later today

JokerNN avatar Jul 15 '19 09:07 JokerNN

@JokerNN would you mind posting an example using JSX? I can't make custom nodes work #281

drummerjolev avatar Jul 15 '19 11:07 drummerjolev

Hey @sedulka, I think I misunderstood your question first time, so I didn't really do it before :) However I think I know what can be done, so Im fiddling in codesandbox and let's see how it goes

JokerNN avatar Jul 17 '19 12:07 JokerNN

@JokerNN Nodes have a data property which is an object. You can store your data in there by modifying node.data directly in your widget. It breaks the one way data flow pattern of React, but it's the most simple and effective way to get the job done.

jackietieu avatar Jul 19 '19 22:07 jackietieu

https://github.com/projectstorm/react-diagrams/tree/master/demos/demo-custom-node1

dylanvorster avatar Jul 22 '19 14:07 dylanvorster

The demo that you send is not solving my issue. I am talking about widget with blocks, from where you can pull them to the diagram. I rewrote it in the other component and need to pass data from that widget to block.

sedulka avatar Jul 29 '19 09:07 sedulka

@sedulka DiagramModel has method getNode(nodeId) you can get node, update properties and then repaint canvas via DiagramEngine method repaintCanvas

alex-enchi avatar Jul 29 '19 09:07 alex-enchi

@sedulka I don't know if it can help you, but if you're trying to pass data from a textInput to the model, look at my repository: https://github.com/mathiasbaldissera/react-diagrams-editable-node There's a node that can be edited, and a serialization button to verify if the data was changed successfully on the model (just use CTRL+F to look the node "content")

mathiasbaldissera avatar Jul 30 '19 02:07 mathiasbaldissera