Skip to content

Commit 5c4d2a5

Browse files
committed
text with frameAnchor: bottom should be correctly aligned with the frame, not one line below
closes #1043
1 parent aa4f690 commit 5c4d2a5

File tree

6 files changed

+120
-6
lines changed

6 files changed

+120
-6
lines changed

src/marks/text.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ function applyMultilineText(selection, {monospace, lineAnchor, lineHeight, lineW
140140
selection.each(function (i) {
141141
const lines = linesof(formatDefault(T[i]));
142142
const n = lines.length;
143-
const y = lineAnchor === "top" ? 0.71 : lineAnchor === "bottom" ? 1 - n : (164 - n * 100) / 200;
143+
const y = lineAnchor === "top" ? 0.71 : lineAnchor === "bottom" ? -0.29 - n : (164 - n * 100) / 200;
144144
if (n > 1) {
145145
for (let i = 0; i < n; ++i) {
146146
if (!lines[i]) continue;

test/output/penguinAnnotated.svg

+85
Loading

test/output/seattlePrecipitationSum.svg

+1-1
Loading

test/plots/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ export {default as morleyBoxplot} from "./morley-boxplot.js";
135135
export {default as moviesProfitByGenre} from "./movies-profit-by-genre.js";
136136
export {default as musicRevenue} from "./music-revenue.js";
137137
export {default as ordinalBar} from "./ordinal-bar.js";
138+
export {default as penguinAnnotated} from "./penguin-annotated.js";
138139
export {default as penguinCulmen} from "./penguin-culmen.js";
139140
export {default as penguinCulmenArray} from "./penguin-culmen-array.js";
140141
export {default as penguinCulmenDelaunay} from "./penguin-culmen-delaunay.js";

test/plots/penguin-annotated.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import * as Plot from "@observablehq/plot";
2+
import * as d3 from "d3";
3+
4+
export default async function () {
5+
const penguins = await d3.csv("data/penguins.csv", d3.autoType);
6+
return Plot.plot({
7+
marginLeft: 75,
8+
x: {insetRight: 10},
9+
marks: [
10+
Plot.frame(),
11+
Plot.barX(
12+
penguins,
13+
Plot.groupY(
14+
{x: "count"},
15+
{
16+
y: "species",
17+
fill: "sex",
18+
title: "sex",
19+
sort: {y: "x", reverse: true}
20+
}
21+
)
22+
),
23+
Plot.text(["Count of penguins\ngrouped by species\n and colored by sex"], {
24+
frameAnchor: "bottom-right",
25+
dx: -3,
26+
lineHeight: 1.2,
27+
fontStyle: "italic"
28+
})
29+
]
30+
});
31+
}

test/plots/seattle-precipitation-sum.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ export default async function () {
1010
Plot.rectY(weather, Plot.map({y}, {x: "date", y: "precipitation", interval: d3.utcDay})),
1111
Plot.textY(
1212
weather,
13-
Plot.map(
14-
{y, text},
15-
{x: "date", y: "precipitation", text: "precipitation", interval: d3.utcDay, frameAnchor: "bottom", dy: -3}
16-
)
13+
Plot.map({y, text}, {x: "date", y: "precipitation", text: "precipitation", interval: d3.utcDay, dy: -6})
1714
),
1815
Plot.ruleY([0])
1916
]

0 commit comments

Comments
 (0)