{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## LayerTargetLocatorTwoOverlappedRectsTest — nearestX case\n", "\n", "Two rects share the same X range. FIRST_RECT is short (height=40), SECOND_RECT is tall (height=300).\n", "\n", "When cursor is at y=50 (above FIRST_RECT but inside SECOND_RECT), X-range lookup matches **both** rects.\n", "Expected: tooltips for both. Bug: only SECOND_RECT tooltip appears." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from lets_plot import *\n", "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import pandas as pd\n", "\n", "df = pd.DataFrame({\n", " 'xmin': [0, 0],\n", " 'xmax': [20, 20],\n", " 'ymin': [0, 0],\n", " 'ymax': [40, 300],\n", " 'label': ['first (short)', 'second (tall)']\n", "})\n", "\n", "# Hover at y≈50 (above the short rect, inside the tall rect).\n", "# Both rects are within x-range [0,20], so nearestX lookup should match both.\n", "# Bug: APPEND_IF_EQUAL drops first rect because its nearest corner (distance≈14)\n", "# loses to second rect (distance=0, cursor is inside it).\n", "(\n", " ggplot(df)\n", " + geom_rect(\n", " aes(xmin='xmin', xmax='xmax', ymin='ymin', ymax='ymax', fill='label'),\n", " alpha=0.4,\n", " tooltips=layer_tooltips().line('@label')\n", " )\n", " + scale_x_continuous(limits=[-5, 60])\n", " + ggtitle('nearestX: hover above short rect — both tooltips expected')\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.11" } }, "nbformat": 4, "nbformat_minor": 4 }