From bd36db062a4c8ae53ead6694d47449315469bf2c Mon Sep 17 00:00:00 2001 From: Kyle Boone Date: Thu, 24 Oct 2019 15:48:37 -0700 Subject: [PATCH] Rate limit text updates --- js/src/mpl_widget.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/js/src/mpl_widget.js b/js/src/mpl_widget.js index c8c8585d..dbd2b130 100644 --- a/js/src/mpl_widget.js +++ b/js/src/mpl_widget.js @@ -374,6 +374,7 @@ var MPLCanvasView = widgets.DOMWidgetView.extend({ mouse_event: function(name) { var that = this; + var last_update = 0; return function(event) { var canvas_pos = utils.get_mouse_position(event); @@ -391,12 +392,18 @@ var MPLCanvasView = widgets.DOMWidgetView.extend({ that.canvas_div.focus(); } - var x = canvas_pos.x * that.ratio; - var y = canvas_pos.y * that.ratio; + // Rate-limit the position text updates so that we don't overwhelm the + // system. + if (Date.now() > last_update + 40) { + last_update = Date.now(); - that.send_message(name, {x: x, y: y, button: event.button, - step: event.step, - guiEvent: utils.get_simple_keys(event)}); + var x = canvas_pos.x * that.ratio; + var y = canvas_pos.y * that.ratio; + + that.send_message(name, {x: x, y: y, button: event.button, + step: event.step, + guiEvent: utils.get_simple_keys(event)}); + } /* This prevents the web browser from automatically changing to * the text insertion cursor when the button is pressed. We want