@@ -18,7 +18,7 @@ def parent(self) -> Graphic | None:
1818 return self ._parent
1919
2020 @property
21- def selection (self ) -> Sequence [float ] | List [ Sequence [ float ] ]:
21+ def selection (self ) -> np . ndarray [float ]:
2222 """
2323 (xmin, xmax, ymin, ymax) of the rectangle selection
2424 """
@@ -319,10 +319,11 @@ def get_selected_data(
319319 # do not need to check for mode for images, because the selector is bounded by the image shape
320320 # will always be `full`
321321 if "Image" in source .__class__ .__name__ :
322- col_ixs = slice (ixs [0 ][0 ], ixs [0 ][- 1 ] + 1 )
323- row_ixs = slice (ixs [1 ][0 ], ixs [1 ][- 1 ] + 1 )
322+ row_ixs , col_ixs = ixs
323+ row_slice = slice (row_ixs [0 ], row_ixs [- 1 ] + 1 )
324+ col_slice = slice (col_ixs [0 ], col_ixs [- 1 ] + 1 )
324325
325- return source .data [row_ixs , col_ixs ]
326+ return source .data [row_slice , col_slice ]
326327
327328 if mode not in ["full" , "partial" , "ignore" ]:
328329 raise ValueError (
@@ -414,7 +415,7 @@ def get_selected_data(
414415
415416 def get_selected_indices (
416417 self , graphic : Graphic = None
417- ) -> Union [ np .ndarray , List [np .ndarray ] ]:
418+ ) -> np .ndarray | tuple [np .ndarray ]:
418419 """
419420 Returns the indices of the ``Graphic`` data bounded by the current selection.
420421
@@ -429,43 +430,43 @@ def get_selected_indices(
429430 -------
430431 Union[np.ndarray, List[np.ndarray]]
431432 data indicies of the selection
432- | list of [x_indices_array , y_indices_array] if the graphic is an image
433+ | tuple of [row_indices , y_indices_array] if the graphic is an image
433434 | list of indices along the x-dimension for each line if graphic is a line collection
434435 | array of indices along the x-dimension if graphic is a line
435436 """
436437 # get indices from source
437438 source = self ._get_source (graphic )
438439
439440 # selector (xmin, xmax, ymin, ymax) values
440- bounds = self .selection
441+ xmin , xmax , ymin , ymax = self .selection
441442
442443 # image data does not need to check for mode because the selector is always bounded
443444 # to the image
444445 if "Image" in source .__class__ .__name__ :
445- xs = np .arange (bounds [ 0 ], bounds [ 1 ] , dtype = int )
446- ys = np .arange (bounds [ 2 ], bounds [ 3 ] , dtype = int )
447- return [ xs , ys ]
446+ col_ixs = np .arange (xmin , xmax , dtype = int )
447+ row_ixs = np .arange (ymin , ymax , dtype = int )
448+ return row_ixs , col_ixs
448449
449450 if "Line" in source .__class__ .__name__ :
450451 if isinstance (source , GraphicCollection ):
451452 ixs = list ()
452453 for g in source .graphics :
453454 data = g .data .value
454455 g_ixs = np .where (
455- (data [:, 0 ] >= bounds [ 0 ] - g .offset [0 ])
456- & (data [:, 0 ] <= bounds [ 1 ] - g .offset [0 ])
457- & (data [:, 1 ] >= bounds [ 2 ] - g .offset [1 ])
458- & (data [:, 1 ] <= bounds [ 3 ] - g .offset [1 ])
456+ (data [:, 0 ] >= xmin - g .offset [0 ])
457+ & (data [:, 0 ] <= xmax - g .offset [0 ])
458+ & (data [:, 1 ] >= ymin - g .offset [1 ])
459+ & (data [:, 1 ] <= ymax - g .offset [1 ])
459460 )[0 ]
460461 ixs .append (g_ixs )
461462 else :
462463 # map only this graphic
463464 data = source .data .value
464465 ixs = np .where (
465- (data [:, 0 ] >= bounds [ 0 ] )
466- & (data [:, 0 ] <= bounds [ 1 ] )
467- & (data [:, 1 ] >= bounds [ 2 ] )
468- & (data [:, 1 ] <= bounds [ 3 ] )
466+ (data [:, 0 ] >= xmin )
467+ & (data [:, 0 ] <= xmax )
468+ & (data [:, 1 ] >= ymin )
469+ & (data [:, 1 ] <= ymax )
469470 )[0 ]
470471
471472 return ixs
0 commit comments