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

Bad synchronisation of the minimap when scale down. #20

Open
antony64240 opened this issue Oct 13, 2023 · 0 comments
Open

Bad synchronisation of the minimap when scale down. #20

antony64240 opened this issue Oct 13, 2023 · 0 comments

Comments

@antony64240
Copy link

antony64240 commented Oct 13, 2023

Hello,

I have a problem when I zoom on my div, the minimap container does not synchronize, when I zoom out, it works, zoom in does not work.

Voici mon code :

function Home() {
  const [zoom, setZoom] = React.useState(1);
  const containerRef = useRef<HTMLDivElement>(null);

  useEffect(() => {
    const onWheel = (e: any) => {
      e.preventDefault();
      setZoom((value) => {
        const newZoom = value + e.deltaY * -0.001;
        if (newZoom > 0.1 && newZoom < 1) {
          return newZoom;
        } else {
          return value;
        }
      });
    };
    nodeRef.current?.addEventListener("wheel", onWheel);
    return () => {
      nodeRef.current?.removeEventListener("wheel", onWheel);
    };
  }, []);

 const renderChild = ({ width, height, left, top, node }) => {
    const classNames = ["node-content"];
    let classNameFound = null;

    node.classList.forEach((className) => {
      if (classNames.includes(className)) {
        classNameFound = className;
        return false;
      }
    });

    if (classNameFound === null)
      return <ChildComponent {...{ width, height, left, top }} />;

    return (
      <div
        style={{
          position: "absolute",
          width,
          height,
          left,
          top,
          backgroundColor: "#" + HEX[classNameFound],
        }}
      />
    );
  };

return (
    <div className="App">
      <div ref={containerRef} className={clsx("container")}>
        <Minimap selector=".node-content" childComponent={renderChild}>
          <div
            ref={nodeRef}
            style={{ scale: zoom }}
            className="flex select-none"
          >
            <NodeComponent type="root" node={nodeRoot} />
          </div>
        </Minimap>
      </div>
    </div>
  );
}

export default Home;

If you have the solution to my problem, I'll take it. Thx, have a good one!

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

1 participant