Skip to content

Commit 15073f5

Browse files
authored
column, not channel (#842)
1 parent e5bb1d6 commit 15073f5

File tree

8 files changed

+45
-45
lines changed

8 files changed

+45
-45
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2139,11 +2139,11 @@ Plot provides a few helpers for implementing transforms.
21392139
21402140
Given an *options* object that may specify some basic transforms (*filter*, *sort*, or *reverse*) or a custom *transform* function, composes those transforms if any with the given *transform* function, returning a new *options* object. If a custom *transform* function is present on the given *options*, any basic transforms are ignored. Any additional input *options* are passed through in the returned *options* object. This method facilitates applying the basic transforms prior to applying the given custom *transform* and is used internally by Plot’s built-in transforms.
21412141
2142-
#### Plot.channel([*source*])
2142+
#### Plot.column([*source*])
21432143
2144-
This helper for constructing derived channels returns a [*channel*, *setChannel*] array. The *channel* object implements *channel*.transform, returning whatever value was most recently passed to *setChannel*. If *setChannel* is not called, then *channel*.transform returns undefined. If a *source* is specified, then *channel*.label exposes the given *source*’s label, if any: if *source* is a string as when representing a named field of data, then *channel*.label is *source*; otherwise *channel*.label propagates *source*.label. This allows derived channels to propagate a human-readable axis or legend label.
2144+
This helper for constructing derived columns returns a [*column*, *setColumn*] array. The *column* object implements *column*.transform, returning whatever value was most recently passed to *setColumn*. If *setColumn* is not called, then *column*.transform returns undefined. If a *source* is specified, then *column*.label exposes the given *source*’s label, if any: if *source* is a string as when representing a named field of data, then *column*.label is *source*; otherwise *column*.label propagates *source*.label. This allows derived columns to propagate a human-readable axis or legend label.
21452145
2146-
Plot.channel is typically used by options transforms to define new channels; these channels are populated (derived) when the custom *transform* function is invoked.
2146+
Plot.column is typically used by options transforms to define new channels; the associated columns are populated (derived) when the **transform** option function is invoked.
21472147
21482148
## Curves
21492149

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export {Text, text, textX, textY} from "./marks/text.js";
1515
export {TickX, TickY, tickX, tickY} from "./marks/tick.js";
1616
export {tree, cluster} from "./marks/tree.js";
1717
export {Vector, vector, vectorX, vectorY} from "./marks/vector.js";
18-
export {valueof, channel} from "./options.js";
18+
export {valueof, column} from "./options.js";
1919
export {filter, reverse, sort, shuffle, basic as transform} from "./transforms/basic.js";
2020
export {bin, binX, binY} from "./transforms/bin.js";
2121
export {group, groupX, groupY, groupZ} from "./transforms/group.js";

src/options.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,10 @@ export function maybeInput(key, options) {
154154
return options[key];
155155
}
156156

157-
// Defines a channel whose values are lazily populated by calling the returned
157+
// Defines a column whose values are lazily populated by calling the returned
158158
// setter. If the given source is labeled, the label is propagated to the
159-
// returned channel definition.
160-
export function channel(source) {
159+
// returned column definition.
160+
export function column(source) {
161161
let value;
162162
return [
163163
{
@@ -168,9 +168,9 @@ export function channel(source) {
168168
];
169169
}
170170

171-
// Like channel, but allows the source to be null.
172-
export function maybeChannel(source) {
173-
return source == null ? [source] : channel(source);
171+
// Like column, but allows the source to be null.
172+
export function maybeColumn(source) {
173+
return source == null ? [source] : column(source);
174174
}
175175

176176
export function labelof(value, defaultValue) {
@@ -179,10 +179,10 @@ export function labelof(value, defaultValue) {
179179
: defaultValue;
180180
}
181181

182-
// Assuming that both x1 and x2 and lazy channels (per above), this derives a
183-
// new a channel that’s the average of the two, and which inherits the channel
184-
// label (if any). Both input channels are assumed to be quantitative. If either
185-
// channel is temporal, the returned channel is also temporal.
182+
// Assuming that both x1 and x2 and lazy columns (per above), this derives a new
183+
// a column that’s the average of the two, and which inherits the column label
184+
// (if any). Both input columns are assumed to be quantitative. If either column
185+
// is temporal, the returned column is also temporal.
186186
export function mid(x1, x2) {
187187
return {
188188
transform(data) {

src/transforms/bin.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {bin as binner, extent, thresholdFreedmanDiaconis, thresholdScott, thresholdSturges, utcTickInterval} from "d3";
2-
import {valueof, range, identity, maybeChannel, maybeTuple, maybeColorChannel, maybeValue, mid, labelof, isTemporal} from "../options.js";
2+
import {valueof, range, identity, maybeColumn, maybeTuple, maybeColorChannel, maybeValue, mid, labelof, isTemporal} from "../options.js";
33
import {coerceDate, coerceNumber} from "../scales.js";
44
import {basic} from "./basic.js";
55
import {hasOutput, maybeEvaluator, maybeGroup, maybeOutput, maybeOutputs, maybeReduce, maybeSort, maybeSubgroup, reduceCount, reduceFirst, reduceIdentity} from "./group.js";
@@ -67,14 +67,14 @@ function binn(
6767
if (gy != null && hasOutput(outputs, "y", "y1", "y2")) gy = null;
6868

6969
// Produce x1, x2, y1, and y2 output channels as appropriate (when binning).
70-
const [BX1, setBX1] = maybeChannel(bx);
71-
const [BX2, setBX2] = maybeChannel(bx);
72-
const [BY1, setBY1] = maybeChannel(by);
73-
const [BY2, setBY2] = maybeChannel(by);
70+
const [BX1, setBX1] = maybeColumn(bx);
71+
const [BX2, setBX2] = maybeColumn(bx);
72+
const [BY1, setBY1] = maybeColumn(by);
73+
const [BY2, setBY2] = maybeColumn(by);
7474

7575
// Produce x or y output channels as appropriate (when grouping).
7676
const [k, gk] = gx != null ? [gx, "x"] : gy != null ? [gy, "y"] : [];
77-
const [GK, setGK] = maybeChannel(k);
77+
const [GK, setGK] = maybeColumn(k);
7878

7979
// Greedily materialize the z, fill, and stroke channels (if channels and not
8080
// constants) so that we can reference them for subdividing groups without
@@ -94,11 +94,11 @@ function binn(
9494
interval, // eslint-disable-line no-unused-vars
9595
...options
9696
} = inputs;
97-
const [GZ, setGZ] = maybeChannel(z);
97+
const [GZ, setGZ] = maybeColumn(z);
9898
const [vfill] = maybeColorChannel(fill);
9999
const [vstroke] = maybeColorChannel(stroke);
100-
const [GF = fill, setGF] = maybeChannel(vfill);
101-
const [GS = stroke, setGS] = maybeChannel(vstroke);
100+
const [GF = fill, setGF] = maybeColumn(vfill);
101+
const [GS = stroke, setGS] = maybeColumn(vstroke);
102102

103103
return {
104104
..."z" in inputs && {z: GZ || z},

src/transforms/group.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {group as grouper, sort, sum, deviation, min, max, mean, median, mode, variance, InternSet, minIndex, maxIndex, rollup} from "d3";
22
import {ascendingDefined, firstof} from "../defined.js";
3-
import {valueof, maybeColorChannel, maybeInput, maybeTuple, maybeChannel, channel, first, identity, take, labelof, range, second, percentile} from "../options.js";
3+
import {valueof, maybeColorChannel, maybeInput, maybeTuple, maybeColumn, column, first, identity, take, labelof, range, second, percentile} from "../options.js";
44
import {basic} from "./basic.js";
55

66
// Group on {z, fill, stroke}.
@@ -51,8 +51,8 @@ function groupn(
5151
filter = filter == null ? undefined : maybeEvaluator("filter", filter, inputs);
5252

5353
// Produce x and y output channels as appropriate.
54-
const [GX, setGX] = maybeChannel(x);
55-
const [GY, setGY] = maybeChannel(y);
54+
const [GX, setGX] = maybeColumn(x);
55+
const [GY, setGY] = maybeColumn(y);
5656

5757
// Greedily materialize the z, fill, and stroke channels (if channels and not
5858
// constants) so that we can reference them for subdividing groups without
@@ -65,11 +65,11 @@ function groupn(
6565
y1, y2, // consumed if y is an output
6666
...options
6767
} = inputs;
68-
const [GZ, setGZ] = maybeChannel(z);
68+
const [GZ, setGZ] = maybeColumn(z);
6969
const [vfill] = maybeColorChannel(fill);
7070
const [vstroke] = maybeColorChannel(stroke);
71-
const [GF = fill, setGF] = maybeChannel(vfill);
72-
const [GS = stroke, setGS] = maybeChannel(vstroke);
71+
const [GF = fill, setGF] = maybeColumn(vfill);
72+
const [GS = stroke, setGS] = maybeColumn(vstroke);
7373

7474
return {
7575
..."z" in inputs && {z: GZ || z},
@@ -148,7 +148,7 @@ export function maybeOutputs(outputs, inputs) {
148148

149149
export function maybeOutput(name, reduce, inputs) {
150150
const evaluator = maybeEvaluator(name, reduce, inputs);
151-
const [output, setOutput] = channel(evaluator.label);
151+
const [output, setOutput] = column(evaluator.label);
152152
let O;
153153
return {
154154
name,

src/transforms/map.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {count, group, rank} from "d3";
2-
import {maybeZ, take, valueof, maybeInput, channel} from "../options.js";
2+
import {maybeZ, take, valueof, maybeInput, column} from "../options.js";
33
import {basic} from "./basic.js";
44

55
export function mapX(m, options = {}) {
@@ -19,7 +19,7 @@ export function map(outputs = {}, options = {}) {
1919
const channels = Object.entries(outputs).map(([key, map]) => {
2020
const input = maybeInput(key, options);
2121
if (input == null) throw new Error(`missing channel: ${key}`);
22-
const [output, setOutput] = channel(input);
22+
const [output, setOutput] = column(input);
2323
return {key, input, output, setOutput, map: maybeMap(map)};
2424
});
2525
return {

src/transforms/stack.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {InternMap, cumsum, group, groupSort, greatest, max, min, rollup, sum} from "d3";
22
import {ascendingDefined} from "../defined.js";
3-
import {field, channel, maybeChannel, maybeZ, mid, range, valueof, maybeZero, one} from "../options.js";
3+
import {field, column, maybeColumn, maybeZ, mid, range, valueof, maybeZero, one} from "../options.js";
44
import {basic} from "./basic.js";
55

66
export function stackX(stackOptions = {}, options = {}) {
@@ -67,9 +67,9 @@ function mergeOptions(options) {
6767

6868
function stack(x, y = one, ky, {offset, order, reverse}, options) {
6969
const z = maybeZ(options);
70-
const [X, setX] = maybeChannel(x);
71-
const [Y1, setY1] = channel(y);
72-
const [Y2, setY2] = channel(y);
70+
const [X, setX] = maybeColumn(x);
71+
const [Y1, setY1] = column(y);
72+
const [Y2, setY2] = column(y);
7373
offset = maybeOffset(offset);
7474
order = maybeOrder(order, offset, ky);
7575
return [

src/transforms/tree.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {stratify, tree} from "d3";
22
import {ascendingDefined} from "../defined.js";
3-
import {channel, identity, isObject, one, valueof} from "../options.js";
3+
import {column, identity, isObject, one, valueof} from "../options.js";
44
import {basic} from "./basic.js";
55

66
export function treeNode({
@@ -18,8 +18,8 @@ export function treeNode({
1818
if (frameAnchor === undefined) frameAnchor = treeAnchor.frameAnchor;
1919
const normalize = normalizer(delimiter);
2020
const outputs = treeOutputs(options, maybeNodeValue);
21-
const [X, setX] = channel();
22-
const [Y, setY] = channel();
21+
const [X, setX] = column();
22+
const [Y, setY] = column();
2323
return {
2424
x: X,
2525
y: Y,
@@ -73,10 +73,10 @@ export function treeLink({
7373
options = {curve, stroke, strokeWidth, strokeOpacity, ...options};
7474
const normalize = normalizer(delimiter);
7575
const outputs = treeOutputs(options, maybeLinkValue);
76-
const [X1, setX1] = channel();
77-
const [X2, setX2] = channel();
78-
const [Y1, setY1] = channel();
79-
const [Y2, setY2] = channel();
76+
const [X1, setX1] = column();
77+
const [X2, setX2] = column();
78+
const [Y1, setY1] = column();
79+
const [Y2, setY2] = column();
8080
return {
8181
x1: X1,
8282
x2: X2,
@@ -256,7 +256,7 @@ function slash(path, i) {
256256
}
257257

258258
// These indexes match the array returned by nodeOutputs. The first two elements
259-
// are always the name of the output and its channel value definition so that
259+
// are always the name of the output and its column value definition so that
260260
// the outputs can be passed directly to Object.fromEntries.
261261
const output_setValues = 2;
262262
const output_evaluate = 3;
@@ -268,7 +268,7 @@ function treeOutputs(options, maybeTreeValue) {
268268
const value = options[name];
269269
const treeValue = maybeTreeValue(value);
270270
if (treeValue !== undefined) {
271-
outputs.push([name, ...channel(value), treeValue]);
271+
outputs.push([name, ...column(value), treeValue]);
272272
}
273273
}
274274
return outputs;

0 commit comments

Comments
 (0)