Skip to content

Commit 3a1dc29

Browse files
authored
Merge pull request fastplotlib#111 from kushalkolar/fix-empty-collection
allow features to work if the CollectionIndexer is empty
2 parents 83bcf1a + c4e7623 commit 3a1dc29

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

fastplotlib/graphics/_base.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -318,11 +318,14 @@ def __init__(
318318
selection
319319
selection_indices: Union[list, range]
320320
"""
321+
self._parent = parent
321322
self._selection = selection
322323
self._selection_indices = selection_indices
323324

324-
for attr_name in self._selection[0].__dict__.keys():
325-
attr = getattr(self._selection[0], attr_name)
325+
# we use parent.graphics[0] instead of selection[0]
326+
# because the selection can be empty
327+
for attr_name in self._parent.graphics[0].__dict__.keys():
328+
attr = getattr(self._parent.graphics[0], attr_name)
326329
if isinstance(attr, GraphicFeature):
327330
collection_feature = CollectionFeature(
328331
parent,
@@ -368,13 +371,16 @@ def __init__(
368371

369372
self._feature_instances: List[GraphicFeature] = list()
370373

371-
for graphic in self._selection:
372-
fi = getattr(graphic, self._feature)
373-
self._feature_instances.append(fi)
374+
if len(self._selection) > 0:
375+
for graphic in self._selection:
376+
fi = getattr(graphic, self._feature)
377+
self._feature_instances.append(fi)
374378

375-
if isinstance(fi, GraphicFeatureIndexable):
376-
self._indexable = True
377-
else:
379+
if isinstance(fi, GraphicFeatureIndexable):
380+
self._indexable = True
381+
else:
382+
self._indexable = False
383+
else: # it's an empty selection so it doesn't really matter
378384
self._indexable = False
379385

380386
def _set(self, value):

0 commit comments

Comments
 (0)