@@ -6,6 +6,7 @@ var Lib = require('@src/lib');
66var Dates = require ( '@src/lib/dates' ) ;
77
88var d3 = require ( 'd3' ) ;
9+ var customMatchers = require ( '../assets/custom_matchers' ) ;
910var createGraphDiv = require ( '../assets/create_graph_div' ) ;
1011var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
1112
@@ -117,3 +118,83 @@ describe('annotations relayout', function() {
117118
118119 } ) ;
119120} ) ;
121+
122+ describe ( 'annotations autosize' , function ( ) {
123+ 'use strict' ;
124+
125+ var mock = Lib . extendDeep ( { } , require ( '@mocks/annotations-autorange.json' ) ) ;
126+ var gd ;
127+
128+ beforeAll ( function ( ) {
129+ jasmine . addMatchers ( customMatchers ) ;
130+ } ) ;
131+
132+ afterEach ( destroyGraphDiv ) ;
133+
134+ it ( 'should adapt to relayout calls' , function ( done ) {
135+ gd = createGraphDiv ( ) ;
136+
137+ function assertRanges ( x , y , x2 , y2 , x3 , y3 ) {
138+ var fullLayout = gd . _fullLayout ;
139+ var PREC = 1 ;
140+
141+ expect ( fullLayout . xaxis . range ) . toBeCloseToArray ( x , PREC , '- xaxis' ) ;
142+ expect ( fullLayout . yaxis . range ) . toBeCloseToArray ( y , PREC , '- yaxis' ) ;
143+ expect ( fullLayout . xaxis2 . range ) . toBeCloseToArray ( x2 , PREC , 'xaxis2' ) ;
144+ expect ( fullLayout . yaxis2 . range ) . toBeCloseToArray ( y2 , PREC , 'yaxis2' ) ;
145+ expect ( fullLayout . xaxis3 . range ) . toBeCloseToArray ( x3 , PREC , 'xaxis3' ) ;
146+ expect ( fullLayout . yaxis3 . range ) . toBeCloseToArray ( y3 , PREC , 'yaxis3' ) ;
147+ }
148+
149+ Plotly . plot ( gd , mock ) . then ( function ( ) {
150+ assertRanges (
151+ [ 0.97 , 2.03 ] , [ 0.97 , 2.03 ] ,
152+ [ - 0.32 , 3.38 ] , [ 0.42 , 2.58 ] ,
153+ [ 0.9 , 2.1 ] , [ 0.86 , 2.14 ]
154+ ) ;
155+
156+ return Plotly . relayout ( gd , {
157+ 'annotations[0].visible' : false ,
158+ 'annotations[4].visible' : false ,
159+ 'annotations[8].visible' : false
160+ } ) ;
161+ } )
162+ . then ( function ( ) {
163+ assertRanges (
164+ [ 1.44 , 2.02 ] , [ 0.97 , 2.03 ] ,
165+ [ 1.31 , 2.41 ] , [ 0.42 , 2.58 ] ,
166+ [ 1.44 , 2.1 ] , [ 0.86 , 2.14 ]
167+ ) ;
168+
169+ return Plotly . relayout ( gd , {
170+ 'annotations[2].visible' : false ,
171+ 'annotations[5].visible' : false ,
172+ 'annotations[9].visible' : false
173+ } ) ;
174+ } )
175+ . then ( function ( ) {
176+ assertRanges (
177+ [ 1.44 , 2.02 ] , [ 0.99 , 1.52 ] ,
178+ [ 0.5 , 2.5 ] , [ 0.42 , 2.58 ] ,
179+ [ 0.5 , 2.5 ] , [ 0.86 , 2.14 ]
180+ ) ;
181+
182+ return Plotly . relayout ( gd , {
183+ 'annotations[0].visible' : true ,
184+ 'annotations[2].visible' : true ,
185+ 'annotations[4].visible' : true ,
186+ 'annotations[5].visible' : true ,
187+ 'annotations[8].visible' : true ,
188+ 'annotations[9].visible' : true
189+ } ) ;
190+ } )
191+ . then ( function ( ) {
192+ assertRanges (
193+ [ 0.97 , 2.03 ] , [ 0.97 , 2.03 ] ,
194+ [ - 0.32 , 3.38 ] , [ 0.42 , 2.58 ] ,
195+ [ 0.9 , 2.1 ] , [ 0.86 , 2.14 ]
196+ ) ;
197+ } )
198+ . then ( done ) ;
199+ } ) ;
200+ } ) ;
0 commit comments