Skip to content

Commit

Permalink
Merge pull request #4181 from t20100/size-for-markers2
Browse files Browse the repository at this point in the history
silx.gui.plot.items: Fixed Marker.setSymbolSize
  • Loading branch information
vallsv authored Jan 16, 2025
2 parents deaaf46 + dd24a6b commit 4101651
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/silx/gui/plot/backends/BackendBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ def addMarker(
text: str | None,
color: str,
symbol: str | None,
symbolsize: float,
linestyle: str | tuple[float, tuple[float, ...] | None],
linewidth: float,
constraint: Callable[[float, float], tuple[float, float]] | None,
Expand Down
3 changes: 2 additions & 1 deletion src/silx/gui/plot/backends/BackendMatplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,7 @@ def addMarker(
text,
color,
symbol,
symbolsize: float,
linestyle,
linewidth,
constraint,
Expand All @@ -968,7 +969,7 @@ def addMarker(
marker = self._getMarkerFromSymbol(symbol)
if x is not None and y is not None:
line = ax.plot(
x, y, linestyle=" ", color=color, marker=marker, markersize=10.0
x, y, linestyle=" ", color=color, marker=marker, markersize=symbolsize
)[-1]

if text is not None:
Expand Down
6 changes: 5 additions & 1 deletion src/silx/gui/plot/backends/BackendOpenGL.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def __init__(
text,
color,
symbol,
symbolsize,
linewidth,
dashoffset,
dashpattern,
Expand All @@ -136,6 +137,7 @@ def __init__(
"color": colors.rgba(color),
"constraint": constraint if isConstraint else None,
"symbol": symbol,
"symbolsize": symbolsize,
"linewidth": linewidth,
"dashoffset": dashoffset,
"dashpattern": dashpattern,
Expand Down Expand Up @@ -737,7 +739,7 @@ def _renderItems(self, overlay=False):
(pixelPos[1],),
marker=item["symbol"],
color=color,
size=11,
size=item["symbolsize"],
)
context.matrix = self.matScreenProj
marker.render(context)
Expand Down Expand Up @@ -1184,6 +1186,7 @@ def addMarker(
text,
color,
symbol,
symbolsize: float,
linestyle,
linewidth,
constraint,
Expand All @@ -1201,6 +1204,7 @@ def addMarker(
text,
color,
symbol,
symbolsize,
linewidth,
dashoffset,
dashpattern,
Expand Down
20 changes: 18 additions & 2 deletions src/silx/gui/plot/items/marker.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,27 @@ def __init__(self):

self._x = None
self._y = None
self._symbol_size = 10.0
self._bgColor: colors.RGBAColorType | None = None
self._constraint = self._defaultConstraint
self.__isBeingDragged = False

def _addRendererCall(self, backend, symbol=None, linestyle="-", linewidth=1):
def _addRendererCall(
self,
backend,
symbol=None,
symbolsize=10.,
linestyle="-",
linewidth=1,
):
"""Perform the update of the backend renderer"""
return backend.addMarker(
x=self.getXPosition(),
y=self.getYPosition(),
text=self.getText(),
color=self.getColor(),
symbol=symbol,
symbolsize=symbolsize,
linestyle=linestyle,
linewidth=linewidth,
constraint=self.getConstraint(),
Expand Down Expand Up @@ -246,6 +255,9 @@ class Marker(MarkerBase, SymbolMixIn):
_DEFAULT_SYMBOL = "+"
"""Default symbol of the marker"""

_DEFAULT_SYMBOL_SIZE = 10.0
"""Default size of marker's symbol"""

def __init__(self):
MarkerBase.__init__(self)
SymbolMixIn.__init__(self)
Expand All @@ -254,7 +266,11 @@ def __init__(self):
self._y = 0.0

def _addBackendRenderer(self, backend):
return self._addRendererCall(backend, symbol=self.getSymbol())
return self._addRendererCall(
backend,
symbol=self.getSymbol(),
symbolsize=self.getSymbolSize(),
)

def _setConstraint(self, constraint):
"""Set the constraint function of the marker drag.
Expand Down

0 comments on commit 4101651

Please sign in to comment.