Skip to content

Commit c8ec5ec

Browse files
authored
use dy to position multi-line text (#1582)
* use dy to position multi-line text * fix blank initial lines
1 parent 46301cf commit c8ec5ec

11 files changed

+143
-139
lines changed

src/marks/text.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,17 @@ function applyMultilineText(selection, mark, T, TL) {
141141
const n = lines.length;
142142
const y = lineAnchor === "top" ? 0.71 : lineAnchor === "bottom" ? 1 - n : (164 - n * 100) / 200;
143143
if (n > 1) {
144+
let m = 0;
144145
for (let i = 0; i < n; ++i) {
146+
++m;
145147
if (!lines[i]) continue;
146148
const tspan = this.ownerDocument.createElementNS(namespaces.svg, "tspan");
147149
tspan.setAttribute("x", 0);
148-
tspan.setAttribute("y", `${(y + i) * lineHeight}em`);
150+
if (i === m - 1) tspan.setAttribute("y", `${(y + i) * lineHeight}em`);
151+
else tspan.setAttribute("dy", `${m * lineHeight}em`);
149152
tspan.textContent = lines[i];
150153
this.appendChild(tspan);
154+
m = 0;
151155
}
152156
} else {
153157
if (y) this.setAttribute("y", `${y * lineHeight}em`);

test/output/covidIhmeProjectedDeaths.svg

Lines changed: 5 additions & 5 deletions
Loading

test/output/letterFrequencyWheel.svg

Lines changed: 26 additions & 26 deletions
Loading

test/output/longLabels.svg

Lines changed: 6 additions & 6 deletions
Loading

test/output/mobyDick.svg

Lines changed: 1 addition & 1 deletion
Loading

test/output/penguinAnnotated.svg

Lines changed: 1 addition & 1 deletion
Loading

test/output/penguinFacetAnnotatedX.svg

Lines changed: 1 addition & 1 deletion
Loading

0 commit comments

Comments
 (0)