diff --git a/js/src/IndexSelector.ts b/js/src/IndexSelector.ts index 4136a5e25..5336deccc 100644 --- a/js/src/IndexSelector.ts +++ b/js/src/IndexSelector.ts @@ -81,7 +81,7 @@ export class IndexSelector extends BaseXSelector { } mousemove() { - if (!this.active) { + if (!this.active || this.dirty) { return; } this.dirty = true; @@ -143,7 +143,10 @@ export class IndexSelector extends BaseXSelector { } else { const pixel = this.scale.scale(selected[0]); if (this.line !== undefined && this.line !== null) { - this.line.attr('x1', 0).attr('x2', 0).attr('visibility', 'visible'); + this.line + .attr('x1', pixel) + .attr('x2', pixel) + .attr('visibility', 'visible'); } //the selected may be called before the index selector is //active for the first time. diff --git a/ui-tests/tests/bqplot.test.ts-snapshots/dark-index-selector-update-ipynb-cell-0-linux.png b/ui-tests/tests/bqplot.test.ts-snapshots/dark-index-selector-update-ipynb-cell-0-linux.png new file mode 100644 index 000000000..b09dc59bb Binary files /dev/null and b/ui-tests/tests/bqplot.test.ts-snapshots/dark-index-selector-update-ipynb-cell-0-linux.png differ diff --git a/ui-tests/tests/bqplot.test.ts-snapshots/dark-index-selector-update-ipynb-cell-1-linux.png b/ui-tests/tests/bqplot.test.ts-snapshots/dark-index-selector-update-ipynb-cell-1-linux.png new file mode 100644 index 000000000..e8f2058c2 Binary files /dev/null and b/ui-tests/tests/bqplot.test.ts-snapshots/dark-index-selector-update-ipynb-cell-1-linux.png differ diff --git a/ui-tests/tests/bqplot.test.ts-snapshots/light-index-selector-update-ipynb-cell-0-linux.png b/ui-tests/tests/bqplot.test.ts-snapshots/light-index-selector-update-ipynb-cell-0-linux.png new file mode 100644 index 000000000..604d89ebf Binary files /dev/null and b/ui-tests/tests/bqplot.test.ts-snapshots/light-index-selector-update-ipynb-cell-0-linux.png differ diff --git a/ui-tests/tests/bqplot.test.ts-snapshots/light-index-selector-update-ipynb-cell-1-linux.png b/ui-tests/tests/bqplot.test.ts-snapshots/light-index-selector-update-ipynb-cell-1-linux.png new file mode 100644 index 000000000..707380839 Binary files /dev/null and b/ui-tests/tests/bqplot.test.ts-snapshots/light-index-selector-update-ipynb-cell-1-linux.png differ diff --git a/ui-tests/tests/notebooks/index_selector_update.ipynb b/ui-tests/tests/notebooks/index_selector_update.ipynb new file mode 100644 index 000000000..007efd743 --- /dev/null +++ b/ui-tests/tests/notebooks/index_selector_update.ipynb @@ -0,0 +1,74 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "06ac2448-da47-4939-a22a-e4b556fba103", + "metadata": {}, + "outputs": [], + "source": [ + "from bqplot import *\n", + "from bqplot.interacts import *\n", + "\n", + "# Create Scatter\n", + "sc_x = LinearScale()\n", + "sc_y = LinearScale()\n", + "\n", + "scatt = Scatter(\n", + " x=list(range(10)), \n", + " y=[20, 3, 23, 5, 6, 12, 23, 14, 20, 3],\n", + " scales={'x': sc_x, 'y': sc_y},\n", + " selected_style={\"opacity\": \"1\"},\n", + " unselected_style={\"opacity\": \"0.2\"}\n", + ")\n", + "\n", + "sel = IndexSelector(\n", + " marks=[scatt], \n", + " scale=sc_x,\n", + " selected=3\n", + ")\n", + "\n", + "ax_x = Axis(scale=sc_x)\n", + "ax_y = Axis(scale=sc_y, orientation='vertical')\n", + "\n", + "fig = Figure(\n", + " marks=[scatt], \n", + " axes=[ax_x, ax_y],\n", + " interaction=sel\n", + ")\n", + "fig" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a0600d9f-2256-4610-a14e-471c255d4924", + "metadata": {}, + "outputs": [], + "source": [ + "sel.selected = 5" + ] + } + ], + "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.10.0" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}