The Graph Engine
Contents
Introduction
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.
Graph Engine Advantages
There are many advantages to using the graph engine, particularly when working with large datasets:
- You don't have to manipulate the chart to run graph analysis.
- You can carry out analysis on a subset of the rendered graph.
- It allows you to use the analysis functions of KeyLines without also rendering the graph visualisation, so you can run graph calculations on larger datasets without having to wait for charts to display.
- It's quicker and easier to carry out graph traversals such as shortestPath, and social network analysis metrics, including degrees or betweenness.
- It's integrated into KeyLines already, so there's no need to add extra files.
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.
Getting started
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();
Graph Engines in NodeJS
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();
See Also
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.