npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

graphology-layout-noverlap

v0.4.2

Published

Noverlap anti-collision layout algorithm for graphology.

Downloads

110,118

Readme

Graphology Noverlap

JavaScript implementation of the Noverlap anti-collision layout algorithm for graphology.

Note that this algorithm is iterative and might not converge easily in some cases.

Installation

npm install graphology-layout-noverlap

Usage

Pre-requisites

Each node's starting position must be set before running the Noverlap anti-collision layout. Two attributes called x and y must therefore be defined for all the graph nodes.

Settings

  • gridSize ?number [20]: number of grid cells horizontally and vertically subdivising the graph's space. This is used as an optimization scheme. Set it to 1 and you will have O(n²) time complexity, which can sometimes perform better with very few nodes.
  • margin ?number [5]: margin to keep between nodes.
  • expansion ?number [1.1]: percentage of current space that nodes could attempt to move outside of.
  • ratio ?number [1.0]: ratio scaling node sizes.
  • speed ?number [3]: dampening factor that will slow down node movements to ease the overall process.

Synchronous layout

import noverlap from 'graphology-layout-noverlap';

const positions = noverlap(graph, {maxIterations: 50});

// With settings:
const positions = noverlap(graph, {
  maxIterations: 50,
  settings: {
    ratio: 2
  }
});

// With a custom input reducer
const positions = noverlap(graph, {
  inputReducer: (key, attr) => ({
    x: store[key].x,
    y: store[key].y,
    size: attr.size
  }),
  outputReducer: (key, pos) => ({x: pos.x * 10, y: pos.y * 10})
});

// To directly assign the positions to the nodes:
noverlap.assign(graph);

Arguments

  • graph Graph: target graph.
  • options object: options:
    • maxIterations ?number [500]: maximum number of iterations to perform before stopping. Note that the algorithm will also stop as soon as converged.
    • inputReducer ?function: a function reducing each node attributes. This can be useful if the rendered positions/sizes of your graph are stored outside of the graph's data. This is the case when using sigma.js for instance.
    • outputReducer ?function: a function reducing node positions as computed by the layout algorithm. This can be useful to map back to a previous coordinates system. This is the case when using sigma.js for instance.
    • settings ?object: the layout's settings (see #settings).

Webworker

If you need to run the layout's computation in a web worker, the library comes with a utility to do so:

Example

import NoverlapLayout from 'graphology-layout-noverlap/worker';

const layout = new NoverlapLayout(graph, params);

// To start the layout. It will automatically stop when converged
layout.start();

// To stop the layout
layout.stop();

// To kill the layout and release attached memory
layout.kill();

// Assess whether the layout is currently running
layout.isRunning();