Skip to content

select{First,Last}[XY] #989

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

Closed
wants to merge 1 commit into from
Closed

Conversation

mbostock
Copy link
Member

Fixes #988.

@mbostock mbostock requested a review from tophtucker July 14, 2022 03:27
Copy link
Contributor

@tophtucker tophtucker left a comment

Choose a reason for hiding this comment

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

❤️

so window leaves undefined points rather than changing the length of the data array? e.g. as you change the k of a Plot.windowY, the extent of the x-axis won't change, it'll just get empty bits at the ends. those points have x values but not y values, right?

when i was struggling earlier, i think i actually tried Plot.selectLastX to see if it'd work. but it'd actually be Plot.selectLastY in my case, right? i think i guessed X because it's the last along the x-axis — but no, it's last in input order, it's selectLastY because Y is what has to be defined.

to position a text label in x and y at the end of the line, i really need the last point where both x and y are defined, right? but one should always imply the other, unless you have weird gappy stuff.

i'm trying to think of when i wouldn't want regular selectLast to have this behavior. maybe something like: i have multi-line chart of stock prices, and wanna put a dot for the current price, but if a stock was delisted a year ago i don't want a dot at the end of that line because that wouldn't be current; its current price is truly undefined.

Fil added a commit that referenced this pull request Jul 14, 2022
@Fil
Copy link
Contributor

Fil commented Jul 14, 2022

Very much needed. But let me suggest a more generic alternative in #991.

Copy link
Contributor

@Fil Fil left a comment

Choose a reason for hiding this comment

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

I'm still not sold on this idea.

It feels like the beginning of an intractable DSL (selectMaxXYRFillOpacity?).

With #993 (and #996 (?)) the original motivation for this change has been solved.

Also, I forgot to mention this alternative:

Plot.selectMaxX({ x: "date", y: "unemployment", filter: "unemployment" })

@mbostock
Copy link
Member Author

mbostock commented Jul 15, 2022

Agreed. This feels too limited and overfit to the particular use case, and it is less likely to be a problem with the non-strict window transform. Though, this PR is slightly more flexible than implied by selectLastX because you can also say select({foo: "last"}, …) to select the last defined value of any channel. But what we really want is to somehow filter on all channels, like mark.filter does, which almost certainly means that selectLast would need to be an initializer rather than a transform so that it can access the computed channels.

I couldn’t figure out how the get the selectMaxX alternative to work, at least not without #993. Or were you just saying that’s equivalent to selectLast? In the case of a window transform, the effective y channel can’t be referred to by name (e.g., “unemployment” or “value”) because it is constructed by the transform.

Another thought here is we could have an offset option to selectFirst and selectLast that lets you chose an item near the start or end.

@mbostock mbostock closed this Jul 15, 2022
@mbostock mbostock deleted the mbostock/select-last-defined branch July 15, 2022 13:43
@Fil
Copy link
Contributor

Fil commented Jul 15, 2022

You're right, the alternative only works on the original data, not in the OP.

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.

Select last defined value (for some given channel)?
3 participants