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

linking Threshold mesh with FloatRangeSlider #77

Closed CagtayFabry closed 3 years ago

CagtayFabry commented 3 years ago

this gif shows a wonderful example of linking min/max values from a FloatRangeSlider with the Threshold class.

I am struggling to find the correct way to forward the tuple provided by FloatRangeSlider.value to the correct jslink call. Could you provide the code snippet from the example? I think this specific example is not included in the documentation

martinRenou commented 3 years ago

FloatRangeSlider.value is a tuple, you unfortunately won't be able to jslink it to the Threshold directly, you'll need to observe its changes:

def on_change(change):
    threshold.min = change['new'][0]
    threshold.max = change['new'][1]

slider.observe(on_change, 'value')
CagtayFabry commented 3 years ago

thanks for the workaround @martinRenou

observe will go through the python kernel if I understand correctly, not as smooth as jslink unfortunately I guess I would have to build my own FloatRangeSlider alternative that exposes min/max traits as single values? (this is probably not as simple as subclassing.. ?)

martinRenou commented 3 years ago

observe will go through the python kernel if I understand correctly, not as smooth as jslink unfortunately

Yes, it's also the reason why I didn't put this example in the documentation, because it would not have been live.

(this is probably not as simple as subclassing.. ?)

Unfortunately no, you would have to write JavaScript code 😈

I guess I would have to build my own FloatRangeSlider alternative that exposes min/max traits as single values?

Another way for you to get a smoother experience would be to that we update ipygany to have a range attribute instead of a min/max for the Threshold, which I actually think would be a good idea for this exact reason.

Yet another way to get around this issue would be to use two sliders, one for min and one for max, this is not perfect but it doesn't require changing ipygany nor writing JavaScript code. (you might even be able to link the min_slider's max attribute to the max_slider's value, and the max_slider's min to the min_slider's value, not perfect but it might work.)

CagtayFabry commented 3 years ago

I did end up doing exactly what you suggested with 2 sliders (linking with min/max works nicely)

I might try to peak into 'Threshold' a bit if I find some time ..

CagtayFabry commented 3 years ago

I am not sure if this was in line with your suggestion but I tried a simple change that allows jslink with FloatRangeSlider #78 @martinRenou

example added to docs: https://github.com/CagtayFabry/ipygany/blob/threshold_range/docs/source/api_reference/threshold.rst

few notes:

martinRenou commented 3 years ago

Thanks a lot for your contribution! This will be included in the coming release

CagtayFabry commented 3 years ago

looking forward to the release 👍

What do you think about adding range to IsoColor as well? Should be straight forward, I could find probably some time over the weekend

martinRenou commented 3 years ago

looking forward to the release +1

It should come soon. There is a couple of fixes to push first, in the JupyterLab 3 update I made some mistakes.

What do you think about adding range to IsoColor as well? Should be straight forward, I could find probably some time over the weekend

👍🏼 that would be super great!

martinRenou commented 3 years ago

Thanks a lot @CagtayFabry! ipygany 0.5.0 is out (on PyPi right now, very soon on conda) with your changes. And I added colormaps and colorbars.