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

Extending jslink? #1109

Open
maartenbreddels opened this issue Feb 14, 2017 · 3 comments
Open

Extending jslink? #1109

maartenbreddels opened this issue Feb 14, 2017 · 3 comments
Milestone

Comments

@maartenbreddels
Copy link
Member

jslink is really useful for having some frontend only communication, however there are more use cases I can think of that would be useful. I wonder if some thought went already into this, if not maybe it is useful to discuss some use cases that could be implemented simply.

  • bijective transformation, for instance a slider that controls the log of a value, or a linear transformation. Could be a js code snippet argument to jslink, or maybe only a property to the Link class, and a different function to set this, e.g. jslinkf((widget1, 'value', 'Math.log(value)'), (widget2, 'value', 'Math.exp(value)'
  • Regarding ToggleButtons / _Selection .value in Python side != .value on js side #1091 I can imagine this. We have a some widget, with a property children (list of widgets), and we want to set another property based on a togglebutton (or any _selector subclass). On the JS side you could use the .index to get the child from the list, and then assign it to a target. jslinkXXX((selector, 'index'), (some_widget, 'children'), (visible_panel_proxy, 'child')). I hope this example is clear.
  • Sometimes if something changes, you do not want to link that 'something', but a propery of that 'something'. Say if scatter.style changes, you want to link scatter.style["color"] to bar.selected_style["color"], e.g. jslinkYYY((scatter, 'style', 'color'), (bar, 'selected_style', 'color')).
@SylvainCorlay
Copy link
Member

SylvainCorlay commented Feb 14, 2017

We were thinking of having a js container run an arbitrary js transformation specified in a third transform argument, a bit like in traitlets' link. Security is tricky, but can probably be achieved.

@jasongrout jasongrout added this to the Backlog milestone Apr 8, 2017
@maartenbreddels
Copy link
Member Author

Been discussing with @SylvainCorlay about transformations,
Similar to traitlets, would be nice to have:

jsdlink((slider1, 'index'), (floattext, 'value'), transformation='log(value)')

We probably don't want to use eval, so that leave us to choose a library for parsing that:
From http://stackoverflow.com/questions/2276021/evaluating-a-string-as-a-mathematical-expression-in-javascript
I found these:

Another option I would like to see, is sth similar, but instead of a math transformation, it's is a non-linear mapping, but an option from say a dict:

animation_delay_toggle_button = widgets.ToggleButtons(
    options=['None', 'Fast, 'Regular', 'Slow'],
    description='Delay:',
)
jsdlink((animation_delay_toggle_button, 'index'), (figure, 'animation_delay'), \
 choice={0:0, 1:100, 2:500, 3:1000})

Using a dict it would also be possible to map strings to values.

Having this in jslink would also be nice, but lets wait the discussion/PR here

@ClementPinard
Copy link

Hi, sorry for digging up this topic, but I stumbled upon it when i searched for linking between a checkbox and a stack

Do you know if there have been some work on extending jslink, especially with the dict mapping ?

I know I can use the observe or interactive_output methods, but these require an active python kernel, and I would like it to be available for static widgets, because the notebook is part of a documentation that gets compiled with sphinx.

For now I'm using ToggleButtons that have an index that I can link with my stack, but having a selector only for 2 values is a bit overkill in my case.

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

4 participants