@@ -460,7 +460,7 @@ HTMLWidgets.widget({
460
460
selection . on ( "change" , selectionChange ) ;
461
461
462
462
// Set a crosstalk variable selection value, triggering an update
463
- graphDiv . on ( x . highlight . on , function turnOn ( e ) {
463
+ var turnOn = function ( e ) {
464
464
if ( e ) {
465
465
var selectedKeys = pointsToKeys ( e . points ) ;
466
466
// Keys are group names, values are array of selected keys from group.
@@ -470,7 +470,9 @@ HTMLWidgets.widget({
470
470
}
471
471
}
472
472
}
473
- } ) ;
473
+ } ;
474
+
475
+ graphDiv . on ( x . highlight . on , debounce ( turnOn , x . highlight . debounce ) ) ;
474
476
475
477
graphDiv . on ( x . highlight . off , function turnOff ( e ) {
476
478
// remove any visual clues
@@ -878,3 +880,25 @@ function removeBrush(el) {
878
880
outlines [ i ] . remove ( ) ;
879
881
}
880
882
}
883
+
884
+
885
+ // https://davidwalsh.name/javascript-debounce-function
886
+
887
+ // Returns a function, that, as long as it continues to be invoked, will not
888
+ // be triggered. The function will be called after it stops being called for
889
+ // N milliseconds. If `immediate` is passed, trigger the function on the
890
+ // leading edge, instead of the trailing.
891
+ function debounce ( func , wait , immediate ) {
892
+ var timeout ;
893
+ return function ( ) {
894
+ var context = this , args = arguments ;
895
+ var later = function ( ) {
896
+ timeout = null ;
897
+ if ( ! immediate ) func . apply ( context , args ) ;
898
+ } ;
899
+ var callNow = immediate && ! timeout ;
900
+ clearTimeout ( timeout ) ;
901
+ timeout = setTimeout ( later , wait ) ;
902
+ if ( callNow ) func . apply ( context , args ) ;
903
+ } ;
904
+ } ;
0 commit comments