Skip to content

Commit

Permalink
[#123] Integrated interactive sliders into UI (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
BraydenThompson authored Mar 15, 2024
1 parent 681da62 commit 6b7aeed
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 118 deletions.
113 changes: 9 additions & 104 deletions GoVizzy/GoVizzy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,12 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"id": "09026008-ce47-49d7-9fca-4b7c123022d1",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/mnt/d/Documents/GoVizzy/s24-slice-n-dice/.venv/lib/python3.11/site-packages/pandas/core/arrays/masked.py:60: UserWarning: Pandas requires version '1.3.6' or newer of 'bottleneck' (version '1.3.5' currently installed).\n",
" from pandas.core import (\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "9c1c4da74c5e45ebbd1e0cf73c8c6f87",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"AppLayout(children=(HBox(children=(Button(button_style='danger', description='[X]', layout=Layout(margin='0 0 …"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"from widgets import form, test_slider\n",
"from widgets import form\n",
"from GoVizzy import plotting, meshes\n",
"from UI import DisplayUI\n",
"import fileInput\n",
Expand All @@ -64,74 +41,20 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"id": "67faad66-2beb-4746-b0a4-21689ddc78d3",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "0e726288d9a94b7490108b39f2bac979",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"AppLayout(children=(HBox(children=(Button(button_style='danger', description='[X]', layout=Layout(margin='0 0 …"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "126f7927239f487f9c864701be943c96",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(Text(value='', description='File Name:'), Button(description='Submit', style=ButtonStyle())), l…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"\n",
"\n",
"%run Main.py"
]
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": null,
"id": "ef52d91c-9d81-41db-953b-78f7ef718f24",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Loading data/rhopol.cube ...\n",
"Done.\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "d55b62f3bc1246d59178a47ba3fe83d0",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Container(children=[VBox(children=(HBox(children=(Label(value='levels:'), FloatSlider(value=0.03, max=1.0, ste…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"# Load Cube File\n",
"cube: Cube = Cube()\n",
Expand All @@ -146,26 +69,10 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": null,
"id": "863d988e-36c3-463b-9b3f-d68e27ceb757",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "b7c37980c359447188ef4fb14cece17b",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Box(children=(Box(children=(Label(value='Path to .cube file'), Textarea(value='')), layout=Layout(display='fle…"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"form"
]
Expand Down Expand Up @@ -195,9 +102,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",

"version": "3.12.2"

}
},
"nbformat": 4,
Expand Down
6 changes: 5 additions & 1 deletion GoVizzy/GoVizzy/plotting.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from widgets import color
from widgets import color, slice_x_slider, slice_y_slider, slice_z_slider
from cube_viskit import Cube
import ipywidgets as widgets
import ipyvolume as ipv
Expand Down Expand Up @@ -117,5 +117,9 @@ def display_cell_slices(self):
slice_y = ipv.plot_plane('y', volume=volume, description="Slice Y", description_color="black", icon="mdi-knife", y_offset=70)
slice_z = ipv.plot_plane('z', volume=volume, description="Slice Z", description_color="black", icon="mdi-knife", z_offset=70)

widgets.jslink((slice_x_slider, 'value'), (slice_x, 'x_offset'))
widgets.jslink((slice_y_slider, 'value'), (slice_y, 'y_offset'))
widgets.jslink((slice_z_slider, 'value'), (slice_z, 'z_offset'))

ipv.show()

15 changes: 7 additions & 8 deletions GoVizzy/UI/DisplayUI.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from widgets import slice_x_slider, slice_y_slider, slice_z_slider
import ipywidgets as widgets
from ipywidgets import Dropdown, VBox, HBox, Output, AppLayout, Layout, Label, Button
from ipywidgets import Dropdown, VBox, HBox, Output, ColorPicker, AppLayout, Layout, Label, Button
import ipyvolume as ipv
import matplotlib.pyplot as plt
import GoVizzy.plotting
import GoVizzy.plotting

# Define globals
selected_option = 'Volumetric'
Expand Down Expand Up @@ -100,23 +101,21 @@ def display_ipyvolume_plot(cube):
with large_box:
#ipv.show()
visualizer = GoVizzy.plotting.Visualizer(cube)
visualizer.display_cell()
visualizer.display_cell_slices()


def display_app(large_box, additional_box):
# Attach the dropdown change handler



# Create a VBox for dropdown
dropdown_container = VBox([dropdown])
# Combine the Output widgets with their descriptions
slice_box = VBox([slice_picker_descr, slice_picker])



# Attach callback function to button click event


menu_options = VBox([dropdown, slice_box, additional_box, newCube_button], layout=Layout(flex='1'))
menu_options = VBox([dropdown, slice_box, additional_box, slice_x_slider, slice_y_slider, slice_z_slider, newCube_button], layout=Layout(flex='1'))
display_box = HBox([large_box, menu_options])


Expand Down
31 changes: 26 additions & 5 deletions GoVizzy/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,32 @@
)


test_slider = FloatSlider(
slice_x_slider = FloatSlider(
value=0,
min=0,
max=10,
max=120,
step=0.1,
description='Example slider!',
description='X slice position',
readout=True,
readout_format='.1f'
)

slice_y_slider = FloatSlider(
value=0,
min=0,
max=120,
step=0.1,
description='Y slice position',
readout=True,
readout_format='.1f'
)

slice_z_slider = FloatSlider(
value=0,
min=0,
max=120,
step=0.1,
description='Z slice position',
readout=True,
readout_format='.1f'
)
Expand All @@ -34,7 +54,7 @@
Textarea()], layout=form_item_layout),
color,
Button(description='Submit', layout=Layout(flex='1 1 0%', width='auto')),
test_slider,
slice_x_slider,
]

# Create the input form box
Expand All @@ -45,4 +65,5 @@
align_items='stretch',
width='50%'
))
form, color, test_slider

form, color, slice_x_slider, slice_y_slider, slice_z_slider

0 comments on commit 6b7aeed

Please sign in to comment.