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§
- Draw
Edge - What an edge looks like, and its attributes. Its points come from the
layout (
GraphLayout::edges); the arrowhead is on its last point, unlessundirected. - Draw
Node - What a node’s box shows, and its attributes. Its geometry comes from the
layout (
PlacedNode); its label lines fromnode_box. - Graph
Style - The colours and class names of a drawing.
- NodeBox
- A node box’s size and its label wrapped to fit.
- Node
Table - A small table in a node’s box, under its label (an influence diagram’s
policy: a row per configuration of the decision’s informational parents,
a column per option with its expected utility, the chosen option
marked). The first column holds the row names, left-aligned; the others
are right-aligned. Size the box with
table_box. - 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). - State
Bar - One state of a discrete node: a row in its box with the state’s name, a bar for its probability and that probability as text, the prior as a faint bar behind it with a tick where it ends (Netica / GeNIe style).
Enums§
- Edge
Line - An edge’s line pattern.
- Node
Icon - A mark on a node, at its top right corner in a small round badge.
- Node
Shape - 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§
Functions§
- diamond_
box - The diamond a
NodeShape::Diamondneeds for its label and an optional value line: the text’s box, its corners on the diamond’s edges. - draw
- Draw a laid-out graph on a
layout.w×layout.hpx canvas:lanesnames the layout’s bands,platesgroup nodes,nodesandedgesare in the layout’s order.themeis 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
drawsets it (its widest line): the layout’sGraphEdge::label_w. - flow_
width - An edge’s width (px) for what it carries,
valueof the graph’smax: 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. - js_
distance - The Jensen–Shannon distance between two distributions over the same states (base 2: 0 the same, 1 disjoint), each normalised to sum to 1; 0 when either sums to 0 or they differ in length.
- node_
box - The box a node needs: its label wrapped onto at most three lines, plus a
line for
value, a badge row forbadgeand a sparkline strip whenspark(asdrawfills it). - node_
size - The size a node of
shapeneeds forlabel(aNodeShape::Boxisnode_boxwithout a value, badge or sparkline). A circle fits its label on one line, at least 30 px across. - states_
box - The box a discrete node needs (a Bayesian network’s node, Netica /
GeNIe style):
node_box’s label, value and badge, then one row per state (its name, a bar and the probability as text), asdrawfills it fromDrawNode::states. No states:node_box. - states_
box_ with_ deltas states_boxwith room for each row’s change after its probability (deltas, seeStateBar::was).- table_
box - The box a node with a
NodeTableneeds:node_box’s label, value and badge, then the header row (when there is one) and a row per table row, asdrawfills it fromDrawNode::table.
Type Aliases§
- Data
Attr - A
data-*attribute: its name (withoutdata-) and value;Noneleaves it off that mark.