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

register additional colormaps #34

Open
maxschmi opened this issue Jan 28, 2025 · 2 comments
Open

register additional colormaps #34

maxschmi opened this issue Jan 28, 2025 · 2 comments

Comments

@maxschmi
Copy link

I would really appreciate a method to extend the available colormaps with own colormaps.

I could imagine a method like:

import { registerColormap } from 'colormap'

registerColormap(key="new_colormap", colors=[[1,1,1],[0,0,0]])

So that you can later on use the colromap like this:

let colors = colormap({colormap: "new_colormap", nshades=10}) 

I think that would be quite easy to implement, as the colormap only needs to get added to colorScale variable, but it propably also needs to be set as a global constant.

@dy
Copy link
Collaborator

dy commented Jan 28, 2025

I think it should be be available now by extending colorScale object:

import colorScale from 'colormap/colorScale.js'
import colormap from 'colormap'

colorScale.new_colormap = [{index:0, rgb:[255,255,255]}, {index:1, rgb:[0,0,0]}]
let colors = colormap({colormap: "new_colormap", nshades=10}) 

@maxschmi
Copy link
Author

That works smooth, thanks.

Or packed inside a function:

import colorScale from 'colormap/colorScale.js';

function registerColormap(key, colormap) {
  if (colormap.every(c => c.index !== undefined && c.rgb?.length == 3)) {
      colorScale[key] = colormap;
  } else {
      throw new Error('Invalid colormap');
  }
}

registerColormap("new_colormap", [{index:0, rgb:[255,255,255]}, {index:1, rgb:[0,0,0]}])

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