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

Add support for popups on selection streams #6168

Merged
merged 31 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
ea8b099
Add support for popups on selection streams
philippjfr Apr 3, 2024
2672a9b
Allow callbacks
philippjfr Apr 3, 2024
9acd56e
Fix unknown reference
ahuang11 Apr 5, 2024
6834a4c
Remove schedule placeholder to make it work with server
ahuang11 Apr 5, 2024
527261a
Refactor and comment
ahuang11 Apr 5, 2024
9f11478
Add docs
ahuang11 Apr 5, 2024
5c6581e
Add docs and fix multiple interactions
ahuang11 Apr 5, 2024
f91fda8
Remove imports
ahuang11 Apr 5, 2024
ce2c500
Add tests
ahuang11 Apr 5, 2024
dcd14e2
Handle case if no streams
ahuang11 Apr 5, 2024
53cc936
Add holoviews plot as first
ahuang11 Apr 8, 2024
4ed644f
Link panel
ahuang11 Apr 8, 2024
bb66e17
Add close button
hoxbro Apr 9, 2024
3c8ae0c
Move pn.extension down to after panel import
hoxbro Apr 9, 2024
dfcc18b
Prettier close symbol
hoxbro Apr 9, 2024
47260d5
Address most comments
ahuang11 Apr 9, 2024
e3a7eaf
Apply fix
ahuang11 Apr 9, 2024
2841411
Add css class + hitbox
ahuang11 Apr 9, 2024
32f3075
no locator
ahuang11 Apr 9, 2024
e90880e
address comments
ahuang11 Apr 9, 2024
db34567
Add back prefix
ahuang11 Apr 9, 2024
df46cf5
Add extra safeguard to if statement
hoxbro Apr 10, 2024
f314692
Ensure events are dispatched after values are known
philippjfr Apr 15, 2024
e84cd34
Position popup relative to selection
philippjfr Apr 15, 2024
749a2dc
Clean up event dispatch in stream callbacks
philippjfr Apr 16, 2024
6122421
Use last point as index
ahuang11 Apr 16, 2024
bb90350
Fix logic and lasso select
ahuang11 Apr 16, 2024
b175723
Cleanup
ahuang11 Apr 16, 2024
9d868d2
Ensure that callback processes final event
philippjfr Apr 17, 2024
c142ab9
Add tests
ahuang11 Apr 17, 2024
26993fe
fix test
ahuang11 Apr 17, 2024
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
163 changes: 162 additions & 1 deletion examples/user_guide/13-Custom_Interactivity.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"import holoviews as hv\n",
"from holoviews import opts\n",
"\n",
"hv.extension('bokeh', 'matplotlib')"
"hv.extension('bokeh')"
]
},
{
Expand Down Expand Up @@ -410,6 +410,167 @@
"source": [
"taps"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Pop-up panes\n",
"\n",
"Sometimes, you might want to display additional info, next to the selection, as a floating pane.\n",
"\n",
"To do this, specify `popup`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"points = hv.Points(np.random.randn(1000, 2))\n",
"\n",
"hv.streams.BoundsXY(source=points, popup=\"Used Box Select\")\n",
"hv.streams.Lasso(source=points, popup=\"Used Lasso Select\")\n",
"hv.streams.Tap(source=points, popup=\"Used Tap\")\n",
"\n",
"points.opts(\n",
" tools=[\"box_select\", \"lasso_select\", \"tap\"],\n",
" active_tools=[\"lasso_select\"],\n",
" size=6,\n",
" color=\"black\",\n",
" fill_color=None,\n",
" width=500,\n",
" height=500\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"An applicable example is using the `popup` to show stats of the selected points."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def popup_stats(index):\n",
" if not index:\n",
" return\n",
" return points.iloc[index].dframe().describe()\n",
"\n",
"\n",
"points = hv.Points(np.random.randn(1000, 2))\n",
"\n",
"hv.streams.Selection1D(\n",
" source=points,\n",
" popup=popup_stats\n",
"\n",
")\n",
"\n",
"points.opts(\n",
" tools=[\"box_select\", \"lasso_select\", \"tap\"],\n",
" active_tools=[\"lasso_select\"],\n",
" size=6,\n",
" color=\"black\",\n",
" fill_color=None,\n",
" width=500,\n",
" height=500\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The contents of the `popup` can be another HoloViews object too, like the distribution of the selected points."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def popup_distribution(index):\n",
" x, y = points.iloc[index].data.T\n",
" return hv.Distribution((x, y)).opts(\n",
" width=100,\n",
" height=100,\n",
" toolbar=None,\n",
" yaxis=\"bare\",\n",
" xlabel=\"\",\n",
" xticks=[-1, 0, 1],\n",
" xlim=(-2, 2),\n",
" )\n",
"\n",
"\n",
"points = hv.Points(np.random.randn(1000, 2))\n",
"\n",
"hv.streams.Selection1D(\n",
" source=points,\n",
" popup=popup_distribution,\n",
")\n",
"\n",
"points.opts(\n",
" tools=[\"box_select\", \"lasso_select\", \"tap\"],\n",
" active_tools=[\"lasso_select\"],\n",
" size=6,\n",
" color=\"black\",\n",
" fill_color=None,\n",
" width=500,\n",
" height=500\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"It can also be a object or any component that can be rendered with Panel, which is an open-source Python library built on top of Bokeh, with a variety of easy-to-use [widgets and panes](https://panel.holoviz.org/reference/index.html#), such as [`Image`](https://panel.holoviz.org/reference/panes/Image.html), [`Button`](https://panel.holoviz.org/reference/widgets/Button.html), [`TextInput`](https://panel.holoviz.org/reference/widgets/TextInput.html), and much more!\n",
"\n",
"To control the visibility of the `popup`, update `visible` parameter of the provided component."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import panel as pn\n",
"pn.extension()\n",
"\n",
"def popup_form(index):\n",
" def hide_popup(_):\n",
" layout.visible = False\n",
"\n",
" if not index:\n",
" return\n",
" df = points.iloc[index].dframe().describe()\n",
" button = pn.widgets.Button(name=\"Close\", sizing_mode=\"stretch_width\")\n",
" layout = pn.Column(button, df)\n",
" button.on_click(hide_popup)\n",
" return layout\n",
"\n",
"\n",
"points = hv.Points(np.random.randn(1000, 2))\n",
"hv.streams.Selection1D(source=points, popup=popup_form)\n",
"\n",
"points.opts(\n",
" tools=[\"box_select\", \"lasso_select\", \"tap\"],\n",
" active_tools=[\"lasso_select\"],\n",
" size=6,\n",
" color=\"black\",\n",
" fill_color=None,\n",
" width=500,\n",
" height=500\n",
")"
]
}
],
"metadata": {
Expand Down
Loading
Loading