Skip to content

Commit ad8600b

Browse files
committed
reindex symbol
1 parent c7f9f69 commit ad8600b

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/options.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import {maybeTimeInterval, maybeUtcInterval} from "./time.js";
77
export const TypedArray = Object.getPrototypeOf(Uint8Array);
88
const objectToString = Object.prototype.toString;
99

10+
// If a reindex is attached to the data, channel values expressed as arrays will
11+
// be reindexed when the channels are instantiated. See exclusiveFacets.
12+
export const reindex = Symbol("reindex");
13+
1014
export function valueof(data, value, type) {
1115
const valueType = typeof value;
1216
return valueType === "string"
@@ -17,7 +21,7 @@ export function valueof(data, value, type) {
1721
? map(data, constant(value), type)
1822
: typeof value?.transform === "function"
1923
? maybeTypedArrayify(value.transform(data), type)
20-
: maybeTake(maybeTypedArrayify(value, type), data?.reindex);
24+
: maybeTake(maybeTypedArrayify(value, type), data?.[reindex]);
2125
}
2226

2327
function maybeTake(values, index) {

src/transforms/exclusiveFacets.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {slice} from "../options.js";
1+
import {reindex, slice} from "../options.js";
22

33
export function exclusiveFacets(data, facets) {
44
if (facets.length === 1) return {data, facets}; // only one facet; trivially exclusive
@@ -20,18 +20,18 @@ export function exclusiveFacets(data, facets) {
2020

2121
// For each overlapping index (duplicate), assign a new unique index at the
2222
// end of the existing array, duplicating the datum. For example, [[0, 1, 2],
23-
// [2, 1, 3]] would become [[0, 1, 2], [4, 5, 3]].
23+
// [2, 1, 3]] would become [[0, 1, 2], [4, 5, 3]]. Also attach a reindex to
24+
// the data to preserve the association of channel values specified as arrays.
2425
data = slice(data);
25-
// Attach a reindex map to the data, to interpret channels specified as arrays.
26-
data.reindex = new Uint32Array(n + overlaps);
26+
const R = (data[reindex] = new Uint32Array(n + overlaps));
2727
facets = facets.map((facet) => slice(facet, Uint32Array));
2828
let j = n;
2929
O.fill(0);
3030
for (const facet of facets) {
3131
for (let k = 0, m = facet.length; k < m; ++k) {
3232
const i = facet[k];
33-
if (O[i]) (facet[k] = j), (data[j] = data[i]), (data.reindex[j] = i), ++j;
34-
else data.reindex[i] = i;
33+
if (O[i]) (facet[k] = j), (data[j] = data[i]), (R[j] = i), ++j;
34+
else R[i] = i;
3535
O[i] = 1;
3636
}
3737
}

0 commit comments

Comments
 (0)