Skip to content

Commit

Permalink
change formatting of hover buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
2320sharon committed Feb 9, 2024
1 parent e0e87a3 commit 863f832
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 47 deletions.
35 changes: 1 addition & 34 deletions src/coastseg/coastseg_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,39 +137,6 @@ def find_shorelines_directory(path, roi_id):
return None


def find_shorelines_directory(path, roi_id):
# List the contents of the specified path
contents = os.listdir(path)

# Check for extracted shorelines geojson file in the specified path
extracted_shorelines_file = [
file
for file in contents
if "extracted_shorelines" in file and file.endswith(".geojson")
]
if extracted_shorelines_file:
return path

# If the file is not found, check for a directory with the ROI ID
roi_directory = [
directory
for directory in contents
if os.path.isdir(os.path.join(path, directory)) and roi_id in directory
]
if roi_directory:
roi_path = os.path.join(path, roi_directory[0])
roi_contents = os.listdir(roi_path)
extracted_shorelines_file = [
file
for file in roi_contents
if "extracted_shorelines" in file and file.endswith(".geojson")
]
if extracted_shorelines_file:
return roi_path

return None


def delete_extracted_shorelines_files(session_path: str, selected_items: List):
"""
Delete the extracted shorelines from the session directory for all the relevant files.
Expand Down Expand Up @@ -278,7 +245,7 @@ def _init_info_boxes(self):
self.map.add(self.warning_widget)

self.roi_html = HTML("""""")
self.roi_box = common.create_hover_box(title="ROI", feature_html=self.roi_html)
self.roi_box = common.create_hover_box(title="ROI", feature_html=self.roi_html,default_msg="Hover over a ROI")
self.roi_widget = WidgetControl(widget=self.roi_box, position="topright")
self.map.add(self.roi_widget)

Expand Down
28 changes: 15 additions & 13 deletions src/coastseg/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1704,7 +1704,7 @@ def mount_google_drive(name: str = "CoastSeg") -> None:
print("Not running in Google Colab.")


def create_hover_box(title: str, feature_html: HTML = HTML("")) -> VBox:
def create_hover_box(title: str, feature_html: HTML = HTML(""),default_msg: str = "Hover over a feature") -> VBox:
"""
Creates a box with a title and optional HTML containing information about the feature that was
last hovered over.
Expand All @@ -1720,26 +1720,28 @@ def create_hover_box(title: str, feature_html: HTML = HTML("")) -> VBox:
Returns:
container (VBox): Box with the given title and details about the feature given by feature_html
"""
padding = "0px 0px 0px 5px" # upper, right, bottom, left
padding = "0px 0px 4px 0px" # upper, right, bottom, left
# create title
title = HTML(f" <h4>{title} Hover </h4>")
# title = HTML(f"<b>{title}</b>")
title_html = HTML(f"<b>{title}</b>", layout=Layout(margin="0px 8px")) # Adjust 10px as needed for left and right margins

# Default message shown when nothing has been hovered
msg = HTML(f"Hover over a feature</br>")
msg = HTML(f"{default_msg}<br/>")
# open button allows user to see hover data
uncollapse_button = ToggleButton(
value=False,
tooltip="Show hover data",
icon="angle-down",
button_style="info",
button_style='primary',
layout=Layout(height="28px", width="28px", padding=padding),
)

# collapse_button collapses hover data
collapse_button = ToggleButton(
close_button = ToggleButton(
value=False,
tooltip="Show hover data",
icon="angle-up",
button_style="info",
tooltip="Close",
icon="times",
button_style="danger",
layout=Layout(height="28px", width="28px", padding=padding),
)

Expand All @@ -1751,22 +1753,22 @@ def create_hover_box(title: str, feature_html: HTML = HTML("")) -> VBox:
container_content.children = [feature_html]

# default configuration for container is in collapsed mode
container_header = HBox([title, uncollapse_button])
container_header = HBox([uncollapse_button,title_html])
container = VBox([container_header])

def uncollapse_click(change: dict):
if feature_html.value == "":
container_content.children = [msg]
elif feature_html.value != "":
container_content.children = [feature_html]
container_header.children = [title, collapse_button]
container_header.children = [close_button,title_html]
container.children = [container_header, container_content]

def collapse_click(change: dict):
container_header.children = [title, uncollapse_button]
container_header.children = [uncollapse_button,title_html]
container.children = [container_header]

collapse_button.observe(collapse_click, "value")
close_button.observe(collapse_click, "value")
uncollapse_button.observe(uncollapse_click, "value")
return container

Expand Down

0 comments on commit 863f832

Please sign in to comment.