|
1 |
| -import {column, maybeColorChannel, maybeNumberChannel, slice, valueof} from "./options.js"; |
2 |
| -import {maybeSymbolChannel} from "./symbols.js"; |
3 |
| -import {maybeFontSizeChannel} from "./marks/text.js"; |
4 |
| -import {maybePathChannel} from "./marks/image.js"; |
| 1 | +import {column, slice, valueof} from "./options.js"; |
5 | 2 |
|
6 | 3 | export function facetReindex(facets, n) {
|
7 | 4 | if (facets.length === 1) return {facets};
|
@@ -54,44 +51,46 @@ export function maybeExpand(X, plan) {
|
54 | 51 |
|
55 | 52 | // Iterate over the options and pull out any that represent columns of values.
|
56 | 53 | const knownChannels = [
|
57 |
| - ["x"], |
58 |
| - ["x1"], |
59 |
| - ["x2"], |
60 |
| - ["y"], |
61 |
| - ["y1"], |
62 |
| - ["y2"], |
63 |
| - ["z"], |
64 |
| - ["ariaLabel"], |
65 |
| - ["href"], |
66 |
| - ["title"], |
67 |
| - ["fill", (value) => maybeColorChannel(value)[0]], |
68 |
| - ["stroke", (value) => maybeColorChannel(value)[0]], |
69 |
| - ["fillOpacity", (value) => maybeNumberChannel(value)[0]], |
70 |
| - ["strokeOpacity", (value) => maybeNumberChannel(value)[0]], |
71 |
| - ["opacity", (value) => maybeNumberChannel(value)[0]], |
72 |
| - ["strokeWidth", (value) => maybeNumberChannel(value)[0]], |
73 |
| - ["symbol", (value) => maybeSymbolChannel(value)[0]], // dot |
74 |
| - ["r", (value) => maybeNumberChannel(value)[0]], // dot |
75 |
| - ["rotate", (value) => maybeNumberChannel(value)[0]], // dot, text |
76 |
| - ["fontSize", (value) => maybeFontSizeChannel(value)[0]], // text |
77 |
| - ["text"], // text |
78 |
| - ["length", (value) => maybeNumberChannel(value)[0]], // vector |
79 |
| - ["width", (value) => maybeNumberChannel(value)[0]], // image |
80 |
| - ["height", (value) => maybeNumberChannel(value)[0]], // image |
81 |
| - ["src", (value) => maybePathChannel(value)[0]], // image |
82 |
| - ["weight", (value) => maybeNumberChannel(value)[0]] // density |
| 54 | + "x", |
| 55 | + "x1", |
| 56 | + "x2", |
| 57 | + "y", |
| 58 | + "y1", |
| 59 | + "y2", |
| 60 | + "z", |
| 61 | + "ariaLabel", |
| 62 | + "href", |
| 63 | + "title", |
| 64 | + "fill", |
| 65 | + "stroke", |
| 66 | + "fillOpacity", |
| 67 | + "strokeOpacity", |
| 68 | + "opacity", |
| 69 | + "strokeWidth", |
| 70 | + "symbol", // dot |
| 71 | + "r", // dot |
| 72 | + "rotate", // dot, text |
| 73 | + "fontSize", // text |
| 74 | + "text", // text |
| 75 | + "length", // vector |
| 76 | + "width", // image |
| 77 | + "height", // image |
| 78 | + "src", // image |
| 79 | + "weight" // density |
83 | 80 | ];
|
84 | 81 |
|
85 |
| -export function maybeExpandOutputs(options) { |
86 |
| - const other = {}; |
87 |
| - const outputs = []; |
88 |
| - for (const [name, test = (value) => value] of knownChannels) { |
89 |
| - const value = test(options[name]); |
| 82 | +export function maybeExpandChannels(options) { |
| 83 | + const channels = {}; |
| 84 | + const [{transform: plan}, setPlan] = column(); |
| 85 | + for (const name of knownChannels) { |
| 86 | + let value = options[name]; |
90 | 87 | if (value != null) {
|
91 |
| - const [V, setV] = column(value); |
92 |
| - other[name] = V; |
93 |
| - outputs.push((data, plan) => setV(maybeExpand(valueof(data, value), plan))); |
| 88 | + if (value.definition) continue; // already planned |
| 89 | + channels[name] = { |
| 90 | + definition: value, |
| 91 | + transform: (data) => maybeExpand(valueof(data, value), plan()) |
| 92 | + }; |
94 | 93 | }
|
95 | 94 | }
|
96 |
| - return [other, outputs]; |
| 95 | + return [channels, setPlan]; |
97 | 96 | }
|
0 commit comments