Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to center a node on from external event #493

Open
hyper-dot opened this issue Feb 2, 2024 · 1 comment
Open

How to center a node on from external event #493

hyper-dot opened this issue Feb 2, 2024 · 1 comment

Comments

@hyper-dot
Copy link

Hi, Really sorry if I wasn't suppose to ask this question. But I really tried everything I could to center a node on render. But couldn't.
I saw the example on code sandbox. It is setting the dimention of tree container. I have also set dimention like that.

    <div
      id="treeWrapper"
      ref={containerRef}
      style={{ width: "100%", height: "100%" }}
      className="fixed"
    >
      <button onClick={handleCenterUser} className="absolute top-4 right-28">
        Center Me
      </button>

      {data ? (
        <Tree
          dimensions={dimentions}
          data={data}
          scaleExtent={{ max: 10, min: 0.3 }}
          pathFunc={stepPathFunc}
          pathClassFunc={customPathClass}
          nodeSize={nodeSize}
          translate={translate}
          orientation="vertical"
          enableLegacyTransitions
          renderCustomNodeElement={(rd3tProps: any) =>
            renderForeignObjectNode({ ...rd3tProps, foreignObjectProps })
          }
        />
</div>
  const handleCenterUser = () => {
    const user = document.getElementById("isuser");
    if (user && containerRef.current) {
      const { x, y } = user.getBoundingClientRect();
      const { height, width } = containerRef.current.getBoundingClientRect();
    }
  };

I am able to get height and width of the container and the x & y cordinates of the node that I want to center. But I am unable to center the node using translate. When I translate using those cordinates I can't move the tree freely.

@vitallygolovanov
Copy link

Just weighing in to say, that I also want to be able to trigger centering/focus on a node externally. User clicks a "show me" button, and the tree centers on their node.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants