Be the first user to complete this post
|Add to List|
Render a d3 tree with a minimum distance between the tree nodes
npm install, and then fire up a node server using
npm run start. I just used a server since my data is kept in a file in the data directory. And d3 need to load the file on the fly. The HTML page where all the magic happens is large_tree_small_viewport.html. So just fire up a browser and go to the page
Now, lets jump into the code.
overflow: auto in its CSS since we want to see scrollbars when the svg size is larger than the container's dimentions.
I will discuss the renderTree function a bit later, but first lets see the function that computes the svg dimentions.
The aim of this function is to determine the minumum size of the SVG such that there is a certain minimum distance between the nodes of the tree.
Getting the depth is pretty straighforward. But you gotta be careful when getting the height. Also keep in mind that this tree is laid out horizontally. We want to determine which level of the tree has the maximum height. This is irrespective of which parent a node belongs to. e.g. Lets say root has 2 nodes - A and B. A has 3 children, B has 5. The total number of nodes at the different levels is the following
- d3 Fundamentals: Creating a simple bar graph
- How to get the data of a node in d3
- Selecting a node in d3js based upon the value of its data
- Creating an Animated Ring or Pie chart in d3js
- d3 Fundamentals : Understanding domain, range and scales in D3js
- A visual explanation of the Enter, Update and Exit Selections in D3js
- Using d3js to draw a bar chart with an axis and some basic transitions