Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

262
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda