@@ -19,7 +19,10 @@ var svgTextUtils = require('../../lib/svg_text_utils');
19
19
var axisIds = require ( '../../plots/cartesian/axis_ids' ) ;
20
20
var anchorUtils = require ( '../legend/anchor_utils' ) ;
21
21
22
- var LINE_SPACING = require ( '../../constants/alignment' ) . LINE_SPACING ;
22
+ var alignmentConstants = require ( '../../constants/alignment' ) ;
23
+ var LINE_SPACING = alignmentConstants . LINE_SPACING ;
24
+ var FROM_TL = alignmentConstants . FROM_TL ;
25
+ var FROM_BR = alignmentConstants . FROM_BR ;
23
26
24
27
var constants = require ( './constants' ) ;
25
28
var getUpdateObject = require ( './get_update_object' ) ;
@@ -58,7 +61,7 @@ module.exports = function draw(gd) {
58
61
var button = d3 . select ( this ) ;
59
62
var update = getUpdateObject ( axisLayout , d ) ;
60
63
61
- d . isActive = isActive ( axisLayout , d , update ) ;
64
+ d . _isActive = isActive ( axisLayout , d , update ) ;
62
65
63
66
button . call ( drawButtonRect , selectorLayout , d ) ;
64
67
button . call ( drawButtonText , selectorLayout , d , gd ) ;
@@ -70,22 +73,17 @@ module.exports = function draw(gd) {
70
73
} ) ;
71
74
72
75
button . on ( 'mouseover' , function ( ) {
73
- d . isHovered = true ;
76
+ d . _isHovered = true ;
74
77
button . call ( drawButtonRect , selectorLayout , d ) ;
75
78
} ) ;
76
79
77
80
button . on ( 'mouseout' , function ( ) {
78
- d . isHovered = false ;
81
+ d . _isHovered = false ;
79
82
button . call ( drawButtonRect , selectorLayout , d ) ;
80
83
} ) ;
81
84
} ) ;
82
85
83
- // N.B. this mutates selectorLayout
84
- reposition ( gd , buttons , selectorLayout , axisLayout . _name ) ;
85
-
86
- selector . attr ( 'transform' , 'translate(' +
87
- selectorLayout . lx + ',' + selectorLayout . ly +
88
- ')' ) ;
86
+ reposition ( gd , buttons , selectorLayout , axisLayout . _name , selector ) ;
89
87
} ) ;
90
88
91
89
} ;
@@ -143,7 +141,7 @@ function drawButtonRect(button, selectorLayout, d) {
143
141
}
144
142
145
143
function getFillColor ( selectorLayout , d ) {
146
- return ( d . isActive || d . isHovered ) ?
144
+ return ( d . _isActive || d . _isHovered ) ?
147
145
selectorLayout . activecolor :
148
146
selectorLayout . bgcolor ;
149
147
}
@@ -175,9 +173,9 @@ function getLabel(opts) {
175
173
return opts . count + opts . step . charAt ( 0 ) ;
176
174
}
177
175
178
- function reposition ( gd , buttons , opts , axName ) {
179
- opts . width = 0 ;
180
- opts . height = 0 ;
176
+ function reposition ( gd , buttons , opts , axName , selector ) {
177
+ var width = 0 ;
178
+ var height = 0 ;
181
179
182
180
var borderWidth = opts . borderwidth ;
183
181
@@ -188,7 +186,7 @@ function reposition(gd, buttons, opts, axName) {
188
186
var tHeight = opts . font . size * LINE_SPACING ;
189
187
var hEff = Math . max ( tHeight * svgTextUtils . lineCount ( text ) , 16 ) + 3 ;
190
188
191
- opts . height = Math . max ( opts . height , hEff ) ;
189
+ height = Math . max ( height , hEff ) ;
192
190
} ) ;
193
191
194
192
buttons . each ( function ( ) {
@@ -207,59 +205,59 @@ function reposition(gd, buttons, opts, axName) {
207
205
// TODO add buttongap attribute
208
206
209
207
button . attr ( 'transform' , 'translate(' +
210
- ( borderWidth + opts . width ) + ',' + borderWidth +
208
+ ( borderWidth + width ) + ',' + borderWidth +
211
209
')' ) ;
212
210
213
211
rect . attr ( {
214
212
x : 0 ,
215
213
y : 0 ,
216
214
width : wEff ,
217
- height : opts . height
215
+ height : height
218
216
} ) ;
219
217
220
218
svgTextUtils . positionText ( text , wEff / 2 ,
221
- opts . height / 2 - ( ( tLines - 1 ) * tHeight / 2 ) + 3 ) ;
219
+ height / 2 - ( ( tLines - 1 ) * tHeight / 2 ) + 3 ) ;
222
220
223
- opts . width += wEff + 5 ;
221
+ width += wEff + 5 ;
224
222
} ) ;
225
223
226
- buttons . selectAll ( 'rect' ) . attr ( 'height' , opts . height ) ;
227
-
228
224
var graphSize = gd . _fullLayout . _size ;
229
- opts . lx = graphSize . l + graphSize . w * opts . x ;
230
- opts . ly = graphSize . t + graphSize . h * ( 1 - opts . y ) ;
225
+ var lx = graphSize . l + graphSize . w * opts . x ;
226
+ var ly = graphSize . t + graphSize . h * ( 1 - opts . y ) ;
231
227
232
228
var xanchor = 'left' ;
233
229
if ( anchorUtils . isRightAnchor ( opts ) ) {
234
- opts . lx -= opts . width ;
230
+ lx -= width ;
235
231
xanchor = 'right' ;
236
232
}
237
233
if ( anchorUtils . isCenterAnchor ( opts ) ) {
238
- opts . lx -= opts . width / 2 ;
234
+ lx -= width / 2 ;
239
235
xanchor = 'center' ;
240
236
}
241
237
242
238
var yanchor = 'top' ;
243
239
if ( anchorUtils . isBottomAnchor ( opts ) ) {
244
- opts . ly -= opts . height ;
240
+ ly -= height ;
245
241
yanchor = 'bottom' ;
246
242
}
247
243
if ( anchorUtils . isMiddleAnchor ( opts ) ) {
248
- opts . ly -= opts . height / 2 ;
244
+ ly -= height / 2 ;
249
245
yanchor = 'middle' ;
250
246
}
251
247
252
- opts . width = Math . ceil ( opts . width ) ;
253
- opts . height = Math . ceil ( opts . height ) ;
254
- opts . lx = Math . round ( opts . lx ) ;
255
- opts . ly = Math . round ( opts . ly ) ;
248
+ width = Math . ceil ( width ) ;
249
+ height = Math . ceil ( height ) ;
250
+ lx = Math . round ( lx ) ;
251
+ ly = Math . round ( ly ) ;
256
252
257
253
Plots . autoMargin ( gd , axName + '-range-selector' , {
258
254
x : opts . x ,
259
255
y : opts . y ,
260
- l : opts . width * ( { right : 1 , center : 0.5 } [ xanchor ] || 0 ) ,
261
- r : opts . width * ( { left : 1 , center : 0.5 } [ xanchor ] || 0 ) ,
262
- b : opts . height * ( { top : 1 , middle : 0.5 } [ yanchor ] || 0 ) ,
263
- t : opts . height * ( { bottom : 1 , middle : 0.5 } [ yanchor ] || 0 )
256
+ l : width * FROM_TL [ xanchor ] ,
257
+ r : width * FROM_BR [ xanchor ] ,
258
+ b : height * FROM_BR [ yanchor ] ,
259
+ t : height * FROM_TL [ yanchor ]
264
260
} ) ;
261
+
262
+ selector . attr ( 'transform' , 'translate(' + lx + ',' + ly + ')' ) ;
265
263
}
0 commit comments