Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
graphology-layout
Advanced tools
Collection of basic layout algorithms to be used with graphology
.
npm install graphology-layout
Basic
Advanced
Utilities
Arranges the node in a circle (or an sphere/hypersphere in higher dimensions).
Example
import {circular} from 'graphology-layout';
// Alternatively, to load only the relevant code:
import circular from 'graphology-layout/circular';
const positions = circular(graph);
// With options:
const positions = circular(graph, {scale: 100});
// To directly assign the positions to the nodes:
circular.assign(graph);
// To pass custom dimensions
const positions = random(graph, {dimensions: ['x1', 'x2']});
Arguments
['x', 'y']
]: dimensions of the layout. Cannot work with dimensions != 2.0.5
]: center of the layout.1
]: scale of the layout.Random layout positioning every node by choosing each coordinates uniformly at random on the interval [0, 1)
.
Example
import {random} from 'graphology-layout';
// Alternatively, to load only the relevant code:
import random from 'graphology-layout/random';
const positions = random(graph);
// With options:
const positions = random(graph, {rng: customRngFunction});
// To directly assign the positions to the nodes:
random.assign(graph);
// To pass custom dimensions
const positions = random(graph, {dimensions: ['x', 'y', 'z']});
Arguments
['x', 'y']
]: dimensions of the layout.0.5
]: center of the layout.Math.random
]: custom RNG function to use.1
]: scale of the layout.Arranges the nodes as a bubble chart, according to specified attributes.
Example
import {circlepack} from 'graphology-layout';
// Alternatively, to load only the relevant code:
import circlepack from 'graphology-layout/circlepack';
const positions = circlepack(graph);
// With options
const positions = circlepack(graph, {
hierarchyAttributes: ['degree', 'community'],
rng: customRngFunction
});
// To directly assign the positions to the nodes:
circlepack.assign(graph);
Arguments
x
]: name of the x position.y
]: name of the y position.0
]: center of the layout.[]
]: attributes used to group nodes.Math.random
]: custom RNG function to use.1
]: scale of the layout.Rotates the node coordinates of the given graph by the given angle in radians (or in degrees using an option).
Note that this function rotates your graph based on its center. If you want to use zero as the center for your rotation, use the centeredOnZero
option. This option can also be used as an optimization strategy if you know your graph is already centered on zero to avoid needing to compute the graph's extent.
Example
import {rotation} from 'graphology-layout';
// Alternatively, to load only the relevant code:
import rotation from 'graphology-layout/rotation';
const positions = rotation(graph, Math.PI / 2);
// With options:
const positions = rotation(graph, Math.PI / 2, {centeredOnZero: true});
// To directly assign the positions to the nodes:
rotation.assign(graph, Math.PI / 2);
Arguments
['x', 'y']
]: dimensions to use for the rotation. Cannot work with dimensions != 2.false
]: whether the given angle is in degrees.false
]: whether to rotate the graph around 0
, rather than the graph's center.Function returning the given graph's layout as {node: {x, y}}
.
Example
import {collectLayout} from 'graphology-layout/utils';
collectLayout(graph);
// Custom dimensions
collectLayout(graph, {dimensions: ['x', 'y', 'z']});
// Non exhaustive (i.e. node having missing dimensions will be returned also)
collectLayout(graph, {exhaustive: false});
Arguments
['x', 'y']
]: array of attribute names for the dimensions.true
]: whether to collect positions of nodes having all the dimensions set.Function returning the given graph's layout as a flat array of length order * dimensions
.
Example
import {collectLayoutAsFlatArray} from 'graphology-layout/utils';
collectLayoutAsFlatArray(graph);
// Custom dimensions
collectLayoutAsFlatArray(graph, {dimensions: ['x', 'y', 'z']});
// Custom type
collectLayoutAsFlatArray(graph, {type: Float32Array});
Arguments
['x', 'y']
]: array of attribute names for the dimensions.Float64Array
]: array class to use.Function assigning a {node: {x, y}}
layout to the given graph.
Example
import {assignLayout} from 'graphology-layout/utils';
assignLayout(graph, layout);
// Custom dimensions
assignLayout(graph, layout, {dimensions: ['x', 'y', 'z']});
Arguments
['x', 'y']
]: array of attribute names for the dimensions.Function assigning a flat array layout to the given graph.
Example
import {assignLayoutAsFlatArray} from 'graphology-layout/utils';
assignLayoutAsFlatArray(graph, layout);
// Custom dimensions
assignLayoutAsFlatArray(graph, layout, {dimensions: ['x', 'y', 'z']});
Arguments
['x', 'y']
]: array of attribute names for the dimensions.FAQs
Collection of basic layout algorithms for graphology.
The npm package graphology-layout receives a total of 19,585 weekly downloads. As such, graphology-layout popularity was classified as popular.
We found that graphology-layout demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.