7 Helpful Sigma.js Examples to Master Graph Visualization

Rapidops, Inc.
25 min readAug 11, 2023

--

Sigma.js is a versatile, open-source JavaScript library dedicated to graph drawing. Using web technologies like WebGL, allows you to display interactive static and dynamic graphs, which aren’t just visually appealing but are also extremely powerful tools for data exploration and storytelling. With its flexible design and high-level customization features, Sigma.js has become a favorite among developers and data analysts alike.

In this blog post, we’ll delve deep into the practical applications of Sigma.js. We’ll start from the basics, learning to set it up and create simple graphs, and gradually move on to more advanced and exciting visualization techniques. Through seven practical examples, you’ll learn to master this tool and gain insights into how to represent and interpret various types of data effectively.

Grab a cup of coffee, roll up your sleeves, and let’s dive into the world of graph visualization with Sigma.js!

What is graph visualization?

Graph visualization, at its core, is a technique of creating visual representations of data that highlights the relationships and patterns among various data points. Unlike traditional charts or graphs, graph visualization is not just about presenting values or quantities, but focuses more on the connections and interactions within the data. In a graph visualization, data is represented in two primary elements: nodes (or vertices) and edges (or links). Nodes represent individual data points, while edges signify the relationships or associations between those points. This method lends itself incredibly well to complex data structures, making them more comprehensible and allowing the viewer to extract meaningful insights.

Importance of graph visualization in data analysis

In data analysis, graph visualization plays a crucial role. The human brain is exceptionally adept at recognizing patterns and understanding information presented visually. By visualizing data as a graph, it becomes significantly easier to comprehend intricate relationships, identify trends, detect anomalies, and make predictions. This is particularly valuable when dealing with complex and large-scale datasets, such as social network data or biological networks. Graph visualization also provides a powerful tool for communicating findings to others, especially to non-technical audiences. By transforming data into an understandable and interactive visual format, complex concepts become digestible, and abstract data takes on a more concrete form.

What is Sigma.js?

Sigma.js is an open-source JavaScript library developed explicitly for graph drawing. It leverages modern web technologies like HTML5 and WebGL to produce high-quality, interactive, and scalable graph visualizations within a web browser. The flexibility of Sigma.js allows developers to visualize static graphs, animate graphs based on user interactions, or even create dynamic graphs that update in real-time.

Sigma.js features

Sigma.js boasts several impressive features that set it apart from other graph visualization libraries. It supports a myriad of layout algorithms, making it adaptable for different visualization needs. It’s capable of handling large datasets efficiently due to its powerful rendering engine that utilizes the capabilities of WebGL. Sigma.js also supports interactivity, allowing users to manipulate the graph, such as zooming, panning, or selecting nodes and edges. Additionally, it offers a great degree of customizability, permitting users to tailor the appearance and behavior of the graph to their preferences.

Sigma.js benefits

Sigma.js brings several benefits to the table. It’s highly performant and capable of rendering large graphs without sacrificing speed or responsiveness. It is open-source, allowing developers to contribute, adapt, and modify the library as per their requirements. Since it runs in web browsers, there’s no need for special software installation to view the visualizations. This also makes the visualizations easily shareable, promoting collaboration. Lastly, its strong support for customization and interactivity empowers developers and data analysts to craft visually compelling and insightful graphs that can not only convey complex information effectively but also engage the audience in an interactive exploration of data.

Step-by-step guide on how to install Sigma.js

Sigma.js can be installed and used in a variety of ways, depending on your project’s needs. However, we will guide you through one of the most common methods — installing Sigma.js via npm, the Node Package Manager. Before we start, make sure you have Node.js and npm installed on your computer. If not, you can download them from Node.js official website.

Here are the steps to install Sigma.js using npm:

  • Open your command prompt or terminal.
  • Navigate to your project directory. For instance, if your project is in a folder named ‘graph-project’ on your desktop, you would type:
  • To install Sigma.js, you would then type:

This command will install Sigma.js in your project directory.

  • Once installed, you will be able to import Sigma.js into your project by adding the following line at the beginning of your JavaScript file:
  • To check if Sigma.js is installed correctly, you can create a simple Sigma instance and log it to the console:

