Convert Figma logo to code with AI

jacomyal logosigma.js

A JavaScript library aimed at visualizing graphs of thousands of nodes and edges

11,199
1,584
11,199
29

Top Related Projects

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

7,849

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

Graph theory (network) library for visualisation and analysis

3D force-directed graph component using ThreeJS/WebGL

Force-directed graph layout using velocity Verlet integration.

1,423

Beautiful Graphs

Quick Overview

Sigma.js is a JavaScript library for visualizing and interacting with network graphs in web applications. It provides a powerful and flexible set of tools for rendering large-scale graphs efficiently, with support for custom rendering and interaction.

Pros

  • High performance rendering of large graphs (up to 100,000 nodes)
  • Customizable appearance and behavior through plugins and settings
  • Supports both WebGL and Canvas rendering
  • Active development and community support

Cons

  • Learning curve for advanced customizations
  • Limited built-in layout algorithms (requires additional libraries for complex layouts)
  • Documentation could be more comprehensive for some advanced features
  • Performance may degrade with very large graphs on mobile devices

Code Examples

  1. Creating a basic graph:
// Create a graph
const graph = new sigma.Graph();

// Add nodes and edges
graph.addNode('n1', { x: 0, y: 0, size: 10, label: 'Node 1' });
graph.addNode('n2', { x: 1, y: 1, size: 10, label: 'Node 2' });
graph.addEdge('e1', 'n1', 'n2');

// Render the graph
new sigma.Sigma(graph, document.getElementById('graph-container'));
  1. Customizing node appearance:
const graph = new sigma.Graph();

graph.addNode('n1', {
  x: 0,
  y: 0,
  size: 15,
  label: 'Custom Node',
  color: '#ff0000',
  type: 'square'
});

new sigma.Sigma(graph, document.getElementById('graph-container'), {
  renderNodes: (context, nodes) => {
    nodes.forEach(node => {
      if (node.type === 'square') {
        context.fillStyle = node.color;
        context.fillRect(node.x - node.size / 2, node.y - node.size / 2, node.size, node.size);
      }
    });
  }
});
  1. Adding interactivity:
const graph = new sigma.Graph();
// ... add nodes and edges

const renderer = new sigma.Sigma(graph, document.getElementById('graph-container'));

renderer.on('clickNode', (event) => {
  console.log('Clicked node:', event.node);
});

renderer.on('enterNode', (event) => {
  event.node.color = '#ff0000';
  renderer.refresh();
});

renderer.on('leaveNode', (event) => {
  event.node.color = null;
  renderer.refresh();
});

Getting Started

  1. Install Sigma.js using npm:

    npm install sigma graphology
    
  2. Create an HTML file with a container for the graph:

    <div id="graph-container"></div>
    
  3. Import and use Sigma.js in your JavaScript file:

    import Graph from "graphology";
    import Sigma from "sigma";
    
    const graph = new Graph();
    graph.addNode("n1", { x: 0, y: 0, size: 10, label: "Node 1" });
    graph.addNode("n2", { x: 1, y: 1, size: 10, label: "Node 2" });
    graph.addEdge("n1", "n2");
    
    const renderer = new Sigma(graph, document.getElementById("graph-container"));
    

This will create a basic graph with two connected nodes. You can then customize the appearance and behavior of the graph using Sigma.js's extensive API and plugins.

Competitor Comparisons

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

Pros of vis-network

  • More comprehensive library with additional features beyond graph visualization
  • Extensive documentation and examples
  • Active community and regular updates

Cons of vis-network

  • Larger file size and potentially heavier performance impact
  • Steeper learning curve due to more complex API

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);

sigma.js:

var s = new sigma({
  container: 'mynetwork',
  graph: {
    nodes: [{id: 'n1', label: 'Node 1'}, {id: 'n2', label: 'Node 2'}],
    edges: [{id: 'e1', source: 'n1', target: 'n2'}]
  }
});

Both libraries offer powerful graph visualization capabilities, but vis-network provides a more comprehensive solution with additional features beyond graph rendering. However, this comes at the cost of a larger file size and potentially more complex usage. sigma.js, on the other hand, focuses specifically on graph visualization and offers a simpler API, making it easier to get started with basic graph rendering tasks.

7,849

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

Pros of vis

  • More comprehensive library with support for various chart types beyond just graphs
  • Offers a Timeline component for visualizing time-based data
  • Provides built-in support for data manipulation and filtering

Cons of vis

  • Larger file size and potentially heavier performance impact
  • Less specialized for large-scale graph rendering compared to sigma.js
  • May have a steeper learning curve due to its broader feature set

Code Comparison

sigma.js:

var s = new sigma({
  container: 'graph-container',
  settings: {
    defaultNodeColor: '#ec5148'
  }
});

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 network = new vis.Network(container, {nodes: nodes, edges: edges}, {});

Summary

While vis offers a more comprehensive set of visualization tools, sigma.js specializes in efficient graph rendering. The choice between the two depends on the specific requirements of your project, with vis being more suitable for diverse visualization needs and sigma.js excelling in large-scale graph applications.

Graph theory (network) library for visualisation and analysis

Pros of Cytoscape.js

  • More comprehensive graph theory algorithms and analysis tools
  • Supports a wider range of graph types and layouts
  • Larger and more active community, with frequent updates

Cons of Cytoscape.js

  • Steeper learning curve due to more complex API
  • Potentially slower rendering for very large graphs
  • Larger file size, which may impact load times

Code Comparison

Sigma.js:

var s = new sigma({
  container: 'graph-container',
  graph: {
    nodes: [{ id: 'n1', label: 'Node 1' }],
    edges: []
  }
});

