Repository navigation
fix: Set selected_index to the row's position in the whole table - #1283
Merged
Merged
Conversation
`selected_index` is documented as usable with `gdf.iloc[layer.selected_index]`, but two things made it wrong: - A click on the first row was ignored. `onClick` returned early on `!pickingInfo.index`, and index 0 is falsy. deck.gl uses -1, not 0, when nothing was picked. - With more than one record batch, the index was the row's position within its batch. Each batch is rendered as its own deck.gl layer, and the picking info from `@geoarrow/deck.gl-geoarrow` is relative to that layer's batch. Lonboard splits large tables into batches automatically, so users with large data got the wrong row. `onClick` now lives on `BaseArrowLayerModel`, receives the batch index of the layer that was clicked, and adds the number of rows in all earlier batches. The H3, A5, geohash and S2 models called `baseLayerProps()` without the batch index. They now pass it, which also means that extension props given as arrays (e.g. `get_filter_value`) use the values of the right batch instead of always those of the first batch. Layers that are not backed by an Arrow table (bitmap, bitmap tile, raster, surface) no longer get an `onClick` handler. They have no rows to select, and they never set `selected_index` before either: they always report index 0, which the old check discarded. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Clicking a heatmap set `selected_index` to an arbitrary number, e.g. 2490556 for a table with 3 rows. deck.gl's HeatmapLayer doesn't support picking: its shader has no picking module, so in the picking pass it draws the heatmap colors, and deck.gl decodes the color under the cursor as if it were an object index. A heatmap is also an aggregation of all rows, so there is no single row that a click could select. Turn picking off for the heatmap, as is already done for the BitmapLayer. This also means that the heatmap no longer hides pickable layers underneath it from clicks and hovers. Co-Authored-By: Claude Fable 5.1 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note
This PR was written by Claude (Claude Code), not by @kylebarron.
Problem
selected_indexis documented as the row that was clicked, usable asgdf.iloc[layer.selected_index]. Three things made it wrong:onClickreturned early on!pickingInfo.index, and index 0 is falsy. deck.gl uses-1, not0, when nothing was picked.@geoarrow/deck.gl-geoarrowis relative to that layer's batch. For a 4-row table in batches of 2, clicking the 4th row gaveselected_index == 1. Lonboard splits large tables into batches automatically, so this affects anyone with large data.HeatmapLayersetselected_indexto an arbitrary number, such as2490556for a 3-row table. deck.gl'sHeatmapLayerdoesn't support picking: it draws the heatmap's colors in the picking pass, and deck.gl decodes the color under the cursor as an index.There was no issue for these. The first two were found while testing the deck.gl 9.4 upgrade (#1272) and exist on deck.gl 9.3 too. The third was found while fixing them.
Changes
This PR has two commits, so the heatmap change can be dropped or split out.
Commit 1: the index
onClickmoves fromBaseLayerModeltoBaseArrowLayerModel. It receives the batch index of the layer that was clicked, returns whenindex < 0, and adds the number of rows in all earlier batches.baseLayerProps()without a batch index. They now pass it.Commit 2: the heatmap
HeatmapModelsetspickable: false, asBitmapModelalready does.Behavior changes to be aware of
get_filter_value) used the first batch's values for every batch. They now use each batch's own values. This is a side effect of passing the batch index.onClickhandler. They never setselected_indexbefore either: they always report index 0, which the old check discarded.pickabletrait has no effect on a heatmap.The tooltip, the side panel and
Map.on_clickare unaffected. They use the picked row object and the coordinate, not the index.Tests
tests/ui/test_picking.pygoes from 4 tests to 26. Each one clicks a feature in the browser and checks the value Python receives.test_click_sets_selected_index×4 (existing)test_click_first_row_sets_selected_index×4test_click_in_later_batch_sets_table_index×12test_click_multipolygon_in_later_batch_sets_table_indextest_click_h3_cell_sets_table_index×3test_click_on_empty_map_does_not_set_selected_indextest_click_heatmap_does_not_set_selected_indexThe ×4 and ×12 tests are parametrized over scatterplot, path, polygon and solid polygon layers.
Against
main's frontend code, 21 of the 26 fail and 5 pass. The 5 are the 4 existing tests and the empty-map click.Geohash, S2, text, column, point cloud, arc and trips layers were also clicked in a browser with the fix, on tables in two batches, and gave the right index. Those checks aren't part of the test suite.
Checks
pytest: 250 passed, 1 skipped.pnpm test: 6 passed.biome check: clean.tsc --noEmit: 7 errors, the same 7 asmain.Not verified
🤖 Written by Claude Code