If everything went well, you should see the Sigma instance logged in your console.

Explanation of necessary libraries and their installation

Sigma.js itself is powerful, but its capabilities can be significantly extended by using additional plugins and libraries. These libraries provide functionalities like advanced layouts, exporting graphs, or handling user interactions more efficiently.

Here are a few noteworthy libraries and how to install them:

  • sigma.plugins.animate: This plugin allows you to animate your graph. Nodes and edges can be moved, colors can be changed, and sizes can be modified over time.

Installation: After installing Sigma.js, use npm to install the animate plugin by typing npm install sigma-plugin-animate in your terminal. You can then import it in your project using require(‘sigma-plugin-animate’);

  • sigma.layouts.forceAtlas2: This plugin offers an advanced layout algorithm named ‘ForceAtlas2’, which is beneficial for visualizing complex graph structures.

Installation: Install it using npm install sigma-layout-forceatlas2 and import it into your project with require(‘sigma-layout-forceatlas2’);

Remember, each plugin is imported the same way as Sigma.js, using the require() function.

Initialization of a Sigma.js graph

Now that you have Sigma.js and some plugins installed, it’s time to initialize your first graph.

First, you need to set up a container for your graph in your HTML file. This can be done by adding a div with a unique id. The Sigma instance will use this div to place the graph.

In your JavaScript file, you can now initialize Sigma:

This code creates a new Sigma instance that will render the graph in the ‘graph-container’ div using a canvas renderer. You can also customize the graph by setting different parameters in the settings object, like edge color, node size, etc.

To populate your graph with nodes and edges, you use the addNode and addEdge methods of the Sigma instance:

Finally, to render the graph, you use the refresh method:

You should now see your first graph, which contains one node and one edge. Congratulations, you’ve just set up and initialized your first Sigma.js graph!

Example 1: Basic node-link diagram

In the realm of graph theory and network analysis, node-link diagrams, also known as network diagrams, are ubiquitous. A node-link diagram comprises two primary elements: nodes, representing entities or data points, and links (or edges), representing the relationships or connections between these entities.

For instance, in a social network, individuals could be represented as nodes, while their friendships or interactions could be depicted as links. A node-link diagram is highly effective in visualizing complex relational data, making it an indispensable tool in domains like social science, bioinformatics, traffic systems, and much more.

While the underlying principle remains the same, node-link diagrams can vary greatly in terms of complexity and appearance. They can be simple and straightforward, or they can incorporate various levels of intricacy and interaction.

Step-by-step guide to creating a basic Node-Link diagram with Sigma.js

Creating a basic node-link diagram using Sigma.js involves a few straightforward steps. Let’s create a simple network with three nodes and three edges.

Setting up the HTML container: As we’ve discussed before, the first step involves setting up an HTML container for your graph. In your HTML file, create a div with a unique id:

Initializing Sigma instance: In your JavaScript file, initialize a Sigma instance that will render the graph in the container div:

Adding nodes: We will add three nodes to the graph using the addNode method. Each node is represented as an object with properties like ‘id’, ‘label’, ‘x’, ‘y’, ‘size’, and ‘color’.

Adding edges: Similarly, we will add three edges using the addEdge method:

Rendering the graph: Lastly, use the refresh method to render the graph:

Exploring options for customizing appearance

Sigma.js offers extensive customization options to tweak the appearance of your node-link diagram. The size, color, and labels of nodes and edges can be customized, among other things.

Customizing nodes:

The size and color of nodes can be customized by setting the ‘size’ and ‘color’ properties when adding a node. The ‘size’ property determines the node’s size, and the ‘color’ property determines its color:

Customizing edges:

Similarly, you can customize the color of edges by setting the ‘color’ property when adding an edge:

Customizing labels:

The ‘label’ property allows you to assign labels to nodes. To display these labels, you need to set the drawLabels setting to true when initializing Sigma:

Showcase of output and interpretation

If you’ve followed the steps correctly, you should now see a triangle of nodes, each node with a unique color and a label, connected by edges in your browser.

In our example, the three nodes might represent three individuals in a social network, with each edge signifying a connection between them. The color of the nodes might represent different attributes of the individuals, such as their age groups or locations.

