score:11
Accepted answer
option 1: modify the json
modify the json file, readme.json
, to use _children
instead of children
.
option 2: edit the javascript
edit the javascript to switch the _children
and children
attributes for every node. this could be done like so
var nodes = flatten(root);
nodes.foreach(function(d) {
d._children = d.children;
d.children = null;
});
here is a jsfiddle for the second option.
score:1
put this here for future readers:
d3.json("json/results.json", function(json) {
root = json;
root.x0 = h / 2;
root.y0 = 0;
function toggleall(d) {
if (d.children) {
d.children.foreach(toggleall);
toggle(d);
}
}
root.children.foreach(toggleall);
toggle(root);
update(root);
});
score:2
var allnode = flatten(root);
for (var i=0;i<allnode.length;i++){click(allnode[i])}
for those still looking for it, here is 2 lines of code. compact and easy to understand.
Source: stackoverflow.com
Related Query
- How can I start with all the nodes collapsed in d3js?
- MultiBar chart with nvd3 / d3 only shows labels for every other tick on the x-axis. How can I get them all to show up?
- d3.js How to make all the nodes collapsed in Collapsible indented Tree
- d3 force collapsible layout - start page with all nodes collapsed
- How to change the colors of all highlighted nodes in d3JS force directed graph?
- d3.js collapsible force layout with all the nodes collapsed
- How can I bring a circle to the front with d3?
- How can I toggle the class of all elements in a selection?
- How to make all the nodes circle the center node?
- How can I set the position of a drop down list with D3.js?
- How can I make my lines spin with the globe?
- d3js v4: How can I apply force to nodes onclick and make it look like a tween?
- How can I add images in the nodes of a D3 Sankey diagram, using the rcv and networkD3 packages in R?
- How can I calculate the degree of nodes in D3 v5?
- How can I display tooltips from multiple maps when mousover on one of the maps in D3js
- d3.js - force - how can I configure the force to place each nodes to grow farther away from the origin nodes?
- How can I put the Germany map on a svg in HTML? D3js
- how to start drawing a line with a space between y-axis and it using d3js
- Using d3 in meteor on windows 8.1, how can I display a world map, zoomed in on the US, with country borders and US state borders?
- How can I make the animation of a circle continous with hovering like this gif in d3.js?
- How can a function with no parameters all of a sudden take parameters in javascript?
- How can I draw links between nodes with D3.js?
- How can I apply a clipPath in SVG with multiple paths and NOT clip out the area between the paths?
- How do you add multiple lines to a D3JS line chart where the depedent variable data sources start at different positions along the range?
- How can I get the d3.js bar chart start from 0 instead of from the top
- How can I detect panning and zooming by the user with d3 zoomBehavior?
- D3 treeview - start with collapsed nodes
- How can you change the height of an x-axis with d3.js
- How can I create a basic bar chart with unique counts on the y axis and a category on the x axis?
- With d3.js, how do you modify corresponding nodes when you have multiple selections for the same data?
More Query from same tag
- D3JS Tree with Axis
- d3 js tooltips wont show
- Weird dependencies between array and a variable that is assigned by an element from that array
- svg : nomber of pixel of a character
- Animating SVG group object using the JavaScript library
- Trying to create a line chart with a linear x-axis, like the time axis, but with numerical data, in DimpleJS
- how to use merged array to d3 collapsable tree
- Javascript d3: Is there a way to programmatically stop dragging an item?
- show dc chart on browser using node.js
- d3: Animate bar chart transforming into pie chart, like Heer and Robertson do?
- How to create a beeswarm plot with variable radius in d3js v5?
- Is traversing all elements in the (MVC) Model necessary every time it is updated?
- adding mouseover event to d3.js bar chart
- Handling click/hover events with d3.js in Analytics Dashboard LWC
- Numbering the "Number of child's" on a parent node in collapsible tree chart in D3
- "Interpolate" is not a function
- Why do my DOM elements lose their location attributes when I size my SVG based on container size?
- Building and displaying a DAG (directed acyclic graph) in D3
- Eliminate sudden additions/deletions in D3 basis line chart transition
- Is there a D3 v4 version of Collapsible Indented Tree?
- How to Dynamically Append Custom D3/SVG Element in Angular
- d3.js Treemap - Is there a way to specify display preference (sorting)?
- DimpleJS. Y axis values in percentages
- Calculate bounding polygon of alpha shape from the Delaunay triangulation
- D3 Nested append with update, selection issues
- d3 bar chart with fixed bar width and fixed spacing to align in center axis line
- Wait for d3 to load
- D3 force layout with highlighting and fading
- How to force the gravity of bubbles in D3.js
- in browser screenshots of nvd3 (or d3 with css)