@@ -5,6 +5,7 @@ var isNumeric = require('fast-isnumeric');
55var tinycolor = require ( 'tinycolor2' ) ;
66
77var Lib = require ( '../../lib' ) ;
8+ var pushUnique = Lib . pushUnique ;
89var strTranslate = Lib . strTranslate ;
910var strRotate = Lib . strRotate ;
1011var Events = require ( '../../lib/events' ) ;
@@ -257,13 +258,40 @@ function _hover(gd, evt, subplot, noHoverEvent, eventTarget) {
257258 // use those instead of finding overlayed plots
258259 var subplots = Array . isArray ( subplot ) ? subplot : [ subplot ] ;
259260
261+ var spId ;
262+
260263 var fullLayout = gd . _fullLayout ;
264+ var hoversubplots = fullLayout . hoversubplots ;
261265 var plots = fullLayout . _plots || [ ] ;
262266 var plotinfo = plots [ subplot ] ;
263267 var hasCartesian = fullLayout . _has ( 'cartesian' ) ;
264268
269+ var hovermode = evt . hovermode || fullLayout . hovermode ;
270+ var hovermodeHasX = ( hovermode || '' ) . charAt ( 0 ) === 'x' ;
271+ var hovermodeHasY = ( hovermode || '' ) . charAt ( 0 ) === 'y' ;
272+
273+ if ( hasCartesian && ( hovermodeHasX || hovermodeHasY ) && hoversubplots === 'axis' ) {
274+ var subplotsLength = subplots . length ;
275+ for ( var p = 0 ; p < subplotsLength ; p ++ ) {
276+ spId = subplots [ p ] ;
277+ if ( plots [ spId ] ) {
278+ // 'cartesian' case
279+
280+ var subplotsWith = (
281+ Axes . getFromId ( gd , spId , hovermodeHasX ? 'x' : 'y' )
282+ ) . _subplotsWith ;
283+
284+ if ( subplotsWith && subplotsWith . length ) {
285+ for ( var q = 0 ; q < subplotsWith . length ; q ++ ) {
286+ pushUnique ( subplots , subplotsWith [ q ] ) ;
287+ }
288+ }
289+ }
290+ }
291+ }
292+
265293 // list of all overlaid subplots to look at
266- if ( plotinfo ) {
294+ if ( plotinfo && hoversubplots !== 'single' ) {
267295 var overlayedSubplots = plotinfo . overlays . map ( function ( pi ) {
268296 return pi . id ;
269297 } ) ;
@@ -277,7 +305,7 @@ function _hover(gd, evt, subplot, noHoverEvent, eventTarget) {
277305 var supportsCompare = false ;
278306
279307 for ( var i = 0 ; i < len ; i ++ ) {
280- var spId = subplots [ i ] ;
308+ spId = subplots [ i ] ;
281309
282310 if ( plots [ spId ] ) {
283311 // 'cartesian' case
@@ -295,8 +323,6 @@ function _hover(gd, evt, subplot, noHoverEvent, eventTarget) {
295323 }
296324 }
297325
298- var hovermode = evt . hovermode || fullLayout . hovermode ;
299-
300326 if ( hovermode && ! supportsCompare ) hovermode = 'closest' ;
301327
302328 if ( [ 'x' , 'y' , 'closest' , 'x unified' , 'y unified' ] . indexOf ( hovermode ) === - 1 || ! gd . calcdata ||
@@ -441,6 +467,12 @@ function _hover(gd, evt, subplot, noHoverEvent, eventTarget) {
441467 // the rest of this function from running and failing
442468 if ( [ 'carpet' , 'contourcarpet' ] . indexOf ( trace . _module . name ) !== - 1 ) continue ;
443469
470+ // within one trace mode can sometimes be overridden
471+ _mode = hovermode ;
472+ if ( helpers . isUnifiedHover ( _mode ) ) {
473+ _mode = _mode . charAt ( 0 ) ;
474+ }
475+
444476 if ( trace . type === 'splom' ) {
445477 // splom traces do not generate overlay subplots,
446478 // it is safe to assume here splom traces correspond to the 0th subplot
@@ -451,12 +483,6 @@ function _hover(gd, evt, subplot, noHoverEvent, eventTarget) {
451483 subploti = subplots . indexOf ( subplotId ) ;
452484 }
453485
454- // within one trace mode can sometimes be overridden
455- _mode = hovermode ;
456- if ( helpers . isUnifiedHover ( _mode ) ) {
457- _mode = _mode . charAt ( 0 ) ;
458- }
459-
460486 // container for new point, also used to pass info into module.hoverPoints
461487 pointData = {
462488 // trace properties
@@ -508,8 +534,6 @@ function _hover(gd, evt, subplot, noHoverEvent, eventTarget) {
508534 pointData . scene = fullLayout . _splomScenes [ trace . uid ] ;
509535 }
510536
511- closedataPreviousLength = hoverData . length ;
512-
513537 // for a highlighting array, figure out what
514538 // we're searching for with this element
515539 if ( _mode === 'array' ) {
@@ -536,12 +560,18 @@ function _hover(gd, evt, subplot, noHoverEvent, eventTarget) {
536560 yval = yvalArray [ subploti ] ;
537561 }
538562
563+ closedataPreviousLength = hoverData . length ;
564+
539565 // Now if there is range to look in, find the points to hover.
540566 if ( hoverdistance !== 0 ) {
541567 if ( trace . _module && trace . _module . hoverPoints ) {
542568 var newPoints = trace . _module . hoverPoints ( pointData , xval , yval , _mode , {
543569 finiteRange : true ,
544- hoverLayer : fullLayout . _hoverlayer
570+ hoverLayer : fullLayout . _hoverlayer ,
571+
572+ // options for splom when hovering on same axis
573+ hoversubplots : hoversubplots ,
574+ gd : gd
545575 } ) ;
546576
547577 if ( newPoints ) {
@@ -662,7 +692,9 @@ function _hover(gd, evt, subplot, noHoverEvent, eventTarget) {
662692 gd . _spikepoints = newspikepoints ;
663693
664694 var sortHoverData = function ( ) {
665- hoverData . sort ( function ( d1 , d2 ) { return d1 . distance - d2 . distance ; } ) ;
695+ if ( hoversubplots !== 'axis' ) {
696+ hoverData . sort ( function ( d1 , d2 ) { return d1 . distance - d2 . distance ; } ) ;
697+ }
666698
667699 // move period positioned points and box/bar-like traces to the end of the list
668700 hoverData = orderRangePoints ( hoverData , hovermode ) ;
0 commit comments