Realistic graphs for force layouts and demos
The Network Graph Data Generator produces nodes and edges for network visualizations — social graphs, dependency trees, knowledge graphs and the like. It always yields a connected graph and lets you dial connectivity from a sparse tree up to a dense mesh, then exports in the format your library expects.
How it works
Generation has two phases. First, the tool builds a random spanning tree: every node after the first links to a randomly chosen earlier node, which guarantees the whole graph is connected with exactly n − 1 edges and no orphans. Second, it adds extra edges until the edge count reaches a target derived from your density setting, computed as (n − 1) + density × (maxEdges − (n − 1)), where maxEdges is the number of distinct pairs (n(n−1)/2 for undirected, n(n−1) for directed). A Set of edge keys prevents duplicate or self-loop edges, and each edge gets a random integer weight.
The three exporters reshape the same graph. The d3-force format emits nodes (with id, label, group and computed degree) and links (source, target, value). The Cytoscape format wraps each node and edge as an element with a data object. The adjacency format outputs an ids array and a weighted matrix, mirrored across the diagonal for undirected graphs.
Tips and example
- For a clean, readable force-layout demo, keep density low (around 20–30 percent) so the graph stays legible.
- Use the adjacency format when feeding a graph algorithm that wants a matrix rather than an edge list.
- A directed graph produces an asymmetric adjacency matrix, which is useful for testing flow or dependency direction rendering.
- Node
degreeis precomputed in the d3 output, so you can size nodes by connection count without recalculating.