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

Custom domains for presets #7

Closed
HHogg opened this issue Apr 23, 2023 · 2 comments
Closed

Custom domains for presets #7

HHogg opened this issue Apr 23, 2023 · 2 comments

Comments

@HHogg
Copy link

HHogg commented Apr 23, 2023

👋 Thanks for the library.

Have you thought about providing custom domains for the presets, similar to how d3-color does it, unless there's a different way of doing this with colorgrad-rs? Something along the lines of...

colorgrad::spectral().domain(my_domain_min, my_domain_max)
@mazznoer
Copy link
Owner

You can use this function to do that.

// map t from range [a, b] to range [0, 1]
fn norm(t: f64, a: f64, b: f64) -> f64
{
    (t-a) * (1.0 / (b-a))
}

let grad = colorgrad::rainbow();

// domain is from -100 to 100.
grad.at(norm(0.0, -100.0, 100.0));

// domain is from 0 to 50.
grad.at(norm(0.0, 0.0, 50.0));

@HHogg
Copy link
Author

HHogg commented Apr 24, 2023

Thanks for the response @mazznoer.

As there is a domain that is used internally, I wonder if you'd be open to an API to allow it to be configured. It would be helpful from an API perspective, where you have a gradient stored and used in lots of place. The current options as you say is to either interpolate the values on each call, or create a proxy to it.

@HHogg HHogg closed this as completed Jul 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants