@@ -376,6 +376,17 @@ export function plot(options = {}) {
376
376
const stateByMark = new Map ( ) ;
377
377
for ( const mark of marks ) {
378
378
if ( stateByMark . has ( mark ) ) throw new Error ( "duplicate mark; each mark must be unique" ) ;
379
+
380
+ // TODO It’s undesirable to set this to an empty object here because it
381
+ // makes it less obvious what the expected type of mark state is. And also
382
+ // when we (eventually) migrate to TypeScript, this would be disallowed.
383
+ // Previously mark state was a {data, facet, channels, values} object; now
384
+ // it looks like we also use: fx, fy, groups, facetChannelLength,
385
+ // facetsIndex. And these are set at various different points below, so
386
+ // there are more intermediate representations where the state is partially
387
+ // initialized. If possible we should try to reduce the number of
388
+ // intermediate states and simplify the state representations to make the
389
+ // logic easier to follow.
379
390
stateByMark . set ( mark , { } ) ;
380
391
}
381
392
@@ -387,7 +398,9 @@ export function plot(options = {}) {
387
398
388
399
// Collect all facet definitions (top-level facets then mark facets),
389
400
// materialize the associated channels, and derive facet scales.
390
- if ( facet || marks . some ( ( mark ) => mark . fx || mark . fy ) ) { // TODO non-null, not truthy
401
+ if ( facet || marks . some ( ( mark ) => mark . fx || mark . fy ) ) {
402
+ // TODO non-null, not truthy
403
+
391
404
// TODO Remove/refactor this: here “top” is pretending to be a mark, but
392
405
// it’s not actually a mark. Also there’s no “top” facet method, and the
393
406
// ariaLabel isn’t used for anything. And eventually top is removed from
@@ -404,7 +417,8 @@ export function plot(options = {}) {
404
417
if ( ! method ) continue ; // TODO explicitly check for null
405
418
const { fx : x , fy : y } = mark ;
406
419
const state = stateByMark . get ( mark ) ;
407
- if ( x == null && y == null && facet != null ) { // TODO strict equality
420
+ if ( x == null && y == null && facet != null ) {
421
+ // TODO strict equality
408
422
if ( method !== "auto" || mark . data === facet . data ) {
409
423
state . groups = stateByMark . get ( top ) . groups ;
410
424
} else {
@@ -419,17 +433,20 @@ export function plot(options = {}) {
419
433
} else {
420
434
const data = arrayify ( mark . data ) ;
421
435
if ( ( x != null || y != null ) && data == null ) throw new Error ( `missing facet data in ${ mark . ariaLabel } ` ) ; // TODO strict equality
422
- if ( x != null ) { // TODO strict equality
436
+ if ( x != null ) {
437
+ // TODO strict equality
423
438
state . fx = Channel ( data , { value : x , scale : "fx" } ) ;
424
439
if ( ! channelsByScale . has ( "fx" ) ) channelsByScale . set ( "fx" , [ ] ) ;
425
440
channelsByScale . get ( "fx" ) . push ( state . fx ) ;
426
441
}
427
- if ( y != null ) { // TODO strict equality
442
+ if ( y != null ) {
443
+ // TODO strict equality
428
444
state . fy = Channel ( data , { value : y , scale : "fy" } ) ;
429
445
if ( ! channelsByScale . has ( "fy" ) ) channelsByScale . set ( "fy" , [ ] ) ;
430
446
channelsByScale . get ( "fy" ) . push ( state . fy ) ;
431
447
}
432
- if ( state . fx || state . fy ) { // TODO strict equality
448
+ if ( state . fx || state . fy ) {
449
+ // TODO strict equality
433
450
const groups = facetGroups ( range ( data ) , state ) ;
434
451
state . groups = groups ;
435
452
// If the top-level faceting is non-trivial, store the corresponding
0 commit comments