Skip to content

Commit 868a6f5

Browse files
committed
comments
1 parent 611cef0 commit 868a6f5

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

src/plot.js

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ export function plot(options = {}) {
3232
const stateByMark = new Map();
3333
for (const mark of marks) {
3434
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.
3546
stateByMark.set(mark, {});
3647
}
3748

@@ -43,7 +54,9 @@ export function plot(options = {}) {
4354

4455
// Collect all facet definitions (top-level facets then mark facets),
4556
// 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+
4760
// TODO Remove/refactor this: here “top” is pretending to be a mark, but
4861
// it’s not actually a mark. Also there’s no “top” facet method, and the
4962
// ariaLabel isn’t used for anything. And eventually top is removed from
@@ -60,7 +73,8 @@ export function plot(options = {}) {
6073
if (!method) continue; // TODO explicitly check for null
6174
const {fx: x, fy: y} = mark;
6275
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
6478
if (method !== "auto" || mark.data === facet.data) {
6579
state.groups = stateByMark.get(top).groups;
6680
} else {
@@ -75,17 +89,20 @@ export function plot(options = {}) {
7589
} else {
7690
const data = arrayify(mark.data);
7791
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
7994
state.fx = Channel(data, {value: x, scale: "fx"});
8095
if (!channelsByScale.has("fx")) channelsByScale.set("fx", []);
8196
channelsByScale.get("fx").push(state.fx);
8297
}
83-
if (y != null) { // TODO strict equality
98+
if (y != null) {
99+
// TODO strict equality
84100
state.fy = Channel(data, {value: y, scale: "fy"});
85101
if (!channelsByScale.has("fy")) channelsByScale.set("fy", []);
86102
channelsByScale.get("fy").push(state.fy);
87103
}
88-
if (state.fx || state.fy) { // TODO strict equality
104+
if (state.fx || state.fy) {
105+
// TODO strict equality
89106
const groups = facetGroups(range(data), state);
90107
state.groups = groups;
91108
// If the top-level faceting is non-trivial, store the corresponding

0 commit comments

Comments
 (0)