#!/usr/bin/env python # coding: utf-8 # # Linking and Layout # # > [ Simple example](./Simple%20example.ipynb) # > # > [ Advanced examples](./More%20examples.ipynb) # > # > Linking and Layout # > # > [ Exporting Images](./Exporting%20Images.ipynb) # # In[1]: from ipysankeywidget import SankeyWidget # > This uses the base [ipywidgets](https://github.com/ipython/ipywidgets) for layout and data, but you can use any widgets! # In[2]: from ipywidgets import ( VBox, HBox, IntSlider, ) # In[3]: links = [ {'source': 'start', 'target': 'A', 'value': 10}, {'source': 'A', 'target': 'B', 'value': 10}, {'source': 'C', 'target': 'A', 'value': 10}, {'source': 'A', 'target': 'C', 'value': 10}, ] # In[4]: sankey = SankeyWidget(links=links) sankey # > A convenience factory function # In[5]: def slider(link, i, sankey): value = IntSlider(description="{source} → {target}".format(**link), min=0, max=10, step=1, value=10) def _change(change): sankey.links[i]["value"] = value.value sankey.send_state() value.observe(_change) return value # Build up a slider per link to control the value: # In[6]: sliders = [slider(link, i, sankey) for i, link in enumerate(links)] # In[7]: box = HBox(children=[sankey, VBox(children=sliders)]) box # In[ ]: