22 lines
863 B
JavaScript
22 lines
863 B
JavaScript
/**
|
|
* Web Worker running the network layout off the page's main thread.
|
|
*
|
|
* In production Vite bundles it into one self-contained classic worker, which
|
|
* older iOS versions also run; under the dev server it runs as a module worker
|
|
* instead, since the dev server serves it unbundled (see getLayoutWorker() in
|
|
* stats-network.js). The work itself lives in network-layout-core.js.
|
|
*/
|
|
import cytoscape from 'cytoscape';
|
|
import fcose from 'cytoscape-fcose';
|
|
import { layoutPositions } from './network-layout-core';
|
|
|
|
cytoscape.use(fcose);
|
|
|
|
self.onmessage = (event) => {
|
|
const { id, nodes, edges, options } = event.data || {};
|
|
|
|
layoutPositions(cytoscape, { nodes, edges, options })
|
|
.then((positions) => self.postMessage({ id, positions }))
|
|
.catch((error) => self.postMessage({ id, error: String((error && error.message) || error) }));
|
|
};
|