@@ -103,75 +103,75 @@ describe('Test shapes defaults:', function() {
103
103
} ) ;
104
104
} ) ;
105
105
106
- describe ( 'Test shapes:' , function ( ) {
107
- 'use strict' ;
106
+ function countShapesInLowerLayer ( gd ) {
107
+ return gd . _fullLayout . shapes . filter ( isShapeInLowerLayer ) . length ;
108
+ }
108
109
109
- var mock = require ( '@mocks/shapes.json' ) ;
110
- var gd ;
110
+ function countShapesInUpperLayer ( gd ) {
111
+ return gd . _fullLayout . shapes . filter ( isShapeInUpperLayer ) . length ;
112
+ }
111
113
112
- beforeEach ( function ( done ) {
113
- gd = createGraphDiv ( ) ;
114
+ function countShapesInSubplots ( gd ) {
115
+ return gd . _fullLayout . shapes . filter ( isShapeInSubplot ) . length ;
116
+ }
114
117
115
- var mockData = Lib . extendDeep ( [ ] , mock . data ) ,
116
- mockLayout = Lib . extendDeep ( { } , mock . layout ) ;
118
+ function isShapeInUpperLayer ( shape ) {
119
+ return shape . layer !== 'below' ;
120
+ }
117
121
118
- Plotly . plot ( gd , mockData , mockLayout ) . then ( done ) ;
119
- } ) ;
122
+ function isShapeInLowerLayer ( shape ) {
123
+ return ( shape . xref === 'paper' && shape . yref === 'paper' ) &&
124
+ ! isShapeInUpperLayer ( shape ) ;
125
+ }
120
126
121
- afterEach ( destroyGraphDiv ) ;
127
+ function isShapeInSubplot ( shape ) {
128
+ return ! isShapeInUpperLayer ( shape ) && ! isShapeInLowerLayer ( shape ) ;
129
+ }
122
130
123
- function countShapesInLowerLayer ( ) {
124
- return gd . _fullLayout . shapes . filter ( isShapeInLowerLayer ) . length ;
125
- }
131
+ function countShapeLowerLayerNodes ( ) {
132
+ return d3 . selectAll ( '.layer-below > .shapelayer' ) . size ( ) ;
133
+ }
126
134
127
- function countShapesInUpperLayer ( ) {
128
- return gd . _fullLayout . shapes . filter ( isShapeInUpperLayer ) . length ;
129
- }
135
+ function countShapeUpperLayerNodes ( ) {
136
+ return d3 . selectAll ( '.layer-above > .shapelayer' ) . size ( ) ;
137
+ }
130
138
131
- function countShapesInSubplots ( ) {
132
- return gd . _fullLayout . shapes . filter ( isShapeInSubplot ) . length ;
133
- }
139
+ function countShapeLayerNodesInSubplots ( ) {
140
+ return d3 . selectAll ( '.layer-subplot' ) . size ( ) ;
141
+ }
134
142
135
- function isShapeInUpperLayer ( shape ) {
136
- return shape . layer !== 'below' ;
137
- }
143
+ function countSubplots ( gd ) {
144
+ return Object . keys ( gd . _fullLayout . _plots || { } ) . length ;
145
+ }
138
146
139
- function isShapeInLowerLayer ( shape ) {
140
- return ( shape . xref === 'paper' && shape . yref === 'paper' ) &&
141
- ! isShapeInUpperLayer ( shape ) ;
142
- }
147
+ function countShapePathsInLowerLayer ( ) {
148
+ return d3 . selectAll ( '.layer-below > .shapelayer > path' ) . size ( ) ;
149
+ }
143
150
144
- function isShapeInSubplot ( shape ) {
145
- return ! isShapeInUpperLayer ( shape ) && ! isShapeInLowerLayer ( shape ) ;
146
- }
151
+ function countShapePathsInUpperLayer ( ) {
152
+ return d3 . selectAll ( '.layer-above > .shapelayer > path' ) . size ( ) ;
153
+ }
147
154
148
- function countShapeLowerLayerNodes ( ) {
149
- return d3 . selectAll ( '.layer-below > .shapelayer' ) . size ( ) ;
150
- }
155
+ function countShapePathsInSubplots ( ) {
156
+ return d3 . selectAll ( '.layer-subplot > .shapelayer > path ' ) . size ( ) ;
157
+ }
151
158
152
- function countShapeUpperLayerNodes ( ) {
153
- return d3 . selectAll ( '.layer-above > .shapelayer' ) . size ( ) ;
154
- }
159
+ describe ( 'Test shapes:' , function ( ) {
160
+ 'use strict' ;
155
161
156
- function countShapeLayerNodesInSubplots ( ) {
157
- return d3 . selectAll ( '.layer-subplot' ) . size ( ) ;
158
- }
162
+ var mock = require ( '@mocks/shapes.json' ) ;
163
+ var gd ;
159
164
160
- function countSubplots ( gd ) {
161
- return Object . keys ( gd . _fullLayout . _plots || { } ) . length ;
162
- }
165
+ beforeEach ( function ( done ) {
166
+ gd = createGraphDiv ( ) ;
163
167
164
- function countShapePathsInLowerLayer ( ) {
165
- return d3 . selectAll ( '.layer-below > .shapelayer > path' ) . size ( ) ;
166
- }
168
+ var mockData = Lib . extendDeep ( [ ] , mock . data ) ,
169
+ mockLayout = Lib . extendDeep ( { } , mock . layout ) ;
167
170
168
- function countShapePathsInUpperLayer ( ) {
169
- return d3 . selectAll ( '.layer-above > .shapelayer > path' ) . size ( ) ;
170
- }
171
+ Plotly . plot ( gd , mockData , mockLayout ) . then ( done ) ;
172
+ } ) ;
171
173
172
- function countShapePathsInSubplots ( ) {
173
- return d3 . selectAll ( '.layer-subplot > .shapelayer > path' ) . size ( ) ;
174
- }
174
+ afterEach ( destroyGraphDiv ) ;
175
175
176
176
describe ( '*shapeLowerLayer*' , function ( ) {
177
177
it ( 'has one node' , function ( ) {
@@ -180,14 +180,14 @@ describe('Test shapes:', function() {
180
180
181
181
it ( 'has as many *path* nodes as shapes in the lower layer' , function ( ) {
182
182
expect ( countShapePathsInLowerLayer ( ) )
183
- . toEqual ( countShapesInLowerLayer ( ) ) ;
183
+ . toEqual ( countShapesInLowerLayer ( gd ) ) ;
184
184
} ) ;
185
185
186
186
it ( 'should be able to get relayout' , function ( done ) {
187
187
Plotly . relayout ( gd , { height : 200 , width : 400 } ) . then ( function ( ) {
188
188
expect ( countShapeLowerLayerNodes ( ) ) . toEqual ( 1 ) ;
189
189
expect ( countShapePathsInLowerLayer ( ) )
190
- . toEqual ( countShapesInLowerLayer ( ) ) ;
190
+ . toEqual ( countShapesInLowerLayer ( gd ) ) ;
191
191
} )
192
192
. catch ( failTest )
193
193
. then ( done ) ;
@@ -201,14 +201,14 @@ describe('Test shapes:', function() {
201
201
202
202
it ( 'has as many *path* nodes as shapes in the upper layer' , function ( ) {
203
203
expect ( countShapePathsInUpperLayer ( ) )
204
- . toEqual ( countShapesInUpperLayer ( ) ) ;
204
+ . toEqual ( countShapesInUpperLayer ( gd ) ) ;
205
205
} ) ;
206
206
207
207
it ( 'should be able to get relayout' , function ( done ) {
208
208
Plotly . relayout ( gd , { height : 200 , width : 400 } ) . then ( function ( ) {
209
209
expect ( countShapeUpperLayerNodes ( ) ) . toEqual ( 1 ) ;
210
210
expect ( countShapePathsInUpperLayer ( ) )
211
- . toEqual ( countShapesInUpperLayer ( ) ) ;
211
+ . toEqual ( countShapesInUpperLayer ( gd ) ) ;
212
212
} )
213
213
. catch ( failTest )
214
214
. then ( done ) ;
@@ -223,15 +223,15 @@ describe('Test shapes:', function() {
223
223
224
224
it ( 'has as many *path* nodes as shapes in the subplot' , function ( ) {
225
225
expect ( countShapePathsInSubplots ( ) )
226
- . toEqual ( countShapesInSubplots ( ) ) ;
226
+ . toEqual ( countShapesInSubplots ( gd ) ) ;
227
227
} ) ;
228
228
229
229
it ( 'should be able to get relayout' , function ( done ) {
230
230
Plotly . relayout ( gd , { height : 200 , width : 400 } ) . then ( function ( ) {
231
231
expect ( countShapeLayerNodesInSubplots ( ) )
232
232
. toEqual ( countSubplots ( gd ) ) ;
233
233
expect ( countShapePathsInSubplots ( ) )
234
- . toEqual ( countShapesInSubplots ( ) ) ;
234
+ . toEqual ( countShapesInSubplots ( gd ) ) ;
235
235
} )
236
236
. catch ( failTest )
237
237
. then ( done ) ;
@@ -464,6 +464,49 @@ describe('shapes axis reference changes', function() {
464
464
} ) ;
465
465
} ) ;
466
466
467
+ describe ( 'shapes edge cases' , function ( ) {
468
+ 'use strict' ;
469
+
470
+ var gd ;
471
+
472
+ beforeAll ( function ( ) {
473
+ jasmine . addMatchers ( customMatchers ) ;
474
+ } ) ;
475
+
476
+ beforeEach ( function ( ) { gd = createGraphDiv ( ) ; } ) ;
477
+
478
+ afterEach ( destroyGraphDiv ) ;
479
+
480
+ it ( 'falls back on shapeLowerLayer for below missing subplots' , function ( done ) {
481
+ Plotly . newPlot ( gd , [
482
+ { x : [ 1 , 3 ] , y : [ 1 , 3 ] } ,
483
+ { x : [ 1 , 3 ] , y : [ 1 , 3 ] , xaxis : 'x2' , yaxis : 'y2' }
484
+ ] , {
485
+ xaxis : { domain : [ 0 , 0.5 ] } ,
486
+ yaxis : { domain : [ 0 , 0.5 ] } ,
487
+ xaxis2 : { domain : [ 0.5 , 1 ] , anchor : 'y2' } ,
488
+ yaxis2 : { domain : [ 0.5 , 1 ] , anchor : 'x2' } ,
489
+ shapes : [ {
490
+ x0 : 1 , x1 : 2 , y0 : 1 , y1 : 2 , type : 'circle' ,
491
+ layer : 'below' ,
492
+ xref : 'x' ,
493
+ yref : 'y2'
494
+ } , {
495
+ x0 : 1 , x1 : 2 , y0 : 1 , y1 : 2 , type : 'circle' ,
496
+ layer : 'below' ,
497
+ xref : 'x2' ,
498
+ yref : 'y'
499
+ } ]
500
+ } ) . then ( function ( ) {
501
+ expect ( countShapePathsInLowerLayer ( ) ) . toBe ( 2 ) ;
502
+ expect ( countShapePathsInUpperLayer ( ) ) . toBe ( 0 ) ;
503
+ expect ( countShapePathsInSubplots ( ) ) . toBe ( 0 ) ;
504
+ } )
505
+ . catch ( failTest )
506
+ . then ( done ) ;
507
+ } ) ;
508
+ } ) ;
509
+
467
510
describe ( 'shapes autosize' , function ( ) {
468
511
'use strict' ;
469
512
0 commit comments