1919from pyqtgraph .widgets .ColorButton import ColorButton
2020from qtpy .QtCore import QSize , Qt , Signal
2121from qtpy .QtGui import QColor , QIcon
22- from qtpy .QtWidgets import QPushButton
22+ from qtpy .QtWidgets import QLabel , QPushButton , QSpinBox
2323from scipy .spatial import cKDTree
2424from shapely .geometry import Point , Polygon
2525from spatialdata ._types import ArrayLike
2626
27+ import napari_spatialdata .constants .config
2728from napari_spatialdata ._model import DataModel
2829from napari_spatialdata ._widgets import AListWidget , ComponentWidget
29- from napari_spatialdata .constants .config import POINT_SIZE_SCATTERPLOT_WIDGET
3030
3131__all__ = [
3232 "PlotWidget" ,
@@ -334,6 +334,7 @@ def __init__(self, viewer: Viewer | None, model: DataModel) -> None:
334334 self .lut : pg .HistogramLUTItem | None = None
335335 self .discrete_color_widget : DiscreteColorWidget | None = None
336336 self .wrapped_widget : QtWidgets .QGraphicsProxyWidget | None = None
337+ self ._point_size : int = napari_spatialdata .constants .config .POINT_SIZE_SCATTERPLOT_WIDGET
337338
338339 self .scatter_plot = self .addPlot (title = "" )
339340 self .scatter_plot .setLabel ("bottom" , self .x_label )
@@ -344,7 +345,10 @@ def __init__(self, viewer: Viewer | None, model: DataModel) -> None:
344345
345346 # Create a separate ScatterPlotItem for the highlighted point
346347 self .hovered_point = pg .ScatterPlotItem (
347- pen = pg .mkPen ("r" , width = 2 ), symbol = "o" , size = POINT_SIZE_SCATTERPLOT_WIDGET , brush = pg .mkBrush (255 , 0 , 0 )
348+ pen = pg .mkPen ("r" , width = 2 ),
349+ symbol = "o" ,
350+ size = self ._point_size + 2 ,
351+ brush = pg .mkBrush (255 , 0 , 0 ),
348352 )
349353 self .scatter_plot .addItem (self .hovered_point )
350354
@@ -417,6 +421,19 @@ def __init__(self, viewer: Viewer | None, model: DataModel) -> None:
417421 self .rectangle_mode_button .setToolTip ("Add rectangular ROIs." )
418422 self .rectangle_mode_button .move (50 , 10 ) # Adjust position as needed
419423
424+ # Point size control
425+ self .point_size_label = QLabel ("Size:" , self )
426+ self .point_size_label .setStyleSheet (f"QLabel {{ color: rgb{ self .color } ; background-color: transparent; }}" )
427+ self .point_size_label .move (130 , 14 )
428+
429+ self .point_size_spinbox = QSpinBox (self )
430+ self .point_size_spinbox .setRange (1 , 50 )
431+ self .point_size_spinbox .setValue (self ._point_size )
432+ self .point_size_spinbox .setFixedWidth (50 )
433+ self .point_size_spinbox .setToolTip ("Adjust point size in scatter plot" )
434+ self .point_size_spinbox .valueChanged .connect (self ._on_point_size_changed )
435+ self .point_size_spinbox .move (165 , 10 )
436+
420437 # Connect mouse events
421438 self .scatter_plot .setMouseEnabled (x = True , y = True )
422439 self .scatter_plot .scene ().sigMouseMoved .connect (self .mouseMoveEvent )
@@ -461,6 +478,25 @@ def update_proximity_sensitivity(self) -> None:
461478 logger .debug ("Updating proximity sensitivity..." )
462479 self .dist_threshold = [x * 15 for x in self .scatter .pixelSize ()] # Adjust this factor as needed
463480
481+ @property
482+ def point_size (self ) -> int :
483+ """Get the current point size for the scatter plot."""
484+ return self ._point_size
485+
486+ @point_size .setter
487+ def point_size (self , value : int ) -> None :
488+ """Set the point size for the scatter plot."""
489+ self ._point_size = value
490+ self .point_size_spinbox .setValue (value )
491+
492+ def _on_point_size_changed (self , value : int ) -> None :
493+ """Handle point size spinbox value change."""
494+ self ._point_size = value
495+ # Update hovered point indicator size to be slightly larger
496+ self .hovered_point .setSize (value + 2 )
497+ if self .scatter is not None :
498+ self .plot ()
499+
464500 def update_hover_highlight (self , x : float , y : float ) -> None :
465501 """Update the hover highlight based on the cursor position."""
466502 if self .kd_tree is not None and self .x_data is not None and self .y_data is not None :
@@ -759,6 +795,7 @@ def plot(self, event: Any = None) -> None:
759795 pen = None ,
760796 symbolPen = self .symbolPen ,
761797 symbol = "o" ,
798+ symbolSize = self ._point_size ,
762799 clear = True ,
763800 symbolBrush = self .brushes ,
764801 )
@@ -773,6 +810,7 @@ def plot(self, event: Any = None) -> None:
773810 fillLevel = 0 ,
774811 pen = None ,
775812 symbolPen = self .symbolPen ,
813+ symbolSize = self ._point_size ,
776814 symbolBrush = self .brushes ,
777815 clear = True ,
778816 )
@@ -785,6 +823,7 @@ def plot(self, event: Any = None) -> None:
785823 fillLevel = 0 ,
786824 pen = None ,
787825 symbolPen = self .symbolPen ,
826+ symbolSize = self ._point_size ,
788827 symbolBrush = self .brushes ,
789828 clear = True ,
790829 )
0 commit comments