Skip to content

The normalize transform should mirror the map transform more closely #1376

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

Open
mbostock opened this issue Mar 23, 2023 · 3 comments
Open

The normalize transform should mirror the map transform more closely #1376

mbostock opened this issue Mar 23, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@mbostock
Copy link
Member

mbostock commented Mar 23, 2023

The normalizeX and normalizeY transforms mirror mapX and mapY, the only difference being that you specify a shorthand basis instead of a generic map. But the normalize method isn’t a transform, like the map transform: it returns a map implementation. And hence you have to use it in conjunction with the map transform like so:

Plot.map({title: Plot.normalize("first")}, {x: "Date", title: "Close", stroke: "Symbol"})

It would be shorter and more consistent to have normalize be a transform just like map, where you declare outputs and inputs:

Plot.normalize({title: "first"}, {x: "Date", title: "Close", stroke: "Symbol"})

If desired, we could retain the existing normalize method as Plot.normalizer or some such. (We might offer a similar Plot.reducer for reducer implementations in the future.) Possibly we could change Plot.normalize while retaining backwards compatibility by checking what you pass in, but it’s a little dicey. 🙂

Inspired by #1354.

@mbostock mbostock added the enhancement New feature or request label Mar 23, 2023
@mbostock
Copy link
Member Author

Plot.window is like Plot.normalize, too (and not Plot.map).

@mbostock
Copy link
Member Author

Another example. Instead of this

Plot.map({stroke: Plot.window({k: 2, reduce: "difference"})}, {x: "date", y: "unemployment", z: "division", stroke: "unemployment"})

we could say this

Plot.window({k: 2, stroke: "difference"}, {x: "date", y: "unemployment", z: "division", stroke: "unemployment"})

You have to mix in the window options with the output channels, but I think that’s okay, and the bin transform does that too.

@mbostock
Copy link
Member Author

I ran into this again because I wanted to apply a tip to a line with a window transform using the title channel. I was confused why the non-windowed values were appearing in the tip because the windowY transform doesn’t affect the title channel.

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

No branches or pull requests

1 participant