@@ -24,30 +24,114 @@ describe('Test shapes:', function() {
24
24
25
25
afterEach ( destroyGraphDiv ) ;
26
26
27
- function countShapeLayers ( ) {
28
- return d3 . selectAll ( '.shapelayer' ) . size ( ) ;
27
+ function countShapesInLowerLayer ( ) {
28
+ return gd . _fullLayout . shapes . filter ( isShapeInLowerLayer ) . length ;
29
29
}
30
30
31
- function countShapePaths ( ) {
32
- return d3 . selectAll ( '.shapelayer > path' ) . size ( ) ;
31
+ function countShapesInUpperLayer ( ) {
32
+ return gd . _fullLayout . shapes . filter ( isShapeInUpperLayer ) . length ;
33
33
}
34
34
35
- describe ( 'DOM' , function ( ) {
36
- it ( 'has one *shapelayer* node' , function ( ) {
37
- expect ( countShapeLayers ( ) ) . toEqual ( 1 ) ;
35
+ function countShapesInSubplots ( ) {
36
+ return gd . _fullLayout . shapes . filter ( isShapeInSubplot ) . length ;
37
+ }
38
+
39
+ function isShapeInUpperLayer ( shape ) {
40
+ return shape . layer !== 'below' ;
41
+ }
42
+
43
+ function isShapeInLowerLayer ( shape ) {
44
+ return ( shape . xref === 'paper' && shape . yref === 'paper' ) &&
45
+ ! isShapeInUpperLayer ( shape ) ;
46
+ }
47
+
48
+ function isShapeInSubplot ( shape ) {
49
+ return ! isShapeInUpperLayer ( shape ) && ! isShapeInLowerLayer ( shape ) ;
50
+ }
51
+
52
+ function countShapeLowerLayerNodes ( ) {
53
+ return d3 . selectAll ( '.shapelayer-below' ) . size ( ) ;
54
+ }
55
+
56
+ function countShapeUpperLayerNodes ( ) {
57
+ return d3 . selectAll ( '.shapelayer-above' ) . size ( ) ;
58
+ }
59
+
60
+ function countShapeLayerNodesInSubplots ( ) {
61
+ return d3 . selectAll ( '.shapelayer-subplot' ) . size ( ) ;
62
+ }
63
+
64
+ function countSubplots ( gd ) {
65
+ return Object . getOwnPropertyNames ( gd . _fullLayout . _plots || { } ) . length ;
66
+ }
67
+
68
+ function countShapePathsInLowerLayer ( ) {
69
+ return d3 . selectAll ( '.shapelayer-below > path' ) . size ( ) ;
70
+ }
71
+
72
+ function countShapePathsInUpperLayer ( ) {
73
+ return d3 . selectAll ( '.shapelayer-above > path' ) . size ( ) ;
74
+ }
75
+
76
+ function countShapePathsInSubplots ( ) {
77
+ return d3 . selectAll ( '.shapelayer-subplot > path' ) . size ( ) ;
78
+ }
79
+
80
+ describe ( '*shapeLowerLayer*' , function ( ) {
81
+ it ( 'has one node' , function ( ) {
82
+ expect ( countShapeLowerLayerNodes ( ) ) . toEqual ( 1 ) ;
83
+ } ) ;
84
+
85
+ it ( 'has as many *path* nodes as shapes in the lower layer' , function ( ) {
86
+ expect ( countShapePathsInLowerLayer ( ) )
87
+ . toEqual ( countShapesInLowerLayer ( ) ) ;
88
+ } ) ;
89
+
90
+ it ( 'should be able to get relayout' , function ( done ) {
91
+ Plotly . relayout ( gd , { height : 200 , width : 400 } ) . then ( function ( ) {
92
+ expect ( countShapeLowerLayerNodes ( ) ) . toEqual ( 1 ) ;
93
+ expect ( countShapePathsInLowerLayer ( ) )
94
+ . toEqual ( countShapesInLowerLayer ( ) ) ;
95
+ } ) . then ( done ) ;
96
+ } ) ;
97
+ } ) ;
98
+
99
+ describe ( '*shapeUpperLayer*' , function ( ) {
100
+ it ( 'has one node' , function ( ) {
101
+ expect ( countShapeUpperLayerNodes ( ) ) . toEqual ( 1 ) ;
38
102
} ) ;
39
103
40
- it ( 'has as many *path* nodes as there are shapes' , function ( ) {
41
- expect ( countShapePaths ( ) ) . toEqual ( mock . layout . shapes . length ) ;
104
+ it ( 'has as many *path* nodes as shapes in the upper layer' , function ( ) {
105
+ expect ( countShapePathsInUpperLayer ( ) )
106
+ . toEqual ( countShapesInUpperLayer ( ) ) ;
42
107
} ) ;
43
108
44
109
it ( 'should be able to get relayout' , function ( done ) {
45
- expect ( countShapeLayers ( ) ) . toEqual ( 1 ) ;
46
- expect ( countShapePaths ( ) ) . toEqual ( mock . layout . shapes . length ) ;
110
+ Plotly . relayout ( gd , { height : 200 , width : 400 } ) . then ( function ( ) {
111
+ expect ( countShapeUpperLayerNodes ( ) ) . toEqual ( 1 ) ;
112
+ expect ( countShapePathsInUpperLayer ( ) )
113
+ . toEqual ( countShapesInUpperLayer ( ) ) ;
114
+ } ) . then ( done ) ;
115
+ } ) ;
116
+ } ) ;
47
117
118
+ describe ( 'each *subplot*' , function ( ) {
119
+ it ( 'has one *shapelayer*' , function ( ) {
120
+ expect ( countShapeLayerNodesInSubplots ( ) )
121
+ . toEqual ( countSubplots ( gd ) ) ;
122
+ } ) ;
123
+
124
+ it ( 'has as many *path* nodes as shapes in the subplot' , function ( ) {
125
+ expect ( countShapePathsInSubplots ( ) )
126
+ . toEqual ( countShapesInSubplots ( ) ) ;
127
+ } ) ;
128
+
129
+ it ( 'should be able to get relayout' , function ( done ) {
48
130
Plotly . relayout ( gd , { height : 200 , width : 400 } ) . then ( function ( ) {
49
- expect ( countShapeLayers ( ) ) . toEqual ( 1 ) ;
50
- expect ( countShapePaths ( ) ) . toEqual ( mock . layout . shapes . length ) ;
131
+ expect ( countShapeLayerNodesInSubplots ( ) )
132
+ . toEqual ( countSubplots ( gd ) ) ;
133
+ expect ( countShapePathsInSubplots ( ) )
134
+ . toEqual ( countShapesInSubplots ( ) ) ;
51
135
} ) . then ( done ) ;
52
136
} ) ;
53
137
} ) ;
@@ -75,33 +159,32 @@ describe('Test shapes:', function() {
75
159
76
160
describe ( 'Plotly.relayout' , function ( ) {
77
161
it ( 'should be able to add a shape' , function ( done ) {
78
- var pathCount = countShapePaths ( ) ;
162
+ var pathCount = countShapePathsInUpperLayer ( ) ;
79
163
var index = countShapes ( gd ) ;
80
164
var shape = getRandomShape ( ) ;
81
165
82
- Plotly . relayout ( gd , 'shapes[' + index + ']' , shape ) . then ( function ( ) {
83
- expect ( countShapeLayers ( ) ) . toEqual ( 1 ) ;
84
- expect ( countShapePaths ( ) ) . toEqual ( pathCount + 1 ) ;
166
+ Plotly . relayout ( gd , 'shapes[' + index + ']' , shape ) . then ( function ( )
167
+ {
168
+ expect ( countShapePathsInUpperLayer ( ) ) . toEqual ( pathCount + 1 ) ;
85
169
expect ( getLastShape ( gd ) ) . toEqual ( shape ) ;
86
170
expect ( countShapes ( gd ) ) . toEqual ( index + 1 ) ;
87
171
} ) . then ( done ) ;
88
172
} ) ;
89
173
90
174
it ( 'should be able to remove a shape' , function ( done ) {
91
- var pathCount = countShapePaths ( ) ;
175
+ var pathCount = countShapePathsInUpperLayer ( ) ;
92
176
var index = countShapes ( gd ) ;
93
177
var shape = getRandomShape ( ) ;
94
178
95
- Plotly . relayout ( gd , 'shapes[' + index + ']' , shape ) . then ( function ( ) {
96
- expect ( countShapeLayers ( ) ) . toEqual ( 1 ) ;
97
- expect ( countShapePaths ( ) ) . toEqual ( pathCount + 1 ) ;
179
+ Plotly . relayout ( gd , 'shapes[' + index + ']' , shape ) . then ( function ( )
180
+ {
181
+ expect ( countShapePathsInUpperLayer ( ) ) . toEqual ( pathCount + 1 ) ;
98
182
expect ( getLastShape ( gd ) ) . toEqual ( shape ) ;
99
183
expect ( countShapes ( gd ) ) . toEqual ( index + 1 ) ;
100
184
} ) . then ( function ( ) {
101
185
Plotly . relayout ( gd , 'shapes[' + index + ']' , 'remove' ) ;
102
186
} ) . then ( function ( ) {
103
- expect ( countShapeLayers ( ) ) . toEqual ( 1 ) ;
104
- expect ( countShapePaths ( ) ) . toEqual ( pathCount ) ;
187
+ expect ( countShapePathsInUpperLayer ( ) ) . toEqual ( pathCount ) ;
105
188
expect ( countShapes ( gd ) ) . toEqual ( index ) ;
106
189
} ) . then ( done ) ;
107
190
} ) ;
0 commit comments