@@ -6,6 +6,7 @@ import {Dimensions} from "./dimensions.js";
6
6
import { Legends , exposeLegends } from "./legends.js" ;
7
7
import { arrayify , isOptions , keyword , range , first , second , where , take } from "./options.js" ;
8
8
import { Scales , ScaleFunctions , autoScaleRange , applyScales , exposeScales } from "./scales.js" ;
9
+ import { selection } from "./selection.js" ;
9
10
import { applyInlineStyles , maybeClassName , styles } from "./style.js" ;
10
11
import { basic } from "./transforms/basic.js" ;
11
12
@@ -102,11 +103,10 @@ export function plot(options = {}) {
102
103
const index = filter ( markIndex . get ( mark ) , channels , values ) ;
103
104
const node = mark . render ( index , scales , values , dimensions , axes ) ;
104
105
if ( node != null ) {
105
- // TODO A more explicit indication that a mark defines a value (e.g., a symbol)?
106
- if ( node . selection !== undefined ) {
107
- initialValue = markValue ( mark , node . selection ) ;
106
+ if ( node [ selection ] !== undefined ) {
107
+ initialValue = markValue ( mark , node [ selection ] ) ;
108
108
node . addEventListener ( "input" , ( ) => {
109
- figure . value = markValue ( mark , node . selection ) ;
109
+ figure . value = markValue ( mark , node [ selection ] ) ;
110
110
} ) ;
111
111
}
112
112
svg . appendChild ( node ) ;
@@ -204,18 +204,6 @@ function markValue(mark, selection) {
204
204
return selection === null ? mark . data : take ( mark . data , selection ) ;
205
205
}
206
206
207
- // Given two (possibly null, possibly an index, but not undefined) selections,
208
- // returns true if the two represent the same selection, and false otherwise.
209
- // This assumes that the selection is a in-order subset of the original index.
210
- export function selectionEquals ( s1 , s2 ) {
211
- if ( s1 === s2 ) return true ;
212
- if ( s1 == null || s2 == null ) return false ;
213
- const n = s1 . length ;
214
- if ( n !== s2 . length ) return false ;
215
- for ( let i = 0 ; i < n ; ++ i ) if ( s1 [ i ] !== s2 [ i ] ) return false ;
216
- return true ;
217
- }
218
-
219
207
class Render extends Mark {
220
208
constructor ( render ) {
221
209
super ( ) ;
@@ -345,13 +333,13 @@ class Facet extends Mark {
345
333
const index = filter ( marksFacetIndex [ i ] , marksChannels [ i ] , values ) ;
346
334
const node = marks [ i ] . render ( index , scales , values , subdimensions ) ;
347
335
if ( node != null ) {
348
- if ( node . selection !== undefined ) {
336
+ if ( node [ selection ] !== undefined ) {
349
337
if ( marks [ i ] . data !== data ) throw new Error ( "selection must use facet data" ) ;
350
338
if ( selectionByFacet === undefined ) selectionByFacet = facetMap ( channels ) ;
351
- selectionByFacet . set ( key , node . selection ) ;
339
+ selectionByFacet . set ( key , node [ selection ] ) ;
352
340
node . addEventListener ( "input" , ( ) => {
353
- selectionByFacet . set ( key , node . selection ) ;
354
- parent . selection = facetSelection ( selectionByFacet ) ;
341
+ selectionByFacet . set ( key , node [ selection ] ) ;
342
+ parent [ selection ] = facetSelection ( selectionByFacet ) ;
355
343
} ) ;
356
344
}
357
345
this . appendChild ( node ) ;
@@ -360,7 +348,7 @@ class Facet extends Mark {
360
348
} ) )
361
349
. node ( ) ;
362
350
if ( selectionByFacet !== undefined ) {
363
- parent . selection = facetSelection ( selectionByFacet ) ;
351
+ parent [ selection ] = facetSelection ( selectionByFacet ) ;
364
352
}
365
353
return parent ;
366
354
}
0 commit comments