I haven't quite found an answer for this using D3. I am making a rectangle tooltip from an svg element that shows up on a graph upon clicking on a node. The text associated with the tooltip, which is from the graph's json, currently only extends horizontally, even if the dimensions of the tooltip are extended vertically. I would like for the rectangle to wrap around the text vertically (like a carriage return), rather than horizontally, given a fixed width for the rectangle.
Below is where I create the tooltip upon clicking a node:
nodes.on("click", function (d){
if (tip){ tip.remove()};
tip = svg.append("g")
.attr("id", "tip")
.attr("transform", "translate(" + (d3.event.pageX - 10) + "," + (d3.event.pageY - 35) + ")");
let rect = tip.append("rect")
.style("fill", "white")
.style("stroke", "steelblue");
tip.append("text")
.text(d.description)
.attr("dy", "1em")
.attr("x", 5);
let bbox = tip.node().getBBox();
rect.attr("width", bbox.width + 5)
.attr("height", bbox.height)
});
Here is a jsfiddle with the current functionality: https://jsfiddle.net/Thegreatmochi/epy6514t/14/