Documentation
¶
Overview ¶
Package render lays out gonx graphs and writes them as self-contained SVG images. It exists so the examples in examples/ can regenerate the README gallery with zero dependencies beyond the standard library; it is NOT part of the gonx API (serialization and rendering are out of scope for the library).
Index ¶
- Constants
- func EdgeAlpha(a float64) string
- func Jitter(pos []Point, amount float64, r *rand.Rand)
- func Ramp(t float64, stops ...string) string
- func Relax(g *gonx.Graph, pos []Point, iters int)
- func SVG(g *gonx.Graph, pos []Point, st Style) string
- func WriteSVG(path string, g *gonx.Graph, pos []Point, st Style) error
- type Point
- type Style
Constants ¶
const ( Bg = "#0d1117" // canvas (GitHub-dark) Ink = "#e6edf3" // light text Indigo = "#6366f1" Cyan = "#22d3ee" Amber = "#fbbf24" Rose = "#fb7185" )
Shared palette so the gallery images read as one set.
Variables ¶
This section is empty.
Functions ¶
func Jitter ¶
Jitter nudges each position by up to ±amount in both axes, deterministically. Useful to break symmetry in hand-seeded layouts before calling Relax.
func Ramp ¶
Ramp linearly interpolates through the given "#rrggbb" color stops at t in [0, 1]. With three stops, t = 0.5 lands exactly on the middle one.
func Relax ¶
Relax refines pos in place with the Fruchterman-Reingold force model: all pairs repel with k^2/d, edges attract with d^2/k, a mild gravity pulls toward the centroid, and a linearly cooling temperature caps each step. O(iters * n^2); intended for the few-hundred-node graphs in the gallery.
Types ¶
type Point ¶
type Point struct{ X, Y float64 }
Point is a node position in layout space (arbitrary units; SVG fits it later).
func CircleLayout ¶
CircleLayout places n nodes evenly on a unit circle, node 0 at twelve o'clock, proceeding clockwise so ascending IDs read like a clock face.
func ForceLayout ¶
ForceLayout computes a Fruchterman-Reingold layout from deterministic random initial positions. Same graph + seed + iters always yields the same picture.
func RandomLayout ¶
RandomLayout scatters n nodes deterministically in the unit square.
type Style ¶
type Style struct {
Width, Height int // canvas size in px (default 1600x1000)
Pad float64 // inner margin in px (default 70)
Background string // default Bg
NodeFill func(u int) string // default Indigo
NodeRadius func(u int) float64 // default 8
NodeStroke string // ring separating overlapping nodes; default Bg
EdgeStroke func(u, v int) string // default EdgeAlpha(0.30)
EdgeWidth func(u, v int) float64 // default 1.4
Label func(u int) string // empty string = no label (default: no labels)
LabelFill func(u int) string // default Bg (dark text on bright nodes)
}
Style controls how a graph is drawn. Per-node and per-edge callbacks may be nil, in which case sensible defaults from the shared palette are used.