@@ -5,7 +5,7 @@ import {Context, create} from "./context.js";
5
5
import { defined } from "./defined.js" ;
6
6
import { Dimensions } from "./dimensions.js" ;
7
7
import { Legends , exposeLegends } from "./legends.js" ;
8
- import { arrayify , isDomainSort , isScaleOptions , keyword , map , maybeNamed , range , second , where , yes } from "./options.js" ;
8
+ import { arrayify , isDomainSort , isScaleOptions , keyword , map , maybeNamed , range , second , valueof , where , yes } from "./options.js" ;
9
9
import { Scales , ScaleFunctions , autoScaleRange , exposeScales , coerceNumbers } from "./scales.js" ;
10
10
import { position , registry as scaleRegistry } from "./scales/index.js" ;
11
11
import { inferDomain } from "./scales/quantitative.js" ;
@@ -366,7 +366,29 @@ export class Mark {
366
366
initialize ( facets , facetChannels ) {
367
367
let data = arrayify ( this . data ) ;
368
368
if ( facets === undefined && data != null ) facets = [ range ( data ) ] ;
369
- if ( this . transform != null ) ( { facets, data} = this . transform ( data , facets ) ) , data = arrayify ( data ) ;
369
+ if ( this . transform != null ) {
370
+ if ( this . channels . time ) {
371
+ // Split facets by keyframe, transform
372
+ const { value} = this . channels . time ;
373
+ const T = valueof ( data , value ) ;
374
+ const times = [ ...new Set ( T ) ] ;
375
+ const n = facets . length ;
376
+ facets = facets . flatMap ( facet => times . map ( time => facet . filter ( i => T [ i ] === time ) ) ) ;
377
+ ( { data, facets} = this . transform ( data , facets ) ) ;
378
+
379
+ // and reassemble
380
+ const TT = [ ] ; // keyframes for the new indices
381
+ this . channels . time . value = { transform : ( ) => TT } ;
382
+ for ( let i = 0 ; i < facets . length ; ++ i ) {
383
+ const time = times [ i % times . length ] ;
384
+ for ( const j of facets [ i ] ) TT [ j ] = time ;
385
+ }
386
+ facets = Array . from ( { length : n } , ( _ , i ) => facets . filter ( ( _ , j ) => j % n === i ) . flat ( ) ) ;
387
+ } else {
388
+ ( { facets, data} = this . transform ( data , facets ) ) ;
389
+ }
390
+ data = arrayify ( data ) ;
391
+ }
370
392
const channels = Channels ( this . channels , data ) ;
371
393
if ( this . sort != null ) channelDomain ( channels , facetChannels , data , this . sort ) ;
372
394
return { data, facets, channels} ;
0 commit comments