Skip to content

Commit f2d1d6a

Browse files
committed
feat: Refactor map filtering logic in DataUI; remove obsolete parameters and improve selection handling
1 parent fc09cf8 commit f2d1d6a

3 files changed

Lines changed: 12 additions & 24 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,5 @@ src/dvue/_version.py
6767
dvue/_version.py
6868
.vscode/settings.json
6969
junit.xml
70-
cache.db
70+
cache.db
71+
.cache-ds/

dvue/actions.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,14 @@ def callback(self, event, dataui):
8787
# contains the columns in display_table.value, which is limited to
8888
# get_table_columns() — it omits hidden catalog metadata columns.
8989
#
90-
# current_view.iloc[selection] correctly resolves filter-relative
91-
# row indices (fixing the earlier bug where _dfcat.iloc[selection]
92-
# used unfiltered indices against a filtered selection). We then
93-
# use .loc[...index...] on _dfcat to retrieve the full rows.
90+
# display_table.selection contains positional indices into
91+
# display_table.value (Panel maps Bokeh ColumnDataSource row numbers
92+
# back to value positions via _map_indexes). Using current_view.iloc
93+
# is wrong when header filters are active because current_view is a
94+
# subset of value with different positional indices.
95+
# display_table.value.iloc[selection] is always correct.
9496
_selection = dataui.display_table.selection
95-
_current_view = dataui.display_table.current_view
96-
_sel_index = _current_view.iloc[_selection].index
97+
_sel_index = dataui.display_table.value.iloc[_selection].index
9798
dfselected = dataui._dfcat.loc[_sel_index].copy()
9899
manager = dataui._dataui_manager
99100
total = len(dfselected)

dvue/dataui.py

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -646,11 +646,6 @@ class DataUI(param.Parameterized):
646646
map_default_span = param.Number(default=15000, doc="Default span for map zoom in meters")
647647
map_non_selection_alpha = param.Number(default=0.2, doc="Non selection alpha")
648648
map_point_size = param.Number(default=10, doc="Point size for map")
649-
map_filters_table = param.Boolean(
650-
default=True,
651-
doc="When enabled, map selections filter the table rows instead of highlighting them. Table selections do not affect the map.",
652-
)
653-
_table_selection_for_map = param.List(default=[], precedence=-1)
654649

655650
query = param.String(
656651
default="",
@@ -910,11 +905,10 @@ def update_map_features(
910905
"""Update the map features based on the selection in the table or filters or query. Also updates if the color or marker by columns are changed"""
911906
query = query.strip()
912907
dfs = self._get_map_catalog()
913-
if map_filters_table:
908+
if self.map_filters_table:
914909
# In filter mode the map is decoupled from the table: always show the
915910
# full map catalog (not restricted to display_table.current_view) and
916-
# never highlight features based on table selection. _table_selection_for_map
917-
# is never updated while this mode is active, so selection is always [].
911+
# never highlight features based on table selection while this mode is active.
918912
current_view = dfs
919913
if isinstance(current_view, gpd.GeoDataFrame):
920914
current_view = current_view.loc[current_view.is_valid]
@@ -1032,18 +1026,13 @@ def _clear_map_filter(self):
10321026
tbl_df = self._get_table_df_for_display(self._dfcat)
10331027
self.display_table.param.update(value=tbl_df, selection=[])
10341028

1035-
def _on_table_selection_changed(self, event):
1036-
"""Gate table-selection → map sync: only propagate when filter mode is off."""
1037-
if not self.map_filters_table:
1038-
self._table_selection_for_map = list(event.new)
1039-
10401029
def _on_map_filter_mode_changed(self, event):
10411030
"""Restore normal table and re-sync map selection when filter mode is toggled off."""
10421031
if not event.new:
10431032
self._clear_map_filter()
10441033
# Re-sync proxy param with current table selection so map highlights
10451034
# immediately reflect any rows selected while filter mode was active.
1046-
self._table_selection_for_map = list(self.display_table.selection)
1035+
self._map_sel_proxy = list(self.display_table.selection)
10471036

10481037
def _apply_map_filter(self, index):
10491038
"""Apply a filter to the table based on the *index* of selected map features.
@@ -1949,7 +1938,6 @@ def _on_column_picker_change(event):
19491938
self.param.map_point_size,
19501939
self.param.query,
19511940
self.param.map_filters_table,
1952-
self.param.map_filters_table,
19531941
]
19541942
if _extra_map_widgets is not None:
19551943
_map_option_items.append(_extra_map_widgets)
@@ -2009,7 +1997,6 @@ def _map_callback(
20091997
map_default_span=map_default_span,
20101998
map_non_selection_alpha=map_non_selection_alpha,
20111999
map_point_size=map_point_size,
2012-
map_filters_table=map_filters_table,
20132000
)
20142001

20152002
self._map_function = hv.DynamicMap(_map_callback, streams=[_self_stream])
@@ -2280,7 +2267,6 @@ def _map_callback(
22802267
map_default_span=map_default_span,
22812268
map_non_selection_alpha=map_non_selection_alpha,
22822269
map_point_size=map_point_size,
2283-
map_filters_table=map_filters_table,
22842270
)
22852271

22862272
self._map_function = hv.DynamicMap(

0 commit comments

Comments
 (0)