@@ -32,6 +32,17 @@ export function plot(options = {}) {
32
32
const stateByMark = new Map ( ) ;
33
33
for ( const mark of marks ) {
34
34
if ( stateByMark . has ( mark ) ) throw new Error ( "duplicate mark; each mark must be unique" ) ;
35
+
36
+ // TODO It’s undesirable to set this to an empty object here because it
37
+ // makes it less obvious what the expected type of mark state is. And also
38
+ // when we (eventually) migrate to TypeScript, this would be disallowed.
39
+ // Previously mark state was a {data, facet, channels, values} object; now
40
+ // it looks like we also use: fx, fy, groups, facetChannelLength,
41
+ // facetsIndex. And these are set at various different points below, so
42
+ // there are more intermediate representations where the state is partially
43
+ // initialized. If possible we should try to reduce the number of
44
+ // intermediate states and simplify the state representations to make the
45
+ // logic easier to follow.
35
46
stateByMark . set ( mark , { } ) ;
36
47
}
37
48
@@ -43,7 +54,9 @@ export function plot(options = {}) {
43
54
44
55
// Collect all facet definitions (top-level facets then mark facets),
45
56
// materialize the associated channels, and derive facet scales.
46
- if ( facet || marks . some ( ( mark ) => mark . fx || mark . fy ) ) { // TODO non-null, not truthy
57
+ if ( facet || marks . some ( ( mark ) => mark . fx || mark . fy ) ) {
58
+ // TODO non-null, not truthy
59
+
47
60
// TODO Remove/refactor this: here “top” is pretending to be a mark, but
48
61
// it’s not actually a mark. Also there’s no “top” facet method, and the
49
62
// ariaLabel isn’t used for anything. And eventually top is removed from
@@ -60,7 +73,8 @@ export function plot(options = {}) {
60
73
if ( ! method ) continue ; // TODO explicitly check for null
61
74
const { fx : x , fy : y } = mark ;
62
75
const state = stateByMark . get ( mark ) ;
63
- if ( x == null && y == null && facet != null ) { // TODO strict equality
76
+ if ( x == null && y == null && facet != null ) {
77
+ // TODO strict equality
64
78
if ( method !== "auto" || mark . data === facet . data ) {
65
79
state . groups = stateByMark . get ( top ) . groups ;
66
80
} else {
@@ -75,17 +89,20 @@ export function plot(options = {}) {
75
89
} else {
76
90
const data = arrayify ( mark . data ) ;
77
91
if ( ( x != null || y != null ) && data == null ) throw new Error ( `missing facet data in ${ mark . ariaLabel } ` ) ; // TODO strict equality
78
- if ( x != null ) { // TODO strict equality
92
+ if ( x != null ) {
93
+ // TODO strict equality
79
94
state . fx = Channel ( data , { value : x , scale : "fx" } ) ;
80
95
if ( ! channelsByScale . has ( "fx" ) ) channelsByScale . set ( "fx" , [ ] ) ;
81
96
channelsByScale . get ( "fx" ) . push ( state . fx ) ;
82
97
}
83
- if ( y != null ) { // TODO strict equality
98
+ if ( y != null ) {
99
+ // TODO strict equality
84
100
state . fy = Channel ( data , { value : y , scale : "fy" } ) ;
85
101
if ( ! channelsByScale . has ( "fy" ) ) channelsByScale . set ( "fy" , [ ] ) ;
86
102
channelsByScale . get ( "fy" ) . push ( state . fy ) ;
87
103
}
88
- if ( state . fx || state . fy ) { // TODO strict equality
104
+ if ( state . fx || state . fy ) {
105
+ // TODO strict equality
89
106
const groups = facetGroups ( range ( data ) , state ) ;
90
107
state . groups = groups ;
91
108
// If the top-level faceting is non-trivial, store the corresponding
0 commit comments