Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

261
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!