While this is a simple example, you can imagine how a larger node-link diagram would provide a powerful way to visualize complex networks — showing clusters of interconnected nodes, or highlighting central nodes with many connections.

This is the power of Sigma.js and node-link diagrams. With a glance, you can understand the structure and relationships within complex datasets. It helps turn abstract data into a tangible, understandable form that can be explored interactively.

Example 2: Interactive graphs

Interactive graphs are an evolution of static data visualizations. They allow users to directly interact with the visualized data, providing a richer, more engaging, and insightful user experience. For instance, an interactive graph might allow users to zoom in or out, select specific nodes or edges, hover over elements to reveal additional information, or even alter the graph structure in real time.

Interactive graphs are not just more engaging; they’re also more informative. They provide users with granular control over their view of the data, letting them explore and understand complex data structures at their own pace and in their own preferred manner. The interactivity can also help reveal patterns and insights that might be missed in a static graph.

Using Sigma.js to make your graph interactive

Sigma.js provides excellent support for creating interactive graphs. By default, Sigma.js comes with basic interactions such as zooming and panning. For more advanced interactivity, you can use event listeners and plugins.

Event listeners in Sigma.js let you bind custom actions to events like clicking or hovering over nodes or edges. For example, you could highlight a node and its neighbors when the node is clicked, or show additional information about a node when the mouse hovers over it.

Sigma.js plugins extend the core library’s capabilities, offering pre-built functionalities for common interactive features. For example, the ‘dragNodes’ plugin allows users to manually reposition nodes by dragging them, and the ‘select’ plugin provides an easy way to select nodes or edges.

How to add event listeners

Adding event listeners in Sigma.js involves using the bind method on your Sigma instance. The bind method takes two arguments: the name of the event, and a callback function to be executed when the event occurs.

Here’s how you would add a click event listener for nodes:

In this example, whenever a node is clicked, the node’s id is logged to the console.

To add a hover event listener, you would use the ‘overNode’ and ‘outNode’ events:

In these examples, when the mouse hovers over a node, the node’s id is logged to the console, and when the mouse leaves a node, that event is also logged.

Exploring the use case through a detailed example

Let’s create an interactive graph where clicking a node changes its color. We will start by creating a simple graph with three nodes and three edges, as shown in the previous example.

In this example, we’re binding a function to the ‘clickNode’ event that changes the color of the clicked node to orange. We get the id of the clicked node from the event data (e.data.node.id), use it to find the corresponding node in the graph (s.graph.nodes(nodeId)), change its color property, and finally call s.refresh() to update the graph’s appearance.

When you open the graph in your browser, you can now click on nodes to change their color. This provides an interactive way to highlight nodes or to mark them as selected.

This is just a basic example of the interactivity that Sigma.js can offer. With more complex event handlers and the use of plugins, you can build rich, interactive graph visualizations that provide a deep, intuitive understanding of your data.

Example 3: Graphs with dynamic data

Dynamic data refers to data that changes over time. In the context of graph visualization, dynamic data could mean a graph where nodes, edges, or their properties change over time. For instance, in a social network, new users might join (new nodes), existing users might form new connections (new edges), or the activity level of users might change (changing node properties).

Dynamic data presents a unique challenge for graph visualization. The visualization needs to accurately reflect the current state of the data at any given moment, but it also needs to handle the constant updates efficiently, without disrupting the user experience.

One common strategy for visualizing dynamic data is to use animations to transition between states smoothly. Another strategy is to allow users to explore the data at different time points, using interactive features such as sliders or playback controls.

Guide on integrating dynamic data using Sigma.js

Integrating dynamic data into a Sigma.js graph involves updating the graph’s nodes and edges based on your data updates. Sigma.js provides methods to add, remove, and update nodes and edges, making it suitable for visualizing dynamic data.

Here’s how you might update a Sigma.js graph with dynamic data:

In this example, we iterate over the updated nodes and edges. For each node or edge, we check if it exists in the graph. If it does, we update its properties. If it doesn’t, we add it to the graph. Finally, we refresh the graph to update its appearance.

Discussion on maintaining performance with large, dynamic data sets Maintaining performance with large, dynamic data sets is a key concern in graph visualization. As the amount of data increases, rendering the graph and updating it with new data can become slower, leading to a poor user experience.

