Skip to content

Commit 2f326d2

Browse files
mbostockFil
andauthored
text stroke channels (#469)
* fix #467; text stroke channels * add wordCloud test * a more representative word cloud Co-authored-by: Philippe Rivière <[email protected]>
1 parent 04e580a commit 2f326d2

File tree

4 files changed

+52
-3
lines changed

4 files changed

+52
-3
lines changed

src/marks/text.js

+17-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export class Text extends Mark {
1313
title,
1414
fill,
1515
fillOpacity,
16+
stroke,
17+
strokeOpacity,
1618
textAnchor,
1719
fontFamily,
1820
fontSize,
@@ -25,6 +27,8 @@ export class Text extends Mark {
2527
...options
2628
} = {}
2729
) {
30+
const [vstroke, cstroke] = maybeColor(stroke, "none");
31+
const [vstrokeOpacity, cstrokeOpacity] = maybeNumber(strokeOpacity);
2832
const [vfill, cfill] = maybeColor(fill, "currentColor");
2933
const [vfillOpacity, cfillOpacity] = maybeNumber(fillOpacity);
3034
const [vrotate, crotate] = maybeNumber(rotate, 0);
@@ -39,11 +43,19 @@ export class Text extends Mark {
3943
{name: "text", value: text},
4044
{name: "title", value: title, optional: true},
4145
{name: "fill", value: vfill, scale: "color", optional: true},
42-
{name: "fillOpacity", value: vfillOpacity, scale: "opacity", optional: true}
46+
{name: "fillOpacity", value: vfillOpacity, scale: "opacity", optional: true},
47+
{name: "stroke", value: vstroke, scale: "color", optional: true},
48+
{name: "strokeOpacity", value: vstrokeOpacity, scale: "opacity", optional: true}
4349
],
4450
options
4551
);
46-
Style(this, {fill: cfill, fillOpacity: cfillOpacity, ...options});
52+
Style(this, {
53+
fill: cfill,
54+
fillOpacity: cfillOpacity,
55+
stroke: cstroke,
56+
strokeOpacity: cstrokeOpacity,
57+
...options
58+
});
4759
this.rotate = crotate;
4860
this.textAnchor = string(textAnchor);
4961
this.fontFamily = string(fontFamily);
@@ -57,7 +69,7 @@ export class Text extends Mark {
5769
render(
5870
I,
5971
{x, y},
60-
{x: X, y: Y, rotate: R, text: T, title: L, fill: F, fillOpacity: FO, fontSize: FS},
72+
{x: X, y: Y, rotate: R, text: T, title: L, fill: F, fillOpacity: FO, fontSize: FS, stroke: S, strokeOpacity: SO},
6173
{width, height, marginTop, marginRight, marginBottom, marginLeft}
6274
) {
6375
const {rotate} = this;
@@ -83,6 +95,8 @@ export class Text extends Mark {
8395
.call(applyAttr, "fill", F && (i => F[i]))
8496
.call(applyAttr, "fill-opacity", FO && (i => FO[i]))
8597
.call(applyAttr, "font-size", FS && (i => FS[i]))
98+
.call(applyAttr, "stroke", S && (i => S[i]))
99+
.call(applyAttr, "stroke-opacity", SO && (i => SO[i]))
86100
.text(i => T[i])
87101
.call(title(L)))
88102
.node();

0 commit comments

Comments
 (0)