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

waffle tips #2132

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft

waffle tips #2132

wants to merge 8 commits into from

Conversation

Fil
Copy link
Contributor

@Fil Fil commented Aug 12, 2024

Positions the tips on waffle marks by “hacking” the x1, x2, y1 and y2 channels, replacing them with the centroid of each waffle, in pixel space.

This kind of works, but it's not satisfying at the moment, because the mark has too little control on where the tips should appear. Currently it can only set px, py to say where the tip should be triggered, but the tip's position can only be controlled by "data" channels (x, y, x1, x2, y1, y2), read by the derive function.

TODO:

  • make it less hacky (possibly by allowing px, py to also drive to position of the tip, not just of the pointer?, or by making derive aware of the scaled values (which we could then hack similarly, instead of hacking the source channels)
  • make the shape (and centroid) computation happen in the initializer instead of render? would feel cleaner, and would allow to make a tip mark with the same geometry but without actually calling the waffle mark.
  • more tests (waffleX, facets…)
  • restore the y channel in the tip contents.
  • [ ] allow tip: {maxRadius: Infinity} (would be welcome in the waffleTip test) (tracked as Erroneous type definition for the tip {maxRadius} option #2134 since it's not linked to this mark)

closes #2129

@mbostock
Copy link
Member

A quick note because I’m not sure I have the bandwidth to work on this now, but I think this should work more like the implicit centroid transform for the geo mark. For one thing, we don’t want the waffle mark to do anything if the tip option isn’t being used. And for two, it might be possible to move this transform/initializer onto the derived tip mark by transforming the tip option (that gets passed through as options to the tip mark), rather than doing the transform on the waffle mark itself.

@Fil Fil marked this pull request as ready for review August 14, 2024 16:47
@Fil Fil requested a review from mbostock August 14, 2024 16:47
@Fil
Copy link
Contributor Author

Fil commented Aug 15, 2024

Would it be interesting to have a way for an initializer to suppress an existing channel (e.g. by returning channels: {y1: null}) ? In this case we could censor y1 and y2, and return y alone, removing the need for the new hint.

(tracked as #2136)

@Fil
Copy link
Contributor Author

Fil commented Aug 15, 2024

Another way of having the right tooltips without the hint would be to change the pair formatting of (a, b) to display a when format(a) === format(b). I think it's a good idea in its own right, too? If the format does not discriminate between the two values of an interval, it seems better to display, say "3" than "3—3".

(tracked as #2135)

@Fil
Copy link
Contributor Author

Fil commented Aug 15, 2024

we don’t want the waffle mark to do anything if the tip option isn’t being used

I now disagree with this, because I want to highlight the particular waffle that is being moused over, and that requires the same secondary initializer to derive centroids, otherwise the highlighted waffle is decided by the corresponding bar position.

export function wafflePointer() {
  const random = d3.randomLcg(42);
  const data = Array.from({length: 100}, (_, i) => ({x: i % 3, fill: random()}));
  return Plot.plot({
    y: {inset: 12},
    marks: [
      Plot.waffleY(data, {x: "x", y: 1, fill: "#888"}),
      Plot.waffleY(data, Plot.pointer({x: "x", y: 1, fill: "fill"}))
    ]
  });
}

EDIT: I tried unsuccessfully to see if we could use the same actual centroid transform.

@Fil Fil marked this pull request as ready for review August 15, 2024 16:43
@Fil
Copy link
Contributor Author

Fil commented Aug 29, 2024

I've fixed the waffle centroids. The number of cases when you include the logic for fractional values is… insane.
Capture d’écran 2024-08-29 à 11 01 09

@mbostock mbostock mentioned this pull request Oct 19, 2024
Copy link
Member

Choose a reason for hiding this comment

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

I love how this image visually captures the surprising number of possible configurations!

@Fil
Copy link
Contributor Author

Fil commented Oct 30, 2024

For a completely different approach, we could use the spatial metaphor, and pass the path to the poi transform (#2098).

@Fil Fil marked this pull request as draft October 30, 2024 16:23
@Fil
Copy link
Contributor Author

Fil commented Oct 30, 2024

integrated in #2215

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

Successfully merging this pull request may close these issues.

Waffle mark tooltips are always on axis line
2 participants