Sigma.js addresses this challenge with several optimizations. For instance, it uses WebGL for rendering, which leverages the GPU’s power and is significantly faster than traditional, CPU-based rendering methods for large graphs. Sigma.js also includes a spatial index, which speeds up operations like finding the nodes or edges at a given location.

However, when dealing with large, dynamic data sets, it’s also important to optimize your own code. Here are a few strategies:

  • Batch updates: Rather than updating the graph every time a single node or edge changes, collect multiple updates and apply them all at once. This can reduce the overhead of refreshing the graph.
  • Limit visible data: If your data set is extremely large, consider only showing a subset of it at any given time. For instance, you might only show the nodes and edges that are within a certain distance from a selected node.
  • Use appropriate data structures: Store your data in a way that makes updates efficient. For instance, if you frequently need to find nodes by their id, consider storing nodes in an object where the keys are node ids.

Presentation of the final result and interpretation

After implementing the strategies mentioned, you will have a graph that can handle dynamic data efficiently. The nodes and edges of your graph will update in real-time as your data changes, providing an accurate, up-to-date representation of your data.

In the final output, you might notice how the graph changes and evolves over time, reflecting the dynamic nature of the underlying data. For example, in a graph representing a social network, you might see new nodes appearing as new users join the network, existing nodes changing size or color as user activity levels change, and new edges forming as users form new connections.

Interpreting a dynamic graph can reveal insights that might not be apparent in a static graph. You can observe trends and patterns over time, identify spikes or drops in activity, and track the evolution of individual nodes or the network as a whole.

By integrating dynamic data into your graph visualizations, you can unlock a deeper understanding of your data, bringing it to life and uncovering the stories it has to tell.

Example 4: Geographical data representation

Geographical data, also known as geospatial data, refers to data that represents physical objects or phenomena that occur on Earth. This includes data about geographic locations (like the coordinates of cities), physical features (like the boundaries of countries or the course of rivers), and events or conditions that have a geographic aspect (like the location of earthquakes or the distribution of temperatures).

Visualizing geographical data helps reveal patterns and insights that might be difficult to spot in raw, tabular data. For instance, by visualizing the locations of earthquakes on a map, you can quickly see if earthquakes are concentrated in certain regions.

Geographical data visualization comes in many forms, from simple point maps that show the locations of individual data points, to complex choropleth maps that color regions based on some metric. Graph visualization can also be used for geographical data, especially when there are relationships between the geographic locations that can be represented as edges.

Process of creating a geo-data visualization using Sigma.js

Creating a geographical data visualization with Sigma.js involves representing your geographic locations as nodes in a graph. You can then use edges to represent relationships between the locations. For instance, if you were visualizing a network of cities, the cities would be the nodes, and the roads connecting them would be the edges.

Here’s how you might create a basic geographic graph visualization with Sigma.js:

In this example, we’re creating a graph with two nodes representing the cities of Paris and New York. The ‘x’ and ‘y’ properties of the nodes are set to the longitude and latitude of the cities, and we add an edge to represent a flight between them.

Explanation of how to handle geo-coordinates and mapping

The example above is a simple representation of geo-data where the ‘x’ and ‘y’ properties of the nodes are set to the longitude and latitude of the cities. However, using raw longitude and latitude values as ‘x’ and ‘y’ coordinates might not give a realistic map-like appearance, due to the spherical shape of the Earth and the distortion introduced by map projections.

To create a more accurate geographical visualization, you would need to convert the geographic coordinates to a suitable map projection. A map projection is a method for representing the curved surface of the Earth on a flat plane. There are many different map projections, each with its own trade-offs between accuracy, area, distance, and direction.

For instance, the Mercator projection is a common choice for web maps. It preserves angles and directions, but distorts area. To use the Mercator projection, you would need to convert your latitudes and longitudes like this:

You would then use the returned ‘x’ and ‘y’ values as the ‘x’ and ‘y’ coordinates for your nodes.

Showcasing the final visualization and its benefits

In the final visualization, you’ll have a graph where the nodes represent geographic locations and the edges represent relationships between them. The nodes will be positioned according to their geographic coordinates, giving a map-like appearance.

