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 🙏

© 2026 – Pkg Stats / Ryan Hefner

bettergraphs

v1.0.11

Published

A library for visualizing graph theory concepts.

Readme

BetterGraphs

A library for visualizing graph theory concepts.

How to use

Step 1 - Import the library


Import D3.js

<script src="https://d3js.org/d3.v6.min.js"></script>

Import BetterGraphs

<script src="https://unpkg.com/bettergraphs/dist/index.js"></script>

Step 2 - Create a graph object


const graph = betterGraphs.graph(divId);

Where div is an id tag of the HTML <div></div> you want to render the graph in.

Step 3 - Call methods


Use the object you declared to call functions.

NOTE: All animationDuration arguments are in milliseconds. If you want an animation to take 1 sec pass in 1000.

# graph.load(graph)

// graph.load() example
graph.load(
  {
    nodes: [
      {id: 1, label: "1"},
      {id: 2, label: "2"},
      {id: 3, label: "3"}
    ],
    links: [
      {source: 1, target: 2},
      {source: 1, target: 3}
    ]
  }
)

# graph.changeVerticesColor(string[], string, number)

First argument is a string array of the vertices you want to color. Second argument is the color you want. Third argument is animation duration.

// changeVerticesColor() example
graph.changeVerticesColor(["1", "2"], "red", 1000);

# graph.changeEdgesColor(string[][], string, number)

First argument is 2d array of strings array of the edges you want to color. Second argument is the color you want. Third argument is animation duration.

// changeEdgesColor() example
graph.changeEdgesColor([["1", "2"], ["1", "3"]], "blue", 1000);

# graph.changeSizeOfVertices(string[], number)

First argument is a string array of the vertices you want to color. Second argument is the radius you want.

// changeSizeOfVertices() example
graph.changeSizeOfVertices(["1", "2"], 25);

# graph.changeSizeOfEdges(string[][], number)

First argument is a 2d array of strings containing edges. Second argument is the stroke width.

// changeSizeOfEdges() example
graph.changeSizeOfEdges([["1", "2"], ["1", "3"]], 15);

# graph.changeAllVerticesColor(string, number)

First argument is the color you want. Second argument is animation duration.

// changeAllVerticesColor() example
graph.changeAllVerticesColor("red", 2500);

# graph.changeAllEdgesColor(string, number)

First argument is the color you want. Second argument is animation duration.

// changeAllEdgesColor() example
graph.changeAllEdgesColor("pink", 1500);

# graph.removeVertex(string)

First argument is the label of the vertex you want to remove.

// removeVertex() example
graph.removeVertex("1");

# graph.addVertex(string)

First argument is the vertex you want to add (its label).

// addVertex() example
graph.addVertex("4");

# graph.addEdge(string, string)

First argument is one of the endpoints of the edge you want to add. The second argument is the other endpoint.

// addEdge() example
graph.addEdge("4", "1");

# graph.addHull(string[])

An array of vertices you want a blob around.

//  addHull() example
graph.addHull("1", "2");

# graph.removeEdge(string, string)

First argument is one of the endpoints of the edge you want to remove. The second argument is the other endpoint.

// removeEdge() example
graph.removeEdge("1", "2");

# graph.changeLabel(string, string)

First argument is the label you want to change. Second argument is what you want to change the label to.

//  changeLabel() example
graph.changeLabel("4", "b");

# graph.generateRandomGraph(number, number)

First argument is amount of vertices. Second argument is amount of edges.

//  generateRandomGraph() example
graph.generateRandomGraph(10, 10);

# graph.contractEdge(string, string)

First argument is one of the endpoints of the edge you want to contract. The second argument is the other endpoint.

//  generateRandomGraph() example
graph.contractEdge("1", "2");

# graph.curveEdge(string, string)

First argument is one of the endpoints of the edge you want to curve. The second argument is the other endpoint.

//  curveEdge() example
graph.curveEdge("1", "2");

NOTE: When you create your links array for your graph you can alternatively pass in an attribute hasCurve: true.

links: [
  { source: 1, target: 2 },
  { source: 2, target: 3, hasCurve: true}, // Curved link.
]

# graph.colorEdgeOnRightClick(string)

First argument is the color you want the edge to be colored.

//  colorEdgeOnRightClick() example
graph.colorEdgeOnRightClick("pink");

Roadmap


  • [x] Change color of vertices
  • [x] Change color of edges
  • [x] Create edge
  • [x] Remove edge
  • [x] create and remove vertices
  • [x] Labels
  • [x] Contract edge
  • [x] Add hull
  • [x] Generate a random graph
  • [x] Color subset of vertices
  • [x] Color subset of edges
  • [x] Change size of node
  • [x] Change size of edges
  • [x] Change edge color by clicking on it
  • [ ] Add live examples of methods
  • [x] Ability for some edges to be curved
  • [ ] Label pointing to a vertex
  • [ ] Move graph to a specific coordinate
  • [ ] Label pointing to blob
  • [ ] Tooltip to vertex
  • [ ] Tooltip to blob
  • [ ] And re-layouting graphs (user can drag nodes to desired positions and take a snapshot)
  • [ ] Hull tube
  • [x] Right click edge to change color