function wrap_text(txt, maxwidth, fsz , txtnm ,svg ) {
let word;
let words = txt.text().split(/\s+/).reverse()
let xx = txt.text()
let line = [],
lineHeight = 1.1,
y = txt.attr("y"),
x = txt.attr("x"),
lineno = 0,
tspan = txt.text(null)
.append("tspan")
.attr("name", `TXT_${xx}`)
.attr("x", x)
.style("font-size", `${fsz}pt`)
.attr("y", y)
while(word = words.pop()) {
line.push(word);
tspan.text(line.join(" "));
let bx = get_bbox(svg, `TXT_${xx}`)
let hh = bx.height / (lineno + 1);
if (bx.width > maxwidth) {
lineno += 1;
line.pop();
tspan.text(line.join(" "));
line = [word];
let addy = parseInt(y) + (hh*lineno)
tspan = txt.append("tspan")
.attr("x", x)
.attr("y", addy)
.style("font-size", `${fsz}pt`)
.text(word);
}
}
lineno = 0;
}