@@ -72,9 +72,22 @@ export function plot(options = {}) {
72
72
}
73
73
}
74
74
75
+ // Aggregate and sort time channels.
76
+ const timeMarks = new Map ( ) ;
77
+ for ( const mark of marks ) {
78
+ if ( mark . timeChannel ) {
79
+ timeMarks . set ( mark , valueof ( mark . data , mark . timeChannel . time . value ) ) ;
80
+ }
81
+ }
82
+ const timeChannels = Array . from ( timeMarks , ( [ , times ] ) => ( { value : times } ) ) ;
83
+ const timeDomain = inferDomain ( timeChannels ) ;
84
+ const times = aggregateTimes ( timeChannels ) ;
85
+
75
86
// Initialize the marks’ state.
76
87
for ( const mark of marks ) {
77
88
if ( stateByMark . has ( mark ) ) throw new Error ( "duplicate mark; each mark must be unique" ) ;
89
+
90
+ // TODO: augment the facets with time, for time-aware marks
78
91
const markFacets = facetsIndex === undefined ? undefined
79
92
: mark . facet === "auto" ? mark . data === facet . data ? facetsIndex : undefined
80
93
: mark . facet === "include" ? facetsIndex
@@ -126,12 +139,6 @@ export function plot(options = {}) {
126
139
127
140
autoScaleLabels ( channelsByScale , scaleDescriptors , axes , dimensions , options ) ;
128
141
129
- // Aggregate and sort time channels.
130
- const timeChannels = findTimeChannels ( stateByMark ) ;
131
- const timeDomain = inferDomain ( timeChannels ) ;
132
- const times = aggregateTimes ( timeChannels ) ;
133
- const timeMarks = [ ] ;
134
-
135
142
// Compute value objects, applying scales as needed.
136
143
for ( const state of stateByMark . values ( ) ) {
137
144
state . values = valueObject ( state . channels , scales ) ;
@@ -217,25 +224,19 @@ export function plot(options = {}) {
217
224
for ( const [ mark , { channels, values, facets} ] of stateByMark ) {
218
225
const facet = facets ? mark . filter ( facets [ j ] ?? facets [ 0 ] , channels , values ) : null ;
219
226
const node = mark . render ( facet , scales , values , subdimensions , context ) ;
220
- if ( node != null ) {
221
- this . appendChild ( node ) ;
222
- if ( channels . time ) timeMarks . push ( { mark, node, facet, interp : Object . fromEntries ( Object . entries ( values ) . map ( ( [ key , value ] ) => [ key , Array . from ( value ) ] ) ) } ) ;
223
- }
227
+ if ( node != null ) this . appendChild ( node ) ;
224
228
}
225
229
} ) ;
226
230
} else {
227
231
for ( const [ mark , { channels, values, facets} ] of stateByMark ) {
228
232
const facet = facets ? mark . filter ( facets [ 0 ] , channels , values ) : null ;
229
233
const index = channels . time ? [ ] : facet ;
230
234
const node = mark . render ( index , scales , values , dimensions , context ) ;
231
- if ( node != null ) {
232
- svg . appendChild ( node ) ;
233
- if ( channels . time ) timeMarks . push ( { mark, node, facet, interp : Object . fromEntries ( Object . entries ( values ) . map ( ( [ key , value ] ) => [ key , Array . from ( value ) ] ) ) } ) ;
234
- }
235
+ if ( node != null ) svg . appendChild ( node ) ;
235
236
}
236
237
}
237
238
238
- if ( timeMarks . length ) {
239
+ if ( timeMarks . size > 0 ) {
239
240
// TODO There needs to be an option to avoid interpolation and just play
240
241
// the distinct times, as given, in ascending order, as keyframes. And
241
242
// there needs to be an option to control the delay, duration, iterations,
@@ -244,7 +245,9 @@ export function plot(options = {}) {
244
245
const delay = 0 ; // TODO configurable; delay initial rendering
245
246
const duration = 5000 ; // TODO configurable
246
247
const startTime = performance . now ( ) + delay ;
247
- requestAnimationFrame ( function tick ( ) {
248
+ console . warn ( timeMarks ) ;
249
+
250
+ if ( false ) requestAnimationFrame ( function tick ( ) {
248
251
const t = Math . max ( 0 , Math . min ( 1 , ( performance . now ( ) - startTime ) / duration ) ) ;
249
252
const currentTime = interpolateTime ( t ) ;
250
253
const i0 = bisectLeft ( times , currentTime ) ;
@@ -353,7 +356,7 @@ export class Mark {
353
356
channels = maybeNamed ( channels ) ;
354
357
if ( extraChannels !== undefined ) channels = { ...maybeNamed ( extraChannels ) , ...channels } ;
355
358
if ( defaults !== undefined ) channels = { ...styles ( this , options , defaults ) , ...channels } ;
356
- if ( time != null ) channels = { time : { value : time } , ... channels } ;
359
+ this . timeChannel = ( time != null ) ? { time : { value : time } } : null ;
357
360
this . channels = Object . fromEntries ( Object . entries ( channels ) . filter ( ( [ name , { value, optional} ] ) => {
358
361
if ( value != null ) return true ;
359
362
if ( optional ) return false ;
0 commit comments