This geographical data representation provides a clear visual context, allowing observers to immediately understand the geographic distribution of the data. For example, in our cities and flights example, we could quickly see which cities are connected by flights and how far apart they are.

The benefit of using Sigma.js for geographic data visualization is its ability to handle large amounts of data and complex networks. Unlike traditional map visualizations, Sigma.js allows you to visualize not just the locations, but also the relationships between them, using edges.

Furthermore, Sigma.js provides all the advantages of graph visualization, such as interactive features and the ability to customize the appearance of nodes and edges. You could, for example, change the size or color of nodes based on some property (like the population of cities), or use different types of edges to represent different types of relationships (like flights vs. road connections).

Example 5: Social network analysis

Social Network Analysis (SNA) is a methodological approach used to analyze social structures through the use of networks and graph theory. It focuses on the relationships between social entities such as individuals, groups, or organizations. By representing these entities as nodes and the relationships between them as edges, we can create a visual representation of a social network.

SNA considers social relationships in terms of network theory, consisting of nodes (representing individual actors within the network) and ties (which represent relationships between the individuals, such as friendship, kinship, organizational position, sexual relationships, etc.). These networks are often depicted in a graph form, with nodes illustrated as points and ties as lines.

Social network analysis has been applied to social science subjects such as sociology, anthropology, and psychology, as well as to diverse fields like biology, computer science, communication studies, economics, geography, information science, organizational studies, and social psychology.

Guide on creating a social network graph using Sigma.js

Creating a social network graph using Sigma.js is relatively straightforward. In a social network, the entities (like people or organizations) are represented as nodes, and the relationships between them (like friendships or collaborations) are represented as edges.

Here’s an example of how you might create a simple social network graph:

In this example, we create a graph with two nodes representing people (Alice and Bob), and an edge representing a friendship between them. The ‘x’ and ‘y’ coordinates of the nodes are random, so the nodes will be placed randomly in the graph. You could replace these with coordinates from a layout algorithm if you want a more structured appearance.

Explanation of key network measures and how to represent them

In social network analysis, there are several key network measures or metrics that are often used to understand the structure and characteristics of the network. These include:

  • Degree: The degree of a node is the number of edges connected to it. In a social network, the degree of a person’s node could represent the number of friends they have.
  • Centrality: There are several types of centrality, including degree centrality, closeness centrality, and betweenness centrality. Each measures a different aspect of a node’s importance or influence in the network.
  • Density: The density of a network is the proportion of possible edges that actually exist. A high-density network means that many of the possible relationships in the network do exist.
  • Clustering coefficient: The clustering coefficient of a node is the proportion of its neighbors that are also neighbors with each other. In a social network, a high clustering coefficient could indicate a tightly-knit group of friends.

Sigma.js doesn’t directly compute these measures, but you can use other libraries (like graphology or NetworkX in Python) to compute them, then represent them in your Sigma.js graph. For example, you could use the size or color of nodes to represent their degree or centrality, or use the thickness or color of edges to represent the strength of relationships.

Final output presentation and interpretation

Once you’ve created your social network graph and represented your network measures, you can present the final output. With Sigma.js’s interactive features, users can explore the graph, zooming in and out, and clicking on nodes and edges to learn more about them.

In the final visualization, the nodes represent individuals or entities in your network, and the edges represent relationships. The visual characteristics of the nodes and edges, such as size or color, might represent different measures or attributes, providing additional information.

For instance, a node’s size could represent its degree, so larger nodes would indicate individuals with more connections. A node’s color could represent its centrality, so more central nodes could be colored differently. An edge’s thickness might represent the strength of a relationship, so thicker edges would indicate stronger relationships.

By interpreting the final visualization, you can uncover insights about your social network. You might identify key individuals, uncover subgroups or communities, identify patterns or anomalies, or understand the overall structure and characteristics of the network.

Overall, Sigma.js provides a powerful, flexible tool for social network analysis. By visually representing social networks, it allows you to explore and understand them in a way that’s intuitive and engaging, unlocking insights that might not be apparent in raw data.

Example 6: Hierarchical edge bundling

