@@ -460,7 +460,7 @@ HTMLWidgets.widget({
460460 selection . on ( "change" , selectionChange ) ;
461461
462462 // Set a crosstalk variable selection value, triggering an update
463- graphDiv . on ( x . highlight . on , function turnOn ( e ) {
463+ var turnOn = function ( e ) {
464464 if ( e ) {
465465 var selectedKeys = pointsToKeys ( e . points ) ;
466466 // Keys are group names, values are array of selected keys from group.
@@ -470,7 +470,9 @@ HTMLWidgets.widget({
470470 }
471471 }
472472 }
473- } ) ;
473+ } ;
474+
475+ graphDiv . on ( x . highlight . on , debounce ( turnOn , x . highlight . debounce ) ) ;
474476
475477 graphDiv . on ( x . highlight . off , function turnOff ( e ) {
476478 // remove any visual clues
@@ -878,3 +880,25 @@ function removeBrush(el) {
878880 outlines [ i ] . remove ( ) ;
879881 }
880882}
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