Skip to content

Commit 267623c

Browse files
committed
strokeWidth as a channel
1 parent b1885ad commit 267623c

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ All marks support the following optional channels:
476476
* **strokeOpacity** - a stroke opacity; bound to the *opacity* scale
477477
* **title** - a tooltip (a string of text, possibly with newlines)
478478

479-
The **fill**, **fillOpacity**, **stroke**, and **strokeOpacity** options can be specified as either channels or constants. When the fill or stroke is specified as a function or array, it is interpreted as a channel; when the fill or stroke is specified as a string, it is interpreted as a constant if a valid CSS color and otherwise it is interpreted as a column name for a channel. Similarly when the fill or stroke opacity is specified as a number, it is interpreted as a constant; otherwise it is interpeted as a channel. When the radius is specified as a number, it is interpreted as a constant; otherwise it is interpreted as a channel.
479+
The **fill**, **fillOpacity**, **stroke**, **strokeWidth**, and **strokeOpacity** options can be specified as either channels or constants. When the fill or stroke is specified as a function or array, it is interpreted as a channel; when the fill or stroke is specified as a string, it is interpreted as a constant if a valid CSS color and otherwise it is interpreted as a column name for a channel. Similarly when the fill or stroke opacity or the stroke width is specified as a number, it is interpreted as a constant; otherwise it is interpreted as a channel. When the radius is specified as a number, it is interpreted as a constant; otherwise it is interpreted as a channel.
480480

481481
The rectangular marks ([bar](#bar), [cell](#cell), and [rect](#rect)) support insets and rounded corner constant options:
482482

src/style.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,16 @@ export function styles(
5858
if (strokeMiterlimit === undefined) strokeMiterlimit = defaultStrokeMiterlimit;
5959
}
6060

61+
const [vstrokeWidth, cstrokeWidth] = maybeNumber(strokeWidth);
62+
6163
// Some marks don’t support fill (e.g., tick and rule).
6264
if (defaultFill !== null) {
6365
mark.fill = impliedString(cfill, "currentColor");
6466
mark.fillOpacity = impliedNumber(cfillOpacity, 1);
6567
}
6668

6769
mark.stroke = impliedString(cstroke, "none");
68-
mark.strokeWidth = impliedNumber(strokeWidth, 1);
70+
mark.strokeWidth = impliedNumber(cstrokeWidth, 1);
6971
mark.strokeOpacity = impliedNumber(cstrokeOpacity, 1);
7072
mark.strokeLinejoin = impliedString(strokeLinejoin, "miter");
7173
mark.strokeLinecap = impliedString(strokeLinecap, "butt");
@@ -80,23 +82,26 @@ export function styles(
8082
{name: "fill", value: vfill, scale: "color", optional: true},
8183
{name: "fillOpacity", value: vfillOpacity, scale: "opacity", optional: true},
8284
{name: "stroke", value: vstroke, scale: "color", optional: true},
83-
{name: "strokeOpacity", value: vstrokeOpacity, scale: "opacity", optional: true}
85+
{name: "strokeOpacity", value: vstrokeOpacity, scale: "opacity", optional: true},
86+
{name: "strokeWidth", value: vstrokeWidth, optional: true}
8487
];
8588
}
8689

87-
export function applyChannelStyles(selection, {title: L, fill: F, fillOpacity: FO, stroke: S, strokeOpacity: SO}) {
90+
export function applyChannelStyles(selection, {title: L, fill: F, fillOpacity: FO, stroke: S, strokeOpacity: SO, strokeWidth: SW}) {
8891
applyAttr(selection, "fill", F && (i => F[i]));
8992
applyAttr(selection, "fill-opacity", FO && (i => FO[i]));
9093
applyAttr(selection, "stroke", S && (i => S[i]));
9194
applyAttr(selection, "stroke-opacity", SO && (i => SO[i]));
95+
applyAttr(selection, "stroke-width", SW && (i => SW[i]));
9296
title(L)(selection);
9397
}
9498

95-
export function applyGroupedChannelStyles(selection, {title: L, fill: F, fillOpacity: FO, stroke: S, strokeOpacity: SO}) {
99+
export function applyGroupedChannelStyles(selection, {title: L, fill: F, fillOpacity: FO, stroke: S, strokeOpacity: SO, strokeWidth: SW}) {
96100
applyAttr(selection, "fill", F && (([i]) => F[i]));
97101
applyAttr(selection, "fill-opacity", FO && (([i]) => FO[i]));
98102
applyAttr(selection, "stroke", S && (([i]) => S[i]));
99103
applyAttr(selection, "stroke-opacity", SO && (([i]) => SO[i]));
104+
applyAttr(selection, "stroke-width", SW && (i => SW[i]));
100105
titleGroup(L)(selection);
101106
}
102107

@@ -141,8 +146,8 @@ export function impliedNumber(value, impliedValue) {
141146
if ((value = number(value)) !== impliedValue) return value;
142147
}
143148

144-
export function filterStyles(index, {fill: F, fillOpacity: FO, stroke: S, strokeOpacity: SO}) {
145-
return filter(index, F, FO, S, SO);
149+
export function filterStyles(index, {fill: F, fillOpacity: FO, stroke: S, strokeOpacity: SO, strokeWidth: SW}) {
150+
return filter(index, F, FO, S, SO, SW);
146151
}
147152

148153
function none(color) {

0 commit comments

Comments
 (0)