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

springy

v2.8.0

Published

A force directed graph layout algorithm in JavaScript.

Downloads

446

Readme

Springy

A force directed graph layout algorithm in JavaScript.

http://getspringy.com/

What is this?

Springy is a force directed graph layout algorithm.

So what does this 'force directed' stuff mean anyway? Excellent question!

It basically means that it uses some real world physics to try and figure out how to show a network graph in a nice way.

Try to imagine it as a bunch of springs connected to each other.

Demo

basic | simplified API | JSON API

Getting Started

springy.js by itself is quite plain and doesn't include any code to do rendering or drag and drop etc. It's just for calculating the layout.

The drawing and interaction stuff is mostly up to you.

However, I've written a little helper jQuery plugin called springyui.js to help get you started. It's got a semi-decent default renderer and some half assed drag and drop.

Basic Usage

See demo.html for the way to add nodes and edges to graph and springyui.js for the rendering example.

Springy 1.1+ supports simplified API for adding nodes and edges, see demo-simple.html:

var graph = new Springy.Graph();
graph.addNodes('mark', 'higgs', 'other', 'etc');
graph.addEdges(
    ['mark', 'higgs'],
    ['mark', 'etc'],
    ['mark', 'other']
);

Springy 1.2+ also accepts JSON, see demo-json.html:

graphJSON = {
  "nodes": ["mark", "higgs", "other", "etc"],
  "edges": [
    ["mark", "higgs"],
    ["mark", "etc"],
    ["mark", "other"]
  ]
};

var graph = new Springy.Graph();
graph.loadJSON(graphJSON);

Advanced Drawing

If you're keen to do your own custom drawing, you'll need to know a few things before you get started.

This is the basic graph API, you can create nodes and edges etc.

// make a new graph
var graph = new Springy.Graph();

// make some nodes
var node1 = graph.newNode({label: '1'});
var node2 = graph.newNode({label: '2'});

// connect them with an edge
graph.newEdge(node1, node2);

So now to draw this graph, lets make a layout object:

var layout = new Springy.Layout.ForceDirected(graph, 400.0, 400.0, 0.5);

I've written a Renderer class, which will handle the rendering loop. You just need to provide some callbacks to do the actual drawing.

var renderer = new Springy.Renderer(layout,
  function clear() {
    // code to clear screen
  },
  function drawEdge(edge, p1, p2) {
    // draw an edge
  },
  function drawNode(node, p) {
    // draw a node
  }
);

Now, just start the rendering loop:

renderer.start();

Further Reading

Have a look at the code in springy.js. Seriously, it's not very much code and it should be pretty easy to understand.

Please let me know if anything is unclear. Feedback is welcome.

Acknowledgements

Thanks to Lachlan Donald for his helpful suggestions and feedback.