@graspologic/layout-core
This library contains all the core logic for executing graph layout algorithms using Web Workers.
Basic Usage
function createWorker(type) {
const workerUrl =
type === 'fa2'
? 'https://path-to-fa2.worker.js'
: 'https://path-to-open-ord.worker.js'
return new Worker(workerUrl)
}
const layoutManager = new LayoutWorkerManager(() => createWorker('fa2'))
layoutManager.on('progress', () => {
renderer.rebind()
renderer.zoomToGraph()
})
layoutManager.layout(renderer.graph)
Webpack createWorker using worker-loader
Below is a basic implementation of creating workers for the LayoutWorkerManager.
Note: This requires Webpack's worker-loader to be installed.
import FA2Worker from 'worker-loader!./@graspologic/layout-fa2/dist/fa2_worker.js'
import OpenOrdWorker from 'worker-loader!./@graspologic/layout-openord/dist/openord_worker.js'
export function createWorker(type) {
if (type === 'fa2') {
return new FA2Worker()
}
return new OpenOrdWorker()
}
Webpack createWorker using raw-loader
Below is a basic implementation of creating workers for the LayoutWorkerManager.
Note: This requires Webpack's raw-loader to be installed.
const FA2_WORKER_SCRIPT = require('!raw-loader!@graspologic/layout-fa2/dist/fa2_worker.js')
.default
const FA2_WORKER_BLOB = new Blob([FA2_WORKER_SCRIPT], {
type: 'text/javascript',
})
const FA2_WORKER_URL = window.URL.createObjectURL(FA2_WORKER_BLOB)
const OPEN_ORD_WORKER_SCRIPT = require('!raw-loader!@graspologic/layout-openord/dist/openord_worker.js')
.default
const OPEN_ORD_WORKER_BLOB = new Blob([OPEN_ORD_WORKER_SCRIPT], {
type: 'text/javascript',
})
const OPEN_ORD_WORKER_URL = window.URL.createObjectURL(OPEN_ORD_WORKER_BLOB)
export function createWorker(type) {
let url = OPEN_ORD_WORKER_URL
if (type === 'fa2') {
url = FA2_WORKER_URL
}
return new Worker(url)
}
See the API documentation or examples for additional examples.