score:1
Accepted answer
in your click
function you need to collapse all nodes, if the clicked is opened.
then open up the node you clicked like below:
function click(d) {
//this collapse all the open nodes, if the clicked node is opened
if(!d.children)
data.children.foreach(collapse);
if (d.children) {
d._children = d.children;
d.children = null;
} else {
d.children = d._children;
d._children = null;
}
update(data);
}
working code here
Source: stackoverflow.com
Related Query
- D3 cluster layout design
- How to add text to Cluster Force Layout bubbles
- Recreate Cluster Force Layout using d3 v4.0
- D3 collapsing cluster layout
- Fading/highlighting in D3 cluster force layout
- Org Chart - Cluster Layout V3 to V4
- problems with latest cluster force layout example
- Links and textPaths in D3 cluster layout
- Specifying a number of nodes in each cluster of clustered force layout in d3js
- d3 cluster layout nodes at a particular depth are not aligned
- d3js Cluster Force Layout IV block by Mike
- How to add hypertext link to Cluster Force Layout circle
- D3 Force Layout where larger nodes cluster in center
- cannot show tooltip on rotating cluster layout
- d3js cluster layout dendogram node links to custom depths
- What's the best way to make a d3.js visualisation layout responsive?
- Adding new nodes to Force-directed layout
- Is there a way to zoom into a D3 force layout graph?
- Fix Node Position in D3 Force Directed Layout
- How to make force layout graph in D3.js responsive to screen/browser size
- Calm down initial tick of a force layout
- D3 Tree Layout Separation Between Nodes using NodeSize
- D3 force directed layout with bounding box
- Simple graph of nodes and links without using force layout
- Dynamically resize the d3 tree layout based on number of childnodes
- How to layout a non-tree hierarchy with D3
- d3.js force layout auto zoom/scale after loading
- Smooth transitioning between tree, cluster, radial tree, and radial cluster layouts
- How to update elements of D3 force layout when the underlying data changes
- d3.js: "Cannot read property 'weight' of undefined" when manually defining both nodes and links for force layout
More Query from same tag
- d3.js - are there more samples for concept maps
- d3.js dynamically append swarms with variable force bounds
- csv data to nested json tree in d3
- embed json file within d3.js
- How to rotate and change font size on x axis
- How should i access specific data from large JSON file using a search button?
- What is this event handler doing?
- Hierarchy's links() function returns empty array
- Compare data element with partial mean in d3
- Is it possible to make offset/shift in d3.js scales?
- d3 input resets radio buttons
- How to group in d3 bar chart
- How do I select an SVG inside an `object` tag?
- Calling specific data in an array created with rollup with d3.js
- Can d3 voronoi map work well with any other projection besides geoAlbers?
- Special donut chart with different rings/arcs for positive and negative values
- Flow Charts and State Machines
- Not understanding result of d3.timeParse?
- stacking axes horizontally on top of each other
- Show texts on Mouseover on links
- Get all dom nodes from d3 selection
- specify position of some nodes in a graph
- Replace string by an other variable with a string
- Labels do not fit correctly on Pie
- Add hyperlink to d3.js table rows and cells
- document.getElementById() does not work with puppeteer finding and id on a <path> element on SVG
- vanilla javascript to Reactjs component?
- ForeignObject not working in IE
- nvd3 piechart.js - How to edit the tooltip?
- plot dots on multiple lines in line chart