Skip to content

Commit

Permalink
Add support for (0, None) linestyle as a valid style for solid line
Browse files Browse the repository at this point in the history
  • Loading branch information
t20100 committed Dec 19, 2023
1 parent 90eca7b commit 5effcd2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/silx/gui/plot/backends/BackendBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def addMarker(
text: str | None,
color: str,
symbol: str | None,
linestyle: str | tuple[float, tuple[float, ...]],
linestyle: str | tuple[float, tuple[float, ...] | None],
linewidth: float,
constraint: Callable[[float, float], tuple[float, float]] | None,
yaxis: str,
Expand Down
13 changes: 11 additions & 2 deletions src/silx/gui/plot/backends/BackendOpenGL.py
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ def _castArrayTo(v):
else:
raise ValueError("Unsupported data type")

_DASH_PATTERNS = { # Convert from linestyle to offset and dash pattern
_DASH_PATTERNS = {
"": (0.0, None),
" ": (0.0, None),
"-": (0.0, ()),
Expand All @@ -884,6 +884,12 @@ def _castArrayTo(v):
":": (0.0, (1, 1.65, 1, 1.65)),
None: (0.0, None),
}
"""Convert from linestyle to (offset, (dash pattern))
Note: dash pattern internal convention differs from matplotlib:
- None: no line at all
- (): "solid" line
"""

def _lineStyleToDashOffsetPattern(
self, style
Expand All @@ -892,8 +898,11 @@ def _lineStyleToDashOffsetPattern(
if style is None or isinstance(style, str):
return self._DASH_PATTERNS[style]

# (offset, (dash pattern))
# (offset, (dash pattern)) case
offset, pattern = style
if pattern is None:
# Convert from matplotlib to internal representation of solid
pattern = ()
if len(pattern) == 2:
pattern = pattern * 2
return offset, pattern
Expand Down
12 changes: 9 additions & 3 deletions src/silx/gui/plot/items/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,7 @@ def setSymbolSize(self, size):

LineStyleType = Union[
str,
Tuple[float, None],
Tuple[float, Tuple[float, float]],
Tuple[float, Tuple[float, float, float, float]],
]
Expand Down Expand Up @@ -888,9 +889,14 @@ def isValidLineStyle(cls, style: LineStyleType | None) -> bool:
if (
len(style) == 2
and isinstance(style[0], float)
and isinstance(style[1], tuple)
and len(style[1]) in (2, 4)
and all(map(lambda item: isinstance(item, float), style[1]))
and (
style[1] is None
or (
isinstance(style[1], tuple)
and len(style[1]) in (2, 4)
and all(map(lambda item: isinstance(item, float), style[1]))
)
)
):
return True
return False
Expand Down

0 comments on commit 5effcd2

Please sign in to comment.