@@ -77,7 +77,9 @@ 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 ] ;
80+ opts = axisOpts [ constants . name ] ,
81+ oppAxisOpts = fullLayout [ Axes . id2name ( axisOpts . anchor ) ] ,
82+ oppAxisRangeOpts = opts [ Axes . id2name ( axisOpts . anchor ) ] ;
8183
8284 // update range
8385 // Expand slider range to the axis range
@@ -141,21 +143,31 @@ module.exports = function(gd) {
141143
142144 opts . _rl = [ range0 , range1 ] ;
143145
146+ if ( oppAxisRangeOpts . rangemode !== 'match' ) {
147+ var range0OppAxis = oppAxisOpts . r2l ( oppAxisRangeOpts . range [ 0 ] ) ,
148+ range1OppAxis = oppAxisOpts . r2l ( oppAxisRangeOpts . range [ 1 ] ) ,
149+ distOppAxis = range1OppAxis - range0OppAxis ;
150+
151+ opts . d2pOppAxis = function ( v ) {
152+ return ( v - range0OppAxis ) / distOppAxis * opts . _height ;
153+ } ;
154+ }
155+
144156 // update inner nodes
145157
146158 rangeSlider
147159 . call ( drawBg , gd , axisOpts , opts )
148160 . call ( addClipPath , gd , axisOpts , opts )
149161 . call ( drawRangePlot , gd , axisOpts , opts )
150- . call ( drawMasks , gd , axisOpts , opts )
162+ . call ( drawMasks , gd , axisOpts , opts , oppAxisRangeOpts )
151163 . call ( drawSlideBox , gd , axisOpts , opts )
152164 . call ( drawGrabbers , gd , axisOpts , opts ) ;
153165
154166 // setup drag element
155167 setupDragElement ( rangeSlider , gd , axisOpts , opts ) ;
156168
157169 // update current range
158- setPixelRange ( rangeSlider , gd , axisOpts , opts ) ;
170+ setPixelRange ( rangeSlider , gd , axisOpts , opts , oppAxisOpts , oppAxisRangeOpts ) ;
159171
160172 // title goes next to range slider instead of tick labels, so
161173 // just take it over and draw it from here
@@ -284,13 +296,17 @@ function setDataRange(rangeSlider, gd, axisOpts, opts) {
284296 } ) ;
285297}
286298
287- function setPixelRange ( rangeSlider , gd , axisOpts , opts ) {
299+ function setPixelRange ( rangeSlider , gd , axisOpts , opts , oppAxisOpts , oppAxisRangeOpts ) {
288300 var hw2 = constants . handleWidth / 2 ;
289301
290302 function clamp ( v ) {
291303 return Lib . constrain ( v , 0 , opts . _width ) ;
292304 }
293305
306+ function clampOppAxis ( v ) {
307+ return Lib . constrain ( v , 0 , opts . _height ) ;
308+ }
309+
294310 function clampHandle ( v ) {
295311 return Lib . constrain ( v , - hw2 , opts . _width + hw2 ) ;
296312 }
@@ -309,6 +325,26 @@ function setPixelRange(rangeSlider, gd, axisOpts, opts) {
309325 . attr ( 'x' , pixelMax )
310326 . attr ( 'width' , opts . _width - pixelMax ) ;
311327
328+ if ( oppAxisRangeOpts . rangemode !== 'match' ) {
329+ var pixelMinOppAxis = opts . _height - clampOppAxis ( opts . d2pOppAxis ( oppAxisOpts . _rl [ 1 ] ) ) ,
330+ pixelMaxOppAxis = opts . _height - clampOppAxis ( opts . d2pOppAxis ( oppAxisOpts . _rl [ 0 ] ) ) ;
331+
332+ rangeSlider . select ( 'rect.' + constants . maskMinOppAxisClassName )
333+ . attr ( 'x' , pixelMin )
334+ . attr ( 'height' , pixelMinOppAxis )
335+ . attr ( 'width' , pixelMax - pixelMin ) ;
336+
337+ rangeSlider . select ( 'rect.' + constants . maskMaxOppAxisClassName )
338+ . attr ( 'x' , pixelMin )
339+ . attr ( 'y' , pixelMaxOppAxis )
340+ . attr ( 'height' , opts . _height - pixelMaxOppAxis )
341+ . attr ( 'width' , pixelMax - pixelMin ) ;
342+
343+ rangeSlider . select ( 'rect.' + constants . slideBoxClassName )
344+ . attr ( 'y' , pixelMinOppAxis )
345+ . attr ( 'height' , pixelMaxOppAxis - pixelMinOppAxis ) ;
346+ }
347+
312348 // add offset for crispier corners
313349 // https://github.com/plotly/plotly.js/pull/1409
314350 var offset = 0.5 ;
@@ -391,7 +427,8 @@ function drawRangePlot(rangeSlider, gd, axisOpts, opts) {
391427 isMainPlot = ( i === 0 ) ;
392428
393429 var oppAxisOpts = Axes . getFromId ( gd , id , 'y' ) ,
394- oppAxisName = oppAxisOpts . _name ;
430+ oppAxisName = oppAxisOpts . _name ,
431+ oppAxisRangeOpts = opts [ oppAxisName ] ;
395432
396433 var mockFigure = {
397434 data : [ ] ,
@@ -412,7 +449,7 @@ function drawRangePlot(rangeSlider, gd, axisOpts, opts) {
412449 mockFigure . layout [ oppAxisName ] = {
413450 type : oppAxisOpts . type ,
414451 domain : [ 0 , 1 ] ,
415- range : oppAxisOpts . range . slice ( ) ,
452+ range : oppAxisRangeOpts . rangemode !== 'match' ? oppAxisRangeOpts . range . slice ( ) : oppAxisOpts . range . slice ( ) ,
416453 calendar : oppAxisOpts . calendar
417454 } ;
418455
@@ -453,7 +490,7 @@ function filterRangePlotCalcData(calcData, subplotId) {
453490 return out ;
454491}
455492
456- function drawMasks ( rangeSlider , gd , axisOpts , opts ) {
493+ function drawMasks ( rangeSlider , gd , axisOpts , opts , oppAxisRangeOpts ) {
457494 var maskMin = rangeSlider . selectAll ( 'rect.' + constants . maskMinClassName )
458495 . data ( [ 0 ] ) ;
459496
@@ -477,6 +514,34 @@ function drawMasks(rangeSlider, gd, axisOpts, opts) {
477514 maskMax
478515 . attr ( 'height' , opts . _height )
479516 . call ( Color . fill , constants . maskColor ) ;
517+
518+ // masks used for oppAxis zoom
519+ if ( oppAxisRangeOpts . rangemode !== 'match' ) {
520+ var maskMinOppAxis = rangeSlider . selectAll ( 'rect.' + constants . maskMinOppAxisClassName )
521+ . data ( [ 0 ] ) ;
522+
523+ maskMinOppAxis . enter ( ) . append ( 'rect' )
524+ . classed ( constants . maskMinOppAxisClassName , true )
525+ . attr ( 'y' , 0 )
526+ . attr ( 'shape-rendering' , 'crispEdges' ) ;
527+
528+ maskMinOppAxis
529+ . attr ( 'width' , opts . _width )
530+ . call ( Color . fill , constants . maskOppAxisColor ) ;
531+
532+ var maskMaxOppAxis = rangeSlider . selectAll ( 'rect.' + constants . maskMaxOppAxisClassName )
533+ . data ( [ 0 ] ) ;
534+
535+ maskMaxOppAxis . enter ( ) . append ( 'rect' )
536+ . classed ( constants . maskMaxOppAxisClassName , true )
537+ . attr ( 'y' , 0 )
538+ . attr ( 'shape-rendering' , 'crispEdges' ) ;
539+
540+ maskMaxOppAxis
541+ . attr ( 'width' , opts . _width )
542+ . style ( 'border-top' , constants . maskOppBorder )
543+ . call ( Color . fill , constants . maskOppAxisColor ) ;
544+ }
480545}
481546
482547function drawSlideBox ( rangeSlider , gd , axisOpts , opts ) {
0 commit comments