fix trail bug

This commit is contained in:
2023-11-02 11:21:34 -04:00
parent befe832516
commit b5ff8d7fef

View File

@@ -288,17 +288,9 @@ async function shootVector(
let trailers = []; let trailers = [];
let lastTrailerUpdate = new Date().getTime(); let lastTrailerUpdate = new Date().getTime();
async function updateTrailers(from = undefined, to = undefined) { async function updateTrailers(from = undefined, to = undefined) {
// We don't want this calculation killing the processor, so it can only happen once every 5 seconds let found = false;
const now = new Date().getTime();
if (now - lastTrailerUpdate < 5000) {
return;
} else {
lastTrailerUpdate = now;
}
if (from !== undefined && to !== undefined) { if (from !== undefined && to !== undefined) {
// check if vector already exists and increase count // check if vector already exists and increase count
let found = false;
trailers.forEach((x) => { trailers.forEach((x) => {
if (x.from == from && x.to == to) { if (x.from == from && x.to == to) {
found = true; found = true;
@@ -313,15 +305,23 @@ async function updateTrailers(from = undefined, to = undefined) {
} }
} }
// We don't want this calculation killing the processor, so it can only happen once every 5 seconds
// unless there's a new vector to the party so its opacity gets set
const now = new Date().getTime();
if (found && now - lastTrailerUpdate < 5000) {
return;
} else {
lastTrailerUpdate = now;
}
// weight brightness of vectors // weight brightness of vectors
let sum = 0; let sum = 0;
const trailCount = trailers.length; const trailCount = trailers.length;
let max = 0; let max = 10;
trailers.forEach((x) => { trailers.forEach((x) => {
sum += x.count; sum += x.count;
if (x.count > max) max = x.count; if (x.count > max) max = x.count;
}); });
if (max < 3) max = 5;
trailers.forEach((x, i) => { trailers.forEach((x, i) => {
let opacity = Math.sqrt(x.count / max); let opacity = Math.sqrt(x.count / max);
x.ref._path.style.opacity = opacity; x.ref._path.style.opacity = opacity;