1.0.1 • Published 6 months ago
@graphty/layout v1.0.1
Layout.js
Layout.js is a JavaScript library for node positioning in graphs. It is a JavaScript port of the layout algorithms found in the Python NetworkX library.
Features
The library offers various graph layout algorithms, including:
- Random Layout
- Circular Layout
- Shell Layout
- Spring Layout (Fruchterman-Reingold)
- Spectral Layout
- Spiral Layout
- Bipartite Layout
- Multipartite Layout
- BFS Layout
- Planar Layout
- Kamada-Kawai Layout
- ForceAtlas2 Layout
- ARF Layout (Attractive and Repulsive Forces)
How to Use
Import the library into your JavaScript project:
import {
randomLayout,
circularLayout,
springLayout
// other layout functions...
} from './layout.js'Usage example:
// Create a graph (data structure with nodes() and edges())
const graph = {
nodes: () => [0, 1, 2, 3],
edges: () => [
[0, 1],
[1, 2],
[2, 3],
[3, 0]
]
}
// Apply a layout
const positions = circularLayout(graph)
// positions will be an object with x,y coordinates for each node
// { 0: [1, 0], 1: [0, 1], 2: [-1, 0], 3: [0, -1] }Requirements
- Modern browser with ES6 support