DAGVIZ Metro styling options¶
This notebook demonstrates the various Metro styling options.
In order to apply styling we need to call render_svg by hand with the appropriate renderer and style configuration.
from dagviz import render_svg
from dagviz.style.metro import svg_renderer, StyleConfig
from IPython.display import HTML
import networkx as nx
First we construct a simple graph that demonstrates all the visual aspects a rendering may have.
g = nx.DiGraph()
g.add_node("a", label="switch(value)")
g.add_node("b", label="case 1")
g.add_node("c", label="case 2")
g.add_node("d", label="case 3")
g.add_node("e", label="end")
g.add_edge("a", "b")
g.add_edge("a", "c")
g.add_edge("a", "d")
g.add_edge("b", "e")
g.add_edge("c", "e")
g.add_edge("d", "e")
Default rendering¶
Without any configuration, we get (of course) the default rendering:
HTML(render_svg(g))
Scale¶
The scale setting determines the amount of space each node has:
HTML(render_svg(g, style=svg_renderer(StyleConfig(scale=20))))
Node radius¶
The node radius determines the size of the bubbles:
HTML(render_svg(g, style=svg_renderer(StyleConfig(node_radius=10))))
Node fill¶
By default the node fill color is automatically selected. This can be overriden by specifying a fixed color:
HTML(render_svg(g, style=svg_renderer(StyleConfig(node_fill="black"))))
Node stroke¶
The node stroke specifies the color of the border of the bubble:
HTML(render_svg(g, style=svg_renderer(StyleConfig(node_stroke="black"))))
Node stroke width¶
The node stroke width determines the width of the border of the bubbles:
HTML(render_svg(g, style=svg_renderer(StyleConfig(node_stroke="black", node_stroke_width=4))))
Edge stroke width¶
The edge stroke width determines the width of the edges:
HTML(render_svg(g, style=svg_renderer(StyleConfig(node_fill="black", edge_stroke_width=10))))
Label font family¶
The default font family for labels is "sans-serif". This can be changes too:
HTML(render_svg(g, style=svg_renderer(StyleConfig(label_font_family="serif"))))
Label font size¶
The font size of the label can be changed as follows:
HTML(render_svg(g, style=svg_renderer(StyleConfig(label_font_size=20))))
Label arrow stroke¶
The label arrow stroke determines the color of the line from node to label:
HTML(render_svg(g, style=svg_renderer(StyleConfig(label_arrow_stroke="black"))))
Label arrow dash array¶
The label arrow dash array determines how the label arrow is dashed:
HTML(render_svg(g, style=svg_renderer(StyleConfig(label_arrow_dash_array="0"))))
Arc radius¶
The arc radius determines the radius of the arc from vertical line to a node:
HTML(render_svg(g, style=svg_renderer(StyleConfig(arc_radius=5))))
Label font color¶
The label font color determines the color of the label text. The default is "currentColor", which inherits from the surrounding context. This is useful for dark backgrounds:
HTML(render_svg(g, style=svg_renderer(StyleConfig(label_font_color="red"))))
Bridge color¶
The bridge color determines the color of the "bridges" that cover the parts of edges crossing other edges. The default is "white", which works well on light backgrounds. Change this to match your background color:
HTML(render_svg(g, style=svg_renderer(StyleConfig(bridge_color="black"))))
Dark theme example¶
By combining label_font_color, bridge_color, and node_stroke, you can create a style suitable for dark backgrounds:
dark_style = svg_renderer(StyleConfig(
node_stroke="black",
label_font_color="white",
bridge_color="black",
label_arrow_stroke="grey",
))
HTML(f'<div style="background: #333; padding: 10px;">{render_svg(g, style=dark_style)}</div>')