Hierarchical Edge Bundling (HEB) is a graph visualization technique that’s particularly useful for displaying hierarchical data. The hierarchy is typically represented as a radial layout, where nodes are placed on concentric circles based on their level in the hierarchy, and edges are bundled together in a way that reflects the hierarchy.

HEB can make complex graphs more understandable by reducing clutter and making it easier to see patterns. The bundling of edges helps to show how nodes are related to each other within the hierarchical structure, and the radial layout can provide a clear, organized view of the hierarchy.

The method is especially useful when dealing with large and complex data structures, such as software dependency graphs, organizational charts, or complex network traffic visualizations, where traditional graph layouts might be overwhelming or confusing.

Step-by-step guide to creating a Hierarchical Edge Bundling graph with Sigma.js

Creating a Hierarchical Edge Bundling graph with Sigma.js is not as straightforward as creating a regular graph, because Sigma.js doesn’t provide built-in support for edge bundling or radial layouts. However, you can use additional libraries or custom code to achieve a similar effect.

The first step is to create the hierarchy and compute the radial positions of the nodes. This can be done with a library like d3-hierarchy, which provides functions for creating and manipulating hierarchical data. You could use its cluster layout to compute the radial positions of nodes.

Next, you would create the edges. In a hierarchical edge bundling graph, an edge typically goes from a node to one of its ancestors or descendants in the hierarchy. To create bundled edges, you would create a series of edges that go from each node to its parent, its parent’s parent, and so on, up to the root of the hierarchy.

Finally, you would add the nodes and edges to a Sigma.js graph and display it. The positions of the nodes would be based on the radial layout computed earlier, and the bundled edges would create the effect of hierarchical edge bundling.

Keep in mind that this approach has limitations, and it might not work well for large or complex hierarchies. For these cases, you might need to use a more advanced visualization library or technique.

Discussing potential use cases

Hierarchical Edge Bundling is particularly useful for visualizing hierarchical or nested data structures where the relationships between elements are crucial.

One typical use case is the visualization of software structures. For example, in software engineering, Hierarchical Edge Bundling could be used to visualize the dependencies between different classes or modules in a software project, helping developers understand the architecture and dependencies of the project.

Similarly, in the field of network security, Hierarchical Edge Bundling can help to visualize the flow of network traffic in a computer network. By representing network entities (like devices or IP addresses) as nodes and network connections as edges, analysts can get a clear, organized view of the network traffic.

Organizational structures can also be visualized using this method. For instance, Hierarchical Edge Bundling can depict the hierarchy of an organization, the reporting structure, and the interactions between different departments, allowing for an easy understanding of the complex relational data.

Presentation of final visualization and interpretation

In the final visualization of a Hierarchical Edge Bundling graph, nodes are placed radially based on their hierarchical level, and edges are bundled together following the hierarchy. This makes for a clean, organized visualization where the hierarchical structure and relationships between nodes are clear.

The interpretation of the graph would depend on the specific data being visualized. However, in general, the distance from the center would indicate the level in the hierarchy, so nodes on the outer circles are lower in the hierarchy. The edges would show relationships between nodes, and the bundling of edges would help to identify groups of nodes that are closely related.

For example, in a software structure visualization, nodes might represent classes or modules, and edges might represent dependencies. Classes that depend on many others would be connected by many edges, and classes that are part of the same package or module would have their edges bundled together.

Example 7: Graph layout algorithms

Graph layout algorithms are mathematical procedures that determine the positions of nodes and the paths of edges in a graph. The primary objective of these algorithms is to design a visually appealing and informative graph. There are many graph layout algorithms available, each with their own strengths, weaknesses, and appropriate use cases.

Force-directed algorithms, for example, treat edges as springs and nodes as objects repelling each other. These algorithms can create visually pleasing layouts that highlight the structure of the graph, but they can be slow for large graphs.

Circular or radial layouts arrange nodes in a circle or series of circles. These layouts are effective for highlighting certain kinds of structures, like hierarchies or communities, but they can be less informative for other kinds of graphs.

Grid or lattice layouts arrange nodes in a regular grid. These layouts can be useful for certain kinds of data, but they might not reveal the structure of the graph as effectively as other layouts.

Illustrating different layout algorithms using Sigma.js

