@@ -643,49 +643,49 @@ function _hover(gd, evt, subplot, noHoverEvent) {
643
643
}
644
644
}
645
645
646
- hoverData . sort ( function ( d1 , d2 ) { return d1 . distance - d2 . distance ; } ) ;
646
+ var sortHoverData = function ( ) {
647
+ hoverData . sort ( function ( d1 , d2 ) { return d1 . distance - d2 . distance ; } ) ;
647
648
648
- // move period positioned points and box/bar-like traces to the end of the list
649
- hoverData = orderRangePoints ( hoverData , hovermode ) ;
649
+ // move period positioned points and box/bar-like traces to the end of the list
650
+ hoverData = orderRangePoints ( hoverData , hovermode ) ;
651
+ } ;
652
+ sortHoverData ( ) ;
650
653
651
654
// If in compare mode, select every point at position
652
655
if (
653
656
helpers . isXYhover ( _mode ) &&
654
657
hoverData [ 0 ] . length !== 0 &&
655
658
hoverData [ 0 ] . trace . type !== 'splom' // TODO: add support for splom
656
659
) {
657
- var initLen = hoverData . length ;
658
660
var winningPoint = hoverData [ 0 ] ;
659
661
660
662
var customXVal = customVal ( 'x' , winningPoint , fullLayout ) ;
661
663
var customYVal = customVal ( 'y' , winningPoint , fullLayout ) ;
662
664
663
665
findHoverPoints ( customXVal , customYVal ) ;
664
666
665
- var k ;
667
+ var finalPoints = [ ] ;
666
668
var seen = { } ;
667
- for ( k = 0 ; k < initLen ; k ++ ) {
668
- seen [ hoverData [ k ] . trace . index ] = true ;
669
- }
670
-
671
- // remove aditions and traces that seen before
672
- for ( k = hoverData . length - 1 ; k >= initLen ; k -- ) {
673
- if (
674
- seen [ hoverData [ k ] . trace . index ]
675
- ) {
676
- hoverData . splice ( k , 1 ) ;
669
+ var insert = function ( hd ) {
670
+ var type = hd . trace . type ;
671
+ var key = (
672
+ type === 'ohlc' ||
673
+ type === 'candlestick'
674
+ ) ? hoverDataKey ( hd ) : hd . trace . index ;
675
+ if ( ! seen [ key ] ) {
676
+ seen [ key ] = true ;
677
+ finalPoints . push ( hd ) ;
677
678
}
678
- }
679
+ } ;
679
680
680
- // Remove duplicated hoverData points
681
- var repeated = { } ;
682
- hoverData = hoverData . filter ( function ( hd ) {
683
- var key = hoverDataKey ( hd ) ;
684
- if ( ! repeated [ key ] ) {
685
- repeated [ key ] = true ;
686
- return repeated [ key ] ;
687
- }
688
- } ) ;
681
+ // insert the winnig point first
682
+ insert ( winningPoint ) ;
683
+ // override from the end
684
+ for ( var k = hoverData . length - 1 ; k > 0 ; k -- ) {
685
+ insert ( hoverData [ k ] ) ;
686
+ }
687
+ hoverData = finalPoints ;
688
+ sortHoverData ( ) ;
689
689
}
690
690
691
691
// lastly, emit custom hover/unhover events
0 commit comments