Skip to content

Commit 626c317

Browse files
committed
feat:map display in panel
1 parent 0f8abec commit 626c317

1 file changed

Lines changed: 105 additions & 36 deletions

File tree

pydelmod/dvue/dataui.py

Lines changed: 105 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ def create_data_table(self, dfs):
512512
},
513513
)
514514

515-
self._display_panel = pn.Row()
515+
self._display_panel = pn.Row(sizing_mode="stretch_both")
516516
self._action_panel = pn.Row()
517517
actions = self._dataui_manager.get_data_actions()
518518

@@ -603,6 +603,92 @@ def _create_main_view(self):
603603
sizing_mode="stretch_both",
604604
)
605605

606+
def set_progress(self, value):
607+
"""
608+
Set the progress bar value.
609+
610+
Parameters:
611+
-----------
612+
value : int
613+
Value between 0-100 for progress percentage, or -1 for indeterminate progress
614+
"""
615+
self.progress_bar.visible = True
616+
if value == -1:
617+
# Set to indeterminate mode
618+
self.progress_bar.indeterminate = True
619+
else:
620+
self.progress_bar.indeterminate = False
621+
self.progress_bar.value = max(
622+
0, min(100, value)
623+
) # Ensure value is between 0-100
624+
625+
def hide_progress(self):
626+
"""Hide the progress bar."""
627+
self.progress_bar.visible = False
628+
self.progress_bar.value = 0
629+
self.progress_bar.indeterminate = False
630+
631+
def show_map_in_display_panel(self, event):
632+
"""Display the map in the display panel area as a closable tab"""
633+
try:
634+
# Set progress indicator while loading the map
635+
self._display_panel.loading = True
636+
self.set_progress(-1) # Start indeterminate progress
637+
638+
# Create a copy of the map for the display panel
639+
map_display = pn.Column(
640+
self._tmap * self._map_function,
641+
min_width=800,
642+
min_height=600,
643+
sizing_mode="stretch_both",
644+
)
645+
646+
# Show 90% progress
647+
self.set_progress(90)
648+
649+
# Check if there are already tabs in the display panel
650+
if len(self._display_panel.objects) > 0 and isinstance(
651+
self._display_panel.objects[0], pn.Tabs
652+
):
653+
# Add to existing tabs
654+
tabs = self._display_panel.objects[0]
655+
656+
# Initialize tab_count if it doesn't exist
657+
if not hasattr(self, "_tab_count"):
658+
self._tab_count = 0
659+
660+
self._tab_count += 1
661+
tabs.append((f"Interactive Map {self._tab_count}", map_display))
662+
tabs.active = len(tabs) - 1 # Activate the new tab
663+
else:
664+
# Create a new tabs panel
665+
self._tab_count = 1
666+
self._display_panel.objects = [
667+
pn.Tabs(
668+
(f"Interactive Map {self._tab_count}", map_display),
669+
closable=True,
670+
dynamic=True,
671+
)
672+
]
673+
674+
# Complete the progress
675+
self.set_progress(100)
676+
except Exception as e:
677+
stack_str = full_stack()
678+
logger.error(stack_str)
679+
if pn.state.notifications is not None:
680+
pn.state.notifications.error(
681+
"Error displaying map: " + str(stack_str), duration=0
682+
)
683+
finally:
684+
self._display_panel.loading = False
685+
# Hide progress after a short delay to show completion
686+
import asyncio
687+
688+
pn.state.curdoc.add_next_tick_callback(
689+
lambda: asyncio.create_task(self._hide_progress_after_delay())
690+
)
691+
606692
def create_view_navigation(self):
607693
"""Create navigation buttons for switching between views"""
608694
nav_buttons = pn.Row(
@@ -685,14 +771,19 @@ def create_view(self, title="Data User Interface"):
685771
value="""Map of geographical features. Click on a feature to see data available in the table. <br/>
686772
See <a href="https://docs.bokeh.org/en/latest/docs/user_guide/interaction/tools.html">Bokeh Tools</a> for toolbar operation"""
687773
)
688-
map_view = fullscreen.FullScreen(
689-
pn.Column(
690-
self._tmap * self._map_function,
691-
map_tooltip,
692-
min_width=450,
693-
min_height=550,
694-
)
774+
775+
# Create a button to show map in display panel
776+
map_display_btn = pn.widgets.Button(
777+
name="Show Map in Display", button_type="primary", icon="map", width=150
778+
)
779+
map_display_btn.on_click(self.show_map_in_display_panel)
780+
781+
map_view = pn.Column(
782+
pn.Row(map_display_btn, pn.layout.HSpacer(), map_tooltip),
783+
self._tmap * self._map_function,
784+
min_width=450,
695785
)
786+
696787
sidebar_view = pn.Column(
697788
pn.Tabs(
698789
("Map", map_view),
@@ -701,10 +792,12 @@ def create_view(self, title="Data User Interface"):
701792
("Map Options", map_options),
702793
),
703794
self.progress_bar,
795+
sizing_mode="stretch_both",
704796
)
705797
else:
706798
sidebar_view = pn.Column(
707-
pn.Tabs(("Options", control_widgets)), self.progress_bar
799+
pn.Tabs(("Options", control_widgets), ("Table Options", table_options)),
800+
self.progress_bar,
708801
)
709802
# Create view navigation buttons
710803
nav_buttons = pn.Row(self.create_view_navigation())
@@ -722,40 +815,16 @@ def create_view(self, title="Data User Interface"):
722815
)
723816

724817
# Add navigation before the main content
725-
template.header.append(nav_buttons)
818+
about_button = self.create_about_button(template)
819+
template.header.append(pn.Row(nav_buttons, pn.layout.HSpacer(), about_button))
726820
template.main.append(self._main_view)
727821

728822
# Adding about button
729823
template.modal.append(self.get_about_text())
730-
sidebar_view.append(self.create_about_button(template))
824+
# sidebar_view.append(self.create_about_button(template))
731825
self._template = template
732826

733827
# finally sync location views
734828
self.setup_location_sync()
735829

736830
return template
737-
738-
def set_progress(self, value):
739-
"""
740-
Set the progress bar value.
741-
742-
Parameters:
743-
-----------
744-
value : int
745-
Value between 0-100 for progress percentage, or -1 for indeterminate progress
746-
"""
747-
self.progress_bar.visible = True
748-
if value == -1:
749-
# Set to indeterminate mode
750-
self.progress_bar.indeterminate = True
751-
else:
752-
self.progress_bar.indeterminate = False
753-
self.progress_bar.value = max(
754-
0, min(100, value)
755-
) # Ensure value is between 0-100
756-
757-
def hide_progress(self):
758-
"""Hide the progress bar."""
759-
self.progress_bar.visible = False
760-
self.progress_bar.value = 0
761-
self.progress_bar.indeterminate = False

0 commit comments

Comments
 (0)