forcelayout

package
v1.37.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2026 License: MIT Imports: 7 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package forcelayout places the notes of a graph and their tags, as d3-force did in the browser: a repulsion between every node (Barnes-Hut), springs along the edges, collisions on a small graph, a pull to the center. Deterministic: the same graph gives the same map.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fit

func Fit(positions map[string]Point) map[string]Point

Fit scales a simulated layout into % of the view, around its center.

func Signature

func Signature(notes []Note, links []Link) string

Signature is a fingerprint of the notes, their tags and links (FNV-1a): a saved layout serves as is only for the same graph.

func Simulate

func Simulate(notes []Note, links []Link, seed map[string]Point) (map[string]Point, error)

Simulate places the notes and their tags, in the simulation's units: see Edges for the springs. The pull to the center weakens as the graph grows (1/√ of its nodes), or a big one shrinks into a ball. seed: a layout saved before; the nodes it lacks start next to a neighbor it has, and the whole only settles a little. Without one, a graph past sampleLimit notes is seeded from a sample of its notes: see fromSample.

func TagNode

func TagNode(tag string) string

TagNode is the node of a tag: notes have uuids, no clash.

Types

type Edge

type Edge struct {
	Source   string
	Target   string
	Strength float64
	Distance float64
}

Edge is a spring: a note to one of its tags, or a [[link]].

func Edges

func Edges(notes []Note, links []Link) []Edge

Edges gives the springs of the graph, a note to each of its tags (notes in order, their tags in order), then the [[links]].

  • A tag pulls by how rare it is among the n notes, log(n / its notes) / log(n): a tag on half of them says little. Shared among the tags of the note, so a note with many tags is not pulled harder than one with a single tag.
  • Its notes sit at √(its notes) collide radii: the room a disk of them needs, so a big tag spreads instead of piling up.
  • A [[link]] is a choice, not a vote: short and strong, weakened only on a note with many of them.
type Link struct {
	Source string
	Target string
}

Link is a [[link]] between two notes.

type Note

type Note struct {
	ID   string
	Tags []string
}

Note is a node of the graph with its tags, each tag a node too.

type Point

type Point struct {
	X float64 `json:"x"`
	Y float64 `json:"y"`
}

Point is a place, in the simulation's units or in % of the view.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL