Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move throttle_function to Bonito #3980

Merged
merged 4 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion WGLMakie/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
22 changes: 2 additions & 20 deletions WGLMakie/src/wglmakie.bundled.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -22960,7 +22942,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());
setTimeout(resize_callback, 50);
}
Expand Down
43 changes: 2 additions & 41 deletions WGLMakie/src/wglmakie.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -338,7 +299,7 @@ function add_canvas_events(screen, comm, resize_to) {
}
}
if (resize_to) {
const resize_callback_throttled = throttle_function(
const resize_callback_throttled = Bonito.throttle_function(
resize_callback,
100
);
Expand Down
Loading