@@ -4225,6 +4225,132 @@ describe('Test axes', function() {
4225
4225
. then ( done , done . fail ) ;
4226
4226
} ) ;
4227
4227
4228
+ it ( 'should handle partial automargin' , function ( done ) {
4229
+ var initialSize ;
4230
+
4231
+ function assertSize ( msg , actual , exp ) {
4232
+ for ( var k in exp ) {
4233
+ var parts = exp [ k ] . split ( '|' ) ;
4234
+ var op = parts [ 0 ] ;
4235
+
4236
+ var method = {
4237
+ '=' : 'toBe' ,
4238
+ grew : 'toBeGreaterThan' ,
4239
+ } [ op ] ;
4240
+
4241
+ var val = initialSize [ k ] ;
4242
+ var msgk = msg + ' ' + k + ( parts [ 1 ] ? ' |' + parts [ 1 ] : '' ) ;
4243
+ var args = op === '~=' ? [ val , 1.1 , msgk ] : [ val , msgk , '' ] ;
4244
+
4245
+ expect ( actual [ k ] ) [ method ] ( args [ 0 ] , args [ 1 ] , args [ 2 ] ) ;
4246
+ }
4247
+ }
4248
+
4249
+ function check ( msg , relayoutObj , exp ) {
4250
+ return function ( ) {
4251
+ return Plotly . relayout ( gd , relayoutObj ) . then ( function ( ) {
4252
+ var gs = Lib . extendDeep ( { } , gd . _fullLayout . _size ) ;
4253
+ assertSize ( msg , gs , exp ) ;
4254
+ } ) ;
4255
+ } ;
4256
+ }
4257
+
4258
+ Plotly . newPlot ( gd , [ {
4259
+ x : [
4260
+ 'short label 1' , 'loooooong label 1' ,
4261
+ 'short label 2' , 'loooooong label 2' ,
4262
+ 'short label 3' , 'loooooong label 3' ,
4263
+ 'short label 4' , 'loooooongloooooongloooooong label 4' ,
4264
+ 'short label 5' , 'loooooong label 5'
4265
+ ] ,
4266
+ y : [
4267
+ 'short label 1' , 'loooooong label 1' ,
4268
+ 'short label 2' , 'loooooong label 2' ,
4269
+ 'short label 3' , 'loooooong label 3' ,
4270
+ 'short label 4' , 'loooooong label 4' ,
4271
+ 'short label 5' , 'loooooong label 5'
4272
+ ]
4273
+ } ] , {
4274
+ margin : { l : 0 , r : 0 , b : 0 , t : 0 } ,
4275
+ width : 600 , height : 600
4276
+ } )
4277
+ . then ( function ( ) {
4278
+ expect ( gd . _fullLayout . xaxis . _tickAngles . xtick ) . toBe ( 30 ) ;
4279
+
4280
+ var gs = gd . _fullLayout . _size ;
4281
+ initialSize = Lib . extendDeep ( { } , gs ) ;
4282
+ } )
4283
+ . then ( check ( 'automargin y' , { 'yaxis.automargin' : true , 'yaxis.tickangle' : 30 , 'yaxis.ticklen' : 30 } , {
4284
+ t : 'grew' , l : 'grew' ,
4285
+ b : '=' , r : '='
4286
+ } ) )
4287
+ . then ( check ( 'automargin not left' , { 'yaxis.automargin' : 'right height' } , {
4288
+ t : 'grew' , l : '=' ,
4289
+ b : '=' , r : '='
4290
+ } ) )
4291
+ . then ( check ( 'automargin keep left height' , { 'yaxis.automargin' : 'left height' } , {
4292
+ t : 'grew' , l : 'grew' ,
4293
+ b : '=' , r : '='
4294
+ } ) )
4295
+ . then ( check ( 'automargin keep bottom right' , { 'yaxis.automargin' : 'bottom right' } , {
4296
+ t : '=' , l : '=' ,
4297
+ b : '=' , r : '='
4298
+ } ) )
4299
+ . then ( check ( 'automargin keep height' , { 'yaxis.automargin' : 'height' } , {
4300
+ t : 'grew' , l : '=' ,
4301
+ b : '=' , r : '='
4302
+ } ) )
4303
+ . then ( check ( 'automargin keep top' , { 'yaxis.automargin' : 'top' } , {
4304
+ t : 'grew' , l : '=' ,
4305
+ b : '=' , r : '='
4306
+ } ) )
4307
+ . then ( check ( 'automargin not top' , { 'yaxis.automargin' : 'bottom width' } , {
4308
+ t : '=' , l : 'grew' ,
4309
+ b : '=' , r : '='
4310
+ } ) )
4311
+ . then ( check ( 'automargin keep left' , { 'yaxis.automargin' : 'left' } , {
4312
+ t : '=' , l : 'grew' ,
4313
+ b : '=' , r : '='
4314
+ } ) )
4315
+ . then ( check ( 'automargin keep width' , { 'yaxis.automargin' : 'width' } , {
4316
+ t : '=' , l : 'grew' ,
4317
+ b : '=' , r : '='
4318
+ } ) )
4319
+ . then ( check ( 'automargin x' , { 'xaxis.automargin' : true , 'yaxis.automargin' : false } , {
4320
+ t : '=' , l : '=' ,
4321
+ b : 'grew' , r : 'grew'
4322
+ } ) )
4323
+ . then ( check ( 'automargin not bottom' , { 'xaxis.automargin' : 'top width' } , {
4324
+ t : '=' , l : '=' ,
4325
+ b : '=' , r : 'grew'
4326
+ } ) )
4327
+ . then ( check ( 'automargin keep right' , { 'xaxis.automargin' : 'right' } , {
4328
+ t : '=' , l : '=' ,
4329
+ b : '=' , r : 'grew'
4330
+ } ) )
4331
+ . then ( check ( 'automargin keep bottom' , { 'xaxis.automargin' : 'bottom' } , {
4332
+ t : '=' , l : '=' ,
4333
+ b : 'grew' , r : '='
4334
+ } ) )
4335
+ . then ( check ( 'automargin keep top right' , { 'xaxis.automargin' : 'top right' } , {
4336
+ t : '=' , l : '=' ,
4337
+ b : '=' , r : 'grew'
4338
+ } ) )
4339
+ . then ( check ( 'automargin keep top left' , { 'xaxis.automargin' : 'top left' } , {
4340
+ t : '=' , l : '=' ,
4341
+ b : '=' , r : '='
4342
+ } ) )
4343
+ . then ( check ( 'automargin keep bottom left' , { 'xaxis.automargin' : 'bottom left' } , {
4344
+ t : '=' , l : '=' ,
4345
+ b : 'grew' , r : '='
4346
+ } ) )
4347
+ . then ( check ( 'turn off automargin' , { 'xaxis.automargin' : false , 'yaxis.automargin' : false } , {
4348
+ t : '=' , l : '=' ,
4349
+ b : '=' , r : '='
4350
+ } ) )
4351
+ . then ( done , done . fail ) ;
4352
+ } ) ;
4353
+
4228
4354
it ( 'should handle cases with free+mirror axes' , function ( done ) {
4229
4355
Plotly . newPlot ( gd , [ {
4230
4356
y : [ 1 , 2 , 1 ]
0 commit comments