Skip to content

Commit

Permalink
Add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ahuang11 committed Apr 5, 2024
1 parent 527261a commit 9f11478
Showing 1 changed file with 122 additions and 0 deletions.
122 changes: 122 additions & 0 deletions examples/user_guide/13-Custom_Interactivity.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,128 @@
"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": [
"def popup_panel(name):\n",
" return f\"You used {name}!\"\n",
"\n",
"points = hv.Points(np.random.randn(1000, 2))\n",
"\n",
"hv.streams.BoundsXY(source=points, popup=popup_panel(\"Box Select\"))\n",
"hv.streams.Lasso(source=points, popup=popup_panel(\"Lasso Select\"))\n",
"hv.streams.Tap(source=points, popup=popup_panel(\"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 any Panel object or any component that can be rendered with Panel.\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",
"\n",
"pn.extension()\n",
"\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

0 comments on commit 9f11478

Please sign in to comment.