Convert Figma logo to code with AI

anvaka logongraph

Beautiful Graphs

1,423
131
1,423
22

Top Related Projects

5,847

Gephi - The Open Graph Viz Platform

Graph theory (network) library for visualisation and analysis

7,849

⚠️ This project is not maintained anymore! Please go to https://github.com/visjs

3D force-directed graph component using ThreeJS/WebGL

Force-directed graph layout using velocity Verlet integration.

:dizzy: Display dynamic, automatically organised, customizable network views.

Quick Overview

ngraph is a graph theory library for JavaScript, designed to work with large graphs efficiently. It provides a set of tools for creating, manipulating, and analyzing graphs, with a focus on performance and flexibility.

Pros

  • High performance, capable of handling large graphs with millions of nodes and edges
  • Modular design, allowing users to pick and choose only the components they need
  • Supports both browser and Node.js environments
  • Extensive documentation and examples

Cons

  • Learning curve may be steep for those new to graph theory
  • Limited built-in visualization capabilities (requires additional libraries for advanced visualizations)
  • Some advanced graph algorithms are not included and may require custom implementation

Code Examples

Creating a graph and adding nodes and edges:

const createGraph = require('ngraph.graph');

let graph = createGraph();
graph.addNode('a');
graph.addNode('b');
graph.addLink('a', 'b');

Performing a breadth-first search:

const createGraph = require('ngraph.graph');
const bfs = require('ngraph.bfs');

let graph = createGraph();
graph.addLink('a', 'b');
graph.addLink('b', 'c');

bfs(graph, 'a', node => {
  console.log(node.id);
});

Finding the shortest path between two nodes:

const createGraph = require('ngraph.graph');
const path = require('ngraph.path');

let graph = createGraph();
graph.addLink('a', 'b');
graph.addLink('b', 'c');

let pathFinder = path.aStar(graph);
let foundPath = pathFinder.find('a', 'c');
console.log(foundPath); // ['a', 'b', 'c']

Getting Started

To use ngraph in your project, first install it via npm:

npm install ngraph.graph

Then, you can import and use it in your JavaScript code:

const createGraph = require('ngraph.graph');

let graph = createGraph();
graph.addNode('hello');
graph.addNode('world');
graph.addLink('hello', 'world');

console.log(graph.getNodesCount()); // 2
console.log(graph.getLinksCount()); // 1

For more advanced usage and additional modules, refer to the official documentation and examples in the GitHub repository.

Competitor Comparisons

5,847

Gephi - The Open Graph Viz Platform

Pros of gephi

  • More comprehensive graph visualization and analysis tool with a full GUI
  • Supports a wider range of graph formats and data import options
  • Offers advanced analytics features like community detection and centrality measures

Cons of gephi

  • Heavier and more resource-intensive, potentially slower for large graphs
  • Steeper learning curve due to its extensive feature set
  • Less suitable for integration into web applications or custom projects

Code comparison

gephi (Java):

Graph graph = new GraphGenerator().generateRandomGraph(100);
RankingController rankingController = Lookup.getDefault().lookup(RankingController.class);
Ranking degreeRanking = rankingController.getModel().getRanking(Ranking.NODE_ELEMENT, Ranking.DEGREE_RANKING);

ngraph (JavaScript):

const graph = createGraph();
for (let i = 0; i < 100; i++) {
  graph.addNode(i);
}
const layout = createLayout(graph);

Summary

gephi is a feature-rich, standalone application for graph analysis and visualization, while ngraph is a lightweight, modular library for graph operations in JavaScript. gephi offers more advanced analytics but is less flexible for custom integrations, whereas ngraph is better suited for web-based graph visualizations and custom graph processing tasks.

Graph theory (network) library for visualisation and analysis

Pros of Cytoscape.js

  • More comprehensive and feature-rich library for graph visualization and analysis
  • Extensive documentation and active community support
  • Built-in support for various graph layouts and styling options

Cons of Cytoscape.js

  • Larger file size and potentially higher memory usage
  • Steeper learning curve due to its extensive API and features
  • May be overkill for simple graph rendering tasks

