Skip to content

Commit 8518555

Browse files
Filmbostock
authored andcommitted
make it easier to create a text halo by defaulting paintOrder to stroke and strokeWidth to 3 if the stroke option is specified.
supersedes #667 closes #666
1 parent e5093ef commit 8518555

File tree

6 files changed

+12
-6
lines changed

6 files changed

+12
-6
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,6 +1128,8 @@ The **fontSize** and **rotate** options can be specified as either channels or c
11281128

11291129
If the **frameAnchor** option is not specified, then **textAnchor** and **lineAnchor** default to middle. Otherwise, **textAnchor** defaults to start if **frameAnchor** is on the left, end if **frameAnchor** is on the right, and otherwise middle. Similarly, **lineAnchor** defaults to top if **frameAnchor** is on the top, bottom if **frameAnchor** is on the bottom, and otherwise middle.
11301130

1131+
If the **stroke** option is specified, the **paintOrder** option defaults to stroke, and the **strokeWidth** option defaults to 3, making it easy to create a “halo” around text labels.
1132+
11311133
#### Plot.text(*data*, *options*)
11321134

11331135
Returns a new text mark with the given *data* and *options*. If neither the **x** nor **y** nor **frameAnchor** options are specified, *data* is assumed to be an array of pairs [[*x₀*, *y₀*], [*x₁*, *y₁*], [*x₂*, *y₂*], …] such that **x** = [*x₀*, *x₁*, *x₂*, …] and **y** = [*y₀*, *y₁*, *y₂*, …].

src/marks/text.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ export class Text extends Mark {
3939
{name: "rotate", value: numberChannel(vrotate), optional: true},
4040
{name: "text", value: text, filter: nonempty}
4141
],
42-
options,
42+
{
43+
...options.stroke && {paintOrder: "stroke", strokeWidth: 3},
44+
...options
45+
},
4346
defaults
4447
);
4548
this.rotate = crotate;

test/output/carsParcoords.svg

Lines changed: 1 addition & 2 deletions
Loading

test/output/metroInequalityChange.svg

Lines changed: 1 addition & 1 deletion
Loading

test/plots/cars-parcoords.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ export default async function() {
3737
marks: [
3838
Plot.ruleY(dimensions),
3939
Plot.line(data, {...xy, z: "name", stroke: "#444", strokeWidth: 0.5, strokeOpacity: 0.5}),
40-
Plot.text(ticks, {...xy, fill: null, stroke: "white", strokeWidth: 3, strokeLinejoin: "round", text: "value"}),
41-
Plot.text(ticks, {...xy, text: "value"})
40+
Plot.text(ticks, {...xy, text: "value", fill: "black", stroke: "white"})
4241
]
4342
});
4443
}

test/plots/metro-inequality-change.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ export default async function() {
3232
y: "R90_10_2015",
3333
filter: "highlight",
3434
text: "nyt_display",
35+
fill: "black",
36+
stroke: "white",
37+
strokeWidth: 4,
3538
dy: -8
3639
})
3740
]

0 commit comments

Comments
 (0)