Skip to content

Commit f6c456e

Browse files
committed
comments
1 parent 4dd08d2 commit f6c456e

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
@@ -376,6 +376,17 @@ export function plot(options = {}) {
376376
const stateByMark = new Map();
377377
for (const mark of marks) {
378378
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.
379390
stateByMark.set(mark, {});
380391
}
381392

@@ -387,7 +398,9 @@ export function plot(options = {}) {
387398

388399
// Collect all facet definitions (top-level facets then mark facets),
389400
// 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+
391404
// TODO Remove/refactor this: here “top” is pretending to be a mark, but
392405
// it’s not actually a mark. Also there’s no “top” facet method, and the
393406
// ariaLabel isn’t used for anything. And eventually top is removed from
@@ -404,7 +417,8 @@ export function plot(options = {}) {
404417
if (!method) continue; // TODO explicitly check for null
405418
const {fx: x, fy: y} = mark;
406419
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
408422
if (method !== "auto" || mark.data === facet.data) {
409423
state.groups = stateByMark.get(top).groups;
410424
} else {
@@ -419,17 +433,20 @@ export function plot(options = {}) {
419433
} else {
420434
const data = arrayify(mark.data);
421435
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
423438
state.fx = Channel(data, {value: x, scale: "fx"});
424439
if (!channelsByScale.has("fx")) channelsByScale.set("fx", []);
425440
channelsByScale.get("fx").push(state.fx);
426441
}
427-
if (y != null) { // TODO strict equality
442+
if (y != null) {
443+
// TODO strict equality
428444
state.fy = Channel(data, {value: y, scale: "fy"});
429445
if (!channelsByScale.has("fy")) channelsByScale.set("fy", []);
430446
channelsByScale.get("fy").push(state.fy);
431447
}
432-
if (state.fx || state.fy) { // TODO strict equality
448+
if (state.fx || state.fy) {
449+
// TODO strict equality
433450
const groups = facetGroups(range(data), state);
434451
state.groups = groups;
435452
// If the top-level faceting is non-trivial, store the corresponding

0 commit comments

Comments
 (0)