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

A map transform for finding last week’s (or whatever) value #1799

Closed
mbostock opened this issue Aug 9, 2023 · 4 comments · Fixed by #1896
Closed

A map transform for finding last week’s (or whatever) value #1799

mbostock opened this issue Aug 9, 2023 · 4 comments · Fixed by #1896
Assignees
Labels
enhancement New feature or request

Comments

@mbostock
Copy link
Member

mbostock commented Aug 9, 2023

With difference charts #159, we often want to compare the value today (or now) to the value some time period ago. Perhaps it would be simple enough, as with the window transform, to shift a column n slots forward or background.

@mbostock mbostock added the enhancement New feature or request label Aug 9, 2023
@mbostock mbostock changed the title A map transform for finding last week’s (or last month’s, or whatever) value A map transform for finding last week’s (or whatever) value Aug 9, 2023
@Fil
Copy link
Contributor

Fil commented Aug 10, 2023

I think this is Plot.window({ anchor: "end", k: n + 1, reduce: "first" }).
See https://observablehq.com/d/1e37e3c09876e460#withwindow

@mbostock
Copy link
Member Author

That makes sense. Maybe we can make a more convenient/memorable form of that. (And probably can also optimize it?)

@Fil
Copy link
Contributor

Fil commented Aug 24, 2023

I'm not convinced we need an additional name for this particular transform (we could always add shiftX as an alias, but adding words has a cost too: documentation, more stuff to memorize, less generalization…). So imho let's try instead to make the existing feature more discoverable — maybe with a nice example notebook.

Also I've looked at how to optimize the first reducer further, but came empty-handed (unless we want to detect that there is only a single and complete series, and use Array.copy()?).

This issue's title makes me think though that sometimes we want to look up a certain channel (date) to derive another channel (value from the same series with the closest date to a week ago, with bisection for example), but it’s a different question? And readily addressable by using a function map on the identity channel (which I added to the notebook, in case we want to use it as a base for a tutorial). It feels a bit complicated, though.

@mbostock
Copy link
Member Author

mbostock commented Aug 24, 2023

Sounds related to the concept of channel aliases? #798 🤔

@mbostock mbostock self-assigned this Nov 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants