Skip to content

Commit f47a889

Browse files
authored
rule strokeOpacity channel (#468)
* fix #466; strokeOpacity channel for rules * add rule strokeOpacity channel test
1 parent 7e45462 commit f47a889

File tree

4 files changed

+1510
-7
lines changed

4 files changed

+1510
-7
lines changed

src/marks/rule.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {create} from "d3";
22
import {filter} from "../defined.js";
3-
import {Mark, identity, maybeColor, title, number} from "../mark.js";
3+
import {Mark, identity, maybeColor, title, number, maybeNumber} from "../mark.js";
44
import {Style, applyDirectStyles, applyIndirectStyles, applyTransform, applyAttr} from "../style.js";
55

66
export class RuleX extends Mark {
@@ -12,32 +12,35 @@ export class RuleX extends Mark {
1212
y2,
1313
title,
1414
stroke,
15+
strokeOpacity,
1516
inset = 0,
1617
insetTop = inset,
1718
insetBottom = inset,
1819
...options
1920
} = {}
2021
) {
2122
const [vstroke, cstroke] = maybeColor(stroke, "currentColor");
23+
const [vstrokeOpacity, cstrokeOpacity] = maybeNumber(strokeOpacity);
2224
super(
2325
data,
2426
[
2527
{name: "x", value: x, scale: "x", optional: true},
2628
{name: "y1", value: y1, scale: "y", optional: true},
2729
{name: "y2", value: y2, scale: "y", optional: true},
2830
{name: "title", value: title, optional: true},
29-
{name: "stroke", value: vstroke, scale: "color", optional: true}
31+
{name: "stroke", value: vstroke, scale: "color", optional: true},
32+
{name: "strokeOpacity", value: vstrokeOpacity, scale: "opacity", optional: true}
3033
],
3134
options
3235
);
33-
Style(this, {stroke: cstroke, ...options});
36+
Style(this, {stroke: cstroke, strokeOpacity: cstrokeOpacity, ...options});
3437
this.insetTop = number(insetTop);
3538
this.insetBottom = number(insetBottom);
3639
}
3740
render(
3841
I,
3942
{x, y},
40-
{x: X, y1: Y1, y2: Y2, title: L, stroke: S},
43+
{x: X, y1: Y1, y2: Y2, title: L, stroke: S, strokeOpacity: SO},
4144
{width, height, marginTop, marginRight, marginLeft, marginBottom}
4245
) {
4346
const index = filter(I, X, Y1, Y2, S);
@@ -53,6 +56,7 @@ export class RuleX extends Mark {
5356
.attr("y1", Y1 ? i => Y1[i] + this.insetTop : marginTop + this.insetTop)
5457
.attr("y2", Y2 ? (y.bandwidth ? i => Y2[i] + y.bandwidth() - this.insetBottom : i => Y2[i] - this.insetBottom) : height - marginBottom - this.insetBottom)
5558
.call(applyAttr, "stroke", S && (i => S[i]))
59+
.call(applyAttr, "stroke-opacity", SO && (i => SO[i]))
5660
.call(title(L)))
5761
.node();
5862
}
@@ -67,32 +71,35 @@ export class RuleY extends Mark {
6771
y,
6872
title,
6973
stroke,
74+
strokeOpacity,
7075
inset = 0,
7176
insetRight = inset,
7277
insetLeft = inset,
7378
...options
7479
} = {}
7580
) {
7681
const [vstroke, cstroke] = maybeColor(stroke, "currentColor");
82+
const [vstrokeOpacity, cstrokeOpacity] = maybeNumber(strokeOpacity);
7783
super(
7884
data,
7985
[
8086
{name: "y", value: y, scale: "y", optional: true},
8187
{name: "x1", value: x1, scale: "x", optional: true},
8288
{name: "x2", value: x2, scale: "x", optional: true},
8389
{name: "title", value: title, optional: true},
84-
{name: "stroke", value: vstroke, scale: "color", optional: true}
90+
{name: "stroke", value: vstroke, scale: "color", optional: true},
91+
{name: "strokeOpacity", value: vstrokeOpacity, scale: "opacity", optional: true}
8592
],
8693
options
8794
);
88-
Style(this, {stroke: cstroke, ...options});
95+
Style(this, {stroke: cstroke, strokeOpacity: cstrokeOpacity, ...options});
8996
this.insetRight = number(insetRight);
9097
this.insetLeft = number(insetLeft);
9198
}
9299
render(
93100
I,
94101
{x, y},
95-
{y: Y, x1: X1, x2: X2, title: L, stroke: S},
102+
{y: Y, x1: X1, x2: X2, title: L, stroke: S, strokeOpacity: SO},
96103
{width, height, marginTop, marginRight, marginLeft, marginBottom}
97104
) {
98105
const index = filter(I, Y, X1, X2);
@@ -108,6 +115,7 @@ export class RuleY extends Mark {
108115
.attr("y1", Y ? i => Y[i] : (marginTop + height - marginBottom) / 2)
109116
.attr("y2", Y ? i => Y[i] : (marginTop + height - marginBottom) / 2)
110117
.call(applyAttr, "stroke", S && (i => S[i]))
118+
.call(applyAttr, "stroke-opacity", SO && (i => SO[i]))
111119
.call(title(L)))
112120
.node();
113121
}

0 commit comments

Comments
 (0)