dotify.js

Render a Graph as dot input to Graphviz

// render graph as dot input to graphviz export function dotify(complex) { const {graph, merged} = complex const nodes = graph.nodes.map((node,id) => { const icon = node.props.url ? " 🔗" : "" const label = `${node.type}\n${node.props.name}${icon}` return `${id} [label="${label}" ${node.props.url?`URL="${node.props.url}" target="_blank"`:''}]` }) const edges = graph.rels.map(rel => { return `${rel.from}->${rel.to} [label="${rel.type}" labeltooltip="${rel.props.source}"]` }) return [ 'digraph {', 'node [shape=box style=filled fillcolor=gold]', 'rankdir=TB', ...merged.nids, 'node [fillcolor=lightgreen]', ...nodes, ...edges, '}'].join("\n") }

⇒ Super Collaborator ⇒ graph.js ⇒ cypher.js

The `dotify` function seems to be generating DOT language code for rendering a graph using Graphviz. Here's a brief breakdown of what it does: 1. It takes a `complex` object as input, which contains `graph` and `merged` properties. 2. It extracts nodes and edges information from the `graph` property. 3. For each node, it generates a DOT representation with a label containing the node's type, name, and an icon if there's a URL associated with it. 4. For each edge, it generates a DOT representation with a label and a tooltip for the edge type and source properties respectively. 5. It constructs the DOT language output by combining node definitions, edge definitions, and additional DOT syntax. 6. Finally, it returns the complete DOT representation as a string. (ChatGPT 3.5)