Skip to content

Commit 1f97ce2

Browse files
committed
brush styles
1 parent 4abc443 commit 1f97ce2

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

src/marks/brush.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import {brush as brusher, brushX as brusherX, brushY as brusherY, create, select} from "d3";
22
import {identity, maybeTuple} from "../options.js";
33
import {Mark} from "../plot.js";
4-
import {applyIndirectStyles} from "../style.js";
4+
import {applyDirectStyles, applyIndirectStyles} from "../style.js";
55

6-
// TODO Allow brush styling?
76
// TODO Disable standard mark channels (e.g., href, title)?
87
const defaults = {
98
ariaLabel: "brush",
10-
fill: null,
11-
stroke: null
9+
fill: "#777",
10+
fillOpacity: 0.3,
11+
stroke: "#fff"
1212
};
1313

1414
// TODO Initial selection?
@@ -30,13 +30,14 @@ export class Brush extends Mark {
3030
}
3131
render(index, scales, {x: X, y: Y}, dimensions) {
3232
const {marginLeft, width, marginRight, marginTop, height, marginBottom} = dimensions;
33+
const {ariaLabel, ariaDescription, ariaHidden, ...options} = this;
3334
const left = marginLeft;
3435
const top = marginTop;
3536
const right = width - marginRight;
3637
const bottom = height - marginBottom;
3738
const mark = this;
3839
const g = create("svg:g")
39-
.call(applyIndirectStyles, this)
40+
.call(applyIndirectStyles, {ariaLabel, ariaDescription, ariaHidden})
4041
.call((X && Y ? brusher : X ? brusherX : brusherY)()
4142
.extent([[left, top], [right, bottom]])
4243
.on("start brush end", function(event) {
@@ -66,6 +67,10 @@ export class Brush extends Mark {
6667
this.selection = S;
6768
this.dispatchEvent(new Event("input", {bubbles: true}));
6869
}))
70+
.call(g => g.selectAll(".selection")
71+
.attr("shape-rendering", null) // reset d3-brush
72+
.call(applyIndirectStyles, options)
73+
.call(applyDirectStyles, options))
6974
.node();
7075
g.selection = null;
7176
return g;

src/style.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ export function styles(
3232
{
3333
ariaLabel: cariaLabel,
3434
fill: defaultFill = "currentColor",
35+
fillOpacity: defaultFillOpacity,
3536
stroke: defaultStroke = "none",
37+
strokeOpacity: defaultStrokeOpacity,
3638
strokeWidth: defaultStrokeWidth,
3739
strokeLinecap: defaultStrokeLinecap,
3840
strokeLinejoin: defaultStrokeLinejoin,
@@ -66,9 +68,9 @@ export function styles(
6668
}
6769

6870
const [vfill, cfill] = maybeColorChannel(fill, defaultFill);
69-
const [vfillOpacity, cfillOpacity] = maybeNumberChannel(fillOpacity);
71+
const [vfillOpacity, cfillOpacity] = maybeNumberChannel(fillOpacity, defaultFillOpacity);
7072
const [vstroke, cstroke] = maybeColorChannel(stroke, defaultStroke);
71-
const [vstrokeOpacity, cstrokeOpacity] = maybeNumberChannel(strokeOpacity);
73+
const [vstrokeOpacity, cstrokeOpacity] = maybeNumberChannel(strokeOpacity, defaultStrokeOpacity);
7274
const [vopacity, copacity] = maybeNumberChannel(opacity);
7375

7476
// For styles that have no effect if there is no stroke, only apply the

test/output/gistempAnomalyBrush.svg

Lines changed: 1 addition & 1 deletion
Loading

0 commit comments

Comments
 (0)