@@ -77,20 +77,16 @@ module.exports = function(gd) {
77
77
// for all present range sliders
78
78
rangeSliders . each ( function ( axisOpts ) {
79
79
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 ) ] ;
88
82
89
83
// update range slider dimensions
90
84
91
85
var margin = fullLayout . margin ,
92
86
graphSize = fullLayout . _size ,
93
- domain = axisOpts . domain ;
87
+ domain = axisOpts . domain ,
88
+ oppDomain = oppAxisOpts . domain ,
89
+ tickHeight = ( axisOpts . _boundingBox || { } ) . height || 0 ;
94
90
95
91
opts . _id = constants . name + axisOpts . _id ;
96
92
opts . _clipId = opts . _id + '-' + fullLayout . _uid ;
@@ -99,8 +95,13 @@ module.exports = function(gd) {
99
95
opts . _height = ( fullLayout . height - margin . b - margin . t ) * opts . thickness ;
100
96
opts . _offsetShift = Math . floor ( opts . borderwidth / 2 ) ;
101
97
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
+ ) ;
104
105
105
106
rangeSlider . attr ( 'transform' , 'translate(' + x + ',' + y + ')' ) ;
106
107
@@ -138,23 +139,33 @@ module.exports = function(gd) {
138
139
139
140
// update margins
140
141
141
- var bb = axisOpts . _boundingBox ? axisOpts . _boundingBox . height : 0 ;
142
-
143
142
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
147
150
} ) ;
151
+
148
152
} ) ;
149
153
} ;
150
154
151
155
function 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 = [ ] ;
156
159
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 ;
158
169
}
159
170
160
171
function setupDragElement ( rangeSlider , gd , axisOpts , opts ) {
@@ -236,16 +247,21 @@ function setDataRange(rangeSlider, gd, axisOpts, opts) {
236
247
dataMax = clamp ( opts . p2d ( opts . _pixelMax ) ) ;
237
248
238
249
window . requestAnimationFrame ( function ( ) {
239
- Plotly . relayout ( gd , 'xaxis .range', [ dataMin , dataMax ] ) ;
250
+ Plotly . relayout ( gd , axisOpts . _name + ' .range', [ dataMin , dataMax ] ) ;
240
251
} ) ;
241
252
}
242
253
243
254
function setPixelRange ( rangeSlider , gd , axisOpts , opts ) {
255
+ var hw2 = constants . handleWidth / 2 ;
244
256
245
257
function clamp ( v ) {
246
258
return Lib . constrain ( v , 0 , opts . _width ) ;
247
259
}
248
260
261
+ function clampHandle ( v ) {
262
+ return Lib . constrain ( v , - hw2 , opts . _width + hw2 ) ;
263
+ }
264
+
249
265
var pixelMin = clamp ( opts . d2p ( axisOpts . _rl [ 0 ] ) ) ,
250
266
pixelMax = clamp ( opts . d2p ( axisOpts . _rl [ 1 ] ) ) ;
251
267
@@ -260,11 +276,18 @@ function setPixelRange(rangeSlider, gd, axisOpts, opts) {
260
276
. attr ( 'x' , pixelMax )
261
277
. attr ( 'width' , opts . _width - pixelMax ) ;
262
278
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
+
263
286
rangeSlider . select ( 'g.' + constants . grabberMinClassName )
264
- . attr ( 'transform' , 'translate(' + ( pixelMin - constants . handleWidth - 1 ) + ',0 )' ) ;
287
+ . attr ( 'transform' , 'translate(' + xMin + ',' + offset + ')' ) ;
265
288
266
289
rangeSlider . select ( 'g.' + constants . grabberMaxClassName )
267
- . attr ( 'transform' , 'translate(' + pixelMax + ',0 )' ) ;
290
+ . attr ( 'transform' , 'translate(' + xMax + ',' + offset + ' )') ;
268
291
}
269
292
270
293
function drawBg ( rangeSlider , gd , axisOpts , opts ) {
@@ -284,14 +307,15 @@ function drawBg(rangeSlider, gd, axisOpts, opts) {
284
307
opts . borderwidth - 1 ;
285
308
286
309
var offsetShift = - opts . _offsetShift ;
310
+ var lw = Drawing . crispRound ( gd , opts . borderwidth ) ;
287
311
288
312
bg . attr ( {
289
313
width : opts . _width + borderCorrect ,
290
314
height : opts . _height + borderCorrect ,
291
315
transform : 'translate(' + offsetShift + ',' + offsetShift + ')' ,
292
316
fill : opts . bgcolor ,
293
317
stroke : opts . bordercolor ,
294
- 'stroke-width' : opts . borderwidth ,
318
+ 'stroke-width' : lw
295
319
} ) ;
296
320
}
297
321
@@ -404,7 +428,8 @@ function drawMasks(rangeSlider, gd, axisOpts, opts) {
404
428
405
429
maskMin . enter ( ) . append ( 'rect' )
406
430
. classed ( constants . maskMinClassName , true )
407
- . attr ( { x : 0 , y : 0 } ) ;
431
+ . attr ( { x : 0 , y : 0 } )
432
+ . attr ( 'shape-rendering' , 'crispEdges' ) ;
408
433
409
434
maskMin
410
435
. attr ( 'height' , opts . _height )
@@ -415,7 +440,8 @@ function drawMasks(rangeSlider, gd, axisOpts, opts) {
415
440
416
441
maskMax . enter ( ) . append ( 'rect' )
417
442
. classed ( constants . maskMaxClassName , true )
418
- . attr ( 'y' , 0 ) ;
443
+ . attr ( 'y' , 0 )
444
+ . attr ( 'shape-rendering' , 'crispEdges' ) ;
419
445
420
446
maskMax
421
447
. attr ( 'height' , opts . _height )
@@ -431,7 +457,8 @@ function drawSlideBox(rangeSlider, gd, axisOpts, opts) {
431
457
slideBox . enter ( ) . append ( 'rect' )
432
458
. classed ( constants . slideBoxClassName , true )
433
459
. attr ( 'y' , 0 )
434
- . attr ( 'cursor' , constants . slideBoxCursor ) ;
460
+ . attr ( 'cursor' , constants . slideBoxCursor )
461
+ . attr ( 'shape-rendering' , 'crispEdges' ) ;
435
462
436
463
slideBox . attr ( {
437
464
height : opts . _height ,
@@ -459,14 +486,15 @@ function drawGrabbers(rangeSlider, gd, axisOpts, opts) {
459
486
x : 0 ,
460
487
width : constants . handleWidth ,
461
488
rx : constants . handleRadius ,
462
- fill : constants . handleFill ,
463
- stroke : constants . handleStroke ,
489
+ fill : Color . background ,
490
+ stroke : Color . defaultLine ,
491
+ 'stroke-width' : constants . handleStrokeWidth ,
464
492
'shape-rendering' : 'crispEdges'
465
493
} ;
466
494
467
495
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 ) ,
470
498
} ;
471
499
472
500
var handleMin = grabberMin . selectAll ( 'rect.' + constants . handleMinClassName )
@@ -489,6 +517,7 @@ function drawGrabbers(rangeSlider, gd, axisOpts, opts) {
489
517
490
518
var grabAreaFixAttrs = {
491
519
width : constants . grabAreaWidth ,
520
+ x : 0 ,
492
521
y : 0 ,
493
522
fill : constants . grabAreaFill ,
494
523
cursor : constants . grabAreaCursor
@@ -499,20 +528,14 @@ function drawGrabbers(rangeSlider, gd, axisOpts, opts) {
499
528
grabAreaMin . enter ( ) . append ( 'rect' )
500
529
. classed ( constants . grabAreaMinClassName , true )
501
530
. attr ( grabAreaFixAttrs ) ;
502
- grabAreaMin . attr ( {
503
- x : constants . grabAreaMinOffset ,
504
- height : opts . _height
505
- } ) ;
531
+ grabAreaMin . attr ( 'height' , opts . _height ) ;
506
532
507
533
var grabAreaMax = grabberMax . selectAll ( 'rect.' + constants . grabAreaMaxClassName )
508
534
. data ( [ 0 ] ) ;
509
535
grabAreaMax . enter ( ) . append ( 'rect' )
510
536
. classed ( constants . grabAreaMaxClassName , true )
511
537
. attr ( grabAreaFixAttrs ) ;
512
- grabAreaMax . attr ( {
513
- x : constants . grabAreaMaxOffset ,
514
- height : opts . _height
515
- } ) ;
538
+ grabAreaMax . attr ( 'height' , opts . _height ) ;
516
539
}
517
540
518
541
function clearPushMargins ( gd ) {
0 commit comments