Remove import statements from web worker file.

This commit is contained in:
Kia Lam 2022-03-09 06:58:43 -08:00
parent 8bf9dd038e
commit e4f0153a7d
2 changed files with 35 additions and 6 deletions

View File

@ -0,0 +1,34 @@
/* eslint-disable no-undef */
importScripts('https://d3js.org/d3-collection.v1.min.js');
importScripts('https://d3js.org/d3-dispatch.v1.min.js');
importScripts('https://d3js.org/d3-quadtree.v1.min.js');
importScripts('https://d3js.org/d3-timer.v1.min.js');
importScripts('https://d3js.org/d3-force.v1.min.js');
onmessage = function calculateLayout({ data: { nodes, links } }) {
const simulation = d3
.forceSimulation(nodes)
.force('charge', d3.forceManyBody(15).strength(-50))
.force(
'link',
d3.forceLink(links).id((d) => d.hostname)
)
.force('collide', d3.forceCollide(62))
.force('forceX', d3.forceX(0))
.force('forceY', d3.forceY(0))
.stop();
for (
let i = 0,
n = Math.ceil(
Math.log(simulation.alphaMin()) / Math.log(1 - simulation.alphaDecay())
);
i < n;
++i
) {
postMessage({ type: 'tick', progress: i / n });
simulation.tick();
}
postMessage({ type: 'end', nodes, links });
};

View File

@ -1,8 +1,3 @@
export default function webWorker() {
return new Worker(
new URL(
'screens/TopologyView/utils/workers/simulationWorker.js',
import.meta.url
)
);
return new Worker(new URL('./simulationWorker.js', import.meta.url));
}