|
1 |
| -import {cross, groups, InternMap} from "d3"; |
| 1 | +import {cross, difference, groups, InternMap} from "d3"; |
2 | 2 | import {create} from "d3";
|
3 | 3 | import {Mark, values, first, second} from "./mark.js";
|
4 | 4 |
|
@@ -36,26 +36,30 @@ class Facet extends Mark {
|
36 | 36 | for (const facetKey of facetsKeys) {
|
37 | 37 | marksIndexByFacet.set(facetKey, new Array(this.marks.length));
|
38 | 38 | }
|
| 39 | + let facetsExclude; |
39 | 40 | for (let i = 0; i < this.marks.length; ++i) {
|
40 | 41 | const mark = this.marks[i];
|
41 |
| - const markFacets = mark.data === this.data ? facetsIndex : undefined; |
42 |
| - const {index, channels} = mark.initialize(markFacets); |
| 42 | + const {facet} = mark; |
| 43 | + const markFacets = facet === "auto" ? mark.data === this.data ? facetsIndex : undefined |
| 44 | + : facet === "include" ? facetsIndex |
| 45 | + : facet === "exclude" ? facetsExclude || (facetsExclude = facetsIndex.map(f => Uint32Array.from(difference(index, f)))) |
| 46 | + : undefined; |
| 47 | + const {index: I, channels} = mark.initialize(markFacets); |
43 | 48 | // If an index is returned by mark.initialize, its structure depends on
|
44 | 49 | // whether or not faceting has been applied: it is a flat index ([0, 1, 2,
|
45 | 50 | // …]) when not faceted, and a nested index ([[0, 1, …], [2, 3, …], …])
|
46 |
| - // when faceted. Faceting is only applied if the mark data is the same as |
47 |
| - // the facet’s data. |
48 |
| - if (index !== undefined) { |
| 51 | + // when faceted. |
| 52 | + if (I !== undefined) { |
49 | 53 | if (markFacets) {
|
50 | 54 | for (let j = 0; j < facetsKeys.length; ++j) {
|
51 |
| - marksIndexByFacet.get(facetsKeys[j])[i] = index[j]; |
| 55 | + marksIndexByFacet.get(facetsKeys[j])[i] = I[j]; |
52 | 56 | }
|
53 | 57 | marksIndex[i] = []; // implicit empty index for sparse facets
|
54 | 58 | } else {
|
55 | 59 | for (let j = 0; j < facetsKeys.length; ++j) {
|
56 |
| - marksIndexByFacet.get(facetsKeys[j])[i] = index; |
| 60 | + marksIndexByFacet.get(facetsKeys[j])[i] = I; |
57 | 61 | }
|
58 |
| - marksIndex[i] = index; |
| 62 | + marksIndex[i] = I; |
59 | 63 | }
|
60 | 64 | }
|
61 | 65 | for (const [, channel] of channels) {
|
|
0 commit comments