Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

graphology

Package Overview
Dependencies
Maintainers
1
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphology

A robust and multipurpose Graph object for JavaScript.

  • 0.25.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
389K
increased by9.53%
Maintainers
1
Weekly downloads
 
Created

What is graphology?

Graphology is a robust and versatile JavaScript library for creating, manipulating, and analyzing graphs. It provides a comprehensive set of tools for working with both directed and undirected graphs, and supports various graph algorithms and data structures.

What are graphology's main functionalities?

Graph Creation

This feature allows you to create a new graph, add nodes, and add edges between nodes. The code sample demonstrates creating a graph, adding two nodes ('John' and 'Jane'), and adding an edge between them.

const Graph = require('graphology');
const graph = new Graph();
graph.addNode('John');
graph.addNode('Jane');
graph.addEdge('John', 'Jane');
console.log(graph.nodes()); // ['John', 'Jane']
console.log(graph.edges()); // [{ source: 'John', target: 'Jane' }]

Graph Algorithms

Graphology supports various graph algorithms, such as Dijkstra's shortest path algorithm. The code sample demonstrates creating a graph with weighted edges and finding the shortest path from node 'A' to node 'C'.

const Graph = require('graphology');
const { dijkstra } = require('graphology-shortest-path');
const graph = new Graph();
graph.addNode('A');
graph.addNode('B');
graph.addNode('C');
graph.addEdge('A', 'B', { weight: 1 });
graph.addEdge('B', 'C', { weight: 2 });
graph.addEdge('A', 'C', { weight: 4 });
const path = dijkstra(graph, 'A', 'C');
console.log(path); // ['A', 'B', 'C']

Graph Analysis

Graphology provides tools for analyzing graphs, such as calculating centrality metrics. The code sample demonstrates creating a graph and calculating the degree centrality of each node.

const Graph = require('graphology');
const { degreeCentrality } = require('graphology-metrics/centrality');
const graph = new Graph();
graph.addNode('A');
graph.addNode('B');
graph.addNode('C');
graph.addEdge('A', 'B');
graph.addEdge('B', 'C');
graph.addEdge('A', 'C');
const centrality = degreeCentrality(graph);
console.log(centrality); // { A: 2, B: 2, C: 2 }

Other packages similar to graphology

Keywords

FAQs

Package last updated on 01 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc