Search

Graph Functions

ReGraph exposes a number of powerful graph analysis functions to add insight to your data. These functions are in the 'regraph/analysis' package.

The example below shows how to remove singletons (nodes without any neighbors) from your data using the degrees function, which returns the number of neighbors each item has.

import React from 'react';
import { Chart} from 'regraph';
import { degrees } from 'regraph/analysis';

async function removeSingletons(items) {
  const neighbors = await degrees(items);
  const filtered = { ...items };
  for (var id in neighbors) {
    if (neighbors[id] < 1) {
      delete filtered[id];
    }
  }
  return filtered;
}

function FilteredChart() {
  const [items, setItems] = React.useState(getData());
  const filter = async () => {
    const filtered = await removeSingletons(items);
    setItems(filtered);
  };

  return (
    <div style={{ width: '100%', height: '100%' }}>
      <button onClick={filter}>Filter</button>
      <Chart items={items} />
    </div>
  );
}

By default, graph functions run on nodes and links in the underlying chart level and ignore combos, summary links and aggregate links. For more details, see the Graph Analysis documentation.

Calculates the betweenness centrality of all nodes in the graph.

Parameters

items
required
object

The items to analyze.

object

Various options which define whether the graph is directed, the result normalized and values associated with the links.

boolean default: false

Whether the betweenness computation should consider the direction of links.

'chart' | 'unnormalized' | 'component' default: 'component'

Normalizes the results to ensure that returned values are between 0 and 1. ‘chart’ normalizes the scores of all nodes on the chart by dividing by a single value. ‘component’ considers each unconnected part of a chart as a separate graph, dividing all connected nodes by the same value, but other components by a different value.

string

The name of the custom property which defines each link's weighting value. Custom properties mean properties set on the data property of the links.

boolean default: false

Specifies if the path length of links are the reciprocal of their value, i.e. ( 1 / value ).

Returns Promise

Returns a Promise which resolves to a dictionary whose properties are the ids of the nodes in the graph. The values are the betweenness values.

Calculates the closeness centrality of all nodes in the graph.

Parameters

items
required
object

The items to analyze.

object

Options which define whether the graph is directed, the result normalized and values associated with the links.

'from' | 'to' | 'any' default: 'any'

Specifies whether to take link direction into account. 'from' only includes links in the direction of arrows, 'to' only includes links against the direction of arrows, and 'any' includes any link regardless of arrows. Note that to use 'from' or 'to', your graph must have arrows on links.

'chart' | 'component' default: 'component'

Normalizes the results to ensure that returned values are between 0 and 1. ‘chart’ normalizes the scores of all nodes on the chart by dividing by a single value. ‘component’ considers each unconnected part of a chart as a separate graph, dividing all connected nodes by the same value, but other components by a different value.

string

The name of the custom property which defines each link's weighting value. Custom properties mean properties set on the data property of the links.

boolean default: false

Specifies if the path length of links are the reciprocal of their value, i.e. ( 1 / value ).

Returns Promise

Returns a Promise which resolves to a dictionary whose properties are the ids of the nodes in the graph. The values are the closeness values.

Groups nodes in the graph into a set of clusters, and then returns an object describing them.

Parameters

items
required
object

The items to analyze.

object

Options which special rules for the clusters calculation.

boolean default: true

Set to true to see the same result every time you run a cluster, or false if you want to see different results.

number default: 5

A number from 0 to 10 that affects cluster size. Higher values give smaller clusters, but more of them; lower values give larger clusters, but not as many.

string

The name of a custom property which defines each link's weighting value. Custom properties mean properties set on the data property of the links. Higher valued links tend to cluster their nodes more closely.

Returns Promise

Returns a Promise which resolves to an array of dictionaries, one entry for each cluster. The values of each dictionary are the items in that cluster.

Returns the separate 'connected components' of the graph.

Parameters

items
required
object

The items to analyze.

Returns Promise

Returns a Promise which resolves to an array of dictionaries, one entry for each component. The values of each dictionary are the items in that component.

Calculates the degrees (number of links) of all nodes in the graph.

Parameters

items
required
object

The items to analyze.

object

Options which define the direction and values associated with the links.

'from' | 'to' | 'any' default: 'any'

Specifies whether to take link direction into account. 'from' counts only links with arrows pointing away from nodes (out-degree), 'to' counts only links with arrows pointing to nodes (in-degree), and 'any' counts all links regardless of whether they have arrows. Note that to use 'from' or 'to', your graph must have arrows on links.

string

The name of the custom property which defines each link's weighting value. Custom properties mean properties set on the data property of the links.

Returns Promise

Returns a Promise which resolves to an object whose properties are the ids of the nodes, the values of which are the degree values.

Calculates the distances of all nodes from the node specified. The distance is the number of edges in a shortest path.

Parameters

items
required
object

The items to analyze.

id
required
string

The id of the node to start from.

object

