Skip to content
Miscellaneous utils for graphology.
JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
.travis.yml
LICENSE.txt
README.md
index.js
is-graph-constructor.js
is-graph.js
merge-clique.js
merge-cycle.js
merge-path.js
merge-star.js
package-lock.json
package.json
subgraph.js
test.js

README.md

Build Status

Graphology Utils

Miscellaneous utility functions to be used with graphology.

Installation

npm install graphology-utils

Usage

#.isGraph

Function returning whether the given value is a graphology implementation's instance.

import Graph from 'graphology';
import {isGraph} from 'graphology-utils';
// Alternatively, if you want to only load the relevant code:
import isGraph from 'graphology-utils/is-graph';

const graph = new Graph();

isGraph(graph);
>>> true

isGraph(45);
>>> false

isGraph({hello: 'world'});
>>> false

Arguments

  • value any: value to test.

#.isGraphConstructor

Function returning whether the given value is a graphology constructor.

import Graph from 'graphology';
import {isGraphConstructor} from 'graphology-utils';
// Alternatively, if you want to only load the relevant code:
import isGraphConstructor from 'graphology-utils/is-graph-constructor';

isGraphConstructor(Graph);
>>> true

isGraphConstructor(45);
>>> false

isGraphConstructor(new Graph());
>>> false

Arguments

  • value any: value to test.

#.mergeCycle

Function adding a star to the given graph.

import Graph from 'graphology';
import {mergeCycle} from 'graphology-utils';
// Alternatively, if you want to only load the relevant code:
import mergeCycle from 'graphology-utils/merge-cycle';

const graph = new Graph();

mergeCycle(graph, [1, 2, 3, 4, 5]);
graph.edges().map(e => graph.extremities(e));
>>> [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1]]

Arguments

  • graph Graph: target graph.
  • cycle array: array of nodes representing the cycle to add.

#.mergePath

Function adding a path to the given graph.

import Graph from 'graphology';
import {mergePath} from 'graphology-utils';
// Alternatively, if you want to only load the relevant code:
import mergePath from 'graphology-utils/merge-path';

const graph = new Graph();

mergePath(graph, [1, 2, 3, 4, 5]);
graph.edges().map(e => graph.extremities(e));
>>> [[1, 2], [2, 3], [3, 4], [4, 5]]

Arguments

  • graph Graph: target graph.
  • path array: array of nodes representing the path to add.

#.mergeStar

Function adding a star to the given graph.

import Graph from 'graphology';
import {mergeStar} from 'graphology-utils';
// Alternatively, if you want to only load the relevant code:
import mergeStar from 'graphology-utils/merge-star';

const graph = new Graph();

mergeStar(graph, [1, 2, 3, 4, 5]);
graph.edges().map(e => graph.extremities(e));
>>> [[1, 2], [1, 3], [1, 4], [1, 5]]

Arguments

  • graph Graph: target graph.
  • star array: array of nodes representing the star to add.

#.subGraph

Function returning the subgraph corresponding to the given list of nodes.

import Graph from 'graphology';
import {subGraph} from 'graphology-utils';
// Alternatively, if you want to only load the relevant code:
import subGraph from 'graphology-utils/subgraph';

const graph = new Graph();

graph.addNode('Dale');
graph.addNode('Laura');
graph.addNode('Norma');
graph.addNode('Shelly');
graph.addEdge('Dale', 'Laura');
graph.addEdge('Dale', 'Norma');
graph.addEdge('Shelly', 'Laura');
graph.addUndirectedEdge('Norma', 'Shelly');

subGraphResult = subGraph(graph, ['Dale', 'Laura']);
subGraphResult.nodes();
>>> [ 'Dale', 'Laura' ]
subGraphResult.forEachEdge(
  (edge, attributes, source, target) => {
    console.log(`Edge from ${source} to ${target}`);
});
>>> 'Edge from Dale to Laura'

Arguments

  • graph Graph: source graph.
  • nodes array|Set|function: the array, set or function defining the subgraph's nodes.
You can’t perform that action at this time.