Skip to content

Commit e6e3bd2

Browse files
committed
default paintOrder
1 parent 8518555 commit e6e3bd2

File tree

5 files changed

+12
-9
lines changed

5 files changed

+12
-9
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,7 @@ 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.
1131+
The **paintOrder** option defaults to “stroke” and the **strokeWidth** option defaults to 3. By setting **fill** to the foreground color and **stroke** to the background color (such as black and white, respectively), you can surround text with a “halo” which may improve legibility against a busy background.
11321132

11331133
#### Plot.text(*data*, *options*)
11341134

src/marks/text.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import {Mark} from "../plot.js";
66
import {applyChannelStyles, applyDirectStyles, applyIndirectStyles, applyAttr, applyTransform, offset, impliedString, applyFrameAnchor} from "../style.js";
77

88
const defaults = {
9-
strokeLinejoin: "round"
9+
strokeLinejoin: "round",
10+
strokeWidth: 3,
11+
paintOrder: "stroke"
1012
};
1113

1214
export class Text extends Mark {
@@ -39,10 +41,7 @@ export class Text extends Mark {
3941
{name: "rotate", value: numberChannel(vrotate), optional: true},
4042
{name: "text", value: text, filter: nonempty}
4143
],
42-
{
43-
...options.stroke && {paintOrder: "stroke", strokeWidth: 3},
44-
...options
45-
},
44+
options,
4645
defaults
4746
);
4847
this.rotate = crotate;

src/style.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ export function styles(
3232
strokeWidth: defaultStrokeWidth,
3333
strokeLinecap: defaultStrokeLinecap,
3434
strokeLinejoin: defaultStrokeLinejoin,
35-
strokeMiterlimit: defaultStrokeMiterlimit
35+
strokeMiterlimit: defaultStrokeMiterlimit,
36+
paintOrder: defaultPaintOrder
3637
}
3738
) {
3839

@@ -73,6 +74,10 @@ export function styles(
7374
if (strokeLinecap === undefined) strokeLinecap = defaultStrokeLinecap;
7475
if (strokeLinejoin === undefined) strokeLinejoin = defaultStrokeLinejoin;
7576
if (strokeMiterlimit === undefined) strokeMiterlimit = defaultStrokeMiterlimit;
77+
78+
// The paint order only takes effect if there is both a fill and a stroke
79+
// (at least if we ignore markers, which no built-in marks currently use).
80+
if (cfill !== "none" && paintOrder === undefined) paintOrder = defaultPaintOrder;
7681
}
7782

7883
const [vstrokeWidth, cstrokeWidth] = maybeNumberChannel(strokeWidth);

test/output/metroInequalityChange.svg

Lines changed: 1 addition & 1 deletion
Loading

test/plots/metro-inequality-change.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ export default async function() {
3434
text: "nyt_display",
3535
fill: "black",
3636
stroke: "white",
37-
strokeWidth: 4,
3837
dy: -8
3938
})
4039
]

0 commit comments

Comments
 (0)