@@ -10,6 +10,7 @@ var subroutines = require('@src/plot_api/subroutines');
10
10
var helpers = require ( '@src/plot_api/helpers' ) ;
11
11
12
12
var d3 = require ( 'd3' ) ;
13
+ var customMatchers = require ( '../assets/custom_matchers' ) ;
13
14
var createGraphDiv = require ( '../assets/create_graph_div' ) ;
14
15
var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
15
16
var fail = require ( '../assets/fail_test' ) ;
@@ -105,6 +106,10 @@ describe('Test plot api', function() {
105
106
describe ( 'Plotly.relayout' , function ( ) {
106
107
var gd ;
107
108
109
+ beforeAll ( function ( ) {
110
+ jasmine . addMatchers ( customMatchers ) ;
111
+ } ) ;
112
+
108
113
beforeEach ( function ( ) {
109
114
gd = createGraphDiv ( ) ;
110
115
} ) ;
@@ -252,6 +257,79 @@ describe('Test plot api', function() {
252
257
. catch ( fail )
253
258
. then ( done ) ;
254
259
} ) ;
260
+
261
+ it ( 'annotations, shapes and images linked to category axes should update properly on zoom/pan' , function ( done ) {
262
+ var jsLogo = 'https://images.plot.ly/language-icons/api-home/js-logo.png' ;
263
+
264
+ function getPos ( sel ) {
265
+ var rect = sel . node ( ) . getBoundingClientRect ( ) ;
266
+ return [ rect . left , rect . bottom ] ;
267
+ }
268
+
269
+ function getAnnotationPos ( ) {
270
+ return getPos ( d3 . select ( '.annotation' ) ) ;
271
+ }
272
+
273
+ function getShapePos ( ) {
274
+ return getPos ( d3 . select ( '.layer-above' ) . select ( '.shapelayer' ) . select ( 'path' ) ) ;
275
+ }
276
+
277
+ function getImagePos ( ) {
278
+ return getPos ( d3 . select ( '.layer-above' ) . select ( '.imagelayer' ) . select ( 'image' ) ) ;
279
+ }
280
+
281
+ Plotly . plot ( gd , [ {
282
+ x : [ 'a' , 'b' , 'c' ] ,
283
+ y : [ 1 , 2 , 1 ]
284
+ } ] , {
285
+ xaxis : { range : [ - 1 , 5 ] } ,
286
+ annotations : [ {
287
+ xref : 'x' ,
288
+ yref : 'y' ,
289
+ x : 'b' ,
290
+ y : 2
291
+ } ] ,
292
+ shapes : [ {
293
+ xref : 'x' ,
294
+ yref : 'y' ,
295
+ type : 'line' ,
296
+ x0 : 'c' ,
297
+ x1 : 'c' ,
298
+ y0 : - 1 ,
299
+ y1 : 4
300
+ } ] ,
301
+ images : [ {
302
+ xref : 'x' ,
303
+ yref : 'y' ,
304
+ source : jsLogo ,
305
+ x : 'a' ,
306
+ y : 1 ,
307
+ sizex : 0.2 ,
308
+ sizey : 0.2
309
+ } ]
310
+ } )
311
+ . then ( function ( ) {
312
+ expect ( getAnnotationPos ( ) ) . toBeCloseToArray ( [ 247.5 , 210.1 ] ) ;
313
+ expect ( getShapePos ( ) ) . toBeCloseToArray ( [ 350 , 369 ] ) ;
314
+ expect ( getImagePos ( ) ) . toBeCloseToArray ( [ 170 , 272.52 ] ) ;
315
+
316
+ return Plotly . relayout ( gd , 'xaxis.range' , [ 0 , 2 ] ) ;
317
+ } )
318
+ . then ( function ( ) {
319
+ expect ( getAnnotationPos ( ) ) . toBeCloseToArray ( [ 337.5 , 210.1 ] ) ;
320
+ expect ( getShapePos ( ) ) . toBeCloseToArray ( [ 620 , 369 ] ) ;
321
+ expect ( getImagePos ( ) ) . toBeCloseToArray ( [ 80 , 272.52 ] ) ;
322
+
323
+ return Plotly . relayout ( gd , 'xaxis.range' , [ - 1 , 5 ] ) ;
324
+ } )
325
+ . then ( function ( ) {
326
+ expect ( getAnnotationPos ( ) ) . toBeCloseToArray ( [ 247.5 , 210.1 ] ) ;
327
+ expect ( getShapePos ( ) ) . toBeCloseToArray ( [ 350 , 369 ] ) ;
328
+ expect ( getImagePos ( ) ) . toBeCloseToArray ( [ 170 , 272.52 ] ) ;
329
+ } )
330
+ . catch ( fail )
331
+ . then ( done ) ;
332
+ } ) ;
255
333
} ) ;
256
334
257
335
describe ( 'Plotly.restyle subroutines switchboard' , function ( ) {
0 commit comments