@@ -3426,3 +3426,157 @@ describe('Test tickformatstops:', function() {
34263426 . then ( done ) ;
34273427 } ) ;
34283428} ) ;
3429+
3430+ describe ( 'Test axis title scoot:' , function ( ) {
3431+ var gd ;
3432+ var mathJaxScriptTag ;
3433+
3434+ beforeAll ( function ( done ) {
3435+ mathJaxScriptTag = document . createElement ( 'script' ) ;
3436+ mathJaxScriptTag . type = 'text/javascript' ;
3437+ mathJaxScriptTag . onload = function ( ) {
3438+ require ( '@src/fonts/mathjax_config' ) ( ) ;
3439+ done ( ) ;
3440+ } ;
3441+ mathJaxScriptTag . onerror = function ( ) {
3442+ fail ( 'MathJax failed to load' ) ;
3443+ } ;
3444+ mathJaxScriptTag . src = '/base/dist/extras/mathjax/MathJax.js?config=TeX-AMS-MML_SVG' ;
3445+ document . body . appendChild ( mathJaxScriptTag ) ;
3446+ } ) ;
3447+
3448+ beforeEach ( function ( ) {
3449+ gd = createGraphDiv ( ) ;
3450+ } ) ;
3451+
3452+ afterEach ( destroyGraphDiv ) ;
3453+
3454+ afterAll ( function ( ) {
3455+ document . body . removeChild ( mathJaxScriptTag ) ;
3456+ delete window . MathJax ;
3457+ } ) ;
3458+
3459+ function assertNoIntersect ( msg ) {
3460+ var gd3 = d3 . select ( gd ) ;
3461+ var xTitle = gd3 . select ( '.g-xtitle' ) ;
3462+ var xTicks = gd3 . selectAll ( '.xtick > text' ) ;
3463+
3464+ expect ( xTitle . size ( ) ) . toBe ( 1 , '1 x-axis title' ) ;
3465+ expect ( xTicks . size ( ) ) . toBeGreaterThan ( 1 , 'x-axis ticks' ) ;
3466+
3467+ var titleTop = xTitle . node ( ) . getBoundingClientRect ( ) . top ;
3468+
3469+ xTicks . each ( function ( _ , i ) {
3470+ var tickBottom = this . getBoundingClientRect ( ) . bottom ;
3471+ expect ( tickBottom ) . toBeLessThan ( titleTop , 'xtick #' + i + ' - ' + msg ) ;
3472+ } ) ;
3473+ }
3474+
3475+ function testTitleScoot ( fig , opts ) {
3476+ var xCategories = opts . xCategories ;
3477+
3478+ return Plotly . plot ( gd , fig )
3479+ . then ( function ( ) { assertNoIntersect ( 'base' ) ; } )
3480+ . then ( function ( ) { return Plotly . relayout ( gd , 'xaxis.titlefont.size' , 40 ) ; } )
3481+ . then ( function ( ) { assertNoIntersect ( 'large title font size' ) ; } )
3482+ . then ( function ( ) { return Plotly . relayout ( gd , 'xaxis.titlefont.size' , null ) ; } )
3483+ . then ( function ( ) { assertNoIntersect ( 'back to base' ) ; } )
3484+ . then ( function ( ) { return Plotly . relayout ( gd , 'xaxis.tickfont.size' , 40 ) ; } )
3485+ . then ( function ( ) { assertNoIntersect ( 'large title font size' ) ; } )
3486+ . then ( function ( ) { return Plotly . relayout ( gd , 'xaxis.tickfont.size' , null ) ; } )
3487+ . then ( function ( ) { assertNoIntersect ( 'back to base 2' ) ; } )
3488+ . then ( function ( ) { return Plotly . update ( gd , { x : [ xCategories ] } , { 'xaxis.tickangle' : 90 } ) ; } )
3489+ . then ( function ( ) { assertNoIntersect ( 'long tick labels' ) ; } )
3490+ . then ( function ( ) { return Plotly . update ( gd , { x : [ null ] } , { 'xaxis.tickangle' : null } ) ; } )
3491+ . then ( function ( ) { assertNoIntersect ( 'back to base 3' ) ; } ) ;
3492+ }
3493+
3494+ var longCats = [ 'aaaaaaaaa' , 'bbbbbbbbb' , 'cccccccc' ] ;
3495+ var texTitle = '$f(x) = \\int_0^\\infty \\psi(t) dt$' ;
3496+ var texCats = [ '$\\phi$' , '$\\nabla \\cdot \\vec{F}$' , '$\\frac{\\partial x}{\\partial y}$' ] ;
3497+ var longTexCats = [
3498+ '$\\int_0^\\infty \\psi(t) dt$' ,
3499+ '$\\alpha \\int_0^\\infty \\eta(t) dt$' ,
3500+ '$\\int_0^\\infty \\zeta(t) dt$'
3501+ ] ;
3502+
3503+ it ( 'should scoot x-axis title below x-axis ticks' , function ( done ) {
3504+ testTitleScoot ( {
3505+ data : [ {
3506+ y : [ 1 , 2 , 1 ]
3507+ } ] ,
3508+ layout : {
3509+ xaxis : { title : 'TITLE' } ,
3510+ width : 500 ,
3511+ height : 500 ,
3512+ margin : { t : 100 , b : 100 , l : 100 , r : 100 }
3513+ }
3514+ } , {
3515+ xCategories : longCats
3516+ } )
3517+ . catch ( failTest )
3518+ . then ( done ) ;
3519+ } ) ;
3520+
3521+ it ( 'should scoot x-axis title (with MathJax) below x-axis ticks' , function ( done ) {
3522+ expect ( window . MathJax ) . toBeDefined ( ) ;
3523+
3524+ testTitleScoot ( {
3525+ data : [ {
3526+ y : [ 1 , 2 , 1 ]
3527+ } ] ,
3528+ layout : {
3529+ xaxis : { title : texTitle } ,
3530+ width : 500 ,
3531+ height : 500 ,
3532+ margin : { t : 100 , b : 100 , l : 100 , r : 100 }
3533+ }
3534+ } , {
3535+ xCategories : longCats
3536+ } )
3537+ . catch ( failTest )
3538+ . then ( done ) ;
3539+ } ) ;
3540+
3541+ it ( 'should scoot x-axis title below x-axis ticks (with MathJax)' , function ( done ) {
3542+ expect ( window . MathJax ) . toBeDefined ( ) ;
3543+
3544+ testTitleScoot ( {
3545+ data : [ {
3546+ x : texCats ,
3547+ y : [ 1 , 2 , 1 ]
3548+ } ] ,
3549+ layout : {
3550+ xaxis : { title : 'TITLE' } ,
3551+ width : 500 ,
3552+ height : 500 ,
3553+ margin : { t : 100 , b : 100 , l : 100 , r : 100 }
3554+ }
3555+ } , {
3556+ xCategories : longTexCats
3557+ } )
3558+ . catch ( failTest )
3559+ . then ( done ) ;
3560+ } ) ;
3561+
3562+ it ( 'should scoot x-axis title (with MathJax) below x-axis ticks (with MathJax)' , function ( done ) {
3563+ expect ( window . MathJax ) . toBeDefined ( ) ;
3564+
3565+ testTitleScoot ( {
3566+ data : [ {
3567+ x : texCats ,
3568+ y : [ 1 , 2 , 1 ]
3569+ } ] ,
3570+ layout : {
3571+ xaxis : { title : texTitle } ,
3572+ width : 500 ,
3573+ height : 500 ,
3574+ margin : { t : 100 , b : 100 , l : 100 , r : 100 }
3575+ }
3576+ } , {
3577+ xCategories : longTexCats
3578+ } )
3579+ . catch ( failTest )
3580+ . then ( done ) ;
3581+ } ) ;
3582+ } ) ;
0 commit comments