From 9f114787a2720b0183592762c37e7062f27f9a2d Mon Sep 17 00:00:00 2001 From: Andrew Huang Date: Fri, 5 Apr 2024 15:32:32 -0700 Subject: [PATCH] Add docs --- .../user_guide/13-Custom_Interactivity.ipynb | 122 ++++++++++++++++++ 1 file changed, 122 insertions(+) diff --git a/examples/user_guide/13-Custom_Interactivity.ipynb b/examples/user_guide/13-Custom_Interactivity.ipynb index 371d3f5749..761bf2c674 100644 --- a/examples/user_guide/13-Custom_Interactivity.ipynb +++ b/examples/user_guide/13-Custom_Interactivity.ipynb @@ -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": {