# Graphology Components

Connected components for `graphology`.

## Installation

``````npm install graphology-components
``````

## Usage

### forEachConnectedComponent

Iterates over the connected components of the given graph using a callback.

``````import {forEachConnectedComponent} from 'graphology-components';

forEachConnectedComponent(graph, component => {
console.log(component);
});
``````

### forEachConnectedComponentOrder

Specialized version of forEachConnectedComponent that iterates over the connected component orders, i.e. the number of nodes they contain.

It consumes less memory than a naive approach mapping the component lengths using `forEachConnectedComponent`.

``````import {forEachConnectedComponentOrder} from 'graphology-components';

forEachConnectedComponentOrder(graph, order => {
console.log(order);
});
``````

### connectedComponents

Returns the list of connected components of the given graph.

``````import {connectedComponents} from 'graphology-components';

const components = connectedComponents(graph);
``````

If your graph is mixed or directed, the result will be what are usually called weakly connected components.

### largestConnectedComponent

Returns the largest connected component of the given graph.

``````import {largestConnectedComponent} from 'graphology-components';

const largest = largestConnectedComponent(graph);
``````

### largestConnectedComponentSubgraph

Returns a subgraph of the largest connected component of the given graph.

``````import {largestConnectedComponentSubgraph} from 'graphology-components';

const subgraph = largestConnectedComponentSubgraph(graph);
``````

### cropToLargestConnectedComponent

Mutates the given graph to remove nodes and edges that are not part of its largest connected component.

``````import {cropToLargestConnectedComponent} from 'graphology-components';

cropToLargestConnectedComponent(graph);
``````

### stronglyConnectedComponents

Returns the list of strongly connected components of the given graph. (mixed or directed)

``````import {stronglyConnectedComponents} from 'graphology-components';

const components = stronglyConnectedComponents(graph);
``````