Skip to content

wrapping labels in zoomable sunburst #1

@virtualgadjo

Description

@virtualgadjo

Hi,
first of all, thanks a lot for this incredible job that has saved me a huge amount of time...
i'm wondering if you had an idea of how to wrap the label text in th zoomable sunburst, i've tried many things among which

label.each(function(d) {
  let text = d3.select(this),
        words = text.text().split(/\s+/).reverse(),
        word,
        line = [],
        lineNumber = 0,
        lineHeight = 1.1, // ems
        x = text.attr("x"),
        y = text.attr("y"),
        dy = parseFloat(text.attr("dy")),
        tspan = text.text(null).append("tspan").attr("x", x).attr("y", y).attr("dy", dy + "em");
  while (word = words.pop()) {
    line.push(word);
    tspan.text(line.join(" "));
    if (tspan.node().getComputedTextLength() > 150) {
      line.pop();
      tspan.text(line.join(" "));
      line = [word];
      tspan = text.append("tspan").attr("x", x).attr("y", y).attr("dy", ++lineNumber * lineHeight + dy + "em").text(word);
    }
  }
});

like this or chained with .text(d => d.data.name) but with no error and... no effect :D
and as i know the former textwrap function is made for d3 v4 and doesn't work in d3 v7, any idea/suggestion would be very welcome :)

have a nice day

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions