58
58
59
59
class _ShapeItem (dict ):
60
60
def __init__ (
61
- self , x , y , shape , color , fill , overlay , linewidth , dashpattern , gapcolor
61
+ self ,
62
+ x ,
63
+ y ,
64
+ shape ,
65
+ color ,
66
+ fill ,
67
+ overlay ,
68
+ linewidth ,
69
+ dashoffset ,
70
+ dashpattern ,
71
+ gapcolor ,
62
72
):
63
73
super (_ShapeItem , self ).__init__ ()
64
74
@@ -85,6 +95,7 @@ def __init__(
85
95
"x" : x ,
86
96
"y" : y ,
87
97
"linewidth" : linewidth ,
98
+ "dashoffset" : dashoffset ,
88
99
"dashpattern" : dashpattern ,
89
100
"gapcolor" : gapcolor ,
90
101
}
@@ -100,6 +111,7 @@ def __init__(
100
111
color ,
101
112
symbol ,
102
113
linewidth ,
114
+ dashoffset ,
103
115
dashpattern ,
104
116
constraint ,
105
117
yaxis ,
@@ -125,6 +137,7 @@ def __init__(
125
137
"constraint" : constraint if isConstraint else None ,
126
138
"symbol" : symbol ,
127
139
"linewidth" : linewidth ,
140
+ "dashoffset" : dashoffset ,
128
141
"dashpattern" : dashpattern ,
129
142
"yaxis" : yaxis ,
130
143
"font" : font ,
@@ -588,6 +601,7 @@ def _renderItems(self, overlay=False):
588
601
color = item ["color" ],
589
602
gapColor = item ["gapcolor" ],
590
603
width = item ["linewidth" ],
604
+ dashOffset = item ["dashoffset" ],
591
605
dashPattern = item ["dashpattern" ],
592
606
)
593
607
context .matrix = self .matScreenProj
@@ -638,6 +652,7 @@ def _renderItems(self, overlay=False):
638
652
(pixelPos [1 ], pixelPos [1 ]),
639
653
color = color ,
640
654
width = item ["linewidth" ],
655
+ dashOffset = item ["dashoffset" ],
641
656
dashPattern = item ["dashpattern" ],
642
657
)
643
658
context .matrix = self .matScreenProj
@@ -671,6 +686,7 @@ def _renderItems(self, overlay=False):
671
686
(0 , height ),
672
687
color = color ,
673
688
width = item ["linewidth" ],
689
+ dashOffset = item ["dashoffset" ],
674
690
dashPattern = item ["dashpattern" ],
675
691
)
676
692
context .matrix = self .matScreenProj
@@ -859,21 +875,28 @@ def _castArrayTo(v):
859
875
else :
860
876
raise ValueError ("Unsupported data type" )
861
877
862
- _DASH_PATTERNS = { # Convert from linestyle to dash pattern
863
- "" : None ,
864
- " " : None ,
865
- "-" : (),
866
- "--" : (3.7 , 1.6 , 3.7 , 1.6 ),
867
- "-." : (6.4 , 1.6 , 1 , 1.6 ),
868
- ":" : (1 , 1.65 , 1 , 1.65 ),
869
- None : None ,
878
+ _DASH_PATTERNS = { # Convert from linestyle to offset and dash pattern
879
+ "" : ( 0.0 , None ) ,
880
+ " " : ( 0.0 , None ) ,
881
+ "-" : (0.0 , () ),
882
+ "--" : (0.0 , ( 3.7 , 1.6 , 3.7 , 1.6 ) ),
883
+ "-." : (0.0 , ( 6.4 , 1.6 , 1 , 1.6 ) ),
884
+ ":" : (0.0 , ( 1 , 1.65 , 1 , 1.65 ) ),
885
+ None : ( 0.0 , None ) ,
870
886
}
871
887
872
- def _lineStyleToDashPattern (
873
- self , style : str | None
874
- ) -> tuple [float , float , float , float ] | tuple [()] | None :
875
- """Convert a linestyle to its corresponding dash pattern"""
876
- return self ._DASH_PATTERNS [style ]
888
+ def _lineStyleToDashOffsetPattern (
889
+ self , style
890
+ ) -> tuple [float , tuple [float , float , float , float ] | tuple [()] | None ]:
891
+ """Convert a linestyle to its corresponding offset and dash pattern"""
892
+ if style is None or isinstance (style , str ):
893
+ return self ._DASH_PATTERNS [style ]
894
+
895
+ # (offset, (dash pattern))
896
+ offset , pattern = style
897
+ if len (pattern ) == 2 :
898
+ pattern = pattern * 2
899
+ return offset , pattern
877
900
878
901
def addCurve (
879
902
self ,
@@ -994,6 +1017,7 @@ def addCurve(
994
1017
if fill is True :
995
1018
fillColor = color
996
1019
1020
+ dashoffset , dashpattern = self ._lineStyleToDashOffsetPattern (linestyle )
997
1021
curve = glutils .GLPlotCurve2D (
998
1022
x ,
999
1023
y ,
@@ -1003,7 +1027,8 @@ def addCurve(
1003
1027
lineColor = color ,
1004
1028
lineGapColor = gapcolor ,
1005
1029
lineWidth = linewidth ,
1006
- lineDashPattern = self ._lineStyleToDashPattern (linestyle ),
1030
+ lineDashOffset = dashoffset ,
1031
+ lineDashPattern = dashpattern ,
1007
1032
marker = symbol ,
1008
1033
markerColor = color ,
1009
1034
markerSize = symbolsize ,
@@ -1108,9 +1133,18 @@ def addShape(
1108
1133
if self ._plotFrame .yAxis .isLog and y .min () <= 0.0 :
1109
1134
raise RuntimeError ("Cannot add item with Y <= 0 with Y axis log scale" )
1110
1135
1111
- dashpattern = self ._lineStyleToDashPattern (linestyle )
1136
+ dashoffset , dashpattern = self ._lineStyleToDashOffsetPattern (linestyle )
1112
1137
return _ShapeItem (
1113
- x , y , shape , color , fill , overlay , linewidth , dashpattern , gapcolor
1138
+ x ,
1139
+ y ,
1140
+ shape ,
1141
+ color ,
1142
+ fill ,
1143
+ overlay ,
1144
+ linewidth ,
1145
+ dashoffset ,
1146
+ dashpattern ,
1147
+ gapcolor ,
1114
1148
)
1115
1149
1116
1150
def addMarker (
@@ -1128,14 +1162,15 @@ def addMarker(
1128
1162
bgcolor : RGBAColorType | None ,
1129
1163
):
1130
1164
font = qt .QApplication .instance ().font () if font is None else font
1131
- dashpattern = self ._lineStyleToDashPattern (linestyle )
1165
+ dashoffset , dashpattern = self ._lineStyleToDashOffsetPattern (linestyle )
1132
1166
return _MarkerItem (
1133
1167
x ,
1134
1168
y ,
1135
1169
text ,
1136
1170
color ,
1137
1171
symbol ,
1138
1172
linewidth ,
1173
+ dashoffset ,
1139
1174
dashpattern ,
1140
1175
constraint ,
1141
1176
yaxis ,
0 commit comments