Code Comparison

Cytoscape.js:

var cy = cytoscape({
  container: document.getElementById('cy'),
  elements: [
    { data: { id: 'a' } },
    { data: { id: 'b' } },
    { data: { source: 'a', target: 'b' } }
  ]
});

ngraph:

var graph = require('ngraph.graph')();
graph.addNode('a');
graph.addNode('b');
graph.addLink('a', 'b');

Summary

Cytoscape.js is a more comprehensive graph visualization library with extensive features and community support, making it suitable for complex graph-related tasks. However, it may be overkill for simpler projects. ngraph, on the other hand, offers a more lightweight and flexible approach to graph manipulation and rendering, but with fewer built-in features and less extensive documentation.

7,849

⚠️ This project is not maintained anymore! Please go to https://github.com/visjs

Pros of vis

  • More comprehensive visualization library with support for various chart types beyond just graphs
  • Larger community and more frequent updates/maintenance
  • Extensive documentation and examples available

Cons of vis

  • Larger file size and potentially heavier performance impact
  • Steeper learning curve due to more complex API and options
  • May be overkill for simple graph visualization needs

Code Comparison

vis:

var nodes = new vis.DataSet([
  {id: 1, label: 'Node 1'},
  {id: 2, label: 'Node 2'}
]);
var edges = new vis.DataSet([
  {from: 1, to: 2}
]);
var container = document.getElementById('mynetwork');
var data = {nodes: nodes, edges: edges};
var options = {};
var network = new vis.Network(container, data, options);

ngraph:

var graph = require('ngraph.graph')();
graph.addNode('a');
graph.addNode('b');
graph.addLink('a', 'b');
var layout = require('ngraph.forcelayout')(graph);
var renderer = require('ngraph.pixel')(graph);
renderer.run();

3D force-directed graph component using ThreeJS/WebGL

Pros of 3d-force-graph

  • Specifically designed for 3D force-directed graphs
  • Built-in support for WebGL rendering
  • Extensive customization options for node and link appearance

Cons of 3d-force-graph

  • Limited to browser environments (WebGL-based)
  • May have higher performance overhead for very large graphs
  • Less flexible for custom layout algorithms

Code Comparison

3d-force-graph:

const Graph = ForceGraph3D()
  (document.getElementById('3d-graph'))
    .graphData(myData)
    .nodeColor(node => node.color)
    .linkWidth(link => link.value);

ngraph:

var graph = require('ngraph.graph')();
var layout = require('ngraph.forcelayout')(graph);
graph.addLink(1, 2);
layout.step();

3d-force-graph focuses on providing a high-level API for creating 3D force-directed graphs in the browser, with built-in rendering and customization options. ngraph, on the other hand, offers a more low-level approach, providing graph data structures and layout algorithms that can be used in various environments, including Node.js.

While 3d-force-graph excels in quickly creating visually appealing 3D graph visualizations, ngraph offers more flexibility for custom implementations and can be used in a wider range of applications beyond visualization.

Force-directed graph layout using velocity Verlet integration.

Pros of d3-force

  • Part of the widely-used D3.js ecosystem, offering seamless integration with other D3 modules
  • Extensive documentation and a large community for support
  • Highly customizable force simulation with various force types

Cons of d3-force

  • Steeper learning curve, especially for those unfamiliar with D3.js
  • May be overkill for simpler graph visualizations
  • Performance can degrade with large datasets

Code Comparison

d3-force:

const simulation = d3.forceSimulation(nodes)
  .force("link", d3.forceLink(links).id(d => d.id))
  .force("charge", d3.forceManyBody())
  .force("center", d3.forceCenter(width / 2, height / 2));

ngraph:

const graph = ngraph.graph();
nodes.forEach(node => graph.addNode(node.id));
links.forEach(link => graph.addLink(link.source, link.target));
const layout = ngraph.forcelayout(graph);

Key Differences

  • ngraph focuses solely on graph layout, while d3-force is part of a larger visualization library
  • ngraph offers better performance for large graphs
  • d3-force provides more built-in force types and easier integration with SVG rendering
  • ngraph has a simpler API, making it easier to get started for basic graph layouts

