@@ -36,10 +36,20 @@ module.exports = function draw(gd) {
36
36
. classed ( constants . containerClassName , true )
37
37
. style ( 'cursor' , 'ew-resize' ) ;
38
38
39
- sliders . exit ( ) . remove ( ) ;
39
+ function clearSlider ( sliderOpts ) {
40
+ if ( sliderOpts . _commandObserver ) {
41
+ sliderOpts . _commandObserver . remove ( ) ;
42
+ delete sliderOpts . _commandObserver ;
43
+ }
44
+
45
+ Plots . autoMargin ( gd , autoMarginId ( sliderOpts ) ) ;
46
+ }
40
47
41
- // If no more sliders, clear the margisn:
42
- if ( sliders . exit ( ) . size ( ) ) clearPushMargins ( gd ) ;
48
+ sliders . exit ( ) . each ( function ( ) {
49
+ d3 . select ( this ) . selectAll ( 'g.' + constants . groupClassName )
50
+ . each ( clearSlider ) ;
51
+ } )
52
+ . remove ( ) ;
43
53
44
54
// Return early if no menus visible:
45
55
if ( sliderData . length === 0 ) return ;
@@ -50,14 +60,9 @@ module.exports = function draw(gd) {
50
60
sliderGroups . enter ( ) . append ( 'g' )
51
61
. classed ( constants . groupClassName , true ) ;
52
62
53
- sliderGroups . exit ( ) . each ( function ( sliderOpts ) {
54
- d3 . select ( this ) . remove ( ) ;
55
-
56
- sliderOpts . _commandObserver . remove ( ) ;
57
- delete sliderOpts . _commandObserver ;
58
-
59
- Plots . autoMargin ( gd , constants . autoMarginIdRoot + sliderOpts . _index ) ;
60
- } ) ;
63
+ sliderGroups . exit ( )
64
+ . each ( clearSlider )
65
+ . remove ( ) ;
61
66
62
67
// Find the dimensions of the sliders:
63
68
for ( var i = 0 ; i < sliderData . length ; i ++ ) {
@@ -92,6 +97,10 @@ module.exports = function draw(gd) {
92
97
} ) ;
93
98
} ;
94
99
100
+ function autoMarginId ( sliderOpts ) {
101
+ return constants . autoMarginIdRoot + sliderOpts . _index ;
102
+ }
103
+
95
104
// This really only just filters by visibility:
96
105
function makeSliderData ( fullLayout , gd ) {
97
106
var contOpts = fullLayout [ constants . name ] ,
@@ -239,7 +248,7 @@ function findDimensions(gd, sliderOpts) {
239
248
marginOpts . r = dims . outerLength * FROM_BR [ xanchor ] ;
240
249
}
241
250
242
- Plots . autoMargin ( gd , constants . autoMarginIdRoot + sliderOpts . _index , marginOpts ) ;
251
+ Plots . autoMargin ( gd , autoMarginId ( sliderOpts ) , marginOpts ) ;
243
252
}
244
253
245
254
function drawSlider ( gd , sliderGroup , sliderOpts ) {
@@ -605,16 +614,3 @@ function drawRail(sliderGroup, sliderOpts) {
605
614
( dims . inputAreaWidth - constants . railWidth ) * 0.5 + dims . currentValueTotalHeight
606
615
) ;
607
616
}
608
-
609
- function clearPushMargins ( gd ) {
610
- var pushMargins = gd . _fullLayout . _pushmargin || { } ,
611
- keys = Object . keys ( pushMargins ) ;
612
-
613
- for ( var i = 0 ; i < keys . length ; i ++ ) {
614
- var k = keys [ i ] ;
615
-
616
- if ( k . indexOf ( constants . autoMarginIdRoot ) !== - 1 ) {
617
- Plots . autoMargin ( gd , k ) ;
618
- }
619
- }
620
- }
0 commit comments