Cytoscape.js:

var cy = cytoscape({
  container: document.getElementById('cy'),
  elements: [
    { data: { id: 'n1', label: 'Node 1' } }
  ]
});

Both libraries allow for easy graph initialization, but Cytoscape.js uses a more object-oriented approach with its elements array. Sigma.js separates nodes and edges in its graph object, which may be more intuitive for simpler graphs.

3D force-directed graph component using ThreeJS/WebGL

Pros of 3d-force-graph

  • Provides 3D visualization capabilities, allowing for more immersive and complex graph representations
  • Offers VR support, enabling users to interact with graphs in virtual reality environments
  • Includes built-in controls for zooming, panning, and rotating the 3D graph

Cons of 3d-force-graph

  • May have a steeper learning curve due to its 3D nature and additional features
  • Potentially higher performance overhead, especially for large graphs or on less powerful devices
  • Limited customization options compared to Sigma.js's extensive API

Code Comparison

Sigma.js:

const s = new sigma({
  graph: {nodes: [], edges: []},
  container: 'graph-container'
});
s.refresh();

3d-force-graph:

const Graph = ForceGraph3D()
  (document.getElementById('3d-graph'))
    .graphData({nodes: [], links: []});

Both libraries offer straightforward initialization, but 3d-force-graph's API is more concise. Sigma.js provides more granular control over graph elements and rendering, while 3d-force-graph focuses on simplicity and 3D capabilities.

Force-directed graph layout using velocity Verlet integration.

Pros of d3-force

  • More flexible and customizable for complex force-directed layouts
  • Part of the larger D3.js ecosystem, offering seamless integration with other D3 modules
  • Extensive documentation and a large community for support

Cons of d3-force

  • Steeper learning curve, especially for those new to D3.js
  • Requires more manual setup and configuration for basic graph visualizations
  • May be overkill for simple network graphs

Code Comparison

sigma.js:

const s = new Sigma(graph, container, {
  renderers: [new Sigma.WebGLRenderer(container)],
});
s.refresh();

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));

Key Differences

  • sigma.js is specifically designed for graph visualization, while d3-force is a more general-purpose force simulation library
  • sigma.js offers better out-of-the-box performance for large graphs, especially with WebGL rendering
  • d3-force provides more control over the physics simulation and layout algorithm
  • sigma.js has a simpler API for basic graph rendering, making it easier for beginners to get started
1,423

Beautiful Graphs

Pros of ngraph

  • More flexible and modular architecture, allowing for easier customization and extension
  • Better performance for large-scale graphs, especially in 3D rendering
  • Supports a wider range of graph algorithms and layouts

Cons of ngraph

  • Steeper learning curve due to its modular nature
  • Less comprehensive documentation compared to sigma.js
  • Fewer built-in visual styling options out of the box

Code Comparison

sigma.js:

var s = new sigma({
  container: 'graph-container',
  graph: {
    nodes: [{ id: 'n1' }, { id: 'n2' }],
    edges: [{ id: 'e1', source: 'n1', target: 'n2' }]
  }
});

ngraph:

var graph = require('ngraph.graph')();
graph.addNode('n1');
graph.addNode('n2');
graph.addLink('n1', 'n2');
var renderer = require('ngraph.pixel')(graph);
renderer.run();

Both libraries allow for creating and rendering graphs, but ngraph's approach is more modular and requires separate steps for graph creation and rendering. sigma.js provides a more integrated solution with a single constructor call. ngraph's flexibility comes at the cost of slightly more verbose code, while sigma.js offers a more streamlined initial setup.

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

Build Status


Sigma.js

Website | Documentation | Storybook


Sigma.js is an open-source JavaScript library aimed at visualizing graphs of thousands of nodes and edges using WebGL, mainly developed by @jacomyal and @Yomguithereal, and built on top of graphology.

How to use in your project

To integrate sigma into your project, follow these simple steps:

  1. Installation: Add sigma and graphology to your project by running the following command:

    npm install sigma graphology
    
  2. Usage: Import sigma into your JavaScript or TypeScript file:

    import Graph from "graphology";
    import Sigma from "sigma";
    

    Then, create a new Sigma instance with your graph data and target container:

    const graph = new Graph();
    graph.addNode("1", { label: "Node 1", x: 0, y: 0, size: 10, color: "blue" });
    graph.addNode("2", { label: "Node 2", x: 1, y: 1, size: 20, color: "red" });
    graph.addEdge("1", "2", { size: 5, color: "purple" });
    
    const sigmaInstance = new Sigma(graph, document.getElementById("container"));
    

How to develop locally

To run the Storybook locally:

git clone git@github.com:jacomyal/sigma.js.git
cd sigma.js
npm install
npm run start

This will open the Storybook in your web browser, which live reloads when you modify the stories or the package sources.

Resources

  • GitHub Project: The source code and collaborative development efforts for Sigma.js are hosted on GitHub.
  • Website: The official website, sigmajs.org, kindly designed by Robin de Mourat from the Sciences-Po médialab team, showcases the library's capabilities.
  • Documentation: A detailed documentation, built with Docusaurus, is available at sigmajs.org/docs. It provides extensive guides and API references for users.
  • Storybook: Interactive examples can be found at sigmajs.org/storybook.
  • Demo: A comprehensive demo, available at sigmajs.org/demo, features a full-featured React-based web application utilizing Sigma.js.

How to contribute

You can contribute by submitting issues tickets and proposing pull requests. Make sure that tests and linting pass before submitting any pull request.

You can also browse the related documentation here.

NPM DownloadsLast 30 Days