| Server IP : 199.250.200.62 / Your IP : 216.73.216.15 Web Server : Apache System : Linux vps37394.inmotionhosting.com 3.10.0-1160.119.1.vz7.224.4 #1 SMP Mon Sep 30 15:36:27 MSK 2024 x86_64 User : jasonp18 ( 1000) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /proc/2/cwd/proc/2/cwd/proc/self/root/opt/imh-python/lib/python3.9/site-packages/pygraph/ |
Upload File : |
"""Provides rendering capabilities for graphs."""
def graph_to_dot(graph, node_renderer=None, edge_renderer=None):
"""Produces a DOT specification string from the provided graph."""
node_pairs = list(graph.nodes.items())
edge_pairs = list(graph.edges.items())
if node_renderer is None:
node_renderer_wrapper = lambda nid: ''
else:
node_renderer_wrapper = lambda nid: ' [%s]' % ','.join(
['%s=%s' % tpl for tpl in list(node_renderer(graph, nid).items())])
# Start the graph
graph_string = 'digraph G {\n'
graph_string += 'overlap=scale;\n'
# Print the nodes (placeholder)
for node_id, node in node_pairs:
graph_string += '%i%s;\n' % (node_id, node_renderer_wrapper(node_id))
# Print the edges
for edge_id, edge in edge_pairs:
node_a = edge['vertices'][0]
node_b = edge['vertices'][1]
graph_string += '%i -> %i;\n' % (node_a, node_b)
# Finish the graph
graph_string += '}'
return graph_string