Skip to content

Commit 7c98a50

Browse files
committed
Add support for (0, None) and (0, ()) linestyle as a valid style for solid line
1 parent 90eca7b commit 7c98a50

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

src/silx/gui/plot/backends/BackendBase.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def addMarker(
216216
text: str | None,
217217
color: str,
218218
symbol: str | None,
219-
linestyle: str | tuple[float, tuple[float, ...]],
219+
linestyle: str | tuple[float, tuple[float, ...] | None],
220220
linewidth: float,
221221
constraint: Callable[[float, float], tuple[float, float]] | None,
222222
yaxis: str,

src/silx/gui/plot/backends/BackendOpenGL.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,7 @@ def _castArrayTo(v):
875875
else:
876876
raise ValueError("Unsupported data type")
877877

878-
_DASH_PATTERNS = { # Convert from linestyle to offset and dash pattern
878+
_DASH_PATTERNS = {
879879
"": (0.0, None),
880880
" ": (0.0, None),
881881
"-": (0.0, ()),
@@ -884,6 +884,12 @@ def _castArrayTo(v):
884884
":": (0.0, (1, 1.65, 1, 1.65)),
885885
None: (0.0, None),
886886
}
887+
"""Convert from linestyle to (offset, (dash pattern))
888+
889+
Note: dash pattern internal convention differs from matplotlib:
890+
- None: no line at all
891+
- (): "solid" line
892+
"""
887893

888894
def _lineStyleToDashOffsetPattern(
889895
self, style
@@ -892,8 +898,11 @@ def _lineStyleToDashOffsetPattern(
892898
if style is None or isinstance(style, str):
893899
return self._DASH_PATTERNS[style]
894900

895-
# (offset, (dash pattern))
901+
# (offset, (dash pattern)) case
896902
offset, pattern = style
903+
if pattern is None:
904+
# Convert from matplotlib to internal representation of solid
905+
pattern = ()
897906
if len(pattern) == 2:
898907
pattern = pattern * 2
899908
return offset, pattern

src/silx/gui/plot/items/core.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,7 @@ def setSymbolSize(self, size):
837837

838838
LineStyleType = Union[
839839
str,
840+
Tuple[float, None],
840841
Tuple[float, Tuple[float, float]],
841842
Tuple[float, Tuple[float, float, float, float]],
842843
]
@@ -888,9 +889,15 @@ def isValidLineStyle(cls, style: LineStyleType | None) -> bool:
888889
if (
889890
len(style) == 2
890891
and isinstance(style[0], float)
891-
and isinstance(style[1], tuple)
892-
and len(style[1]) in (2, 4)
893-
and all(map(lambda item: isinstance(item, float), style[1]))
892+
and (
893+
style[1] is None
894+
or style[1] == ()
895+
or (
896+
isinstance(style[1], tuple)
897+
and len(style[1]) in (2, 4)
898+
and all(map(lambda item: isinstance(item, float), style[1]))
899+
)
900+
)
894901
):
895902
return True
896903
return False

0 commit comments

Comments
 (0)