From 6efba2ab2dcce5a46402e5d6d1f56b87f651ba21 Mon Sep 17 00:00:00 2001 From: Ben Arthur Date: Thu, 20 Jun 2024 08:53:25 -0400 Subject: [PATCH 1/2] move throttle_function to Bonito --- WGLMakie/src/wglmakie.bundled.js | 22 ++-------------- WGLMakie/src/wglmakie.js | 43 ++------------------------------ 2 files changed, 4 insertions(+), 61 deletions(-) diff --git a/WGLMakie/src/wglmakie.bundled.js b/WGLMakie/src/wglmakie.bundled.js index d0668a19b6a..9eb4d0be9cd 100644 --- a/WGLMakie/src/wglmakie.bundled.js +++ b/WGLMakie/src/wglmakie.bundled.js @@ -22773,24 +22773,6 @@ function start_renderloop(three_scene) { render_scene(three_scene); renderloop(); } -function throttle_function(func, delay) { - let prev = 0; - let future_id = undefined; - function inner_throttle(...args) { - const now = new Date().getTime(); - if (future_id !== undefined) { - clearTimeout(future_id); - future_id = undefined; - } - if (now - prev > delay) { - prev = now; - return func(...args); - } else { - future_id = setTimeout(()=>inner_throttle(...args), now - prev + 1); - } - } - return inner_throttle; -} function get_body_size() { const bodyStyle = window.getComputedStyle(document.body); const width_padding = parseInt(bodyStyle.paddingLeft, 10) + parseInt(bodyStyle.paddingRight, 10) + parseInt(bodyStyle.marginLeft, 10) + parseInt(bodyStyle.marginRight, 10); @@ -22870,7 +22852,7 @@ function add_canvas_events(screen, comm, resize_to) { ] }); } - const notify_mouse_throttled = throttle_function(mouse_callback, 40); + const notify_mouse_throttled = Bonito.throttle_function(mouse_callback, 40); function mousemove(event) { notify_mouse_throttled(event); return false; @@ -22941,7 +22923,7 @@ function add_canvas_events(screen, comm, resize_to) { }); } if (resize_to) { - const resize_callback_throttled = throttle_function(resize_callback, 100); + const resize_callback_throttled = Bonito.throttle_function(resize_callback, 100); window.addEventListener("resize", (event)=>resize_callback_throttled()); resize_callback_throttled(); } diff --git a/WGLMakie/src/wglmakie.js b/WGLMakie/src/wglmakie.js index 110273d7883..25e2e2b9f66 100644 --- a/WGLMakie/src/wglmakie.js +++ b/WGLMakie/src/wglmakie.js @@ -84,45 +84,6 @@ function start_renderloop(three_scene) { renderloop(); } -// from: https://www.geeksforgeeks.org/javascript-throttling/ -function throttle_function(func, delay) { - // Previously called time of the function - let prev = 0; - // ID of queued future update - let future_id = undefined; - function inner_throttle(...args) { - // Current called time of the function - const now = new Date().getTime(); - - // If we had a queued run, clear it now, we're - // either going to execute now, or queue a new run. - if (future_id !== undefined) { - clearTimeout(future_id); - future_id = undefined; - } - - // If difference is greater than delay call - // the function again. - if (now - prev > delay) { - prev = now; - // "..." is the spread operator here - // returning the function with the - // array of arguments - return func(...args); - } else { - // Otherwise, we want to queue this function call - // to occur at some later later time, so that it - // does not get lost; we'll schedule it so that it - // fires just a bit after our choke ends. - future_id = setTimeout( - () => inner_throttle(...args), - now - prev + 1 - ); - } - } - return inner_throttle; -} - function get_body_size() { const bodyStyle = window.getComputedStyle(document.body); // Subtract padding that is added by VSCode @@ -239,7 +200,7 @@ function add_canvas_events(screen, comm, resize_to) { comm.notify({ mouseposition: [x, y] }); } - const notify_mouse_throttled = throttle_function(mouse_callback, 40); + const notify_mouse_throttled = Bonito.throttle_function(mouse_callback, 40); function mousemove(event) { notify_mouse_throttled(event); @@ -318,7 +279,7 @@ function add_canvas_events(screen, comm, resize_to) { comm.notify({ resize: [width / winscale, height / winscale] }); } if (resize_to) { - const resize_callback_throttled = throttle_function( + const resize_callback_throttled = Bonito.throttle_function( resize_callback, 100 ); From 5f81c9e24801fb8a4dacc1fc97117a3abd3e0c32 Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 5 Aug 2024 16:27:06 +0200 Subject: [PATCH 2/2] use new Bonito with throttle --- WGLMakie/Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WGLMakie/Project.toml b/WGLMakie/Project.toml index 83e2626802d..be7bfb9687d 100644 --- a/WGLMakie/Project.toml +++ b/WGLMakie/Project.toml @@ -20,7 +20,7 @@ ShaderAbstractions = "65257c39-d410-5151-9873-9b3e5be5013e" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" [compat] -Bonito = "3.0.0" +Bonito = "3.1.2" Colors = "0.11, 0.12" FileIO = "1.1" FreeTypeAbstraction = "0.10"