The graph engine powers the analysis features in KeyLines, keeping them separate from the methods used to render charts. This allows you to build a graph engine, loading any data, and run graph functions, such as traversals and SNA computations, without having to display every chart item first.
A graph engine considers the underlying level of the chart and so is particularly suited to calculating neighbours or centrality measures.
There are many advantages to using the graph engine, particularly when working with large datasets:
The Graph Engine also can be used in a server-side Node.js application.
Note that the graph engine is not a graph database. It's designed to perform graph traversals and run efficiently in a web browser, not to hold billions of nodes and edges in a back-end environment.
These steps show how to create a Graph Engine using getGraphEngine(), and perform computation tasks without rendering the chart.
Step 1 - Create a Graph Engine instance:
const graph = KeyLines.getGraphEngine();
Step 2 - Use the KeyLines Graph Engine API to load the data:
const data = { type: 'LinkChart', items: [ ... ] };
graph.load(data);
You can also load a saved chart (or serialize the current one) in the Graph Engine instance:
graph.load(chart.serialize());
Step 3 - Perform the graph traversals or SNA computations:
const degrees = graph.degrees();
You can use the graph engine in any javascript environment, including NodeJS.
Here are some useful code-snippets to set up the KeyLines Graph Engine in NodeJS.
Step 1 - Import keylines:
import KeyLines from 'keylines/esm';
Step 2 - Create a Graph Engine instance:
const graph = KeyLines.getGraphEngine();
Step 3 - Use the KeyLines Graph Engine API to load data:
const data = {type: 'LinkChart', items: [ ... ]};
graph.load(data);
or load a saved chart in the Graph Engine instance:
graph.load(savedChart);
Step 4 - Perform the graph traversals or SNA computations:
const degrees = graph.degrees();
The KeyLines graph engine comes with many centrality measures that can be used for social network analysis. See the Graph Centrality documentation for details.
A Graph Engine instance offers every function available in chart.graph(), plus methods to load and manipulate the data. If a method in the API Reference is labelled +graphOnly(), it's only available in the Graph Engine.