Skip to content
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

Precompute scaled channels. #280

Merged
merged 8 commits into from Mar 29, 2021
Merged

Precompute scaled channels. #280

merged 8 commits into from Mar 29, 2021

Conversation

mbostock
Copy link
Member

@mbostock mbostock commented Mar 28, 2021

This is a hack (I don’t think we’d want to use a getter for this — I’m thinking instead there would need to be a phase after the scales are constructed where Plot computes the scaled channels), but it works for the letterFrequencyBar and penguinSex examples.

Screen Shot 2021-03-28 at 11 41 11 AM

Also, mark rendering ends up being simpler to boot.

Fixes #52.

@mbostock mbostock requested a review from Fil March 28, 2021 18:42
@Fil
Copy link
Contributor

Fil commented Mar 28, 2021

I gave it a go as well and I think it's going to work well. We'll still need to pass the scales for some marks (axes, for example); I'm not sure we need to pass the unscaled channels, but it might be interesting for some user-defined marks to have access to the raw channel.

@mbostock mbostock marked this pull request as ready for review March 28, 2021 23:50
src/plot.js Outdated
Comment on lines 133 to 137
return Object.fromEntries(Object.entries(scales).map(([name, {scale}]) => [name, scale]));
return Object.fromEntries(Object.entries(scales).map(([name, scale]) => [name, nullsafe(scale)]));
}

// TODO https://github.com/d3/d3-scale/pull/241/files
function nullsafe({type, scale}) {
return type === "quantitative"
? Object.assign(x => x === null ? NaN : scale(x), scale)
: scale;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we land d3/d3-scale#241 we can revert this part.

This was referenced Mar 29, 2021
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.

I checked it against two of my "Plot plugin" experiments, and everything works perfectly. We don't need the unscaled channels (or rather, in cases they are needed, they should be requested explicitly by the mark's constructor).

In #281 I've salvaged an example that I used in the (obsolete) #271.

@mbostock mbostock merged commit b31e739 into main Mar 29, 2021
@mbostock mbostock deleted the mbostock/scaled-channels branch March 29, 2021 16:44
@mbostock mbostock mentioned this pull request Aug 5, 2021
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants