@@ -659,6 +659,88 @@ describe('subplot creation / deletion:', function() {
659659 . then ( done ) ;
660660 } ) ;
661661
662+ it ( 'should clear obsolete content out of axis layers when changing overlaying configuation' , function ( done ) {
663+ function data ( ) {
664+ return [
665+ { x : [ 1 , 2 ] , y : [ 1 , 2 ] } ,
666+ { x : [ 1 , 2 ] , y : [ 1 , 2 ] , xaxis : 'x2' , yaxis : 'y2' }
667+ ] ;
668+ }
669+
670+ function fig0 ( ) {
671+ return {
672+ data : data ( ) ,
673+ layout : {
674+ xaxis2 : { side : 'top' , overlaying : 'x' } ,
675+ yaxis2 : { side : 'right' , overlaying : 'y' }
676+ }
677+ } ;
678+ }
679+
680+ function fig1 ( ) {
681+ return {
682+ data : data ( ) ,
683+ layout : {
684+ xaxis2 : { side : 'top' , domain : [ 0.37 , 1 ] } ,
685+ yaxis2 : { side : 'right' , overlaying : 'y' }
686+ }
687+ } ;
688+ }
689+
690+ function getParentClassName ( query , level ) {
691+ level = level || 1 ;
692+ var cl = gd . querySelector ( 'g.cartesianlayer' ) ;
693+ var node = cl . querySelector ( query ) ;
694+ while ( level -- ) node = node . parentNode ;
695+ return node . getAttribute ( 'class' ) ;
696+ }
697+
698+ function _assert ( msg , exp ) {
699+ expect ( getParentClassName ( '.xtick' ) )
700+ . toBe ( exp . xtickParent , 'xitck parent - ' + msg ) ;
701+ expect ( getParentClassName ( '.x2tick' ) )
702+ . toBe ( exp . x2tickParent , 'x2tick parent - ' + msg ) ;
703+ expect ( getParentClassName ( '.trace' + gd . _fullData [ 0 ] . uid , 2 ) )
704+ . toBe ( exp . trace0Parent , 'data[0] parent - ' + msg ) ;
705+ expect ( getParentClassName ( '.trace' + gd . _fullData [ 1 ] . uid , 2 ) )
706+ . toBe ( exp . trace1Parent , 'data[1] parent - ' + msg ) ;
707+ }
708+
709+ Plotly . react ( gd , fig0 ( ) )
710+ . then ( function ( ) {
711+ _assert ( 'x2/y2 both overlays' , {
712+ xtickParent : 'xaxislayer-above' ,
713+ x2tickParent : 'x2y2-x' ,
714+ trace0Parent : 'plot' ,
715+ trace1Parent : 'x2y2'
716+ } ) ;
717+ } )
718+ . then ( function ( ) {
719+ return Plotly . react ( gd , fig1 ( ) ) ;
720+ } )
721+ . then ( function ( ) {
722+ _assert ( 'x2 free / y2 overlaid' , {
723+ xtickParent : 'xaxislayer-above' ,
724+ x2tickParent : 'xaxislayer-above' ,
725+ trace0Parent : 'plot' ,
726+ trace1Parent : 'plot'
727+ } ) ;
728+ } )
729+ . then ( function ( ) {
730+ return Plotly . react ( gd , fig0 ( ) ) ;
731+ } )
732+ . then ( function ( ) {
733+ _assert ( 'back to x2/y2 both overlays' , {
734+ xtickParent : 'xaxislayer-above' ,
735+ x2tickParent : 'x2y2-x' ,
736+ trace0Parent : 'plot' ,
737+ trace1Parent : 'x2y2'
738+ } ) ;
739+ } )
740+ . catch ( failTest )
741+ . then ( done ) ;
742+ } ) ;
743+
662744 it ( 'clear axis ticks, labels and title when relayout an axis to `*visible:false*' , function ( done ) {
663745 function _assert ( xaxis , yaxis ) {
664746 var g = d3 . select ( '.subplot.xy' ) ;
0 commit comments