Skip to content

Nodes fall outside of <Provider> #266

Open

Description

@rpickler

I'm very inexperienced with React, and have lost myself in this little experiment I chose for myself.

Starting from one of the examples, I wanted to create a custom node shape with a single toggle control on the node. The trick is that the toggle is shared among all nodes, where only one can be in the 'on' state across the whole graph.

Screenshot from 2020-09-04 06-45-29

Toggling that flag on a single node is fairly straight forward, but making it global is where I run into difficulty. I've tried all manner of Redux and React Hooks, but they all fail because the nodes that are created by my renderNode function fall out of the <Provider> tree. (According to the React Components debugger, this happens with standard nodes as well.)

Digging into your code, and an afternoon's worth of googling, it appears this happens because of the ref used to defer the drawing of the nodes.

https://github.com/uber/react-digraph/blob/master/src/components/graph-view.js#L1605
https://github.com/uber/react-digraph/blob/master/src/components/graph-view.js#L1375

Thanks for any help you can give. I was impressed with the project a few years ago when I first poked at it, and I'm very much so after returning to it this week.

Activity

  1. ajbogh commented on Nov 16, 2020

    @ajbogh
    Contributor

    I'm not sure if your issue is similar, but this StackOverflow question has a similar problem with react-dom render.

    https://stackoverflow.com/questions/37269530/how-to-render-redux-container-in-reactdom-render-method

    Another method is to activate a side panel when the user clicks on the node and display all of the node's settings. The side panel would be within the Provider's context. Selecting the "on" state on one node could update the graph and the blue box would light up on that selected node while all others turn off. To force a graph update you need to produce a new nodes array in the process.

    I also noticed that your edges aren't touching the sides of your nodes, instead they're pointing to the middle. We have edge-intercept code that should point them to the sides if you use similar code to our example project, having a width and height property in the correct places is the key.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions