My question is regarding how to center multiple elements in one node after line wrapping. I'm utilizing code example given here on word wrapping: http://bl.ocks.org/mbostock/7555321 to create multiple tspan objects.
After creating/drawing all the tspan objects, I define the location of the X and Y. First I get the text area of the entire tspan and create a box around it:
var tspanbbox = d3.select(this).select("tspan").node().getBBox();
var node_bbox = {"height": tspanbbox.height+5, "width": tspanbbox.width+5};
var rect = d3.select(this).select('rect');
rect.attr("x", -node_bbox.width/2).attr("y", -node_bbox.height/2)
rect.attr("width", node_bbox.width).attr("height", node_bbox.height+10);
and then I added the attribute for the tspan, the text that's within rect.
tspan.attr("x", -node_bbox.x).attr("y", -node_bbox.y);
This code correctly prints a box around the area around the text, but there's overflowing text.
https://i.stack.imgur.com/iHTUN.jpg
So what I'm trying to do is to center the group as an entity rather than the first tspan (what I'm assuming is the first line after the GO term).
If I try to alter the tspan attribute (as shown in the code above), only one of the tspan objects move. If I do it with all of them using selectAll("tspan")
, all of them the tspans are grouped on the same y axis.
Is there any way of going about this properly?