score:1
You would attach the event handlers to the html the same way you would to an svg element
// Enter any new nodes at the parent's previous position.
node.enter()
// append an html div
.append("div")
// event handlers
.on("click", function(d) {
// your code to add a new node
})
(Last time I checked d3's event handlers are pretty basic and don't support custom events)
Handling window resizing can be tricky as you have to set the canvas and html container dimensions before generating the tree.
A quick and dirty way of handling this would be to set very large sizes for the html container
vis = d3.select("#chart-inner").append("svg:svg").attr("id", "svg-container").attr("width", 40000).attr("height", 20000).append("svg:g").attr("transform", "translate(0,100)");
Then wrap it all up with a container div
<div id="chart" style="width:100%; overflow:hidden">
<div id="chart-inner">
It's not really an ideal solution. If you want to do it properly, you'll have to work out the depth and width of the tree based on the initial html element size (which would involve a lot of 'walking' the data to work out).
Source: stackoverflow.com
Related Query
- d3.js binary tree with HTML as the nodes
- the lines' points x1, x2, y1, y2 do not coincide with nodes in a radial tree
- is there any method to draw a tree with a root , the root's previous nodes and successor nodes?
- How can I start with all the nodes collapsed in d3js?
- D3 updating graph with new elements create edges with the wrong nodes
- d3.js How to make all the nodes collapsed in Collapsible indented Tree
- D3: Tree diagram with images and circles as nodes
- Select all the paths and parent nodes of a child node in tree layout
- How to dynamically reposition binary tree nodes visually
- Updating data values with HTML input and changing the data array
- D3.js Tree with Numbering on Nodes
- Updating nodes and links with labels in d3 force directed network graph is not removing the nodes properly
- Display the text inside the nodes in Tree graph in d3.js
- custom html boxes in tree layout with d3.js
- tree.nodeSize() not working in D3 tree graph to inc. the space between nodes
- Easiest way to select parent nodes multiple parents up in the tree in D3
- Add custom html to nodes in d3 js tree
- D3 Tree Chart with left and right nodes on every nodes
- D3 tree and positioning JQuery UI Dialog with nodes
- Draw graph for child nodes on click of the node of tree pattern in d3.js
- d3.js draw line source and target is different (from an arc generated by d3.svg.arc() to the nodes with Cardinal position)
- With d3.js, how do you modify corresponding nodes when you have multiple selections for the same data?
- Is there any way to download the html table just beside an svg along with the svg?
- D3js Is it possible create view like tree structure with custom nodes
- How to vary the size of piechart in d3 with tree layout
- Collapsible tidy horizontal tree from obervablehq migrated to html is rendering only a single large node in the middle
- Separate the nodes and avoid overlapping in tree graph in d3.js
- Start with closed nodes in indented tree
- Select only the X value of nodes data with D3
- HTML + (NV)D3: Can't place a div on top of a div of the chart even with > z-index
More Query from same tag
- D3.js v5 Get data from value
- d3.js move node and label together
- Update polygon when points change in d3
- D3js Force-directed graph link intersections avoid
- Stacked Bar Chart Labels - D3
- How should I remove nodes in d3-force?
- ticks with an ordinal scale?
- Why doesn't this D3 chart redraw when I repeatedly call it's original draw function?
- Add Tooltips to Interactive D3 Diagram in D3
- D3 chart, adding more info to the one the chart brings by default
- Bar Chart Not Rendering As Intended in d3.JS
- Error: <path> attribute d: expected number - when trying to build a line chart with D3
- Best way to arrange tick text using d3
- cannot use d3 to create a word cloud
- d3 change scale domain and keep the zoom working as expected
- Fix Piechart label overlap using C3/D3
- Why my D3.js Dropdown filter is random ?
- How to assign click event to every svg element in d3js
- D3 force simulation in Angular
- Missing links in force directed graph
- Convert table data to tree data JSON format (parent, child) d3.js dynamically?
- How to select data
- D3: combine circles and images
- Interactive Legend on force layout with d3.legend
- How to label a force directed Graph on d3?
- Ordinal scale category10 mapping everything to same color
- D3 geometric zoom when there is no SVG element under the cursor
- How to display data value on every layout of stacked barchart in d3
- d3.min.js Uncaught TypeError: a.map is not a function
- Origin null is not allowed by Access-Control-Allow-Origin.