Open mbostock opened 1 year ago
Plot.window is like Plot.normalize, too (and not Plot.map).
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.
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.
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:
It would be shorter and more consistent to have normalize be a transform just like map, where you declare outputs and inputs:
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. :slightly_smiling_face:
Inspired by #1354.