aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTerry Truong <terry06890@gmail.com>2023-01-28 22:31:38 +1100
committerTerry Truong <terry06890@gmail.com>2023-01-28 22:31:38 +1100
commit2a217a42b17e78814eecbe84028cf38b3f9327b7 (patch)
treead67bbfd0f5763f2bf3e44e04ef8a95bac662f0f
parent0d8eba5548db35d13cda6d4632786afba6140e1e (diff)
Adjust onEventDisplay() to be more reponsive
-rw-r--r--src/App.vue21
-rw-r--r--src/util.ts2
2 files changed, 18 insertions, 5 deletions
diff --git a/src/App.vue b/src/App.vue
index bfd2730..c0e68a3 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -359,18 +359,31 @@ async function handleOnEventDisplay(
}
}
+let lastEventDisplayHdlrTime = 0;
const timelineTimeouts: Map<number, number> = new Map();
// Maps timeline IDs to setTimeout() timeouts (used to throttle handleEventDisplay() per-timeline)
+const EVENT_DISPLAY_HDLR_DELAY = 150;
function onEventDisplay(
timelineId: number, eventIds: number[], firstDate: HistDate, lastDate: HistDate, scaleIdx: number){
if (timelineTimeouts.has(timelineId)){
clearTimeout(timelineTimeouts.get(timelineId));
- }
- timelineTimeouts.set(timelineId, window.setTimeout(async () => {
timelineTimeouts.delete(timelineId);
- handleOnEventDisplay(timelineId, eventIds, firstDate, lastDate, scaleIdx);
- }, 150));
+ }
+ const currentTime = new Date().getTime();
+ if (currentTime - lastEventDisplayHdlrTime > EVENT_DISPLAY_HDLR_DELAY){
+ lastEventDisplayHdlrTime = currentTime;
+ window.setTimeout(async () => {
+ await handleOnEventDisplay(timelineId, eventIds, firstDate, lastDate, scaleIdx);
+ lastEventDisplayHdlrTime = new Date().getTime();
+ }, EVENT_DISPLAY_HDLR_DELAY);
+ } else {
+ timelineTimeouts.set(timelineId, window.setTimeout(async () => {
+ timelineTimeouts.delete(timelineId);
+ await handleOnEventDisplay(timelineId, eventIds, firstDate, lastDate, scaleIdx);
+ lastEventDisplayHdlrTime = new Date().getTime();
+ }, EVENT_DISPLAY_HDLR_DELAY));
+ }
}
// ========== For info modal ==========
diff --git a/src/util.ts b/src/util.ts
index 96741b2..587ad66 100644
--- a/src/util.ts
+++ b/src/util.ts
@@ -54,7 +54,7 @@ export function makeThrottledSpaced(hdlr: (...args: any[]) => void, delay: numbe
hdlr(...args);
lastHdlrTime = new Date().getTime();
} else {
- endHdlr = window.setTimeout(async () => {
+ endHdlr = window.setTimeout(() => {
endHdlr = 0;
hdlr(...args);
lastHdlrTime = new Date().getTime();