Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

421
Visualizações
How can I bind zoom buttons to react d3 tree?

I’m trying to figure out how to bind zoom buttons to react d3 tree, however I haven’t found an approach that works while still maintaining the position.

The position resets every time I update the zoomLevel, meaning if I pan somewhere and adjust the zoomLevel, it jumps to the middle of the tree.

I want something like this https://jsfiddle.net/vbabenko/jcsqqu6j/9/

const TreeWrapper: FC<any> = ({ data }) => {
  const [zoomLevel, setZoomLevel] = useState(1);

  const scaleExtent = { min: 0.5, max: 3 };

  const zoomIn = () =>
    zoomLevel < scaleExtent.max &&
    setZoomLevel((prevLevel) => prevLevel + 0.25);

  const zoomOut = () =>
    zoomLevel > scaleExtent.min &&
    setZoomLevel((prevLevel) => prevLevel - 0.25);

  return (
    <Card title={null}>
      <button onClick={zoomIn} type="button">
        +
      </button>
      <button onClick={zoomOut} type="button">
        -
      </button>
      <Tree
        zoom={zoomLevel}
        scaleExtent={scaleExtent}
        translate={translate}
        zoom={zoomLevel}
        zoomable={true}
        initialDepth={1}
        collapsible={true}
        separation={{ siblings: 2, nonSiblings: 2 }}
        renderCustomNodeElement={(rd3tProps) =>
          renderForeignObjectNode({ ...rd3tProps, foreignObjectProps })
        }
        orientation="vertical"
        data={data}
      />
    </Card>
  );
};
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda