Force
A force-directed layout of a graph's nodes and edges, simulated live.
Static preview; loading the interactive plot
<script>
import {
Plot,
Force,
Edges,
Nodes,
Segments,
Points,
GraphData,
} from "hmplot";
const data = {
source: ["A", "A", "B", "C", "D"],
target: ["B", "C", "C", "D", "E"],
};
</script>
<Plot {data} height={300}>
<GraphData source="source" target="target"
><Force warmup={300}>
<Edges><Segments start="start" end="end" /></Edges>
<Nodes><Points position="position" /></Nodes>
</Force></GraphData
>
</Plot>
Usage
Provides Nodes and Edges scopes. Initializes paused. running plays and pauses it, and each change of step, reset, reheat or release runs that action once, so a Checkbox and Buttons can drive it: running={input("run")}, reset={input("reset")}. The handle’s action(id) does the same from code. Defaults include seed 42, link distance 30, repulsion 30, and velocity decay 0.4. Supports 2D/3D and node dragging; topology changes reset the layout.
Requires graph data from GraphData. Outputs are visible to children only. Transforms retain the previous complete result while an update prepares. To let the viewer change a setting, read an input in it: repulsion={input("repulsion")} (Python repulsion=hm.input.repulsion), where repulsion is a Slider.