hexbin as a transform#804
Closed
Fil wants to merge 1 commit into
Closed
Conversation
Member
|
I don’t think this approach will work… it’ll lead to the same duplicate computation of channels problem we had in the mbostock/layout branch. I need to think about this more. |
Member
|
I think probably the hexbin will need to declare a transform, too, and redefine any channels that are needed by outputs so that they are cached. It can then reference those values in the initializer. |
Member
|
To elaborate, I think we’ll need something more like this: {
const z = "species";
const [Z, setZ] = Plot.channel(z);
return Plot.plot({
grid: true,
marks: [
Plot.dot(penguins, {
x: "culmen_depth_mm",
y: "culmen_length_mm",
z: Z, // optionally make the z channel available to dot (no effect here)
symbol: "hexagon",
transform(data, facets) {
setZ(Plot.valueof(data, z)); // compute the z channel from the data
return {data, facets};
},
initialize([index], {x: {value: X}, y: {value: Y}}, {x, y}) {
console.log(Z.transform()); // access the previously-computed z values
const bins = Hexbin().x(i => x(X[i])).y(i => y(Y[i])).radius(20)(index);
return {
facets: [d3.range(bins.length)],
channels: {
x: {value: bins.map(bin => bin.x)},
y: {value: bins.map(bin => bin.y)},
r: {value: bins.map(bin => bin.length), radius: 20, scale: "r"}
}
};
}
})
]
});
}To break it down:
Because the channels are computed in a mark transform, they’ll have access to the (possibly transformed) data, so we won’t need to pass that data separately to the initializer. And because the options transform can declare the channel as an option, it won’t be computed twice. |
mbostock
reviewed
Mar 11, 2022
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
am i on the right track?
(I can't see how to access Z )