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
objectVarious options which define whether the graph is directed, the result normalized and values associated with the links.
booleandefault: falseWhether 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.
stringThe name of the custom property which defines each link's weighting value. Custom properties mean properties set on the data property of the links.
booleandefault: falseSpecifies 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
objectOptions 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.
stringThe name of the custom property which defines each link's weighting value. Custom properties mean properties set on the data property of the links.
booleandefault: falseSpecifies 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
objectOptions which special rules for the clusters calculation.
booleandefault: trueSet to true to see the same result every time you run a cluster, or false if you want to see different results.
numberdefault: 5A 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.
stringThe 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
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
objectOptions 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.
stringThe 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
objectOptions 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.
stringThe 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.
booleandefault: falseSpecifies 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
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
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
string | array of strings | objectThe 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).
objectOptions 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.
numberdefault: 1Defines 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
objectOptions which define special rules for the Page Rank computation.
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
objectVarious 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.
stringThe name of the custom property which defines each link's weighting value. Custom properties mean properties set on the data property of the links.
booleandefault: falseSpecifies 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
requirednumberThe length of the shortest path - more precisely the combined link value of the path.
items
requiredobjectA dictionary whose properties are the ids of items on the shortest paths. The values are the item definitions.
one
requiredarray of stringsAn array of ids describing the same path as onePath, but containing nodes only. Includes the start and end nodes.
onePath
requiredarray of stringsOne of the shortest paths found - returned an array of alternating node and link ids. Includes the start and end nodes.