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

259
Visualizações
why data().join() behave differently on g elements with d3.js

i have a function that accepts different data arrays and draw a treemap using d3.js

the structure require a g element with a rect and text in it so for every data node there is a g element to group rect and text and i use join() to keep the elements on the screen linked to the datasets i pass in

strangly when running something like :

svg.selectAll("g").data(myDataArray).join("g").append("rect")

it works fine and the g binds to myDataArray nodes except the first g

the first g never changes instead it gets filled with rect elements anytime i pass a different myDataArray and the rest of the g elements just works as intended and gets the new data displayed in them and the old gets removed except the first element on the other hand when i test it using other elements say i do this :

svg.selectAll("div").data(myDataArray).join("div").append("h1");

every thing works as intended and every data node gets a div with h1 inside showing the data and also the first div update its h1 unlike the first g element that just keep adding rect elements inside it everytime myDataArray gets changed i have tried so many different ways to debug but couldnt understand why this thing happen on g elements but not other type of containers

about 4 years ago · Santiago Gelvez
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