Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Voronoi initializer (for pointer interactions) #1623

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

Fil
Copy link
Contributor

@Fil Fil commented May 23, 2023

new description!

This PR chiefly addresses #1622, making the voronoi mark work with the tip option. A notable performance issue in the modified usStateCapitalsVoronoi test is that the clip path is created anew each time we rerender the mark (this is addressed separately, in #1624).

A secondary issue (#1858, making voronoi work with exclusive facets) was first addressed in an ad hoc fashion (in 71c49a2). After this review comment suggesting that this should be centralized, I reverted the change in 70f2352, then used the new exclusiveFacets transform (introduced in #1648) in 972558c et sq.

Closes #1622
Closes #1858.

src/marks/delaunay.js Outdated Show resolved Hide resolved
@mbostock
Copy link
Member

I couldn’t resist trying the Voronoi initializer idea… I dunno if we need to make similar changes to the Delaunay marks? I think maybe it doesn’t make sense there, though, because there’s a not a 1:1 correspondence between the data and the geometry.

Screen.Recording.2023-05-23.at.7.01.59.PM.mov

src/marks/delaunay.js Outdated Show resolved Hide resolved
@Fil
Copy link
Contributor Author

Fil commented May 24, 2023

the voronoi cell now depends on i and fi (with a test showing facet: exclude)

@Fil Fil marked this pull request as ready for review May 24, 2023 03:01
@Fil Fil changed the title selectively generate one voronoi cell with the pointer Voronoi initializer (for pointer interactions) May 24, 2023
@Fil Fil mentioned this pull request May 28, 2023
Copy link
Member

@mbostock mbostock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems mostly fine… but there’s something that bothers me. I guess it’s that we need to create nested/faceted channels because we can’t assume that the facets are exclusive. #1648 And our workaround abuses how channels are intended to be represented (parallel to the data). And it’s especially funny that the Voronoi mark handles this but the stack transform doesn’t—the stack transform is far more frequently used!

I would rather fix the non-exclusive facet problem generally rather than apply the workaround in this PR. I think we probably need a redux of the approach in #1069. Ideally, it’s like a transform wrapper that says “this transform/initializer needs exclusive facets”, and it expands the faceted index and channels as needed to meet the constraint that the facets are exclusive, and the downstream code therefore doesn’t need any changing.

@Fil Fil force-pushed the fil/voronoi-initializer branch 2 times, most recently from 4996723 to 3792cc5 Compare August 21, 2023 07:56
@Fil Fil mentioned this pull request Aug 21, 2023
@Fil
Copy link
Contributor Author

Fil commented Aug 21, 2023

It works! Applying the exclusiveFacets to the voronoi mark only for now (I saw that it didn't work with the voronoiMesh).

@Fil
Copy link
Contributor Author

Fil commented Aug 21, 2023

In the documentation there is a voronoi mark with the centroid initializer, and the reindexation logic fails in that case.

@Fil
Copy link
Contributor Author

Fil commented Aug 21, 2023

I'm not sure how to apply exclusiveFacets properly. At least we now have test cases. Rather than a transform as it is now, I wonder if it could be a (private?) option flag instead, that asks Plot to apply this before any other transform. It would feel less "ad hoc" for the voronoi marks.

@Fil
Copy link
Contributor Author

Fil commented Sep 13, 2023

I've updated the description of this PR. I'd like to find a cleaner way to apply the exclusiveFacets transform (DONE)

@Fil Fil mentioned this pull request Sep 13, 2023
src/marks/delaunay.js Outdated Show resolved Hide resolved
@Fil Fil force-pushed the fil/voronoi-initializer branch from 2967384 to 95f9f1c Compare July 12, 2024 11:44
Comment on lines +300 to +307
// TODO Accept other types of clips (paths, urls, x, y, other marks…)?
// https://github.com/observablehq/plot/issues/181
export function maybeClip(clip) {
if (clip === true) clip = "frame";
else if (clip === false) clip = null;
else if (clip != null) clip = keyword(clip, "clip", ["frame", "sphere"]);
return clip;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn’t look used. Is this needed as part of this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. This was the result of a bad merge operation (this part belongs to #1624).

[x, y] = maybeTuple(x, y);
return new DelaunayMark(data, {...options, x, y});
return new DelaunayMark(data, {...basic({...options, x, y}, exclusiveFacets), initializer});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is exclusiveFacets only needed in the Voronoi case, not the general case of all Delaunay marks?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I think so. The hand-wavy "proof" is that the voronoi cells are "more" associated to each data point, and can be separated by facet after the transform, whereas the delaunay triangles (and mesh) are tied to the whole group of points, and can't be separated post-transform (any triangle that is not joining 3 points in the same facet would be inconsistent).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants