-
Notifications
You must be signed in to change notification settings - Fork 185
More support for labels with channel reducers and values #1364
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
Comments
We do already implement reducer labels, but you have to specify it as a reducer implementation (and ignore the TypeScript lint because we haven’t declared label as an optional property on the ReducerImplementation interface): Plot.barY(
penguins,
Plot.groupX(
{
y: {reduce: (index, values) => d3.count(index, (i) => values[i]), label: "# of specimens"},
fill: (values) => d3.mode(values)
},
{x: "species", fill: "island", fy: "sex"}
)
).plot() We could also support this as a decorated reducer function Plot.barY(
penguins,
Plot.groupX(
{
y: Object.assign((values) => d3.count(values), {label: "# of specimens"}),
fill: (values) => d3.mode(values)
},
{x: "species", fill: "island", fy: "sex"}
)
).plot() if we changed reduceFunction like so function reduceFunction(f) {
return {
label: labelof(f),
reduce(I, X, extent) {
return f(take(X, I), extent);
}
};
} There are maybe some other places where we could generate default reducer labels, too. The TODO in the code here is referring to the fact that we haven’t documented the existing support for labels on ReducerImplementation, not that we haven’t implemented it. Lines 32 to 35 in 2ac08e2
Whereas the TODO here was referring to the fact that it would be nice to specify a label as part of a ChannelValueSpec, parallel to a scale override: Line 143 in 2ac08e2
So, if we add label to a ChannelReducerSpec, we should do that to ChannelValueSpec, too. And it would complicated the duck test that I propose we add in #1367. |
I think there’s a similar bug here reading inputs e.g. in the map transform. For example I was expecting to be able to feed the map transform x: {value: "foo", label: "Foo"}, because you can feed that e.g. to a line mark. But the map transform’s maybeInput doesn’t check for scale overrides and labels, so it’s not able to read this channel values, and therefore you can’t propagate the channel label. |
I've updated the examples/test with the newer reduceIndex syntax. |
Related #1873? |
This should display "# of specimens" as the y label:
Excerpted from #1360
First tentative: 9dfeb79
The text was updated successfully, but these errors were encountered: