@@ -53,6 +53,10 @@ var cartesianScatterPoints = {
53
53
splom : true
54
54
} ;
55
55
56
+ function distanceSort ( a , b ) {
57
+ return a . distance - b . distance ;
58
+ }
59
+
56
60
// fx.hover: highlight data on hover
57
61
// evt can be a mousemove event, or an object with data about what points
58
62
// to hover on
@@ -270,15 +274,21 @@ function _hover(gd, evt, subplot, noHoverEvent, eventTarget) {
270
274
var hovermodeHasX = ( hovermode || '' ) . charAt ( 0 ) === 'x' ;
271
275
var hovermodeHasY = ( hovermode || '' ) . charAt ( 0 ) === 'y' ;
272
276
277
+ var firstXaxis ;
278
+ var firstYaxis ;
279
+
273
280
if ( hasCartesian && ( hovermodeHasX || hovermodeHasY ) && hoversubplots === 'axis' ) {
274
281
var subplotsLength = subplots . length ;
275
282
for ( var p = 0 ; p < subplotsLength ; p ++ ) {
276
283
spId = subplots [ p ] ;
277
284
if ( plots [ spId ] ) {
278
285
// 'cartesian' case
279
286
287
+ firstXaxis = Axes . getFromId ( gd , spId , 'x' ) ;
288
+ firstYaxis = Axes . getFromId ( gd , spId , 'y' ) ;
289
+
280
290
var subplotsWith = (
281
- Axes . getFromId ( gd , spId , hovermodeHasX ? 'x' : 'y' )
291
+ hovermodeHasX ? firstXaxis : firstYaxis
282
292
) . _subplotsWith ;
283
293
284
294
if ( subplotsWith && subplotsWith . length ) {
@@ -661,6 +671,9 @@ function _hover(gd, evt, subplot, noHoverEvent, eventTarget) {
661
671
var thisSpikeDistance ;
662
672
663
673
for ( var i = 0 ; i < pointsData . length ; i ++ ) {
674
+ if ( firstXaxis && firstXaxis . _id !== pointsData [ i ] . xa . _id ) continue ;
675
+ if ( firstYaxis && firstYaxis . _id !== pointsData [ i ] . ya . _id ) continue ;
676
+
664
677
thisSpikeDistance = pointsData [ i ] . spikeDistance ;
665
678
if ( spikeOnWinning && i === 0 ) thisSpikeDistance = - Infinity ;
666
679
@@ -700,9 +713,23 @@ function _hover(gd, evt, subplot, noHoverEvent, eventTarget) {
700
713
gd . _spikepoints = newspikepoints ;
701
714
702
715
var sortHoverData = function ( ) {
703
- if ( hoversubplots !== 'axis' ) {
704
- hoverData . sort ( function ( d1 , d2 ) { return d1 . distance - d2 . distance ; } ) ;
705
- }
716
+ var hoverDataInSubplot = hoverData . filter ( function ( a ) {
717
+ return (
718
+ ( firstXaxis && firstXaxis . _id === a . xa . _id ) &&
719
+ ( firstYaxis && firstYaxis . _id === a . ya . _id )
720
+ ) ;
721
+ } ) ;
722
+
723
+ var hoverDataOutSubplot = hoverData . filter ( function ( a ) {
724
+ return ! (
725
+ ( firstXaxis && firstXaxis . _id === a . xa . _id ) &&
726
+ ( firstYaxis && firstYaxis . _id === a . ya . _id )
727
+ ) ;
728
+ } ) ;
729
+
730
+ hoverDataInSubplot . sort ( distanceSort ) ;
731
+ hoverDataOutSubplot . sort ( distanceSort ) ;
732
+ hoverData = hoverDataInSubplot . concat ( hoverDataOutSubplot ) ;
706
733
707
734
// move period positioned points and box/bar-like traces to the end of the list
708
735
hoverData = orderRangePoints ( hoverData , hovermode ) ;
0 commit comments