Skip to content

Commit

Permalink
EBR-35: comment the connectivity notebook cell that leads to freeze o…
Browse files Browse the repository at this point in the history
…f jupyter lab, add parameters height and width for Connectivity3DViewer
  • Loading branch information
915-Misan-Teodora committed Mar 28, 2024
1 parent 7843e1d commit f3e2bd6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 67 deletions.
37 changes: 17 additions & 20 deletions notebooks/Connectivity.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,17 @@
"tags": []
},
"outputs": [],
"source": [
"from tvbwidgets.api import ConnectivityWidgetReact\n",
"from tvb.datatypes.connectivity import Connectivity\n",
"\n",
"connectivity = Connectivity.from_file() # defaults to connectivy_76.zip\n",
"\n",
"\n",
"wid = ConnectivityWidgetReact(connectivity=connectivity)\n",
"wid"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from tvbwidgets.api import ConnectivityWidget\n",
"from tvb.datatypes.connectivity import Connectivity\n",
"import pyvista as pv\n",
"import numpy as np\n",
"pv.set_jupyter_backend('pythreejs')\n",
"pv.set_jupyter_backend(\"pythreejs\")\n",
"\n",
"conn = Connectivity.from_file() # defaults to connectivy_76.zip\n",
"conn.configure()\n",
"\n",
"wid = ConnectivityWidget(conn, default_active_tab='viewers') # default_active_tab can be any value between 'viewers'|'operations'|'both'\n",
"wid = ConnectivityWidget(conn, default_active_tab='viewers', width=500, height=500) # default_active_tab can be any value between 'viewers'|'operations'|'both'\n",
"\n",
"display(wid)"
]
Expand All @@ -63,7 +47,20 @@
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"source": [
"# Using the React Connectivity widget may lead to Jupyter Lab freezing or crashing.\n",
"# If you choose to use it, we recommend to run it in Mozilla Firefox web browser.\n",
"\n",
"\n",
"# from tvbwidgets.api import ConnectivityWidgetReact\n",
"# from tvb.datatypes.connectivity import Connectivity\n",
"\n",
"# connectivity = Connectivity.from_file() # defaults to connectivy_76.zip\n",
"\n",
"\n",
"# wid = ConnectivityWidgetReact(connectivity=connectivity)\n",
"# wid"
]
}
],
"metadata": {
Expand All @@ -82,7 +79,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.13"
"version": "3.9.18"
}
},
"nbformat": 4,
Expand Down
22 changes: 10 additions & 12 deletions tvbwidgets/ui/connectivity_ipy/connectivity_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,10 @@ def on_ctx_change(value):

class Connectivity3DViewer(ipywidgets.VBox):

def __init__(self, **kwargs):
def __init__(self, width, height, **kwargs):
self.output = PyVistaOutput()
self.output.plotter.window_size = [width, height]
self.output.plotter.set_background("darkgrey")

super(Connectivity3DViewer, self).__init__([self.output], *kwargs)

Expand All @@ -120,7 +122,7 @@ def __init__(self, **kwargs):
def __init_view_connectivity(self):
self.output.plotter.clear()
points, edges = self.__add_actors()
points_toggle, edges_toggle, labels_toggle = self.__init_controls()
points_toggle, edges_toggle = self.__init_controls()

def on_change_points(change):
if change['new']:
Expand All @@ -140,12 +142,10 @@ def on_change_edges(change):

edges_toggle.observe(on_change_edges, 'value')

window_controls = self.output.get_window_controls()

self.children = [
ipywidgets.HBox(children=(
points_toggle, edges_toggle, labels_toggle)),
window_controls,
points_toggle, edges_toggle)),
self.output]
self.output.display_actor(points)
self.output.display_actor(edges)
Expand All @@ -159,9 +159,7 @@ def __init_controls(self):
description='Edges',
)

labels_toggle = ipywidgets.ToggleButton(value=False,
description='Labels')
return points_toggle, edges_toggle, labels_toggle
return points_toggle, edges_toggle

def __add_actors(self):
plotter = self.output.plotter
Expand Down Expand Up @@ -197,11 +195,11 @@ def __extract_edges(self):


class ConnectivityViewers(ipywidgets.Accordion):
def __init__(self, **kwargs):
def __init__(self, width, height, **kwargs):
super().__init__(**kwargs)
self.children = [
Connectivity2DViewer(),
Connectivity3DViewer()
Connectivity3DViewer(width, height)
]
self.set_title(0, '2D Connectivity Matrix viewer')
self.set_title(1, '3D Connectivity viewer')
Expand Down Expand Up @@ -235,7 +233,7 @@ def get_connectivity(self, gid=None):
return None
return conn[0]

def __init__(self, connectivity, default_active_tab='both', **kwargs):
def __init__(self, connectivity, default_active_tab='both', width=500, height=500, **kwargs):

style = self.DEFAULT_BORDER
super().__init__(**kwargs, layout=style)
Expand All @@ -246,7 +244,7 @@ def __init__(self, connectivity, default_active_tab='both', **kwargs):
viewers_visible = default_active_tab in ['both', 'viewers']
operations_visible = default_active_tab in ['both', 'operations']

self.viewers_tab = ConnectivityViewers()
self.viewers_tab = ConnectivityViewers(width, height)
self.viewers_tab.layout.display = viewers_visible and 'inline-block' or 'none'
self.operations_tab = ConnectivityOperations()
self.operations_tab.layout.display = operations_visible and 'inline-block' or 'none'
Expand Down
35 changes: 0 additions & 35 deletions tvbwidgets/ui/connectivity_ipy/outputs_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#
# (c) 2022-2023, TVB Widgets Team
#
import ipywidgets

from tvbwidgets.ui.connectivity_ipy.config import ConnectivityConfig
from tvbwidgets.ui.connectivity_ipy.exceptions import UnknownOutputException
Expand Down Expand Up @@ -42,40 +41,6 @@ def update_plot(self):
self.clear_output(wait=True)
self.plotter.show()

def get_window_controls(self):
height = ipywidgets.IntSlider(
value=self.CONFIG.size[1],
min=50,
max=1500,
step=1,
orientation='horizontal',
description='Plot height',
continuous_update=False,
)
width = ipywidgets.IntSlider(
value=self.CONFIG.size[0],
min=50,
max=1500,
step=1,
orientation='horizontal',
description='Plot width',
continuous_update=False,
)

self.plotter.window_size = [width.value, height.value]

def on_change_height(value):
self.plotter.window_size = [width.value, value['new']]
self.update_plot()

def on_change_width(value):
self.plotter.window_size = [value['new'], height.value]
self.update_plot()

height.observe(on_change_height, 'value')
width.observe(on_change_width, 'value')
return ipywidgets.HBox(children=(width, height))


def output_3d_factory(output_type):
"""Factory function for a custom 3d output"""
Expand Down

0 comments on commit f3e2bd6

Please sign in to comment.