Skip to content

Commit 8713cdc

Browse files
committed
lineHeight option
1 parent f854feb commit 8713cdc

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,6 +1081,9 @@ In addition to the [standard mark options](#marks), the following optional chann
10811081

10821082
The following text-specific constant options are also supported:
10831083

1084+
* **textAnchor** - TODO
1085+
* **lineAnchor** - TODO
1086+
* **lineHeight** - TODO
10841087
* **fontFamily** - the font name; defaults to [system-ui](https://drafts.csswg.org/css-fonts-4/#valdef-font-family-system-ui)
10851088
* **fontSize** - the font size in pixels; defaults to 10
10861089
* **fontStyle** - the [font style](https://developer.mozilla.org/en-US/docs/Web/CSS/font-style); defaults to normal

src/marks/text.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export class Text extends Mark {
1717
text = indexOf,
1818
textAnchor,
1919
lineAnchor = "middle",
20+
lineHeight = 1,
2021
fontFamily,
2122
fontSize,
2223
fontStyle,
@@ -41,6 +42,7 @@ export class Text extends Mark {
4142
this.rotate = crotate;
4243
this.textAnchor = impliedString(textAnchor, "middle");
4344
this.lineAnchor = keyword(lineAnchor, "lineAnchor", ["top", "middle", "bottom"]);
45+
this.lineHeight = +lineHeight;
4446
this.fontFamily = string(fontFamily);
4547
this.fontSize = cfontSize;
4648
this.fontStyle = string(fontStyle);
@@ -79,7 +81,7 @@ export class Text extends Mark {
7981
}
8082
}
8183

82-
function applyMultilineText(selection, {lineAnchor}, T) {
84+
function applyMultilineText(selection, {lineAnchor, lineHeight}, T) {
8385
if (!T) return;
8486
const format = isTemporal(T) ? isoFormat : isNumeric(T) ? formatNumber() : string;
8587
selection.each(function(i) {
@@ -90,7 +92,7 @@ function applyMultilineText(selection, {lineAnchor}, T) {
9092
for (let i = 0; i < n; ++i) {
9193
const tspan = document.createElementNS(namespaces.svg, "tspan");
9294
tspan.setAttribute("x", 0);
93-
tspan.setAttribute("y", `${y + i}em`);
95+
tspan.setAttribute("y", `${y + i * lineHeight}em`);
9496
tspan.textContent = lines[i];
9597
this.appendChild(tspan);
9698
}

0 commit comments

Comments
 (0)