jupyter-widgets-contrib / ipygany

3-D Scientific Visualization in the Jupyter Notebook
BSD 3-Clause "New" or "Revised" License
487 stars 53 forks source link

Controling/adding colormaps in colormap widget #93

Open pierre-sepulchre opened 3 years ago

pierre-sepulchre commented 3 years ago

Would it be possible to add more colormaps in the dedicated widget, i.e. using custom colormaps defined earlier in the notebooks ? In : # Colormap choice widget colormap = Dropdown( options=colormaps, description='colormap:' )

For now colormaps is :

{'BrBG': 0, 'PRGn': 1, 'PiYG': 2, 'PuOr': 3, 'RdBu': 4, 'RdGy': 5, 'RdYlBu': 6, 'RdYlGn': 7, 'Spectral': 8, 'BuGn': 9, 'BuPu': 10, 'GnBu': 11, 'OrRd': 12, 'PuBuGn': 13, 'PuBu': 14, 'PuRd': 15, 'RdPu': 16, 'YlGnBu': 17, 'YlGn': 18, 'YlOrBr': 19, 'YlOrRd': 20, 'Blues': 21, 'Greens': 22, 'Greys': 23, 'Purples': 24, 'Reds': 25, 'Oranges': 26, 'Cividis': 27, 'CubehelixDefault': 28, 'Rainbow': 29, 'Warm': 30, 'Cool': 31, 'Sinebow': 32, 'Turbo': 33, 'Viridis': 34, 'Magma': 35, 'Inferno': 36, 'Plasma': 37}

WesleyTheGeolien commented 3 years ago

I'm guessing:

class IsoColorModel extends EffectModel {

  defaults() {
    return {...super.defaults(),
      _model_name: IsoColorModel.model_name,
      min: 0.,
      max: 0.,
      range: [0., 0.],
      colormap: 34,
      type: 'linear',
    };
  }

this is getting passed to this w:

function deserialize_float32array (data: any, manager: any) {
    return new Float32Array(data.data.buffer);
}

which is somehow changing the colormap?

I saw something about d3 in the commit log as well ....

Could an option be to interpret the python (or other) colormap then pass the data array through to the javascript somehow?

martinRenou commented 3 years ago

I started some work in draft PRs (see https://github.com/QuantStack/ipygany/pull/23 and https://github.com/QuantStack/GanyJS/pull/9) to add Paraview colormaps support, and my idea was that at some point users could define their own colormaps with a list of colors and control points, just like in Paraview.

This is not possible yet though.

martinRenou commented 3 years ago

Could an option be to interpret the python (or other) colormap then pass the data array through to the javascript somehow?

The IsoColor is not using deserialize_float32array, it is just passing the colormap index (34 by default for Viridis), that the JavaScript side is able to map to the right colormap in GanyJS.