Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@graspologic/layout-core

Package Overview
Dependencies
Maintainers
3
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@graspologic/layout-core

  • 0.7.0-8
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
3
Weekly downloads
 
Created
Source

@graspologic/layout-core

This library contains all the core logic for executing graph layout algorithms using Web Workers.

Basic Usage

// See below for other implementations of createWorker
function createWorker(type) {
	// A url to either
	//
	// OpenOrd:
	// @graspologic/layout-openord/dist/openord_worker.js
	//
	// or
	//
	// ForceAtlas2:
	// @graspologic/layout-fa2/dist/fa2_worker.js
	//
	const workerUrl =
		type === 'fa2'
			? 'https://path-to-fa2.worker.js'
			: 'https://path-to-open-ord.worker.js'
	return new Worker(workerUrl)
}

// Construct the layout manager which manages the layout worker scripts
const layoutManager = new LayoutWorkerManager(() => createWorker('fa2'))

// A layout tick was performed
layoutManager.on('progress', () => {
	// As the layout progresses, tell the graph renderer to rebind to the underlying data
	renderer.rebind()

	// Tell the renderer to re-fit to the graph
	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'

/**
 * Creates a worker for the given type
 */
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.

// Loads the FA2 script as a raw string
const FA2_WORKER_SCRIPT = require('!raw-loader!@graspologic/layout-fa2/dist/fa2_worker.js')
	.default

// Create a blob for the worker script
const FA2_WORKER_BLOB = new Blob([FA2_WORKER_SCRIPT], {
	type: 'text/javascript',
})

// Create a blob url for the fa2 worker script
const FA2_WORKER_URL = window.URL.createObjectURL(FA2_WORKER_BLOB)

// Loads the OpenOrd script as a raw string
const OPEN_ORD_WORKER_SCRIPT = require('!raw-loader!@graspologic/layout-openord/dist/openord_worker.js')
	.default

// Create a blob for the worker script
const OPEN_ORD_WORKER_BLOB = new Blob([OPEN_ORD_WORKER_SCRIPT], {
	type: 'text/javascript',
})

// Create a blob url for the openORD worker script
const OPEN_ORD_WORKER_URL = window.URL.createObjectURL(OPEN_ORD_WORKER_BLOB)

/**
 * Creates a worker for the given type
 */
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.

FAQs

Package last updated on 22 Feb 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc