Skip to main content

Module graph

Module graph 

Source
Expand description

Drawing a laid-out graph of boxes: swimlane bands, edges (polylines with an arrowhead, a linetype, a width and an optional label placed clear of the boxes) and node boxes (a wrapped label, an optional value line, status badge and sparkline, and an accent bar), as one GGPlot of ordinary layers.

Works with graph_layout: size the boxes with node_box, lay them out with layered, then draw the result. What each mark says and what colour it takes is the caller’s (the DrawNode / DrawEdge fields); where things go inside a box and along an edge is decided here. Every mark carries the caller’s data-* attributes, and what belongs to one node is wrapped in <g data-of="<id>">, so a browser can address a node as one element. Moved here from anofox-visualization’s ::DIAGRAM (sipemu/ggplot-rs#497, DataZooDE/anofox-visualization#1153).

Structs§

DrawEdge
What an edge looks like, and its attributes. Its points come from the layout (GraphLayout::edges); the arrowhead is on its last point, unless undirected.
DrawNode
What a node’s box shows, and its attributes. Its geometry comes from the layout (PlacedNode); its label lines from node_box.
GraphStyle
The colours and class names of a drawing.
NodeBox
A node box’s size and its label wrapped to fit.
Plate
A plate: a dashed box around a collection of nodes (indices in the layout’s order), labelled at its top left (x_t, t = 1..T).

Enums§

EdgeLine
An edge’s line pattern.
NodeShape
A node’s mark. A factor graph (Forney style) draws factors as boxes, variables as circles (filled when observed), equality nodes as small squares, deterministic (delta) nodes as small filled squares, and constants as plain text.

Constants§

BELIEF_H
BELIEF_W
A belief curve’s size over its node (px).

Functions§

draw
Draw a laid-out graph on a layout.w × layout.h px canvas: lanes names the layout’s bands, plates group nodes, nodes and edges are in the layout’s order. theme is the base (a void theme; the legend is turned off). Render the result with e.g. render_svg_native_at(0.0, 0.0, w, h) at the canvas size rounded up.
edge_label_width
The width (px) of an edge label as draw sets it (its widest line): the layout’s GraphEdge::label_w.
flow_width
An edge’s width (px) for what it carries, value of the graph’s max: area-true (sqrt), 1.4 px to 7 px; 1.6 px without a value; dotted edges 3–6 px so their dots show. Rounded to 0.1 px.
node_box
The box a node needs: its label wrapped onto at most three lines, plus a line for value, a badge row for badge and a sparkline strip when spark (as draw fills it).
node_size
The size a node of shape needs for label (a NodeShape::Box is node_box without a value, badge or sparkline). A circle fits its label on one line, at least 30 px across.

Type Aliases§

DataAttr
A data-* attribute: its name (without data-) and value; None leaves it off that mark.