Skip to content

Commit a7f7ba9

Browse files
committed
maybeChannel
1 parent 1a5d831 commit a7f7ba9

File tree

10 files changed

+37
-37
lines changed

10 files changed

+37
-37
lines changed

src/channel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const channelRegistry = new Map([
3838
["weight", {definition: maybeNumberChannel}] // density
3939
]);
4040

41-
export function definition(name, value, defaultValue) {
41+
export function maybeChannel(name, value, defaultValue) {
4242
if (!channelRegistry.has(name)) {
4343
warn(`The ${name} channel is not registered and might be incompatible with some transforms.`);
4444
}

src/legends/swatches.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {inferFontVariant} from "../axes.js";
33
import {maybeAutoTickFormat} from "../axis.js";
44
import {Context, create} from "../context.js";
55
import {isNoneish} from "../options.js";
6-
import {definition} from "../channel.js";
6+
import {maybeChannel} from "../channel.js";
77
import {isOrdinalScale, isThresholdScale} from "../scales.js";
88
import {applyInlineStyles, impliedString, maybeClassName} from "../style.js";
99

@@ -43,14 +43,14 @@ export function legendSymbols(
4343
} = {},
4444
scale
4545
) {
46-
const [vf, cf] = definition("fill", fill);
47-
const [vs, cs] = definition("stroke", stroke);
46+
const [vf, cf] = maybeChannel("fill", fill);
47+
const [vs, cs] = maybeChannel("stroke", stroke);
4848
const sf = maybeScale(scale, vf);
4949
const ss = maybeScale(scale, vs);
5050
const size = r * r * Math.PI;
51-
fillOpacity = definition("fillOpacity", fillOpacity)[1];
52-
strokeOpacity = definition("strokeOpacity", strokeOpacity)[1];
53-
strokeWidth = definition("strokeWidth", strokeWidth)[1];
51+
fillOpacity = maybeChannel("fillOpacity", fillOpacity)[1];
52+
strokeOpacity = maybeChannel("strokeOpacity", strokeOpacity)[1];
53+
strokeWidth = maybeChannel("strokeWidth", strokeWidth)[1];
5454
return legendItems(
5555
symbol,
5656
options,

src/marks/cell.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {identity, indexOf, maybeTuple} from "../options.js";
2-
import {definition} from "../channel.js";
2+
import {maybeChannel} from "../channel.js";
33
import {applyTransform} from "../style.js";
44
import {AbstractBar} from "./bar.js";
55

@@ -55,7 +55,7 @@ export function cell(data, options = {}) {
5555
*/
5656
export function cellX(data, options = {}) {
5757
let {x = indexOf, fill, stroke, ...remainingOptions} = options;
58-
if (fill === undefined && definition("stroke", stroke)[0] === undefined) fill = identity;
58+
if (fill === undefined && maybeChannel("stroke", stroke)[0] === undefined) fill = identity;
5959
return new Cell(data, {...remainingOptions, x, fill, stroke});
6060
}
6161

@@ -73,6 +73,6 @@ export function cellX(data, options = {}) {
7373
*/
7474
export function cellY(data, options = {}) {
7575
let {y = indexOf, fill, stroke, ...remainingOptions} = options;
76-
if (fill === undefined && definition("stroke", stroke)[0] === undefined) fill = identity;
76+
if (fill === undefined && maybeChannel("stroke", stroke)[0] === undefined) fill = identity;
7777
return new Cell(data, {...remainingOptions, y, fill, stroke});
7878
}

src/marks/dot.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {path, symbolCircle} from "d3";
22
import {create} from "../context.js";
33
import {positive} from "../defined.js";
44
import {identity, maybeFrameAnchor, maybeTuple} from "../options.js";
5-
import {definition} from "../channel.js";
5+
import {maybeChannel} from "../channel.js";
66
import {Mark} from "../plot.js";
77
import {
88
applyChannelStyles,
@@ -24,9 +24,9 @@ const defaults = {
2424
export class Dot extends Mark {
2525
constructor(data, options = {}) {
2626
const {x, y, r, rotate, symbol = symbolCircle, frameAnchor} = options;
27-
const [vrotate, crotate] = definition("rotate", rotate, 0);
28-
const [vsymbol, csymbol] = definition("symbol", symbol);
29-
const [vr, cr] = definition("r", r, vsymbol == null ? 3 : 4.5);
27+
const [vrotate, crotate] = maybeChannel("rotate", rotate, 0);
28+
const [vsymbol, csymbol] = maybeChannel("symbol", symbol);
29+
const [vr, cr] = maybeChannel("r", r, vsymbol == null ? 3 : 4.5);
3030
super(
3131
data,
3232
{

src/marks/image.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
impliedString,
1212
applyFrameAnchor
1313
} from "../style.js";
14-
import {definition} from "../channel.js";
14+
import {maybeChannel} from "../channel.js";
1515

1616
const defaults = {
1717
ariaLabel: "image",
@@ -24,9 +24,9 @@ export class Image extends Mark {
2424
let {x, y, width, height, src, preserveAspectRatio, crossOrigin, frameAnchor} = options;
2525
if (width === undefined && height !== undefined) width = height;
2626
else if (height === undefined && width !== undefined) height = width;
27-
const [vs, cs] = definition("src", src);
28-
const [vw, cw] = definition("width", width, 16);
29-
const [vh, ch] = definition("height", height, 16);
27+
const [vs, cs] = maybeChannel("src", src);
28+
const [vw, cw] = maybeChannel("width", width, 16);
29+
const [vh, ch] = maybeChannel("height", height, 16);
3030
super(
3131
data,
3232
{

src/marks/text.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
applyFrameAnchor
2727
} from "../style.js";
2828
import {maybeIntervalMidX, maybeIntervalMidY} from "../transforms/interval.js";
29-
import {definition} from "../channel.js";
29+
import {maybeChannel} from "../channel.js";
3030

3131
const defaults = {
3232
ariaLabel: "text",
@@ -54,8 +54,8 @@ export class Text extends Mark {
5454
fontWeight,
5555
rotate
5656
} = options;
57-
const [vrotate, crotate] = definition("rotate", rotate, 0);
58-
const [vfontSize, cfontSize] = definition("fontSize", fontSize);
57+
const [vrotate, crotate] = maybeChannel("rotate", rotate, 0);
58+
const [vfontSize, cfontSize] = maybeChannel("fontSize", fontSize);
5959
super(
6060
data,
6161
{

src/marks/vector.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {create} from "../context.js";
22
import {radians} from "../math.js";
33
import {maybeFrameAnchor, maybeTuple, keyword, identity} from "../options.js";
4-
import {definition} from "../channel.js";
4+
import {maybeChannel} from "../channel.js";
55
import {Mark} from "../plot.js";
66
import {
77
applyChannelStyles,
@@ -22,8 +22,8 @@ const defaults = {
2222
export class Vector extends Mark {
2323
constructor(data, options = {}) {
2424
const {x, y, length, rotate, anchor = "middle", frameAnchor} = options;
25-
const [vl, cl] = definition("length", length, 12);
26-
const [vr, cr] = definition("rotate", rotate, 0);
25+
const [vl, cl] = maybeChannel("length", length, 12);
26+
const [vr, cr] = maybeChannel("rotate", rotate, 0);
2727
super(
2828
data,
2929
{

src/style.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {defined, nonempty} from "./defined.js";
33
import {formatDefault} from "./format.js";
44
import {string, number, isNoneish, isNone, isRound, keyof} from "./options.js";
55
import {warn} from "./warnings.js";
6-
import {definition} from "./channel.js";
6+
import {maybeChannel} from "./channel.js";
77

88
export const offset = typeof window !== "undefined" && window.devicePixelRatio > 1 ? 0 : 0.5;
99

@@ -71,11 +71,11 @@ export function styles(
7171
if (isNoneish(defaultStroke) && !isNoneish(stroke)) defaultFill = "none";
7272
}
7373

74-
const [vfill, cfill] = definition("fill", fill, defaultFill);
75-
const [vfillOpacity, cfillOpacity] = definition("fillOpacity", fillOpacity, defaultFillOpacity);
76-
const [vstroke, cstroke] = definition("stroke", stroke, defaultStroke);
77-
const [vstrokeOpacity, cstrokeOpacity] = definition("strokeOpacity", strokeOpacity, defaultStrokeOpacity);
78-
const [vopacity, copacity] = definition("opacity", opacity);
74+
const [vfill, cfill] = maybeChannel("fill", fill, defaultFill);
75+
const [vfillOpacity, cfillOpacity] = maybeChannel("fillOpacity", fillOpacity, defaultFillOpacity);
76+
const [vstroke, cstroke] = maybeChannel("stroke", stroke, defaultStroke);
77+
const [vstrokeOpacity, cstrokeOpacity] = maybeChannel("strokeOpacity", strokeOpacity, defaultStrokeOpacity);
78+
const [vopacity, copacity] = maybeChannel("opacity", opacity);
7979

8080
// For styles that have no effect if there is no stroke, only apply the
8181
// defaults if the stroke is not the constant none. (If stroke is a channel,
@@ -95,7 +95,7 @@ export function styles(
9595
if (!isNone(cfill) && paintOrder === undefined) paintOrder = defaultPaintOrder;
9696
}
9797

98-
const [vstrokeWidth, cstrokeWidth] = definition("strokeWidth", strokeWidth);
98+
const [vstrokeWidth, cstrokeWidth] = maybeChannel("strokeWidth", strokeWidth);
9999

100100
// Some marks don’t support fill (e.g., tick and rule).
101101
if (defaultFill !== null) {

src/transforms/bin.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
thresholdSturges,
88
utcTickInterval
99
} from "d3";
10-
import {definition} from "../channel.js";
10+
import {maybeChannel} from "../channel.js";
1111
import {
1212
valueof,
1313
identity,
@@ -158,8 +158,8 @@ function binn(
158158
...options
159159
} = inputs;
160160
const [GZ, setGZ] = maybeColumn(z);
161-
const [vfill] = definition("fill", fill);
162-
const [vstroke] = definition("stroke", stroke);
161+
const [vfill] = maybeChannel("fill", fill);
162+
const [vstroke] = maybeChannel("stroke", stroke);
163163
const [GF, setGF] = maybeColumn(vfill);
164164
const [GS, setGS] = maybeColumn(vstroke);
165165

src/transforms/group.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import {
2929
second,
3030
percentile
3131
} from "../options.js";
32-
import {definition} from "../channel.js";
32+
import {maybeChannel} from "../channel.js";
3333
import {basic} from "./basic.js";
3434

3535
/**
@@ -135,8 +135,8 @@ function groupn(
135135
...options
136136
} = inputs;
137137
const [GZ, setGZ] = maybeColumn(z);
138-
const [vfill] = definition("fill", fill);
139-
const [vstroke] = definition("stroke", stroke);
138+
const [vfill] = maybeChannel("fill", fill);
139+
const [vstroke] = maybeChannel("stroke", stroke);
140140
const [GF, setGF] = maybeColumn(vfill);
141141
const [GS, setGS] = maybeColumn(vstroke);
142142

0 commit comments

Comments
 (0)