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

infergraph.js

v1.0.0

Published

A library for (di)graph creating, analysing, and inference

Downloads

4

Readme

infergraph.js

A library for (di)graph creating, analysing, and inference.

Get Started

Load

var ig = require("infergraph.js");

Undirected graph

Generate a graph

var g = ig.newGraph();

Add nodes

infergraph.js provides three ways to add a node

// 1. By name
g.addNode("Node1");

// 2. By name and attributes
g.addNode(["Node2", {A1: "a1", A2: "a2"}]);

// 3. By dictionary ("id" is necessary)
g.addNode({id: "Node3", A1: "a1", A2: "a2"});

Adding many nodes at once is possible

g.addNodes(["Node1", ["Node2", {A1: "a1"}], {id: "Node3", A1: "a2"}]);

Get nodes and edit attributes of nodes

When you request nodes from a graph, infergraph.js will firstly render a selector. With the selector, you can modify and query attributes of the targeted nodes. You can edit the attributes of a node by chaining. Attributes can be values of output of functions

var node = g.getNode("Node1")
             .attr("A1", 1) // edit an attribute with a value
             .attr("A2", 2)
             .attr("A3", d => d.A1 + d.A2) // edit an attribute with a function
             .get(); // finally get the node

Or getting and editing many nodes at one time by names or a filter function.

var nodes = g.getNodes(["Node1", "Node2"])
             .attr("A1", 1)
             .get(); // get all the selected nodes as an array


g.getNodes(node => {...})
 .attr("A1", 1);

Add edges

Giving the names of source node, target node, and weight (optional, default=0), an edge will be build between nodes


g.addEdge("Src1", "Tar1", weight);

g.addEdge("Src2", "Tar2");

As in undirected graphs, you can add edges as cycles or complete graphs

g.addCycle(["Node1", ..., "NodeN"], weight)

g.linkCompletely(["Node1", ..., "NodeN"], weight)

Query relations

// check if two nodes are neighbours to each other
g.isNeighbour("Neighbour", "ofWhom");

// get a selector with all neighbour nodes
g.getNeighbours("ofWhom");

// get a key list of all neighbour nodes
g.getNeighbourKeys("ofWhom");

Directed graph (DiGraph)

The rules of adding nodes and edges in directed graph are exactly the same the undirected graph version. However, the shortcut functions of addCycle and linkCompleted does not support DiGraph. The major difference is the relation querying.

Query relations

You and find parents, children, ancestors, and descendants of nodes

// check relations
g.isParent("parent", "ofWhom");
g.isChild("child", "ofWhom");
g.isAncestor("ancestor", "ofWhom");
g.isDescendant("descendant", "ofWhom");

// get a selector with all neighbour nodes
g.getParents("ofWhom");
g.getChildren("ofWhom");
g.getAncestors("ofWhom");
g.getDescendants("ofWhom");

// get a key list of all neighbour nodes
g.getParentKeys("ofWhom");
g.getChildKeys("ofWhom");
g.getAncestorKeys("ofWhom");
g.getDescendantKeys("ofWhom");

Query the order of a directed graph (acyclic graph only)

You can get the topological order of a DiGraph

g.getOrder()

License

This project is licensed under the MIT License - see the LICENSE file for details