@@ -2783,6 +2783,148 @@ describe('Test axes', function() {
27832783
27842784 } ) ;
27852785 } ) ;
2786+
2787+ describe ( 'zeroline visibility logic' , function ( ) {
2788+ var gd ;
2789+ beforeEach ( function ( ) {
2790+ gd = createGraphDiv ( ) ;
2791+ } ) ;
2792+ afterEach ( destroyGraphDiv ) ;
2793+
2794+ function assertZeroLines ( expectedIDs ) {
2795+ var sortedIDs = expectedIDs . slice ( ) . sort ( ) ;
2796+ var zlIDs = [ ] ;
2797+ d3 . select ( gd ) . selectAll ( '.zl' ) . each ( function ( ) {
2798+ var cls = d3 . select ( this ) . attr ( 'class' ) ;
2799+ var clsMatch = cls . match ( / [ x y ] \d * (? = z l ) / g) [ 0 ] ;
2800+ zlIDs . push ( clsMatch ) ;
2801+ } ) ;
2802+ zlIDs . sort ( ) ;
2803+ expect ( zlIDs ) . toEqual ( sortedIDs ) ;
2804+ }
2805+
2806+ it ( 'works with a single subplot' , function ( done ) {
2807+ Plotly . newPlot ( gd , [ { x : [ 1 , 2 , 3 ] , y : [ 1 , 2 , 3 ] } ] , {
2808+ xaxis : { range : [ 0 , 4 ] , showzeroline : true , showline : true } ,
2809+ yaxis : { range : [ 0 , 4 ] , showzeroline : true , showline : true } ,
2810+ width : 600 ,
2811+ height : 600
2812+ } )
2813+ . then ( function ( ) {
2814+ assertZeroLines ( [ ] ) ;
2815+ return Plotly . relayout ( gd , { 'xaxis.showline' : false } ) ;
2816+ } )
2817+ . then ( function ( ) {
2818+ assertZeroLines ( [ 'y' ] ) ;
2819+ return Plotly . relayout ( gd , { 'xaxis.showline' : true , 'yaxis.showline' : false } ) ;
2820+ } )
2821+ . then ( function ( ) {
2822+ assertZeroLines ( [ 'x' ] ) ;
2823+ return Plotly . relayout ( gd , { 'yaxis.showline' : true , 'yaxis.range' : [ 4 , 0 ] } ) ;
2824+ } )
2825+ . then ( function ( ) {
2826+ assertZeroLines ( [ 'y' ] ) ;
2827+ return Plotly . relayout ( gd , { 'xaxis.range' : [ 4 , 0 ] , 'xaxis.side' : 'top' } ) ;
2828+ } )
2829+ . then ( function ( ) {
2830+ assertZeroLines ( [ 'x' ] ) ;
2831+ return Plotly . relayout ( gd , { 'yaxis.side' : 'right' , 'xaxis.anchor' : 'free' , 'xaxis.position' : 1 } ) ;
2832+ } )
2833+ . then ( function ( ) {
2834+ assertZeroLines ( [ ] ) ;
2835+ return Plotly . relayout ( gd , { 'xaxis.range' : [ 0 , 4 ] , 'yaxis.range' : [ 0 , 4 ] } ) ;
2836+ } )
2837+ . then ( function ( ) {
2838+ assertZeroLines ( [ 'x' , 'y' ] ) ;
2839+ return Plotly . relayout ( gd , { 'xaxis.mirror' : 'all' , 'yaxis.mirror' : true } ) ;
2840+ } )
2841+ . then ( function ( ) {
2842+ assertZeroLines ( [ ] ) ;
2843+ return Plotly . relayout ( gd , { 'xaxis.range' : [ - 0.1 , 4 ] , 'yaxis.range' : [ - 0.1 , 4 ] } ) ;
2844+ } )
2845+ . then ( function ( ) {
2846+ assertZeroLines ( [ 'x' , 'y' ] ) ;
2847+ } )
2848+ . catch ( failTest )
2849+ . then ( done ) ;
2850+ } ) ;
2851+
2852+ it ( 'works with multiple coupled subplots' , function ( done ) {
2853+ Plotly . newPlot ( gd , [
2854+ { x : [ 1 , 2 , 3 ] , y : [ 1 , 2 , 3 ] } ,
2855+ { x : [ 1 , 2 , 3 ] , y : [ 1 , 2 , 3 ] , xaxis : 'x2' } ,
2856+ { x : [ 1 , 2 , 3 ] , y : [ 1 , 2 , 3 ] , yaxis : 'y2' }
2857+ ] , {
2858+ xaxis : { range : [ 0 , 4 ] , showzeroline : true , domain : [ 0 , 0.4 ] } ,
2859+ yaxis : { range : [ 0 , 4 ] , showzeroline : true , domain : [ 0 , 0.4 ] } ,
2860+ xaxis2 : { range : [ 0 , 4 ] , showzeroline : true , domain : [ 0.6 , 1 ] } ,
2861+ yaxis2 : { range : [ 0 , 4 ] , showzeroline : true , domain : [ 0.6 , 1 ] } ,
2862+ width : 600 ,
2863+ height : 600
2864+ } )
2865+ . then ( function ( ) {
2866+ assertZeroLines ( [ 'x' , 'x' , 'y' , 'y' , 'x2' , 'y2' ] ) ;
2867+ return Plotly . relayout ( gd , { 'xaxis.showline' : true , 'xaxis.mirror' : 'all' } ) ;
2868+ } )
2869+ . then ( function ( ) {
2870+ assertZeroLines ( [ 'x' , 'x' , 'y' , 'x2' ] ) ;
2871+ return Plotly . relayout ( gd , { 'yaxis.showline' : true , 'yaxis.mirror' : 'all' } ) ;
2872+ } )
2873+ . then ( function ( ) {
2874+ // x axis still has a zero line on xy2, and y on x2y
2875+ // all the others have disappeared now
2876+ assertZeroLines ( [ 'x' , 'y' ] ) ;
2877+ return Plotly . relayout ( gd , { 'xaxis.mirror' : 'allticks' , 'yaxis.mirror' : 'allticks' } ) ;
2878+ } )
2879+ . then ( function ( ) {
2880+ // allticks works the same as all
2881+ assertZeroLines ( [ 'x' , 'y' ] ) ;
2882+ } )
2883+ . catch ( failTest )
2884+ . then ( done ) ;
2885+ } ) ;
2886+
2887+ it ( 'works with multiple overlaid subplots' , function ( done ) {
2888+ Plotly . newPlot ( gd , [
2889+ { x : [ 1 , 2 , 3 ] , y : [ 1 , 2 , 3 ] } ,
2890+ { x : [ 1 , 2 , 3 ] , y : [ 1 , 2 , 3 ] , xaxis : 'x2' , yaxis : 'y2' }
2891+ ] , {
2892+ xaxis : { range : [ 0 , 4 ] , showzeroline : true } ,
2893+ yaxis : { range : [ 0 , 4 ] , showzeroline : true } ,
2894+ xaxis2 : { range : [ 0 , 4 ] , showzeroline : true , side : 'top' , overlaying : 'x' } ,
2895+ yaxis2 : { range : [ 0 , 4 ] , showzeroline : true , side : 'right' , overlaying : 'y' } ,
2896+ width : 600 ,
2897+ height : 600
2898+ } )
2899+ . then ( function ( ) {
2900+ assertZeroLines ( [ 'x' , 'y' , 'x2' , 'y2' ] ) ;
2901+ return Plotly . relayout ( gd , { 'xaxis.showline' : true , 'yaxis.showline' : true } ) ;
2902+ } )
2903+ . then ( function ( ) {
2904+ assertZeroLines ( [ ] ) ;
2905+ return Plotly . relayout ( gd , {
2906+ 'xaxis.range' : [ 4 , 0 ] ,
2907+ 'yaxis.range' : [ 4 , 0 ] ,
2908+ 'xaxis2.range' : [ 4 , 0 ] ,
2909+ 'yaxis2.range' : [ 4 , 0 ]
2910+ } ) ;
2911+ } )
2912+ . then ( function ( ) {
2913+ assertZeroLines ( [ 'x' , 'y' , 'x2' , 'y2' ] ) ;
2914+ return Plotly . relayout ( gd , {
2915+ 'xaxis.showline' : false ,
2916+ 'yaxis.showline' : false ,
2917+ 'xaxis2.showline' : true ,
2918+ 'yaxis2.showline' : true
2919+ } ) ;
2920+ } )
2921+ . then ( function ( ) {
2922+ assertZeroLines ( [ ] ) ;
2923+ } )
2924+ . catch ( failTest )
2925+ . then ( done ) ;
2926+ } ) ;
2927+ } ) ;
27862928} ) ;
27872929
27882930function getZoomInButton ( gd ) {
0 commit comments