@@ -51,7 +51,7 @@ ScatterRegl.calc = function calc(container, trace) {
51
51
var yaxis = Axes . getFromId ( container , trace . yaxis ) ;
52
52
var markerOpts = trace . marker ;
53
53
54
- // FIXME: find a better way to obtain subplot object from trace
54
+ // FIXME: is it the best way to obtain subplot object from trace
55
55
var subplot = layout . _plots [ trace . xaxis + trace . yaxis ] ;
56
56
57
57
// makeCalcdata runs d2c (data-to-coordinate) on every point
@@ -440,6 +440,11 @@ ScatterRegl.calc = function calc(container, trace) {
440
440
}
441
441
}
442
442
}
443
+ //expand no-markers axes
444
+ else {
445
+ Axes . expand ( xaxis , stash . rawx , { padded : true } ) ;
446
+ Axes . expand ( yaxis , stash . rawy , { padded : true } ) ;
447
+ }
443
448
444
449
445
450
// make sure scene exists
@@ -703,10 +708,10 @@ ScatterRegl.plot = function plot(container, subplot, cdata) {
703
708
var yaxis = Axes . getFromId ( container , trace . yaxis || 'y' ) ;
704
709
705
710
var range = [
706
- xaxis . range [ 0 ] ,
707
- yaxis . range [ 0 ] ,
708
- xaxis . range [ 1 ] ,
709
- yaxis . range [ 1 ]
711
+ xaxis . _rl [ 0 ] ,
712
+ yaxis . _rl [ 0 ] ,
713
+ xaxis . _rl [ 1 ] ,
714
+ yaxis . _rl [ 1 ]
710
715
] ;
711
716
712
717
var viewport = [
@@ -766,7 +771,7 @@ ScatterRegl.plot = function plot(container, subplot, cdata) {
766
771
} ;
767
772
768
773
769
- ScatterRegl . hoverPoints = function hover ( pointData , xval , yval ) {
774
+ ScatterRegl . hoverPoints = function hover ( pointData , xval , yval , hovermode ) {
770
775
var cd = pointData . cd ,
771
776
stash = cd [ 0 ] . t ,
772
777
trace = cd [ 0 ] . trace ,
@@ -775,6 +780,7 @@ ScatterRegl.hoverPoints = function hover(pointData, xval, yval) {
775
780
positions = stash . positions ,
776
781
x = stash . rawx ,
777
782
y = stash . rawy ,
783
+ scene = stash . scene ,
778
784
xpx = xa . c2p ( xval ) ,
779
785
ypx = ya . c2p ( yval ) ,
780
786
ids ;
@@ -787,7 +793,18 @@ ScatterRegl.hoverPoints = function hover(pointData, xval, yval) {
787
793
// );
788
794
789
795
//FIXME: this works only for the case of linear points
790
- ids = stash . tree . within ( xval , yval , MAXDIST / xa . _m ) ;
796
+ if ( hovermode === 'x' ) {
797
+ ids = stash . tree . range (
798
+ xa . p2c ( xpx - MAXDIST ) , ya . _rl [ 0 ] ,
799
+ xa . p2c ( xpx + MAXDIST ) , ya . _rl [ 1 ]
800
+ ) ;
801
+ }
802
+ else {
803
+ ids = stash . tree . range (
804
+ xa . p2c ( xpx - MAXDIST ) , ya . p2c ( ypx + MAXDIST ) ,
805
+ xa . p2c ( xpx + MAXDIST ) , ya . p2c ( ypx - MAXDIST )
806
+ ) ;
807
+ }
791
808
}
792
809
else if ( stash . ids ) {
793
810
ids = stash . ids ;
@@ -796,17 +813,29 @@ ScatterRegl.hoverPoints = function hover(pointData, xval, yval) {
796
813
797
814
// pick the id closest to the point
798
815
// note that point possibly may not be found
799
- var min = MAXDIST , id , ptx , pty ;
800
-
801
- for ( var i = 0 ; i < ids . length ; i ++ ) {
802
- ptx = x [ ids [ i ] ] ;
803
- pty = y [ ids [ i ] ] ;
804
- var dx = xa . c2p ( ptx ) - xpx , dy = ya . c2p ( pty ) - ypx ;
805
-
806
- var dist = Math . sqrt ( dx * dx + dy * dy ) ;
807
- if ( dist < min ) {
808
- min = dist ;
809
- id = ids [ i ] ;
816
+ var min = MAXDIST , id , ptx , pty , i ;
817
+
818
+ if ( hovermode === 'x' ) {
819
+ for ( i = 0 ; i < ids . length ; i ++ ) {
820
+ ptx = x [ ids [ i ] ] ;
821
+ var dx = Math . abs ( xa . c2p ( ptx ) - xpx ) ;
822
+ if ( dx < min ) {
823
+ min = dx ;
824
+ id = ids [ i ] ;
825
+ }
826
+ }
827
+ }
828
+ else {
829
+ for ( i = 0 ; i < ids . length ; i ++ ) {
830
+ ptx = x [ ids [ i ] ] ;
831
+ pty = y [ ids [ i ] ] ;
832
+ var dx = xa . c2p ( ptx ) - xpx , dy = ya . c2p ( pty ) - ypx ;
833
+
834
+ var dist = Math . sqrt ( dx * dx + dy * dy ) ;
835
+ if ( dist < min ) {
836
+ min = dist ;
837
+ id = ids [ i ] ;
838
+ }
810
839
}
811
840
}
812
841
0 commit comments