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

Feature request: Invert a ColorScheme (inverse of get) #10

Closed
NHDaly opened this issue Jan 16, 2018 · 4 comments · Fixed by #11
Closed

Feature request: Invert a ColorScheme (inverse of get) #10

NHDaly opened this issue Jan 16, 2018 · 4 comments · Fixed by #11

Comments

@NHDaly
Copy link
Contributor

NHDaly commented Jan 16, 2018

Hi! I came across the need to convert a heatmap image to an Array of continuous values, and in the process discovered this cool package. ColorSchemes is exactly what I wanted to represent with code the continuous semantics humans put on a heatmap. Thanks!

But in my case, I already had pixels, and I wanted to find out where each pixel lies on the this continuous ColorScheme, rather than the other way around (the functionality provided by get(cscheme, x).

I've done this before in JavaScript via d3 to create a map legend you can mouse over:

var legendScale = d3.scale.log()
      .domain([minValue,maxValue])
      .range([0,legend.width()]);
// ...
$(legend).mousemove(function(e){
  offset = $(this).offset();
  xPos = e.pageX - offset.left;
  value = prettifyNum(parseFloat(legendScale.invert(xPos).toPrecision(2)));
  mouseovertext[0].textContent=value;
});

So anyway, this is a Feature Request to be able to do the same thing with ColorScheme.jl! 😸


I should've checked to see if this functionality already exists somewhere else, or if it's even a thing people would want, but I got carried away and I wrote it myself... I put the functionality in this package here:
https://github.com/NHDaly/ColorSchemesInvert.jl/blob/master/README.ipynb

If this is something people think makes sense, I can open a pull request to merge that functionality into this package. What do you think?

@NHDaly
Copy link
Contributor Author

NHDaly commented Jan 16, 2018

Actually, after thinking about this a bit more, there are two separate parts to what I'm asking for...

  1. The first is simply the ability to invert a linspace. That is, given a simple continuous scale, find the value in the domain at which the scale's range equals my value. That is what I did in the javascript above, and it is a completely independent question from this package. I should perhaps bring this question somewhere else.

  2. The second request is to be able to find out that same thing (which value in the domain produces my range value, or color) but for a not-obviously-continuous value -- one that can't be represented by a linspace. This second class of problem is the problem space that this package works in: it provides a way to describe all colors used in an image on a single continuous scale. So for my initial use case (reading the values off an a heatmap image), this package seems like the correct place. :)

But if there already exists the ability to invert a linspace as I described in 1, above, then maybe we could implement the behavior I described in 2 as another method of that function. This would mirror the way this package provides another method for get.

Thanks! :)

@cormullion
Copy link
Member

Hi! If you want to add your code to this package (via a PR if you like), I’d be delighted to help/assist in any way. This package could do with some more skilled contributors, I don’t understand what the code does myself sometimes ... :)

@NHDaly
Copy link
Contributor Author

NHDaly commented Jan 17, 2018

:) Hi @cormullion! :) Thanks, I've opened a PR.

Yeah, I'm looking forward to working together! I'm not sure if this is better discussed over there in the PR or here, but hopefully the README.ipynb demonstrates a bit about what I had in mind! :)

And haha okay sure. I'm not sure if I'll be a great long-term maintainer; I don't spend too much time working in this space either, mostly i was just playing. But yeah I'm happy to help out if needed!

@cormullion
Copy link
Member

Looks pretty good to me. The package will need an overhaul in a few months when everything breaks on the road to v0.7/v1.0, so I think we should merge this and see how it works/what needs revising.

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

Successfully merging a pull request may close this issue.

2 participants