:dizzy: Display dynamic, automatically organised, customizable network views.

Pros of vis-network

  • More comprehensive documentation and examples
  • Wider range of built-in layout algorithms
  • Better support for large-scale networks and performance optimization

Cons of vis-network

  • Steeper learning curve due to more complex API
  • Heavier library size, which may impact load times for smaller projects

Code Comparison

vis-network:

var nodes = new vis.DataSet([
  {id: 1, label: 'Node 1'},
  {id: 2, label: 'Node 2'}
]);
var edges = new vis.DataSet([
  {from: 1, to: 2}
]);
var container = document.getElementById('mynetwork');
var data = {nodes: nodes, edges: edges};
var options = {};
var network = new vis.Network(container, data, options);

ngraph:

var graph = require('ngraph.graph')();
graph.addNode('1', {label: 'Node 1'});
graph.addNode('2', {label: 'Node 2'});
graph.addLink('1', '2');
var renderGraph = require('ngraph.pixel');
renderGraph(graph);

Both libraries offer graph visualization capabilities, but vis-network provides a more feature-rich and flexible solution at the cost of increased complexity. ngraph focuses on simplicity and performance, making it suitable for smaller projects or specific use cases where minimalism is preferred.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

ngraph

Ngraph is a set of graph related algorithms. It can be used in a browser or on the server side. This repository is a collection of examples, which show how to use some of them or build your own.

What is available?

At the core of the library is ngraph.graph package, which simply represents a graph data structure.

Interactive renderer

This is set of libraries that use ngraph modules to provide rendering in the browser:

  • VivaGraph, one of the fastest graph drawing libraries is now constructed from ngraph modules. It is an opinionated set of modules packed together.
  • ngraph.pixel - Fast 3D graph renderer based on low level ShaderMaterial from three.js

Algorithms

Clusters/Community Detection

  • ngraph.cw - fast community detection algorithm, based on label propagation
  • ngraph.louvain - another state of the art algorithm, uses modularity optimization.

Graph metrics

Serialization

  • Dot files serializer from/to
  • (Gephi) gexf file - Source; Demo
  • Binary format - space-efficient format for large graphs. E.g. 5 million edges, 1 million nodes requires only 23 MB of space.

Graph layout

  • ngraph.forcelayout performs force based layout in arbitrary dimensions space (2D, 3D, 4D, and so on).

When layout in the browser is not feasible (e.g. the graph is too large to achieve decent performance) we can compute layout offline and provide static positions to the browser:

  • ngraph.offline.layout is an npm module to perform such layout. If this module is too slow, you can also try:
  • ngraph.native which is fully implemented in C++ and is 9x faster thant javascript version.

Other

There are plenty modules within ngraph family: this npm search shows most of them

Playground

You can quickly start a new project with core ngraph modules using this template project: https://github.com/anvaka/graph-start

Building your own modules

This repository has multiple examples how to build your own module which suits your needs best:

Video

Here is an introduction video to this library: Browserify Monolith. This library has also appeared in TEDx talk at Stanford: The Beauty I See in Algebra by Margot Gerritsen. It has also appeared in this TEDx talk How can visualizing our personal data empower our health? by Amina Qutub

Why?

I built vivagraph to learn javascript two years ago. I definitely learned a lot and vivagraph itself is a pretty decent graph drawing library.

However vivagraph is built in monolithic way. For example, if I wanted to add new streaming traversal API I could not justify it inside monolithic "graph drawing" library.

Ngraph opens huge possibilities, with each module being available on npm. Now you can pick just what you need and swap out parts which are not relevant to your project.

I'm not abandoning vivagraph by any means. Quite the opposite, this repository is a next step of evolution.

How to run examples locally?

ngraph is powered by npm. All examples require a bundle.js file, which is produced by executing npm start command inside folder with example. Make sure you have all modules installed inside a folder (npm install inside folder with example will download all dependencies).

Looking for alternatives?

I'm trying to put up a list of all known graph drawing libraries. Please find it here

license

MIT

NPM DownloadsLast 30 Days