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

Fixes popup being invisible forever after closing once #6347

Merged
merged 6 commits into from
Jul 31, 2024
Merged

Conversation

ahuang11
Copy link
Collaborator

Changes from #6207 made some examples not useful

This closes #6342 by:

  1. checking whether the popup stream is callable; if it isn't, we cannot do if popup_is_callable and not popup_pane.visible, or else it'll be invisible forever if user has a on_click(layout.visible = False) like the example below
import panel as pn
import numpy as np
import holoviews as hv
hv.extension("bokeh")


points = hv.Points(np.random.randn(1000, 2))

def form(name):
    text_input = pn.widgets.TextInput(name='Description')
    button = pn.widgets.Button(name='Save', on_click=lambda _: layout.param.update(visible=False))
    layout = pn.Column(f'# {name}', text_input, button)
    return layout

hv.streams.BoundsXY(source=points, popup=form('Bounds'))
hv.streams.Lasso(source=points, popup=form('Lasso'))
hv.streams.Tap(source=points, popup=form('Tap'))

pn.panel(points.opts(tools=['box_select', 'lasso_select', 'tap'], width=600, height=600, size=6, color='black', fill_color=None)).servable()

Here's a demo applying these fixes:

Screen.Recording.2024-07-29.at.10.44.53.AM.mov
  1. if existing popup is invisible, we need to make it visible again or else it'll not show the user defined layout again
import holoviews as hv
import panel as pn
import numpy as np
hv.extension("bokeh")
pn.extension()

def popup_form(index):
    def hide_popup(_):
        layout.visible = False

    if not index:
        return
    df = points.iloc[index].dframe().describe()
    button = pn.widgets.Button(name="Close", sizing_mode="stretch_width")
    layout = pn.Column(button, df)
    button.on_click(hide_popup)
    return layout


points = hv.Points(np.random.randn(1000, 2))
hv.streams.Selection1D(source=points, popup=popup_form)

points.opts(
    tools=["box_select", "lasso_select", "tap"],
    active_tools=["lasso_select"],
    size=6,
    color="black",
    fill_color=None,
    width=500,
    height=500
)

Demo after fix:

Screen.Recording.2024-07-29.at.10.46.39.AM.mov

These changes also keep compatibility with holonote

import panel as pn
import numpy as np
import pandas as pd
import hvplot.pandas
import numpy as np
import holoviews as hv

from holonote.annotate import SQLiteDB, Annotator
from holonote.app import PanelWidgets

pn.extension()

curve = pd.read_parquet("../holonote/examples/assets/example.parquet").hvplot(x="TIME")
connector = SQLiteDB(table_name="test_app")
fields = ["Stoppage", "Reason", "Category"]
annotator = Annotator({"TIME": np.datetime64}, fields=fields, connector=connector)
annotator_element = annotator * curve

fields_values = {
    "Stoppage": ["Yes", "No"],
    "Category": ["Mechanical", "Electrical", "Process", "Other"],
}

w = PanelWidgets(annotator, field_values=fields_values, as_popup=True)
pn.serve(annotator_element)
Screen.Recording.2024-07-29.at.10.48.27.AM.mov

:) and welcome back Simon

@ahuang11 ahuang11 added the type: bug Something isn't correct or isn't working label Jul 29, 2024
if popup is None:
if self._panel.visible:
self._panel.visible = False
return

if event is not None:
position = self._get_position(event)
Copy link
Collaborator Author

@ahuang11 ahuang11 Jul 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this down inside existing popup since it's unused if there's no existing popup.

Copy link

codecov bot commented Jul 29, 2024

Codecov Report

Attention: Patch coverage is 51.35135% with 18 lines in your changes missing coverage. Please review.

Project coverage is 88.47%. Comparing base (c1e22a3) to head (9fea81c).
Report is 1 commits behind head on main.

Files Patch % Lines
holoviews/tests/ui/bokeh/test_callback.py 43.75% 18 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6347      +/-   ##
==========================================
- Coverage   88.50%   88.47%   -0.03%     
==========================================
  Files         323      323              
  Lines       68093    68125      +32     
==========================================
+ Hits        60263    60275      +12     
- Misses       7830     7850      +20     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@hoxbro
Copy link
Member

hoxbro commented Jul 31, 2024

Thank you for the quick fix.

:) and welcome back Simon

Nice to be back 🙂

@hoxbro hoxbro merged commit 4b6c437 into main Jul 31, 2024
13 checks passed
@hoxbro hoxbro deleted the fix_popup branch July 31, 2024 07:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't correct or isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot reopen popup when using reference examples
2 participants