Skip to content

@mk7s/holochart-traces-graph ​

Classes ​

ClassDescription
GraphLayoutWorkerA layout worker and the requests sent to it. Most callers use the shared one through layoutInWorker; make your own for a worker that serves one chart and ends with it.

Interfaces ​

InterfaceDescription
AdjacencyMatrixA graph as a matrix: the x, y and z of a heatmap trace.
AdjacencyMatrixOptionsOptions of fromAdjacencyMatrix.
AdjacencyOptionsOptions of adjacencyMatrix.
ArcLayoutOptionsOptions of arcLayout. Lengths are layout units (CSS px).
ArcLayoutResultWhat arcLayout returns: the positions and routes, and the order it chose.
BundleGraphThe links and, for hierarchical bundling, the hierarchy. A LayoutGraph fits.
BundleOptionsOptions of bundleLinks: the method, the shared strength, and the options of both methods (each reads its own and ignores the other's).
BundlePositionsNode centers, as a LayoutResult has them. The number of nodes is the length of the arrays.
BundleResultWhat bundleLinks returns.
BundleSpaceThe space links are bundled in: positions in it are (v − origin) × scale of the calc's linear coordinates, per axis. A computed arrangement is in layout units, a px each, and is bundled as it is. Positions that are data ('preset') may be anything on either axis, dates against counts: they are bundled as they will be drawn, an estimate of their px in the plot area, so that the angles and lengths the bundling compares are the ones on screen.
ChordArcThe arc of one node.
ChordCalcCalcdata of a chord trace.
ChordGroupArcThe arc of one group, around the arcs of its nodes.
ChordLayout-
ChordLayoutInputWhat chordLayout lays out.
ChordLayoutOptions-
ChordRibbonThe ribbon of one link: a span of its source's arc and a span of its target's.
ChordTraceGroupsThe outer ring of node.group: one arc around the nodes of every group, with its name.
ChordTraceGroupsTextfontFont of the group labels, drawn across the radius outside the group arcs. Default: textfont, bold.
ChordTraceLinkThe links: ribbons between the arcs.
ChordTraceNodeThe nodes: arcs of the ring.
ChordTraceNodeLineOutlines of the node arcs.
ChordTraceTextfontFont of the node labels. Default: layout.font.
CircularOptionsOptions of circularLayout.
CommunityOptionsOptions of louvain and modularity.
ComponentsThe connected components of a graph.
DegreesDegrees of every node.
DendrogramOptionsOptions of dendrogramLayout. Lengths are layout units (CSS px).
DendrogramResultWhat dendrogramLayout returns.
EdgeListOptionsOptions of fromEdgeList.
EncodedLayoutResultA LayoutResult, or what a layout returns on top of one (order, hidden, valueAxis, …), ready to post: fields holds every property that is not a list of routes (typed arrays, which are transferred, and plain values, which are cloned), routes every list of routes by property name (routes, a tree's parentRoutes).
EncodedRoutesA list of routes as three arrays: route k is kind[k] (0: none, the link is straight; 1: a polyline; 2: a spline) and its points are points[start[k] … start[k + 1]).
ForceBundleOptionsOptions of forceBundle.
ForceBundleResultWhat forceBundle returns.
ForceOptions-
ForceStartPositions a force layout goes on from, one per node (NaN: none), and how warm it is there.
Graph3dCalc-
Graph3dPlanesThe planes of arrangement: 'layered'.
Graph3dTraceForceOptions of the force layout in three dimensions: of arrangement: 'force', and of the nodes within their planes with 'layered' (where linkdistance defaults to layered.ranksep). Lengths are layout units.
Graph3dTraceHighlightHighlighting: the neighbourhood of the node or link under the pointer (or of highlight.nodes), and a shortest path between the two nodes of highlight.path. What is highlighted keeps its look, its label shows even where there was no room for it, and everything else is dimmed; only colors change. A hover comes first, then highlight.nodes, then a path.
Graph3dTraceLayeredThe layout of arrangement: 'layered': cycles are broken as in the 2D layered layout (the reversed links keep their direction in the drawing), every node gets a rank, each rank is a plane, and the nodes of a plane are spread by the force layout (force) with their coordinate along axis held.
Graph3dTraceLinkThe links.
Graph3dTraceLinkArrowArrowheads, as cones. Their tips stop at the node's surface, whatever its size.
Graph3dTraceNodeThe nodes.
Graph3dTraceNodeLineOutlines of the nodes (node.render: 'sprite' only).
GraphBundleWhat calc knows of the bundling of a trace's links.
GraphCalc-
GraphDataWhat an adapter returns.
GraphForceWhat force.simulate needs to run the layout of a calc again, step by step.
GraphGuidesLines an arrangement draws behind the graph (the axes of a hive plot) and their names.
GraphLayoutWorkerOptionsOptions of a GraphLayoutWorker.
GraphLikeAnything with nodes and links by index: a GraphData, or a trace's two containers.
GraphLinkDataThe link container: one entry per link in every array that is present.
GraphModel-
GraphNodeDataThe node container: one entry per node in every array that is present.
GraphPathInfoA highlighted path as an app reads it: indices are the trace's own.
GraphPendingWhat a calc waits for: the request the view makes, and the key its answer is kept under.
GraphTraceArcOptions of arrangement: 'arc'. Lengths are layout units: CSS px at the size the graph is laid out for, before it is fitted to the plot area.
GraphTraceCustomThe layout of arrangement: 'custom'.
GraphTraceForceOptions of arrangement: 'force'. Lengths are layout units: CSS px at the size the graph is laid out for, before it is fitted to the plot area.
GraphTraceForceStartA picture the layout goes on from, in place of the spiral: where every node is, and how warm the layout still is there. Pinned nodes (node.x and node.y) are where those say; the layout is centered on the middle of these positions and not moved afterwards. The chart writes it when a node is dragged, so that the figure is the picture on screen: at rest (alpha: 0) on a drop, with alpha: 0.3 when a pinned node is released, and once more at rest when a layout shown with force.simulate has settled. While it is at rest the other force options change nothing: unset it to lay the graph out afresh.
GraphTraceHighlightHighlighting: the neighbourhood of the node or link under the pointer (or of highlight.nodes), and a shortest path between two selected nodes or the two of highlight.path. What is highlighted keeps its look, its label shows even where there was no room for it, and everything else is dimmed; nothing is laid out or built again. A hover comes first, then highlight.nodes, then a path.
GraphTraceHiveOptions of arrangement: 'hive'. A link between two nodes of one axis is not drawn: a hive plot shows what goes on between the axes.
GraphTraceLayeredOptions of arrangement: 'layered'. Lengths are layout units: CSS px at the size the graph is laid out for, before it is fitted to the plot area.
GraphTraceLinkThe links.
GraphTraceLinkArrowArrowheads. Their tips stop at the node's edge, whatever its size.
GraphTraceLinkBundleLink bundling. Default: none.
GraphTraceLinkSecondaryStyle of the links an arrangement sets apart from the others: with 'layered', the links that close a cycle, which the layout had to turn around to give every other link one direction (back edges; their arrowheads still point the way the data says); with 'tree', 'radial' and 'dendrogram', the links that are not part of the tree (they skip levels or join two branches, and are drawn straight). Default: dashed and a little fainter.
GraphTraceNodeThe nodes.
GraphTraceNodeLineOutlines of the nodes.
GraphTraceNodeTextfontFont of the node labels. Default: layout.font, with the automatic halo (shadow: auto). Family, size, weight and style set the size of box nodes.
GraphTraceSelectedStyle of selected nodes while a selection is active (box or lasso select, selectedpoints). Links between two selected nodes keep their style; the others are dimmed.
GraphTraceSelectedNodeStyle of selected nodes.
GraphTraceTreeOptions of the tree arrangements: 'tree', 'radial' and 'dendrogram'. The tree is the one parents gives; with link.source / link.target, each node hangs from the first node that links to it, starting at the nodes without incoming links, and the links left over are drawn in the link.secondary style. Lengths are layout units: CSS px at the size the graph is laid out for, before it is fitted to the plot area.
GraphTraceTreeSector'radial': the part of the circle the tree fans out over.
GraphTraceUnselectedStyle of unselected nodes while a selection is active (box or lasso select, selectedpoints). Links between two selected nodes keep their style; the others are dimmed.
GraphTraceUnselectedNodeStyle of unselected nodes.
GraphTreeThe tree a tree arrangement drew, for collapsing and expanding.
GridOptionsOptions of gridLayout.
HierarchicalBundleOptionsOptions of hierarchicalBundle.
HiveLayoutOptionsOptions of hiveLayout. Lengths are layout units (CSS px), angles degrees.
HiveLayoutResultWhat hiveLayout returns: the positions and routes, and the axes it made.
Layered3dOptionsOptions of layeredLayout3d.
Layered3dResultWhat layeredLayout3d returns: positions, and where the planes are.
LayeredOptions-
LayoutBundleInfoHow the bundling of a request went (see BundleResult).
LayoutClusterA labelled frame around a group of nodes (a layered cluster), in layout units.
LayoutGraphA graph as a layout sees it: node and link counts and one typed array per property.
LayoutHandlerA handler made by createLayoutHandler.
LayoutHandlerEnvironmentWhat the handler needs from its surroundings; the defaults are right outside of tests.
LayoutProgressPositions of a simulation on its way to rest. The arrays are the caller's to keep.
LayoutProgressOptionsHow often a simulation reports its positions.
LayoutRequestPage → worker: lay out a graph.
LayoutResultWhere a layout put everything. Arrays are owned by the caller from here on.
LayoutRunInfoHow a finished layout went.
LayoutRunOptionsOptions of one layoutInWorker call.
LayoutSimulationA layout that settles over time (force): the trace runs it to rest in calc, or steps it frame by frame for simulate: true and while a node is dragged.
LayoutWorkerLikeThe part of a Worker the client uses.
LinkRouteA link's path when it is not the straight line between its ends.
MatrixLinksLinks of a square matrix, for chordLayout.
MetricOptionsOptions shared by the measures.
PlotAreaThe size in px of the area a trace is laid out for.
RadialTreeOptionsOptions of radialTreeLayout. Lengths are layout units (CSS px), angles degrees.
RadialTreeResultWhat radialTreeLayout returns.
RealAxisAn axis that carries data under a computed arrangement, and whether it runs backwards.
TidyTreeOptionsOptions of tidyTreeLayout. Lengths are layout units (CSS px).
TreeLayoutResultWhat a tree layout returns on top of positions.
TreeOptionsOptions every tree layout takes.

Type Aliases ​

Type AliasDescription
ArcOrderHow arcLayout orders the nodes along the line.
ArcSidesWhich side of the line the arcs are drawn on.
ChordLinkSortThe order of the link ends within an arc.
ChordNodeSortThe order of the arcs around the ring.
ChordTraceChord diagram: nodes as arcs of a ring, as wide as their flow, and links as ribbons between them; from node / link (as sankey and graph take them) or from a square matrix.
CollapsedInputWhich subtrees are folded: node indices, or a mask with one byte per node (Uint8Array).
ForceAlgorithm- 'spring': the d3-force model. Links are springs with a rest length, every pair of nodes repels, velocities decay and the whole cools on a fixed schedule. Even link lengths; the usual choice up to a few thousand nodes. - 'forceatlas2': the ForceAtlas2 model (Jacomy et al. 2014). Links attract in proportion to their length, nodes repel in proportion to their degrees, and the step size adapts to how much the nodes swing. It pulls communities apart better on graphs with hubs.
Graph3dArrangementA value of graph3d's arrangement.
Graph3dTraceNetwork graph in a 3D scene: nodes as lit spheres or sprites and the links between them as lines or tubes, at given positions or placed by a layout in space.
GraphArrangementA value of arrangement.
GraphLayoutA layout: positions for graph. Deterministic: the same input gives the same output on every machine (no Math.random, no time, no iteration order of hashed collections), so visual baselines, server rendering and exports agree.
GraphTraceNetwork graph: nodes and the links between them, at given positions or placed by a layout.
LabelRuleWhat an arrangement says about where its labels have room (node.textposition: 'auto'). Angles are degrees counter-clockwise from the x axis in layout coordinates (y up), as the layouts return them.
LayeredRankdirWhere the ranks run: top to bottom, bottom to top, left to right or right to left.
LayeredRankerHow ranks are assigned (see rank.ts).
LayeredRoutingHow links are routed (see route.ts).
LayoutMessageEverything the page sends.
LayoutResponseEverything the worker sends.
LayoutThreadWhere a layout ran: in the worker, or on the main thread in slices.
LinkWeightModeWhat a link's weight (link.value) does, relative to the median weight of the graph: - 'strength': a heavier link pulls harder (both algorithms); - 'distance': a heavier link is shorter. 'spring': its rest length is linkDistance divided by the relative weight, kept within a quarter to four times linkDistance. 'forceatlas2' has no rest length, so this is the same as 'strength' there; - 'none': weights are ignored.
NodeSortHow nodeOrder sorts.
PerNodeA value for every node, or one value per node (NaN: none for that node).
PostLayoutResponseSends a response; transfer lists the buffers that move with it.
TracesGraphAny trace of @mk7s/holochart-traces-graph, discriminated on type. Type a partial bundle's figures with it: FigureInput<TracesGraph>.
TreeLinkShapeHow the tree edges of a tidy or radial tree are drawn.
TreeOrientationWhere the root is: top ('TB'), bottom ('BT'), left ('LR') or right ('RL').
TreeSortHow siblings are ordered.
WorkerArrangementAn arrangement the worker can run.

Variables ​

VariableDescription
chord-
chordAttributesThe chord schema.
circularLayoutNodes on a circle around the origin.
graph-
GRAPH_ARRANGEMENTSEvery value of the trace's arrangement.
graph3d-
GRAPH3D_ARRANGEMENTSarrangement values of graph3d: the layouts that place nodes in space.
graph3dAttributesThe graph3d schema.
graphAttributesThe graph schema.
gridLayoutNodes on a grid centered on the origin; the first row is on top (the largest y).
layeredLayoutThe layered layout as the graph trace calls it: layered: { rankdir, ranksep, nodesep, … } (see LayeredOptions). Returns a position per node, a route per link (also for straight ones: routes end on the nodes' outlines), the links it reversed, and the cluster frames when clusters is on.
LAYOUT_PROTOCOLVersion of this protocol: the worker reports it in ready, and the client checks it.
presetLayoutPositions as given.
tracesGraphEvery graph module, for register(...tracesGraph).
tracesGraph3dThe graph3d trace with the 3D scene it is drawn in, for register(...tracesGraph3d). Apart from tracesGraph, so that an app with 2D graphs only does not bundle the 3D package.
WORKER_ARRANGEMENTSThe arrangements the worker can run: every built-in one.

Functions ​

FunctionDescription
adjacencyMatrixThe adjacency matrix of a graph, with rows and columns reordered so that its structure shows (backlog G8): it reads at densities where a node-link drawing is a hairball. Draw it with { type: 'heatmap', x, y, z }. An undirected graph (directed: false) fills both triangles.
arcLayoutAn arc diagram of graph: nodes on one line through the origin, links as half circles. See the module comment for the steps and for what happens to self-links and parallel links.
bundleLinksBundle the links of a laid-out graph: hierarchical bundling when it has groups, force-directed bundling when it has none (see BundleOptions.method). positions are the node centers a layout returned; the number of nodes is their length.
chordLayoutLay a chord diagram out (see the module comment).
connectedComponentsConnected components, ignoring the direction of links (the weak components of a directed graph). A node without links is a component of its own.
createForceSimulationA force simulation of graph, at its start positions and alpha 1. Step it with tick; drag a node with pin and reheat. x, y (and z with dimensions: 3) are its own arrays, updated in place.
createLayoutHandlerA handler that answers through post. It keeps the requests that are running, so one handler serves one connection (a worker's, or the client's fallback).
decodeResultThe result encodeResult was given, with the same properties.
degreesThe degree of every node. With weighted, each link counts as its value (the node's strength). Links with an end that is not a node are skipped.
dendrogramLayoutLays a tree or forest out as a dendrogram. Linear in nodes + links (sorting aside).
encodeResultresult in the form it is posted in. Nothing is copied but the routes' points.
forceBundleForce-directed edge bundling: a 'polyline' route for every link that was pulled into a bundle and undefined for a link that stays straight. See the module comment for the model, its bounds and which links stay straight.
forceLayoutThe force layout as a GraphLayout: a simulation run for options.ticks ticks (or to rest, if a given alphaDecay gets there sooner), cleared of the last overlaps when collide is on, then centered on options.center (the origin by default). It is not centered along an axis where a node is pinned or a positional target is set: those coordinates mean what they say.
forceLayout3dA 3D force layout of graph (dimensions: 3, whatever options says).
fromAdjacencyMatrixA graph from a square adjacency matrix: matrix[i][j] is the weight of the link from row i to column j. Entries that are not finite numbers are no link; the diagonal gives self-links.
fromDotParse DOT text into a graph. Throws a SyntaxError that names the offset when the text is not DOT. See the module comment for what is read and what is kept.
fromEdgeListA graph from a list of edges: [source, target] or [source, target, value] tuples, or objects with those keys. Ends are node ids (strings or numbers), not indices. Edges without two usable ends are skipped.
fromNodeLinkA graph from node-link JSON, whichever of these shapes it has:
graphLayoutWorkerThe layout worker every graph trace of the page shares, made on first use.
graphPathThe path a graph trace highlights: between the two nodes of highlight.path, else between the two selected nodes (selectedpoints) when exactly two are and highlight.mode has 'path'. trace is a defaulted trace, chart.fullData[i], which holds the selection made on the chart; read it in a selected listener or after an update. undefined: no path is asked for, or there is none between the two nodes.
hierarchicalBundleHierarchical edge bundling: one entry per link (the indices of graph.source), a 'spline' route for every link that is bundled and undefined for a link that stays straight. See the module comment for the hierarchy, the curve and which links stay straight. Without a hierarchy (no groups and no parents) every entry is undefined.
hiveLayoutA hive plot of graph: nodes on axes around the origin, links as curves between the axes. See the module comment for the steps and for the links that are left out.
isLayoutAbortWhether error is the rejection of a cancelled or superseded layout, which is not a failure.
layeredLayout3dThe layered layout in space (see the module comment).
layoutInWorkerLay a graph out in the shared layout worker, or on the main thread in slices when there is no worker: see GraphLayoutWorker.run and LayoutRunOptions.
louvainCommunities by the Louvain method (Blondel et al. 2008): the community of each node, numbered from 0 in the order of each community's first node. Links are read as undirected and weighted by link.value. Deterministic: there is no random node order, so the result is one of the partitions Louvain can find, always the same one.
matrixLinksThe links of a square matrix (matrix[i][j]: flow from i to j), see the module comment. Missing cells are 0; negative and non-numeric ones are dropped and counted.
modularityModularity of a partition (Newman and Girvan): the share of link weight inside communities minus what a random graph with the same degrees would have. Between −0.5 and 1; 0 for one community holding everything.
radialTreeLayoutLays a tree or forest out on rings around its root. Linear in nodes + links (sorting aside).
registerGraphLayoutRegister a layout for arrangement: 'custom' with custom: { name, options }: the layout is called with the graph and custom.options, in calc. Registering a name again replaces it. Returns a function that removes the layout (only if it is still the one registered).
setGraphWorkerUrlServe the worker file from a URL of your own: copy dist/layout-worker.js of @mk7s/holochart-traces-graph (one file, no imports) to your site and give its address here, before the first graph is laid out. For apps whose Content Security Policy or bundler keeps the file from loading from where the package looks for it. null goes back to the default. A worker that is already running is ended; the next layout starts one from the new address.
tidyTreeLayoutLays a tree or forest out as a tidy tree. Linear in nodes + links (sorting aside).

Released under the MIT License.