@graspologic/layout-core
Last updated 2 months ago by stopyoukid .
MIT · Original npm · Tarball · package.json
$ cnpm install @graspologic/layout-core 
SYNC missed versions from official npm registry.

@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.onProgress.subscribe(() => {
	// 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.

Current Tags

  • 0.4.1-beta.14.0                                ...           beta.14 (5 months ago)
  • 0.6.0                                ...           latest (2 months ago)
  • 0.4.0                                ...           local.1 (5 months ago)
  • 0.7.0-7                                ...           prerelease (16 days ago)

17 Versions

  • 0.7.0-7                                ...           16 days ago
  • 0.7.0-6                                ...           16 days ago
  • 0.7.0-5                                ...           a month ago
  • 0.7.0-4                                ...           a month ago
  • 0.7.0-3                                ...           a month ago
  • 0.0.7-3                                ...           a month ago
  • 0.7.0-2                                ...           2 months ago
  • 0.7.0-1                                ...           2 months ago
  • 0.7.0-0                                ...           2 months ago
  • 0.6.0                                ...           2 months ago
  • 0.5.0                                ...           3 months ago
  • 0.5.0-3                                ...           3 months ago
  • 0.5.0-2                                ...           3 months ago
  • 0.5.0-1                                ...           3 months ago
  • 0.5.0-modularize                                ...           3 months ago
  • 0.4.1-beta.14.0                                ...           5 months ago
  • 0.4.0                                ...           5 months ago
Downloads
Today 0
This Week 0
This Month 33
Last Day 0
Last Week 0
Last Month 57
Dependencies (3)
Dev Dependencies (3)

Copyright 2014 - 2017 © taobao.org |