@@ -7,6 +7,10 @@ import {maybeTimeInterval, maybeUtcInterval} from "./time.js";
7
7
export const TypedArray = Object . getPrototypeOf ( Uint8Array ) ;
8
8
const objectToString = Object . prototype . toString ;
9
9
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
+
10
14
export function valueof ( data , value , type ) {
11
15
const valueType = typeof value ;
12
16
return valueType === "string"
@@ -17,7 +21,11 @@ export function valueof(data, value, type) {
17
21
? map ( data , constant ( value ) , type )
18
22
: typeof value ?. transform === "function"
19
23
? maybeTypedArrayify ( value . transform ( data ) , type )
20
- : maybeTypedArrayify ( value , type ) ;
24
+ : maybeTake ( maybeTypedArrayify ( value , type ) , data ?. [ reindex ] ) ;
25
+ }
26
+
27
+ function maybeTake ( values , index ) {
28
+ return index ? take ( values , index ) : values ;
21
29
}
22
30
23
31
function maybeTypedMap ( data , f , type ) {
@@ -170,6 +178,7 @@ export function isScaleOptions(option) {
170
178
171
179
// Disambiguates an options object (e.g., {y: "x2"}) from a channel value
172
180
// definition expressed as a channel transform (e.g., {transform: …}).
181
+ // TODO Check typeof option[Symbol.iterator] !== "function"?
173
182
export function isOptions ( option ) {
174
183
return isObject ( option ) && typeof option . transform !== "function" ;
175
184
}
@@ -223,7 +232,7 @@ export function where(data, test) {
223
232
224
233
// Returns an array [values[index[0]], values[index[1]], …].
225
234
export function take ( values , index ) {
226
- return map ( index , ( i ) => values [ i ] ) ;
235
+ return map ( index , ( i ) => values [ i ] , values . constructor ) ;
227
236
}
228
237
229
238
// If f does not take exactly one argument, wraps it in a function that uses take.
0 commit comments