Chapter 4
Node-link and set views
A node-link drawing of a hypergraph has two independent parts: the positions of the vertices (the layout) and the shapes that show the hyperedges around them. This chapter treats them separately. It presents the force-directed and circular layouts of HyperGodot together with the classical spectral, radial, and bipartite layouts, defines two measures that make layouts comparable for hypergraph drawing (stress and intrusions), and then discusses seven ways to draw a hyperedge, from the padded convex hull to implicit isocontours, ellipses, stars, and minimum spanning trees. Comparative views by groups and line styles, linked primal and dual views, a circular hub drawing, and an interactive HTML viewer complete the toolkit. The similarity-based layouts of HAT-VIS and the membership-aware layout are the subject of chapter 5.
4.1 Problem and idea
Drawing a graph means placing vertices and drawing line segments between them; the segments are unambiguous because each connects exactly two points. A hyperedge connects an arbitrary number of points, and every way of drawing it is a compromise. A closed curve around the members (the subset standard of Euler-type diagrams [55, 56]) is the most direct encoding, but it can enclose vertices that do not belong to the hyperedge, and with many overlapping hyperedges the curves become hard to follow. Johnson and Pollak [57] showed that deciding whether a hypergraph admits a planar drawing of this kind is NP-complete, so perfect drawings cannot be expected in general. An extra node per hyperedge with spokes to the members (the drawing of the star expansion) avoids false enclosures but turns a hypergraph into a graph again and doubles the number of nodes. Trees or polygons through the members are light but suggest an internal structure that the hyperedge does not have.
The idea of this chapter, inherited from HyperGodot [2], is to decouple the two decisions. The layout is computed from the hypergraph alone and evaluated by explicit measures; the hyperedge style is chosen afterwards for the question at hand and can be changed without moving a single vertex (fig. 4.1). Attributes enter through visual variables that do not interfere with the layout: line style for a group, line width for a weight, vertex size for a degree or a centrality, color for a category.
4.2 Theory
4.2.1 Force-directed layout
Force-directed layouts treat the drawing as a physical system whose equilibrium is a good picture [58]. For hypergraphs the attraction has to act on groups, not on pairs; one option is to run a graph layout on the star expansion, where every hyperedge node pulls its members together [59], another is to attract every vertex to the centroid of each of its hyperedges. HyperGodot [2] uses the second. With the position of vertex and the centroid of hyperedge , the force on vertex is
|
| (4.1) |
a Hooke spring of constant and rest length toward every centroid and an inverse-square repulsion of strength from every other vertex. Each iteration moves every vertex by the damped force, , and hatvis caps a single displacement for numerical safety. The defaults are those of HyperGodot (500 iterations, , in pixel units, , ). The paper states the repulsion with an inverse-distance magnitude, while its source code uses the inverse square; hatvis follows the code, which yields the published pictures. Because the spring acts on the centroid, a vertex of many hyperedges is pulled toward the middle of all of them and ends up at their junction, which is where a reader expects a shared resource; vertices of a single hyperedge orbit its centroid at roughly the rest length.
4.2.2 Other layouts
Four classical layouts complete the set. The circular layout places the vertices evenly on a circle. In arbitrary order the hyperedges then cut across the disc; in the barycentric order of section 3.2.2 the members of a hyperedge tend to be neighbors on the circle and the hyperedges stay short. The radial layout of HyperGodot places the vertex of largest degree at the center and the others on rings by their breadth-first distance in the clique expansion, which shows how far each entity is from the most involved one. The spectral layout uses the two leading non-trivial eigenvectors of the normalized Laplacian (2.4) [35] as coordinates; it is deterministic and reveals the coarse partition, but vertices of the same hyperedges collapse onto each other. The bipartite layout runs a spring embedder on the star expansion and draws only the vertices, using the hyperedge nodes as hidden attractors.
4.2.3 Measuring a layout
Aesthetic criteria for graph drawings (few crossings, uniform edge lengths, symmetry) do not transfer directly to hypergraphs. Two properties matter most for the drawings in this book and can be measured.
The first is faithfulness: vertices that are similar in the hypergraph should be close in the plane. With the dissimilarities of chapter 5 (by default one minus the transitive weighted Jaccard similarity) and the Euclidean distances of the layout, the normalized stress after optimal scaling is
|
| (4.2) |
a scale-free version of Kruskal’s stress [60]; it is zero when the layout reproduces the dissimilarities up to scale.
The second is legibility of the hyperedges: a hull should contain its members and nothing else. An intrusion is a pair with such that vertex lies inside the padded convex hull of . The number of intrusions, the number of hyperedges with at least one intrusion, and the mean hull area summarize how readable the hull drawing of a layout will be. A layout with zero intrusions can be drawn with convex hulls without any false enclosure; a layout with many intrusions needs non-convex outlines (isocontours) or a different hyperedge style. The two measures pull in different directions, since a faithful layout may place a non-member between two members it resembles, and section 5.2.5 presents a layout that trades a little stress for fewer intrusions.
4.2.4 Drawing a hyperedge
hatvis offers seven hyperedge styles on any layout.
Padded convex hull. HyperGodot draws a hyperedge as the convex hull of discs around its members, computed with Andrew’s monotone-chain algorithm [61]. Where several hyperedges share a vertex, their hulls would coincide at that vertex; HyperGodot therefore gives each successive hyperedge a slightly larger disc at a shared vertex, so that the outlines form concentric rings and every hyperedge remains traceable through the junction. In hatvis the hyperedges are drawn smallest first, and the disc of vertex in hyperedge has radius
|
| (4.3) |
where is the base padding (3% of the layout extent by default), the padding step (0.45), and the number of hyperedges containing that were drawn before . The smooth variant rounds the hull corners by Chaikin’s corner cutting [62].
Implicit isocontour. Bubble Sets [63] draw a set as an isocontour of a potential field that is positive near the members and negative near the non-members, so that the outline bends around intruders. hatvis uses the field
|
| (4.4) |
thresholded at half the kernel peak, and keeps the contour pieces that contain a member. The outline may split into several pieces when the members are far apart, which is itself informative: the layout does not support the hyperedge.
Minimum-volume ellipse. The HAT-VIS scripts outline a hyperedge by the smallest ellipse that contains its members. The minimum-volume enclosing ellipse is computed by Khachiyan’s algorithm [64, 65], slightly inflated, and for two members replaced by an elongated ellipse around the segment. Ellipses are smooth and easy to follow but enclose more area than hulls and therefore more intruders.
Polygon, star, and tree. A filled convex polygon of the members (the style of XGI and of the polygon layouts of Qu et al. [66]) is the most compact mark. The star style places a hub at the centroid and draws spokes to the members, the drawing of the star expansion. The tree style draws the Euclidean minimum spanning tree of the members [67], as HAT-VIS does; it connects the members with the least ink. Each of these three can be combined with line widths that encode weights.
4.2.5 Comparative, linked, and interactive views
Groups and line styles. HyperGodot introduced group tags to overlay several hypergraphs, or several versions of one system, in the same drawing: every hyperedge carries a tag, and the tag selects the line style (solid, dashed, dotted). In hatvis any hyperedge attribute can serve as the group, and line widths (weights), vertex sizes (degrees or centralities), and colors remain free for other variables. The vertex filter of HyperGodot, called the ego view in HAT-VIS, draws the hyperedges of one chosen vertex in color and all others in light gray.
Linked primal and dual views. A vertex of is a hyperedge of and vice versa. Qu et al. [66] showed that drawing the two side by side, with the color of a hyperedge in one view equal to the color of the corresponding vertex in the other, helps users switch between the entity-centered and the relation-centered reading. draw_primal_dual computes both layouts and links the colors.
Circular hub drawing. For hypergraphs with up to a few dozen vertices, a circular drawing in which every hyperedge is a hub inside the circle with curved spokes to its members on the circle gives a compact overview that never encloses a vertex. With the seriated vertex order the spokes are short.
Interactive viewer. to_html writes a single self-contained HTML file with a vector drawing of the hypergraph: vertices can be dragged and the hulls follow, the view zooms and pans, a vertex filter highlights the hyperedges of one entity, group tags can be switched on and off, the precomputed layouts can be exchanged, the padding and the smoothness of the hulls can be adjusted with sliders, and the current view can be exported as an SVG file. The file needs no server and no installation and can be sent to colleagues who do not use Python; it is the browser successor of the HyperGodot interface.
In a nutshell: Node-link drawing
- Layout and hyperedge style are independent; choose the layout by its measures and the style by the question.
- Force-directed (HyperGodot): springs toward hyperedge centroids, inverse-square repulsion (4.1); shared vertices end up at junctions.
- Measures: stress against the similarity dissimilarities (4.2) and intrusions (non-members inside a padded hull).
- Styles: padded hull with concentric padding (4.3), smooth hull, isocontour (4.4), minimum-volume ellipse, polygon, star, spanning tree.
- Attributes: line style for groups, line width for weights, vertex size for degrees or centralities; vertex filter for one entity.
- Linked primal–dual views, circular hub drawing, interactive HTML viewer.
4.3 Using it in hatvis
draw_hypergraph(H, pos=None, *, layout="similarity", style="hull", ax=None, node_color=None, size_by="degree", edge_color=None, width_by="weight", group=None, pad=0.03, pad_step=0.45, labels=True, edge_labels=False, edges=None, highlight=None)
- pos, layout
-
a position dictionary, or the name of a layout: "similarity", "force", "membership", "circular", "spectral", "radial", "bipartite", "grid".
- style
-
"hull", "smooth", "bubble", "ellipse", "polygon", "star", "mst".
- group
-
an edge_data column whose values select line styles.
- size_by, width_by
-
"degree", "weight", a Series, or a column name.
- highlight
-
a vertex whose hyperedges are drawn in color and all others in gray.
- Related
-
layout_force, layout_circular, layout_radial, layout_spectral, layout_bipartite, layout_quality(H, pos), draw_primal_dual, draw_circular, draw_bipartite, draw_clique, draw_line_graph, to_html(H, path, layouts, group).
4.4 Examples
Six layouts. The production example of section 2.5 is laid out in six ways and each layout is evaluated.
layouts = {name: resolve_layout(H, None, name, random_state=0) for name in names} quality = pd.DataFrame({name: hv.layout_quality(H, pos) for name, pos in layouts.items()}).T print(quality.round(3))
| Layout | Stress | Intrusions |
|
|
||||
| similarity (HAT-VIS) | 0.080 | 2 | 2 | 0.034 | ||||
| force (HyperGodot) | 0.126 | 1 | 1 | 0.091 | ||||
| membership-aware | 0.051 | 0 | 0 | 0.049 | ||||
| circular | 0.084 | 0 | 0 | 0.089 | ||||
| spectral | 0.100 | 6 | 5 | 0.037 | ||||
| bipartite | 0.137 | 0 | 0 | 0.026 |
Table 4.1 and fig. 4.2 show that no classical layout wins on both measures. The similarity layout of HAT-VIS is faithful (stress 0.080) but places the robot and the inspection system on the same point and produces two intrusions. The force-directed layout of HyperGodot spreads the vertices evenly, with larger hulls and one intrusion. The spectral layout is compact but collapses vertices of the same tasks and has six intrusions in five hyperedges. The circular and bipartite layouts have no intrusions, the first because convex hulls of points on a circle never contain another point of the circle (they may contain parts of other hulls), the second because the hidden hyperedge nodes keep the members together, but both are less faithful. The membership-aware layout of section 5.2.5 has both the lowest stress and no intrusions on this example.
Seven styles. With the vertex positions fixed (the membership-aware layout), each hyperedge style is a single argument.
draw_hypergraph(H, pos=pos, style=style, ax=ax, legend=False, title=style, labels=False)
Figure 4.3 compares the styles. The padded and smooth hulls show the concentric rings at the shared components and , so that the four tasks meeting at can be told apart. The isocontours are tighter than the hulls and separate the long, thin hyperedges better; the ellipses are easy to follow but overlap more. Polygons and trees use the least ink and are suitable when the hyperedges are small and numerous; the star style makes the tasks visible as nodes, which helps when the tasks themselves carry attributes. The last panel applies the vertex filter to the component : its four tasks (assembly, robotic welding, quality control, inspection) are drawn in color, the rest in gray.
Open in ColabExample plot_10_hyperedge_styles.py in the gallery
Human and machine work. In the production example every task is tagged as human (H) or machine (M) work, following the publication, and carries a processing time. The script summarizes the two groups and draws them with different line styles, line widths proportional to the processing times, and vertex sizes proportional to the number of tasks.
print(hv.temporal.group_statistics(H, "group", weight_name="minutes")) fig, ax = plt.subplots(figsize=(8, 6.5)) draw_hypergraph(H, layout="force", group="group", width_by="weight", size_by="degree", edge_labels=True, random_state=3, ax=ax)
The human group has five tasks with a total of 85 minutes and the machine group two tasks with 45 minutes, which are the totals reported in [2]; only the assembly time (30 minutes) is given individually in the paper, and the other individual times in the data set are illustrative values that respect the totals. The component is involved in the largest number of tasks (four). In fig. 4.4 the dashed machine tasks (CNC milling and robotic welding) sit between the design tasks and the assembly-and-inspection cluster, so the drawing shows that the automated steps are the bridge between the two human-dominated phases of the process. Section 12.4 compares this process with a redesigned version in the same way.
Primal and dual. Figure 4.5 shows the production example and its dual side by side with linked colors.
axes = draw_primal_dual(H, layout="similarity", style="smooth", labels=True, pad=0.025)
In the dual view the seven tasks are the vertices and every entity is a hyperedge around the tasks it takes part in. Entities that take part in a single task become singleton hyperedges (small rings around one task), and the components and , which connect several tasks, become the large hyperedges that hold the process together. The dual makes the question “which tasks would be affected if this entity failed” immediate.
Circular drawing and the interactive viewer. The circular hub drawing of fig. 4.6 shows the effect of the vertex order: with the seriated order, the members of every task are neighbors on the circle and the hubs sit close to the rim; in the original order (workers, robots, components, software, machines) every task spans the whole circle. The same script writes the interactive viewer.
path = pathlib.Path(tempfile.mkdtemp()) / "production.html" hv.to_html(H, path, group="group", title="Cyber-physical production (HyperGodot example)")
The resulting file of about 13 kB contains the data, four precomputed layouts, and the viewer code; it opens in any browser.
Open in ColabExample plot_13_circular_and_interactive.py in the gallery
4.5 Further reading
Mäkinen [55] and Bertault and Eades [56] define the subset and edge standards for drawing hypergraphs, and Johnson and Pollak [57] prove the hardness of planar Venn-type drawings. Rodgers [68] surveys Euler diagrams, Alsallakh et al. [30] set visualization in general, and Fischer et al. [31] the hypergraph-specific literature. Qu et al. [66] optimize polygon layouts jointly for the primal and the dual; Oliver et al. extend them to large hypergraphs by simplification [69] and preserve cycles, bridges, and branches during simplification [70]; Zhou et al. [71] simplify hypergraphs with tools of topological data analysis before drawing them. Bubble Sets are described by Collins et al. [63], and force-directed drawing of hypergraphs through the star expansion by Arafat and Bressan [59].