@@ -249,6 +249,59 @@ describe('relayout', function() {
249249 done ( ) ;
250250 } ) ;
251251 } ) ;
252+
253+ } ) ;
254+
255+ describe ( 'axis ranges' , function ( ) {
256+ var gd ;
257+
258+ beforeEach ( function ( ) {
259+ gd = createGraphDiv ( ) ;
260+ } ) ;
261+
262+ afterEach ( destroyGraphDiv ) ;
263+
264+ it ( 'should translate points and text element' , function ( done ) {
265+ var mockData = [ {
266+ x : [ 1 ] ,
267+ y : [ 1 ] ,
268+ text : [ 'A' ] ,
269+ mode : 'markers+text'
270+ } ] ;
271+
272+ function assertPointTranslate ( pointT , textT ) {
273+ var TOLERANCE = 10 ;
274+
275+ var gd3 = d3 . select ( gd ) ,
276+ points = gd3 . selectAll ( 'g.scatter.trace path.point' ) ,
277+ texts = gd3 . selectAll ( 'g.scatter.trace text' ) ;
278+
279+ expect ( points . size ( ) ) . toEqual ( 1 ) ;
280+ expect ( texts . size ( ) ) . toEqual ( 1 ) ;
281+
282+ expect ( points . attr ( 'x' ) ) . toBe ( null ) ;
283+ expect ( points . attr ( 'y' ) ) . toBe ( null ) ;
284+ expect ( texts . attr ( 'transform' ) ) . toBe ( null ) ;
285+
286+ var translate = Lib . getTranslate ( points ) ;
287+ expect ( Math . abs ( translate . x - pointT [ 0 ] ) ) . toBeLessThan ( TOLERANCE ) ;
288+ expect ( Math . abs ( translate . y - pointT [ 1 ] ) ) . toBeLessThan ( TOLERANCE ) ;
289+
290+ expect ( Math . abs ( texts . attr ( 'x' ) - textT [ 0 ] ) ) . toBeLessThan ( TOLERANCE ) ;
291+ expect ( Math . abs ( texts . attr ( 'y' ) - textT [ 1 ] ) ) . toBeLessThan ( TOLERANCE ) ;
292+ }
293+
294+ Plotly . plot ( gd , mockData ) . then ( function ( ) {
295+ assertPointTranslate ( [ 270 , 135 ] , [ 270 , 135 ] ) ;
296+
297+ return Plotly . relayout ( gd , 'xaxis.range' , [ 2 , 3 ] ) ;
298+ } )
299+ . then ( function ( ) {
300+ assertPointTranslate ( [ 0 , 540 ] , [ - 540 , 135 ] ) ;
301+ } )
302+ . then ( done ) ;
303+ } ) ;
304+
252305 } ) ;
253306
254307} ) ;
0 commit comments