mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-14 03:31:50 +02:00
feat!: ability to disable scatter from waveform & compatible crosshair with down sampling
This commit is contained in:
@ -552,6 +552,7 @@ class BECFigure(RPCBase):
|
|||||||
def image(
|
def image(
|
||||||
self,
|
self,
|
||||||
monitor: "str" = None,
|
monitor: "str" = None,
|
||||||
|
monitor_type: "Literal['1d', '2d']" = "2d",
|
||||||
color_bar: "Literal['simple', 'full']" = "full",
|
color_bar: "Literal['simple', 'full']" = "full",
|
||||||
color_map: "str" = "magma",
|
color_map: "str" = "magma",
|
||||||
data: "np.ndarray" = None,
|
data: "np.ndarray" = None,
|
||||||
@ -856,6 +857,7 @@ class BECImageShow(RPCBase):
|
|||||||
def image(
|
def image(
|
||||||
self,
|
self,
|
||||||
monitor: "str",
|
monitor: "str",
|
||||||
|
monitor_type: "Literal['1d', '2d']" = "2d",
|
||||||
color_map: "Optional[str]" = "magma",
|
color_map: "Optional[str]" = "magma",
|
||||||
color_bar: "Optional[Literal['simple', 'full']]" = "full",
|
color_bar: "Optional[Literal['simple', 'full']]" = "full",
|
||||||
downsample: "Optional[bool]" = True,
|
downsample: "Optional[bool]" = True,
|
||||||
@ -868,6 +870,7 @@ class BECImageShow(RPCBase):
|
|||||||
|
|
||||||
Args:
|
Args:
|
||||||
monitor(str): The name of the monitor to display.
|
monitor(str): The name of the monitor to display.
|
||||||
|
monitor_type(Literal["1d","2d"]): The type of monitor to display.
|
||||||
color_bar(Literal["simple","full"]): The type of color bar to display.
|
color_bar(Literal["simple","full"]): The type of color bar to display.
|
||||||
color_map(str): The color map to use for the image.
|
color_map(str): The color map to use for the image.
|
||||||
data(np.ndarray): Custom data to display.
|
data(np.ndarray): Custom data to display.
|
||||||
@ -1180,6 +1183,7 @@ class BECImageWidget(RPCBase):
|
|||||||
def image(
|
def image(
|
||||||
self,
|
self,
|
||||||
monitor: "str",
|
monitor: "str",
|
||||||
|
monitor_type: "Optional[Literal['1d', '2d']]" = "2d",
|
||||||
color_map: "Optional[str]" = "magma",
|
color_map: "Optional[str]" = "magma",
|
||||||
color_bar: "Optional[Literal['simple', 'full']]" = "full",
|
color_bar: "Optional[Literal['simple', 'full']]" = "full",
|
||||||
downsample: "Optional[bool]" = True,
|
downsample: "Optional[bool]" = True,
|
||||||
@ -2096,6 +2100,15 @@ class BECWaveform(RPCBase):
|
|||||||
colormap(str, optional): Scale the colors of curves to colormap. If None, use the default color palette.
|
colormap(str, optional): Scale the colors of curves to colormap. If None, use the default color palette.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@rpc_call
|
||||||
|
def enable_scatter(self, enable: "bool"):
|
||||||
|
"""
|
||||||
|
Enable/Disable scatter plot on all curves.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
enable(bool): If True, enable scatter markers; if False, disable them.
|
||||||
|
"""
|
||||||
|
|
||||||
@rpc_call
|
@rpc_call
|
||||||
def enable_fps_monitor(self, enable: "bool" = True):
|
def enable_fps_monitor(self, enable: "bool" = True):
|
||||||
"""
|
"""
|
||||||
@ -2419,6 +2432,15 @@ class BECWaveformWidget(RPCBase):
|
|||||||
enabled(bool): If True, enable the FPS monitor.
|
enabled(bool): If True, enable the FPS monitor.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@rpc_call
|
||||||
|
def enable_scatter(self, enabled: "bool"):
|
||||||
|
"""
|
||||||
|
Enable the scatter plot of the plot widget.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
enabled(bool): If True, enable the scatter plot.
|
||||||
|
"""
|
||||||
|
|
||||||
@rpc_call
|
@rpc_call
|
||||||
def lock_aspect_ratio(self, lock: "bool"):
|
def lock_aspect_ratio(self, lock: "bool"):
|
||||||
"""
|
"""
|
||||||
|
@ -8,6 +8,14 @@ from qtpy.QtCore import QObject, Qt
|
|||||||
from qtpy.QtCore import Signal as pyqtSignal
|
from qtpy.QtCore import Signal as pyqtSignal
|
||||||
|
|
||||||
|
|
||||||
|
class NonDownsamplingScatterPlotItem(pg.ScatterPlotItem):
|
||||||
|
def setDownsampling(self, ds=None, auto=None, method=None):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def setClipToView(self, state):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Crosshair(QObject):
|
class Crosshair(QObject):
|
||||||
positionChanged = pyqtSignal(tuple)
|
positionChanged = pyqtSignal(tuple)
|
||||||
positionClicked = pyqtSignal(tuple)
|
positionClicked = pyqtSignal(tuple)
|
||||||
@ -64,7 +72,7 @@ class Crosshair(QObject):
|
|||||||
continue
|
continue
|
||||||
pen = item.opts["pen"]
|
pen = item.opts["pen"]
|
||||||
color = pen.color() if hasattr(pen, "color") else pg.mkColor(pen)
|
color = pen.color() if hasattr(pen, "color") else pg.mkColor(pen)
|
||||||
marker_moved = pg.ScatterPlotItem(
|
marker_moved = NonDownsamplingScatterPlotItem(
|
||||||
size=10, pen=pg.mkPen(color), brush=pg.mkBrush(None)
|
size=10, pen=pg.mkPen(color), brush=pg.mkBrush(None)
|
||||||
)
|
)
|
||||||
marker_moved.skip_auto_range = True
|
marker_moved.skip_auto_range = True
|
||||||
@ -73,7 +81,7 @@ class Crosshair(QObject):
|
|||||||
|
|
||||||
# Create glowing effect markers for clicked events
|
# Create glowing effect markers for clicked events
|
||||||
for size, alpha in [(18, 64), (14, 128), (10, 255)]:
|
for size, alpha in [(18, 64), (14, 128), (10, 255)]:
|
||||||
marker_clicked = pg.ScatterPlotItem(
|
marker_clicked = NonDownsamplingScatterPlotItem(
|
||||||
size=size,
|
size=size,
|
||||||
pen=pg.mkPen(None),
|
pen=pg.mkPen(None),
|
||||||
brush=pg.mkBrush(color.red(), color.green(), color.blue(), alpha),
|
brush=pg.mkBrush(color.red(), color.green(), color.blue(), alpha),
|
||||||
|
@ -72,6 +72,7 @@ class BECWaveform(BECPlotBase):
|
|||||||
"set_y_lim",
|
"set_y_lim",
|
||||||
"set_grid",
|
"set_grid",
|
||||||
"set_colormap",
|
"set_colormap",
|
||||||
|
"enable_scatter",
|
||||||
"enable_fps_monitor",
|
"enable_fps_monitor",
|
||||||
"lock_aspect_ratio",
|
"lock_aspect_ratio",
|
||||||
"export",
|
"export",
|
||||||
@ -371,6 +372,20 @@ class BECWaveform(BECPlotBase):
|
|||||||
else:
|
else:
|
||||||
raise ValueError("Identifier must be either an integer (index) or a string (curve_id).")
|
raise ValueError("Identifier must be either an integer (index) or a string (curve_id).")
|
||||||
|
|
||||||
|
def enable_scatter(self, enable: bool):
|
||||||
|
"""
|
||||||
|
Enable/Disable scatter plot on all curves.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
enable(bool): If True, enable scatter markers; if False, disable them.
|
||||||
|
"""
|
||||||
|
for curve in self.curves:
|
||||||
|
if isinstance(curve, BECCurve):
|
||||||
|
if enable:
|
||||||
|
curve.set_symbol("o") # You can choose any symbol you like
|
||||||
|
else:
|
||||||
|
curve.set_symbol(None)
|
||||||
|
|
||||||
def plot(
|
def plot(
|
||||||
self,
|
self,
|
||||||
arg1: list | np.ndarray | str | None = None,
|
arg1: list | np.ndarray | str | None = None,
|
||||||
|
@ -42,7 +42,7 @@ class CurveConfig(ConnectionConfig):
|
|||||||
parent_id: Optional[str] = Field(None, description="The parent plot of the curve.")
|
parent_id: Optional[str] = Field(None, description="The parent plot of the curve.")
|
||||||
label: Optional[str] = Field(None, description="The label of the curve.")
|
label: Optional[str] = Field(None, description="The label of the curve.")
|
||||||
color: Optional[str | tuple] = Field(None, description="The color of the curve.")
|
color: Optional[str | tuple] = Field(None, description="The color of the curve.")
|
||||||
symbol: Optional[str] = Field("o", description="The symbol of the curve.")
|
symbol: Optional[str | None] = Field("o", description="The symbol of the curve.")
|
||||||
symbol_color: Optional[str | tuple] = Field(
|
symbol_color: Optional[str | tuple] = Field(
|
||||||
None, description="The color of the symbol of the curve."
|
None, description="The color of the symbol of the curve."
|
||||||
)
|
)
|
||||||
@ -201,7 +201,8 @@ class BECCurve(BECConnector, pg.PlotDataItem):
|
|||||||
symbol(str): Symbol of the curve.
|
symbol(str): Symbol of the curve.
|
||||||
"""
|
"""
|
||||||
self.config.symbol = symbol
|
self.config.symbol = symbol
|
||||||
self.apply_config()
|
self.setSymbol(symbol)
|
||||||
|
self.updateItems()
|
||||||
|
|
||||||
def set_symbol_color(self, symbol_color: str):
|
def set_symbol_color(self, symbol_color: str):
|
||||||
"""
|
"""
|
||||||
|
@ -53,6 +53,7 @@ class BECWaveformWidget(BECWidget, QWidget):
|
|||||||
"set_auto_range",
|
"set_auto_range",
|
||||||
"set_grid",
|
"set_grid",
|
||||||
"enable_fps_monitor",
|
"enable_fps_monitor",
|
||||||
|
"enable_scatter",
|
||||||
"lock_aspect_ratio",
|
"lock_aspect_ratio",
|
||||||
"export",
|
"export",
|
||||||
"export_to_matplotlib",
|
"export_to_matplotlib",
|
||||||
@ -650,6 +651,15 @@ class BECWaveformWidget(BECWidget, QWidget):
|
|||||||
"""
|
"""
|
||||||
self.waveform.set_outer_axes(show)
|
self.waveform.set_outer_axes(show)
|
||||||
|
|
||||||
|
def enable_scatter(self, enabled: bool):
|
||||||
|
"""
|
||||||
|
Enable the scatter plot of the plot widget.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
enabled(bool): If True, enable the scatter plot.
|
||||||
|
"""
|
||||||
|
self.waveform.enable_scatter(enabled)
|
||||||
|
|
||||||
def lock_aspect_ratio(self, lock: bool):
|
def lock_aspect_ratio(self, lock: bool):
|
||||||
"""
|
"""
|
||||||
Lock the aspect ratio of the plot widget.
|
Lock the aspect ratio of the plot widget.
|
||||||
|
Reference in New Issue
Block a user