score:2

Accepted answer

I realized I was using the number of lines - 1 instead of just the number of lines. Removing the -1 solved the issue.

if (lineNumber > 0) {
  const startDy = -(lineNumber * (lineHeight / 2));  // here was the issue
  text
    .selectAll("tspan")
    .attr("dy", (d, i) => startDy + lineHeight * i + "em");
}

Related Query

More Query from same tag