Skip to content

Conversation

@mbostock
Copy link
Member

@mbostock mbostock commented May 15, 2023

I want to write an interactive index chart where the user specifies the date at which to normalize series. This means I can’t use the built-in first normalize basis; I need to find the appropriate starting value for each series based on the given date. While I could do this outside of Plot, I’d prefer to implement this within the existing normalize transform, which means I want access to the index (I) within the normalize basis method. This PR allows that, maintaining backwards compatibility by checking the length of the reduce function. This applies to both the normalize and window transforms.

@mbostock mbostock requested a review from Fil May 15, 2023 00:26
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.

It's always delicate when the arguments change with the function's length. For example you you passed d3.min as a reducer you'd now have to pass (I, v) => d3.min(I, i => v[i]) instead. But I don't see a working alternative, so I guess it's the way to go.

@mbostock
Copy link
Member Author

Yes, relevant xkcd. I don’t think we can avoid backwards incompatibility entirely but this feels reasonable to me. I would expect people to specify the min (named) reducer instead of passing in d3.min directly, for example.

@mbostock mbostock merged commit 47f06e6 into main May 15, 2023
@mbostock mbostock deleted the mbostock/normalize-index branch May 15, 2023 16:18
@mbostock
Copy link
Member Author

I should have added this to the map transform, too. This should use a taker instead:

const M = f(take(S, I));

@mbostock mbostock mentioned this pull request May 15, 2023
chaichontat pushed a commit to chaichontat/plot that referenced this pull request Jan 14, 2024
* index-aware reducer functions

* simplify
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.

3 participants