score:5
I've never worked on anything that required me to use urls in an svg object before, so I'm not sure if the way I implemented it is the most efficient/correct. I would be interested in knowing if there is a more correct way to do this.
So here's a codepen of what I believe you wanted: https://codepen.io/anon/pen/WKrKmq?editors=0011
Building off of the code you provided from the d3.js collapsible tree bl.ock, I started by populating the treeData with the following properties; 'events', 'tickets', and 'url'. After that it was pretty simple:
nodeEnter.append('text')
.attr('x', function(d) {
return -15;
})
.attr('y', function(d) {
return 11
})
.text(function(d) {
return 'tickets - ' + d.tickets;
})
.on('click', function(d) {
window.location = d.url;
})
.style('font-size', '6px');
nodeEnter.append('text')
.attr('x', function(d) {
return -15;
})
.attr('y', function(d) {
return -5
})
.text(function(d) {
return 'events - ' + d.events;
})
.on('click', function(d) {
window.location = d.url;
})
.style('font-size', '6px');
I also increased the seperation between nodes here:
var tree = d3.layout.tree()
.separation(function(d) { return 5; })
.size([viewerHeight, viewerWidth]);
score:2
Have you tried to hard code an SVG with the tags you want? Normal HTML tags are not allowed inside an SVG tag. Just add the text like the tree node text and make them clickable.
What you need to do is at the point where you create the circle with the text and the .on('click', click);
inside the g.node
create two new g
elements, one contains the circle and text and has the .on('click', click);
. In the other add your new text elements and also make them respond to a .on('click', textClick);
.
Source: stackoverflow.com
Related Query
- How to add HTML code to D3 tree chart at node?
- How to add a shape on a chart node in d3.js?
- How to add progress bar inside a tree structure node or on mouse hover in D3
- Trying to add a second parent node to a child node using d3 tree chart library
- d3.js how to dynamically add nodes to a tree
- How to add drop shadow to d3.js pie or donut chart
- Add Node to D3 Tree v4
- Add hyperlink to node text on a collapsible tree
- How to add compound node in a D3 force layout?
- how to display name of node when mouse over on node in collapsible tree graph
- How to add a nice legend to a d3 pie chart
- d3.js How to add lines to a bar chart
- How to add columnn titles in a Sankey chart networkD3
- How do I add labels to d3.js force bubble chart
- How to make an interactive tree chart with d3?
- how to add legend to a pie chart using D3js? And how to centralise the pie chart?
- How to add a line on x-axis on a horizontal bar chart in d3
- How can I connect two parent node into one child node and how to make a tooltip for each node in the tree pragmatically? in D3 js (SVG)
- How to remove node on tree layout D3.js?
- How to add an html form in D3?
- How to add a fixed range vertical line to a D3.js chart
- How to add space between bars in a grouped bar chart in a nvd3 grouped multibar chart?
- How can I add zooming to the d3 collapsible tree example?
- How to add tooltips in a D3 donut chart
- d3.js: How to add value below the label in donut chart
- How to add a force drag event in D3 and make the node stay where i leave it?
- How to add text in the center of node in force directed graph?
- python: how to save dynamically rendered html web page code
- How to add events to the individual sections(arcs) of a pie chart created out of d3.js?
- How to close and just later add HTML element in D3.JS?
More Query from same tag
- dc.js - rangeChart bars disappearing when filtered out
- Implementing complex Processing pushMatrix/popMatrix logic with d3js
- Implementing d3.js in angular 4
- Difference between d3.js and d3.v3.js
- d3 transition error
- Clear d3.js charts before loading new chart
- D3.js - Uncaught TypeError: .enter(...).append(...).merge is not a function
- Change label text color in row chart
- Adding image in d3.js
- rickshaw: how to translate days months?
- D3.js update leaves duplicate svg elements
- How to programmatically zoom to Elements in D3 in responsive map?
- Map D3 year to x axis
- How can I start with all the nodes collapsed in d3js?
- Text rotation within an arc using D3JS
- d3 multiple graph not working
- Word cloud popup video
- Deleting node from graph is wrong
- collapse specific nodes on load in d3 tree
- d3 - Rotate x-axis labels
- D3 Tooltip issues with displaying d on hover
- How to convert pixel to translate value in d3?
- onMouseOver event doesn't work on canvas / d3 (tooltip)
- Need help in ngx-graph links layout
- d3js maximum and minimum on x scale.
- node and subnodes linking in D3.js
- D3.symbol in the corner of the screen. I would like to move it
- How to get boundary of zoomed & paned svg in d3
- How to find the extents in an array of nested objects?
- d3 xhr adding loading cursor