@@ -77,20 +77,16 @@ module.exports = function(gd) {
7777 // for all present range sliders
7878 rangeSliders . each ( function ( axisOpts ) {
7979 var rangeSlider = d3 . select ( this ) ,
80- opts = axisOpts [ constants . name ] ;
81-
82- // compute new slider range using axis autorange if necessary
83- // copy back range to input range slider container to skip
84- // this step in subsequent draw calls
85- if ( ! opts . range ) {
86- opts . _input . range = opts . range = Axes . getAutoRange ( axisOpts ) ;
87- }
80+ opts = axisOpts [ constants . name ] ,
81+ oppAxisOpts = fullLayout [ Axes . id2name ( axisOpts . anchor ) ] ;
8882
8983 // update range slider dimensions
9084
9185 var margin = fullLayout . margin ,
9286 graphSize = fullLayout . _size ,
93- domain = axisOpts . domain ;
87+ domain = axisOpts . domain ,
88+ oppDomain = oppAxisOpts . domain ,
89+ tickHeight = ( axisOpts . _boundingBox || { } ) . height || 0 ;
9490
9591 opts . _id = constants . name + axisOpts . _id ;
9692 opts . _clipId = opts . _id + '-' + fullLayout . _uid ;
@@ -99,8 +95,13 @@ module.exports = function(gd) {
9995 opts . _height = ( fullLayout . height - margin . b - margin . t ) * opts . thickness ;
10096 opts . _offsetShift = Math . floor ( opts . borderwidth / 2 ) ;
10197
102- var x = margin . l + ( graphSize . w * domain [ 0 ] ) ,
103- y = fullLayout . height - opts . _height - margin . b ;
98+ var x = Math . round ( margin . l + ( graphSize . w * domain [ 0 ] ) ) ;
99+
100+ var y = Math . round (
101+ margin . t + graphSize . h * ( 1 - oppDomain [ 0 ] ) +
102+ tickHeight +
103+ opts . _offsetShift + constants . extraPad
104+ ) ;
104105
105106 rangeSlider . attr ( 'transform' , 'translate(' + x + ',' + y + ')' ) ;
106107
@@ -138,23 +139,33 @@ module.exports = function(gd) {
138139
139140 // update margins
140141
141- var bb = axisOpts . _boundingBox ? axisOpts . _boundingBox . height : 0 ;
142-
143142 Plots . autoMargin ( gd , opts . _id , {
144- x : 0 , y : 0 , l : 0 , r : 0 , t : 0 ,
145- b : opts . _height + fullLayout . margin . b + bb ,
146- pad : 15 + opts . _offsetShift * 2
143+ x : domain [ 0 ] ,
144+ y : oppDomain [ 0 ] ,
145+ l : 0 ,
146+ r : 0 ,
147+ t : 0 ,
148+ b : opts . _height + margin . b + tickHeight ,
149+ pad : constants . extraPad + opts . _offsetShift * 2
147150 } ) ;
151+
148152 } ) ;
149153} ;
150154
151155function makeRangeSliderData ( fullLayout ) {
152- if ( ! fullLayout . xaxis ) return [ ] ;
153- if ( ! fullLayout . xaxis [ constants . name ] ) return [ ] ;
154- if ( ! fullLayout . xaxis [ constants . name ] . visible ) return [ ] ;
155- if ( fullLayout . _has ( 'gl2d' ) ) return [ ] ;
156+ var axes = Axes . list ( { _fullLayout : fullLayout } , 'x' , true ) ,
157+ name = constants . name ,
158+ out = [ ] ;
156159
157- return [ fullLayout . xaxis ] ;
160+ if ( fullLayout . _has ( 'gl2d' ) ) return out ;
161+
162+ for ( var i = 0 ; i < axes . length ; i ++ ) {
163+ var ax = axes [ i ] ;
164+
165+ if ( ax [ name ] && ax [ name ] . visible ) out . push ( ax ) ;
166+ }
167+
168+ return out ;
158169}
159170
160171function setupDragElement ( rangeSlider , gd , axisOpts , opts ) {
@@ -236,16 +247,21 @@ function setDataRange(rangeSlider, gd, axisOpts, opts) {
236247 dataMax = clamp ( opts . p2d ( opts . _pixelMax ) ) ;
237248
238249 window . requestAnimationFrame ( function ( ) {
239- Plotly . relayout ( gd , 'xaxis .range', [ dataMin , dataMax ] ) ;
250+ Plotly . relayout ( gd , axisOpts . _name + ' .range', [ dataMin , dataMax ] ) ;
240251 } ) ;
241252}
242253
243254function setPixelRange ( rangeSlider , gd , axisOpts , opts ) {
255+ var hw2 = constants . handleWidth / 2 ;
244256
245257 function clamp ( v ) {
246258 return Lib . constrain ( v , 0 , opts . _width ) ;
247259 }
248260
261+ function clampHandle ( v ) {
262+ return Lib . constrain ( v , - hw2 , opts . _width + hw2 ) ;
263+ }
264+
249265 var pixelMin = clamp ( opts . d2p ( axisOpts . _rl [ 0 ] ) ) ,
250266 pixelMax = clamp ( opts . d2p ( axisOpts . _rl [ 1 ] ) ) ;
251267
@@ -260,11 +276,18 @@ function setPixelRange(rangeSlider, gd, axisOpts, opts) {
260276 . attr ( 'x' , pixelMax )
261277 . attr ( 'width' , opts . _width - pixelMax ) ;
262278
279+ // add offset for crispier corners
280+ // https://github.com/plotly/plotly.js/pull/1409
281+ var offset = 0.5 ;
282+
283+ var xMin = Math . round ( clampHandle ( pixelMin - hw2 ) ) - offset ,
284+ xMax = Math . round ( clampHandle ( pixelMax - hw2 ) ) + offset ;
285+
263286 rangeSlider . select ( 'g.' + constants . grabberMinClassName )
264- . attr ( 'transform' , 'translate(' + ( pixelMin - constants . handleWidth - 1 ) + ',0 )' ) ;
287+ . attr ( 'transform' , 'translate(' + xMin + ',' + offset + ')' ) ;
265288
266289 rangeSlider . select ( 'g.' + constants . grabberMaxClassName )
267- . attr ( 'transform' , 'translate(' + pixelMax + ',0 )' ) ;
290+ . attr ( 'transform' , 'translate(' + xMax + ',' + offset + ' )') ;
268291}
269292
270293function drawBg ( rangeSlider , gd , axisOpts , opts ) {
@@ -284,14 +307,15 @@ function drawBg(rangeSlider, gd, axisOpts, opts) {
284307 opts . borderwidth - 1 ;
285308
286309 var offsetShift = - opts . _offsetShift ;
310+ var lw = Drawing . crispRound ( gd , opts . borderwidth ) ;
287311
288312 bg . attr ( {
289313 width : opts . _width + borderCorrect ,
290314 height : opts . _height + borderCorrect ,
291315 transform : 'translate(' + offsetShift + ',' + offsetShift + ')' ,
292316 fill : opts . bgcolor ,
293317 stroke : opts . bordercolor ,
294- 'stroke-width' : opts . borderwidth ,
318+ 'stroke-width' : lw
295319 } ) ;
296320}
297321
@@ -404,7 +428,8 @@ function drawMasks(rangeSlider, gd, axisOpts, opts) {
404428
405429 maskMin . enter ( ) . append ( 'rect' )
406430 . classed ( constants . maskMinClassName , true )
407- . attr ( { x : 0 , y : 0 } ) ;
431+ . attr ( { x : 0 , y : 0 } )
432+ . attr ( 'shape-rendering' , 'crispEdges' ) ;
408433
409434 maskMin
410435 . attr ( 'height' , opts . _height )
@@ -415,7 +440,8 @@ function drawMasks(rangeSlider, gd, axisOpts, opts) {
415440
416441 maskMax . enter ( ) . append ( 'rect' )
417442 . classed ( constants . maskMaxClassName , true )
418- . attr ( 'y' , 0 ) ;
443+ . attr ( 'y' , 0 )
444+ . attr ( 'shape-rendering' , 'crispEdges' ) ;
419445
420446 maskMax
421447 . attr ( 'height' , opts . _height )
@@ -431,7 +457,8 @@ function drawSlideBox(rangeSlider, gd, axisOpts, opts) {
431457 slideBox . enter ( ) . append ( 'rect' )
432458 . classed ( constants . slideBoxClassName , true )
433459 . attr ( 'y' , 0 )
434- . attr ( 'cursor' , constants . slideBoxCursor ) ;
460+ . attr ( 'cursor' , constants . slideBoxCursor )
461+ . attr ( 'shape-rendering' , 'crispEdges' ) ;
435462
436463 slideBox . attr ( {
437464 height : opts . _height ,
@@ -459,14 +486,15 @@ function drawGrabbers(rangeSlider, gd, axisOpts, opts) {
459486 x : 0 ,
460487 width : constants . handleWidth ,
461488 rx : constants . handleRadius ,
462- fill : constants . handleFill ,
463- stroke : constants . handleStroke ,
489+ fill : Color . background ,
490+ stroke : Color . defaultLine ,
491+ 'stroke-width' : constants . handleStrokeWidth ,
464492 'shape-rendering' : 'crispEdges'
465493 } ;
466494
467495 var handleDynamicAttrs = {
468- y : opts . _height / 4 ,
469- height : opts . _height / 2 ,
496+ y : Math . round ( opts . _height / 4 ) ,
497+ height : Math . round ( opts . _height / 2 ) ,
470498 } ;
471499
472500 var handleMin = grabberMin . selectAll ( 'rect.' + constants . handleMinClassName )
@@ -489,6 +517,7 @@ function drawGrabbers(rangeSlider, gd, axisOpts, opts) {
489517
490518 var grabAreaFixAttrs = {
491519 width : constants . grabAreaWidth ,
520+ x : 0 ,
492521 y : 0 ,
493522 fill : constants . grabAreaFill ,
494523 cursor : constants . grabAreaCursor
@@ -499,20 +528,14 @@ function drawGrabbers(rangeSlider, gd, axisOpts, opts) {
499528 grabAreaMin . enter ( ) . append ( 'rect' )
500529 . classed ( constants . grabAreaMinClassName , true )
501530 . attr ( grabAreaFixAttrs ) ;
502- grabAreaMin . attr ( {
503- x : constants . grabAreaMinOffset ,
504- height : opts . _height
505- } ) ;
531+ grabAreaMin . attr ( 'height' , opts . _height ) ;
506532
507533 var grabAreaMax = grabberMax . selectAll ( 'rect.' + constants . grabAreaMaxClassName )
508534 . data ( [ 0 ] ) ;
509535 grabAreaMax . enter ( ) . append ( 'rect' )
510536 . classed ( constants . grabAreaMaxClassName , true )
511537 . attr ( grabAreaFixAttrs ) ;
512- grabAreaMax . attr ( {
513- x : constants . grabAreaMaxOffset ,
514- height : opts . _height
515- } ) ;
538+ grabAreaMax . attr ( 'height' , opts . _height ) ;
516539}
517540
518541function clearPushMargins ( gd ) {
0 commit comments