Options for the direction and values associated with the paths.

'from' | 'to' | 'any' default: 'any'

Specifies whether to take link direction into account. 'from' only includes links in the direction of arrows, 'to' only includes links against the direction of arrows, and 'any' includes any link regardless of arrows. Note that to use 'from' or 'to', your graph must have arrows on links.

string

The name of the custom property which defines the distance value of a link. Custom properties mean properties set on the data property of the links.

boolean default: false

Specifies if the path length of links are the reciprocal of their value, i.e. ( 1 / value ).

Returns Promise

Returns a Promise which resolves to a dictionary object, where the properties are the ids of the nodes and the values are the distances.

Computes the eigenvector centrality of each node.

Parameters

items
required
object

The items to analyze.

object

Options which define special rules for the eigencentrality computation.

string

The name of the custom property which defines each link's weighting value. Custom properties mean properties set on the data property of the links. If not set, all links have value 1.

Returns Promise

Returns a Promise which resolves to a dictionary object, where the properties are the ids of the nodes and the values are the eigenvector centralities.

Calculates subgraphs of the graph where each node has a degree at least k. It works by successively removing nodes of degree less than k until no further nodes can be removed.

Parameters

items
required
object

The items to analyze.

Returns Promise

Returns a Promise which resolves to an object which describes the kCores found.

Calculates the list of neighboring (i.e. linked) items to the ids supplied.

Parameters

items
required
object

The items to analyze.

string | array of strings | object

The items whose neighbors should be found. Can be either a string id, an array of string ids, or an object of items (indexed by id).

object

Options which define special rules for items iteration.

'from' | 'to' | 'any' default: 'any'

Specifies whether to take link direction into account. 'from' only finds neighbors in the direction of arrows, 'to' only finds neighbors against the direction of arrows, and 'any' finds neighbors on any link regardless of arrows. Note that to use 'from' or 'to', your graph must have arrows on links.

number default: 1

Defines how far away neighbors can be from the passed ids.

Returns Promise

Returns a Promise which resolves to a dictionary of neighboring items.

Computes the Page Rank of each node.

Parameters

items
required
object

The items to analyze.

object

Options which define special rules for the Page Rank computation.

boolean default: true

Whether the Page Rank computation should consider the direction of links.

string

The name of the custom property which defines each link's weighting value. Custom properties mean properties set on the data property of the links. If not set, all links have value 1.

Returns Promise

Returns a Promise which resolves to a dictionary object, where the properties are the ids of the nodes and the values are the Page Rank scores.

Calculates all the shortest paths between the nodes specified.

Parameters

items
required
object

The items to analyze.

string

The id of the starting node on the path.

string

The id of the ending node on the path.

object

Various options for the direction and values associated with the paths.

'from' | 'to' | 'any' default: 'any'

Specifies whether to take link direction into account. 'from' only traverses links in the direction of arrows, 'to' only traverses links against the direction of arrows, and 'any' can traverse any link regardless of arrows. Note that to use 'from' or 'to', your graph must have arrows on links.

string

The name of the custom property which defines each link's weighting value. Custom properties mean properties set on the data property of the links.

boolean default: false

Specifies if the path length of links are the reciprocal of their value, i.e. ( 1 / value ).

Returns Promise<ShortestPathsResult>

Returns a Promise which resolves to an object which describes the path structure.

distance

required
number

The length of the shortest path - more precisely the combined link value of the path.

items

required
object

A dictionary whose properties are the ids of items on the shortest paths. The values are the item definitions.

one

required
array of strings

An array of ids describing the same path as onePath, but containing nodes only. Includes the start and end nodes.

onePath

required
array of strings

One of the shortest paths found - returned an array of alternating node and link ids. Includes the start and end nodes.

Terms of use

These terms do not alter or supersede any existing agreements between you (or your employer) and us.

By accessing or using any Content you agree to be bound by these Terms of Use. Please review these terms carefully before using the website.

The contents of this website, including but not limited to any text, code samples, API references, schemas, interactive tools, and other materials (collectively, the 'Content'), are made available for informational and internal evaluation purposes only. All intellectual property rights in the Content are reserved. No licence is granted to use the Content for any commercial purpose, or to copy, distribute, modify, reverse-engineer, or incorporate any part of the Content into any product or service, without our prior written consent.

This Content is provided “as is” and “as available,” without any representations, warranties, or guarantees of any kind, whether express or implied, including but not limited to implied warranties of merchantability, fitness for a particular purpose, non-infringement, or accuracy. To the fullest extent permitted by applicable law, we expressly exclude and disclaim all implied warranties, conditions, and other terms that might otherwise be implied.

We disclaim all liability for any loss or damage, whether direct, indirect, incidental, consequential, or otherwise, arising from any reliance placed on the Content or from your use of it, to the fullest extent permitted by applicable law. By continuing to access or use the Content, you acknowledge and agree to these terms.