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-generators

v0.11.2

Published

Various graph generators for graphology.

Downloads

35,668

Readme

Graphology Generators

Various graph generators to be used with graphology.

Installation

npm install graphology-generators

Usage

Classic graphs

Complete

Creates a complete graph.

import Graph, {UndirectedGraph} from 'graphology';
import {complete} from 'graphology-generators/classic';
// Alternatively, if you only want to load relevant code
import complete from 'graphology-generators/classic/complete';

// Creating a complete graph
const graph = complete(Graph, 10);

// Using another constuctor to create, say, a complete undirected graph
const graph = complete(UndirectedGraph, 10);

Arguments

  • constructor Class: a graphology constructor.
  • order number: number of nodes in the generated graph.

Empty

Creates an empty graph with the desired number of nodes and no edges.

import Graph, {UndirectedGraph} from 'graphology';
import {empty} from 'graphology-generators/classic';
// Alternatively, if you only want to load relevant code
import empty from 'graphology-generators/classic/empty';

// Creating an empty graph
const graph = empty(Graph, 10);

// Using another constuctor to create, say, an empty undirected graph
const graph = empty(UndirectedGraph, 10);

Arguments

  • constructor Class: a graphology constructor.
  • order number: number of nodes in the generated graph.

Ladder

Creates a ladder graph with the desired length. Note that the generated graph will logically have twice the number of nodes.

import Graph, {UndirectedGraph} from 'graphology';
import {ladder} from 'graphology-generators/classic';
// Alternatively, if you only want to load relevant code
import ladder from 'graphology-generators/classic/ladder';

// Creating a ladder graph
const graph = ladder(Graph, 10);

// Using another constuctor to create, say, a undirected ladder graph
const graph = ladder(UndirectedGraph, 10);

Arguments

  • constructor Class: a graphology constructor.
  • length number: length of the ladder.

Path

Creates a path graph.

import Graph, {UndirectedGraph} from 'graphology';
import {path} from 'graphology-generators/classic';
// Alternatively, if you only want to load relevant code
import path from 'graphology-generators/classic/path';

// Creating a path graph
const graph = path(Graph, 10);

// Using another constuctor to create, say, a path undirected graph
const graph = path(UndirectedGraph, 10);

Arguments

  • constructor Class: a graphology constructor.
  • order number: number of nodes in the generated graph.

Community graphs

Caveman

Creates a Caveman graph containing l components of k nodes.

import Graph, {UndirectedGraph} from 'graphology';
import {caveman} from 'graphology-generators/community';
// Alternatively, if you only want to load relevant code
import caveman from 'graphology-generators/community/caveman';

// Creating a caveman graph
const graph = caveman(Graph, 6, 8);

Arguments

  • constructor Class: a graphology constructor.
  • l number: number of components in the graph.
  • k number: number of nodes of the components.

Connected Caveman

Creates a Connected Caveman graph containing l components of k nodes.

import Graph, {UndirectedGraph} from 'graphology';
import {connectedCaveman} from 'graphology-generators/community';
// Alternatively, if you only want to load relevant code
import connectedCaveman from 'graphology-generators/community/connected-caveman';

// Creating a connected caveman graph
const graph = connectedCaveman(Graph, 6, 8);

Arguments

  • constructor Class: a graphology constructor.
  • l number: number of components in the graph.
  • k number: number of nodes of the components.

Random graphs

Clusters

Creates a graph with the desired number of nodes & edges and having a given number of clusters.

import Graph from 'graphology';
import {clusters} from 'graphology-generators/random';
// Alternatively, if you only want to load relevant code
import clusters from 'graphology-generators/random/clusters';

// Creating a random clustered graph
const graph = clusters(Graph, {
  order: 100,
  size: 1000,
  clusters: 5
});

Arguments

  • constructor Class: a graphology constructor.
  • options object: options:
    • order number: number of nodes of the generated graph.
    • size number: number of edges of the generated graph.
    • clusters number: number of clusters of the generated graph.
    • clusterDensity ?number [0.5]: Probability that an edge will link two nodes of the same cluster.
    • rng ?function: custom RNG function.

Erdos-Renyi

Creates an Erdos-Renyi, or binomial graph.

import Graph from 'graphology';
import {erdosRenyi} from 'graphology-generators/random';
// Alternatively, if you only want to load relevant code
import erdosRenyi from 'graphology-generators/random/erdos-renyi';

// Creating a binomial graph
const graph = erdosRenyi(Graph, {order: 10, probability: 0.5});

// If your graph is sparse (low probability), you can use the `sparse` version
// which runs in O(m + n) rather than O(n^2)
const graph = erdosRenyi.sparse(Graph, {order: 1000, probability: 0.1});

Arguments

  • constructor Class: a graphology constructor.
  • options object: options:
    • order number: number of nodes of the generated graph.
    • probability number: probability for edge creation. (i.e. density you try to approximate in the generated graph).
    • approximateSize: alternatively, you can pass an approximate number of edges you are trying to get in the generated graph.
    • rng ?function: custom RNG function.

Girvan-Newman

Creates a Girvan-Newman random graph as described in:

Community Structure in social and biological networks. Girvan Newman, 2002. PNAS June, vol 99 n 12

import Graph from 'graphology';
import {girvanNewman} from 'graphology-generators/random';
// Alternatively, if you only want to load relevant code
import girvanNewman from 'graphology-generators/random/girvan-newman';

// Creating a binomial graph
const graph = girvanNewman(Graph, {zOut: 4});

Arguments

  • constructor Class: a graphology constructor.
  • options object: options:
    • zOut number: zout parameter.
    • rng ?function: custom RNG function.

Small graphs

Krackhardt kite

Returns the Krackhardt kite graph.

import Graph from 'graphology';
import {krackhardtKite} from 'graphology-generators/small';
// Alternatively, if you only want to load relevant code
import krackhardtKite from 'graphology-generators/small/krackhardt-kite';

// Creating a random clustered graph
const graph = krackhardtKite(Graph);

Arguments

  • constructor Class: a graphology constructor.

Social graphs

Florentine Families

Returns the Florentine families' graph.

import Graph from 'graphology';
import {florentineFamilies} from 'graphology-generators/florentine-families';
// Alternatively, if you only want to load relevant code
import florentineFamilies from 'graphology-generators/social/florentine-families';

// Generating the graph
const graph = florentineFamilies(Graph);

Arguments

  • constructor Class: a graphology constructor.

Karate Club

Returns Zachary's karate club graph.

import Graph from 'graphology';
import {karateClub} from 'graphology-generators/karate-club';
// Alternatively, if you only want to load relevant code
import karateClub from 'graphology-generators/social/karate-club';

// Generating the graph
const graph = karateClub(Graph);

Arguments

  • constructor Class: a graphology constructor.