Skip to content

Commit a3075a7

Browse files
committed
Plot.map becomes reindex-aware
1 parent 7999256 commit a3075a7

File tree

4 files changed

+851
-4
lines changed

4 files changed

+851
-4
lines changed

src/transforms/map.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {count, group, rank} from "d3";
22
import {maybeZ, take, valueof, maybeInput, column} from "../options.js";
33
import {basic} from "./basic.js";
4+
import {facetReindex, getter, expander} from "../facet.js";
45

56
/**
67
* ```js
@@ -58,11 +59,13 @@ export function map(outputs = {}, options = {}) {
5859
});
5960
return {
6061
...basic(options, (data, facets) => {
62+
// make facets exclusive
63+
facets = facetReindex(facets, data.length);
6164
const Z = valueof(data, z);
62-
const X = channels.map(({input}) => valueof(data, input));
63-
const MX = channels.map(({setOutput}) => setOutput(new Array(data.length)));
65+
const X = channels.map(({input}) => expander(facets, valueof(data, input)));
66+
const MX = channels.map(({setOutput}) => setOutput(new Array((facets.plan || data).length)));
6467
for (const facet of facets) {
65-
for (const I of Z ? group(facet, (i) => Z[i]).values() : [facet]) {
68+
for (const I of Z ? group(facet, getter(facets, Z)).values() : [facet]) {
6669
channels.forEach(({map}, i) => map.map(I, X[i], MX[i]));
6770
}
6871
}

0 commit comments

Comments
 (0)