Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
231 views
in Technique[技术] by (71.8m points)

javascript - In D3, how can I select specific children elements of current node in zoomable treemap?

I'm trying to access children nodes of currently zoomed in cell in D3 zoomable Treemap. Specifically, I'd like to replace the href attribute in nested image nodes.

Is there a way of selecting just the children elements of the current node inside function zoomed(d){}, ideally without filtering the whole treemap, i.e. by utilising node.children property?

Something like this:

function zoomed(d) {

  // get children nodes data
  const currentChildren = d.children; // [Zh, Zh, Zh] - ok

  // select all children of current node
  // and select their image nodes
  // then update href attribute
  d3.select(this)
    .select(d => d.children)
    .selectAll("image")
    .attr("href", d => "/img/" + d.data.image);

}

Each cell structure is this:

g
  rect
  clipPath
  svg
    image
question from:https://stackoverflow.com/questions/66066789/in-d3-how-can-i-select-specific-children-elements-of-current-node-in-zoomable-t

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...