Sigma.js does not have built-in support for many graph layout algorithms, but it provides the flexibility for users to implement their own or use other libraries to compute node positions. Let’s explore a couple of layout algorithms.

ForceAtlas2 (force-directed): This is a force-directed layout included with Sigma.js. You can apply it as follows:

In this example, ‘graph’ is your Sigma.js graph, and the other parameters are options for the layout. ‘worker: true’ allows the layout to run in a web worker, ‘autoStop: true’ makes it stop automatically when it stabilizes, ‘background: true’ lets it run in the background, ‘scaleRatio’ and ‘gravity’ control the behavior of the forces.

Circular layout: There’s no built-in support for a circular layout in Sigma.js, but you can easily implement it yourself. Here’s a simple example:

In this example, ‘graph’ is your Sigma.js graph, and ‘radius’ is the radius of the circle. The code computes the angle and position of each node, arranges them in a circle, and then refreshes the graph.

Explanation of how to choose and implement the appropriate algorithm

The choice of layout algorithm depends on the data you’re visualizing and the insights you want to convey. Force-directed layouts are often a good default choice because they can reveal the overall structure of the graph. However, for large graphs, they can be slow and might not provide a clear view of the structure.

Circular or radial layouts can be useful for highlighting hierarchical or community structures, but they might not be as effective for other kinds of graphs. Grid or lattice layouts can provide a clear, regular arrangement of nodes, but they might not reveal the structure of the graph as effectively as other layouts.

Once you’ve chosen a layout algorithm, you can implement it in Sigma.js by setting the ‘x’ and ‘y’ properties of each node. You can compute these positions yourself, use another library, or use a built-in layout like ForceAtlas2.

After setting the node positions, you should call s.refresh() to update the graph with the new layout. If you’re running a dynamic layout that updates the positions over time (like a force-directed layout), you might want to call s.refresh() regularly to show the progress of the layout.

Showcasing the result and interpretation of different layouts

Once you’ve applied a layout algorithm, the result is a graph where the positions of nodes and paths of edges are determined by the algorithm. This can provide a clear, organized view of the graph and highlight the structure of the data.

For example, with a force-directed layout, nodes that are closely connected will be drawn together, while nodes that are not connected will be pushed apart. This can reveal clusters or communities in the graph, as well as central nodes that are highly connected. However, for large or dense graphs, the result might be a hairball that’s hard to interpret.

With a circular layout, nodes will be evenly spaced around a circle. If the edges represent hierarchical or cyclic relationships, this can provide a clear view of the structure. However, for other kinds of graphs, the result might be less informative.

In interpreting the result, keep in mind that the layout algorithm is just a tool for visualizing the graph. The real insights come from the data itself. The layout can help you see the structure of the data and guide your interpretation, but it’s up to you to make sense of it.

Take your graph visualization to the next level with Sigma.js

Discover the power of Sigma.js for flexible and versatile graph visualization. At Rapidops, we believe in the transformative potential of data-driven insights. Leverage technology to drive your business forward with advanced data visualization and digital solutions. Contact us to unlock the full potential of your data!

Frequently Asked Questions

SigmaJS is a free and open-source JavaScript library for creating interactive visualizations. In this section, we will answer some of the most common questions about SigmaJS.

Is Sigma JS open source?

Yes, Sigma JS is open source. It is licensed under the MIT License, which means that you can use it for free, modify it, and redistribute it. The source code is available on GitHub.

Here are some links to the Sigma JS website and GitHub repository:

What graph algorithms are implemented in sigma.js?

None in sigma.js, but graphology has a lot, from ForceAtlas2 layout to various metrics or even community detection. You can see an overview in the documentation.

Why should I use sigma.js and not d3.js?

Sigma.js renders graphs using WebGL. It allows drawing larger graphs faster than with Canvas or SVG based solutions. It also makes custom rendering way harder to develop.

Can I use sigma.js in my React application?

Yes, the best way is certainly to use the @react-sigma. The example on top of this page is developed using it, you can check the sourcecode to get an idea.

--

--

Rapidops, Inc.
Rapidops, Inc.

Written by Rapidops, Inc.

Rapidops is a product design, development & analytics consultancy. Follow us for insights on web, mobile, data, cloud, IoT. Website: https://www.rapidops.com/

No responses yet