score:2
I would guess that the node that you pass into the second node as a child needs to be a reference to the first one, not the new Object that you are creating. Try this;
function flatten1() {
var nodes = [];
var node1 = {name: 'child1', size: 100, id: 1};
nodes.push(node1);
var node2 = {name: 'parent', children: [node1], id: 2};
nodes.push(node2);
return nodes;
}
If that works then it gives you some idea on how to shape the rest of your flatten algorithm.
Source: stackoverflow.com
Related Query
- d3.js force layout graph : how to build the nodes object from scratch?
- How to make the distance from nodes in d3.js force layout larger?
- How do I transition from a force layout graph to one where I have positioned the nodes?
- how to implement zoom in d3 graph of force directed layout and position the nodes
- How to get the same node positions in d3's force layout graph
- How to get web element (id) from the element position in D3.js force graph
- d3.js - force - how can I configure the force to place each nodes to grow farther away from the origin nodes?
- How do I group the nodes in a force directed graph
- How to change the data in a force layout graph dynamically ? D3
- How do I limit the panning on a force directed graph layout without axis ? D3/JS
- How to change the colors of nodes in force directed graph in d3js using javascript?
- How to make force layout graph in D3.js responsive to screen/browser size
- Simple graph of nodes and links without using force layout
- How to update elements of D3 force layout when the underlying data changes
- How to speed up the force layout animation in d3.js
- Labels / text on the nodes of a D3 force directed graph
- how find out if force layout done placing the nodes?
- How can I show a graph using d3 force layout with initial positions set and no movement at all?
- How to increase the length of a link in D3 force layout
- How to visualize groups of nodes in a d3 force-directed graph layout
- D3 bubble chart / pack layout - How to make bubbles radiate out from the largest bubbles to the smallest?
- how to control the simulation speed of d3 force layout
- How do I control the bounce entry of a Force Directed Graph in D3?
- enclosing the nodes of a d3 force directed graph in a circle or a polygon or a cloud
- d3.js: How to remove nodes when link-data updates in a force layout
- Place pie charts on nodes of force directed layout graph in D3
- D3 force layout graph with nodes positioned in a grid
- How to change the distance between nodes in a force layout?
- How to check d3 js force graph for nodes with no links and remove them?
- How to stop a d3 force graph layout simulation?
More Query from same tag
- d3 arc transition error when toggling sweep-flag
- Remove NaN values from data in D3.js
- Reading CSV's in D3 v5 JS: Why am I having trouble grabbing data?
- data uri as background image of svg not converted to canvas on safari live site
- getting the centroid co-ordinates in d3
- Keys not binding correctly to elements in D3
- d3.js plot airport map points on map with coordinates on different file
- Stacked bar chart transition
- Grid-lines are being recreated and overlaid on each other
- Chrome 34 SVG Bug
- d3.js drag node boundaries not working for linked path
- .data() is not a function
- How do you export multiple d3 charts to powerpoint?
- create a responsive svg with react
- Callbacks with D3
- Axis and svg text elements hide each other
- Displaying crossover only in d3.js Slankey (Dynamic, Interactive)
- Can you use transition().delay() and .classed() together?
- D3 trouble parsing CSV file
- How to set custom labels on the bars?
- How to animate line graph in D3
- D3 JS creating a legend for a chart
- Unnecessary gap in line graph paths
- D3.js in line Chart fetch data from local variable
- Invoke a callback at the end of a transition
- How to draw clickable line in PIXI.js using PIXI.Graphics?
- d3 line chart cutting off at the top
- Use of "i" in function (d, i) in d3.js
- Javascript OOP, getters, setters, run - D3.js - make graph resuable by option settings
- D3 function for gauge-like scale to produce: [-2, -1, 0, 0, 1, 2]