Files
oikos/web/node_modules/graphology-layout-forceatlas2/README.md
dtoro d4d99a7473
Some checks failed
ci / build-test (push) Has been cancelled
ci / docker-build (push) Has been cancelled
feat: Phase 1 — extract the client (web SPA + desktop) to dtoro/oikos-web
Problem: the hexagonal refactor churns the backend tree for nine more
phases; the UI delivery stack (web/ SPA, cmd/desktop Wails wrapper,
compose/web image) must move to its own repo first so doc/layout
rewrites land once on a backend-only tree.

Change:
- New repo git.hubris.network/dtoro/oikos-web (v0.33.0): web/, desktop/
  (updateURL repointed to oikos-web releases), compose/, own CI (web +
  desktop jobs), own deploy script (CI-green gate, TOCTOU guard,
  version-tagged images, prune-to-3), own webhook receiver on :9798 +
  launchd unit, own compose project publishing the same 8091:80.
- Cutover executed on mac-mini in order: oikos stack's web service
  stopped+removed, oikos-web project brought up on 8091; outer Caddy
  untouched (targets the published port) — serving + Authentik flow +
  /wails 404 quirk verified post-cutover.
- Stripped from oikos: web/, cmd/desktop/, compose/web/, desktop CI
  workflow, ci.yml web job, Makefile ui/desktop/desktop-package/install
  targets, the compose web service, oikos-web from deploy.sh's fallback
  prune list; wails + go-keyring dropped from go.mod, vendor synced.
- README / CONTRIBUTING / AGENTS.md / .agents dev+operations docs now
  point at the new repo; mbse + mascot design docs carry a path note.

Risk: production SPA serving depends on the new pipeline now; rollback
is versioned-image re-up of the old web service from a pre-split
checkout (port 8091). Desktop builds installed before the split still
check dtoro/oikos releases — one manual reinstall, noted in the
oikos-web release notes.

Verification: go vet, make test (race), make generate-check, golangci
(no new findings; baseline down 400→365); post-cutover curls —
localhost:8091 200, /wails/runtime.js 404, outer Caddy 302 Authentik.
2026-08-15 22:27:52 +02:00

114 lines
4.3 KiB
Markdown

# Graphology ForceAtlas2
JavaScript implementation of the [ForceAtlas2](https://journals.plos.org/plosone/article?id=10.1371/journal.pone.0098679) algorithm for [graphology](https://graphology.github.io).
## Reference
> Jacomy M, Venturini T, Heymann S, Bastian M (2014) ForceAtlas2, a Continuous Graph Layout Algorithm for Handy Network Visualization Designed for the Gephi Software. PLoS ONE 9(6): e98679. https://doi.org/10.1371/journal.pone.0098679
## Installation
```
npm install graphology-layout-forceatlas2
```
## Usage
- [Pre-requisite](#pre-requisite)
- [Settings](#settings)
- [Synchronous layout](#synchronous-layout)
- [Webworker](#webworker)
- [#.inferSettings](#infersettings)
### Pre-requisites
Each node's starting position must be set before running ForceAtlas 2 layout. Two attributes called `x` and `y` must therefore be defined for all the graph nodes. [graphology-layout](https://github.com/graphology/graphology-layout) can be used to initialize these attributes to a [random](https://github.com/graphology/graphology-layout#random) or [circular](https://github.com/graphology/graphology-layout#circular) layout, if needed.
Note also that the algorithm has an edge-case where the layout cannot be computed if all of your nodes starts with `x=0` and `y=0`.
### Settings
- **adjustSizes** _?boolean_ [`false`]: should the node's sizes be taken into account?
- **barnesHutOptimize** _?boolean_ [`false`]: whether to use the Barnes-Hut approximation to compute repulsion in `O(n*log(n))` rather than default `O(n^2)`, `n` being the number of nodes.
- **barnesHutTheta** _?number_ [`0.5`]: Barnes-Hut approximation theta parameter.
- **edgeWeightInfluence** _?number_ [`1`]: influence of the edge's weights on the layout. To consider edge weight, don't forget to pass `weighted` as `true` when applying the [synchronous layout](#synchronous-layout) or when instantiating the [worker](#webworker).
- **gravity** _?number_ [`1`]: strength of the layout's gravity.
- **linLogMode** _?boolean_ [`false`]: whether to use Noack's LinLog model.
- **outboundAttractionDistribution** _?boolean_ [`false`]
- **scalingRatio** _?number_ [`1`]
- **slowDown** _?number_ [`1`]
- **strongGravityMode** _?boolean_ [`false`]
### Synchronous layout
```js
import forceAtlas2 from 'graphology-layout-forceatlas2';
const positions = forceAtlas2(graph, {iterations: 50});
// With settings:
const positions = forceAtlas2(graph, {
iterations: 50,
settings: {
gravity: 10
}
});
// To directly assign the positions to the nodes:
forceAtlas2.assign(graph);
```
_Arguments_
- **graph** _Graph_: target graph.
- **options** _object_: options:
- **iterations** _number_: number of iterations to perform.
- **getEdgeWeight** _?string\|function_ [`weight`]: name of the edge weight attribute or getter function. Defaults to `weight`.
- **settings** _?object_: the layout's settings (see [#settings](#settings)).
### Webworker
If you need to run the layout's computation in a web worker, the library comes with a utility to do so:
_Example_
```js
import FA2Layout from 'graphology-layout-forceatlas2/worker';
// The parameters are the same as for the synchronous version, minus `iterations` of course
const layout = new FA2Layout(graph, {
settings: {gravity: 1}
});
// To start the layout
layout.start();
// To stop the layout
layout.stop();
// To kill the layout and release attached memory
layout.kill();
// Assess whether the layout is currently running
layout.isRunning();
```
**WARNING!**: if you are using [`webpack`](https://webpack.js.org/) to bundle your code, avoid the `cheap-eval`-like options for the [`devtool`](https://webpack.js.org/configuration/devtool/) setting. Some users noticed that it interacts in mysterious ways with the library's code and cause performance to drop dramatically when using the worker. Note that this should have been fixed from v0.5.0.
### #.inferSettings
If you don't know how to tune the layout's settings and want to infer them from your graph, you can use the `#.inferSettings` method:
```js
import forceAtlas2 from 'graphology-layout-forceatlas2';
const sensibleSettings = forceAtlas2.inferSettings(graph);
const positions = forceAtlas2(graph, {
iterations: 50,
settings: sensibleSettings
});
// Alternatively using the graph's order instead of a graph instance
const sensibleSettings = forceAtlas2.inferSettings(500);
```