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

EBR-35: comment connectivity notebook cell #66

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading