gv(3sharp)

πŸ“¦
version 16.1.0 Β· 5 versions
, in arch rolling

okay so this is gv(3sharp) and it’s literally the graph-manipulation manual, bestie πŸ’…βœ¨ buckle up because we’re about to make graphviz make sense.

🌸 NAME 🌸

gv_sharp β€” graph manipulation in sharp πŸ¦‹

⭐ SYNOPSIS ⭐

no synopsis lines here, bestie β€” it jumps straight into USAGE and INTRODUCTION ✨

🧚 USAGE 🧚

the original has no usage text here, just vibes 😭

πŸ’– INTRODUCTION πŸ’–

gv_sharp is a dynamically loaded extension for sharp that gives you access to the graph facilities of graphviz. no cap, that’s the whole intro and it ate 🫢


πŸ¦‹ COMMANDS πŸ¦‹

okay so this is the whole command menu. every signature is kept exactly as the original has it β€” no renames, no β€œfixing,” no funny business πŸ”₯

✨ New graphs ✨

New empty graph

SWIGTYPE_p_Agraph_t gv.graph (string name);
SWIGTYPE_p_Agraph_t gv.digraph (string name);
SWIGTYPE_p_Agraph_t gv.strictgraph (string name);
SWIGTYPE_p_Agraph_t gv.strictdigraph (string name);

four ways to start a fresh empty graph, each one taking a name and handing you back a graph handle πŸ‘‘

New graph from a dot-syntax string or file

SWIGTYPE_p_Agraph_t gv.readstring (string string);
SWIGTYPE_p_Agraph_t gv.read (string filename);
SWIGTYPE_p_Agraph_t gv.read (SWIGTYPE_p_FILE f);

readstring takes a dot-syntax string, and read takes either a filename or an open FILE handle. super straightforward, iconic behavior 🌟

Add new subgraph to existing graph

SWIGTYPE_p_Agraph_t gv.graph (SWIGTYPE_p_Agraph_t g, string name);

drops a new subgraph into an existing graph g, with the name you pass in πŸŽ€

🌈 New nodes 🌈

Add new node to existing graph

SWIGTYPE_p_Agnode_t gv.node (SWIGTYPE_p_Agraph_t g, string name);

adds a new node to graph g and gives you the node handle back πŸ’«

πŸ’« New edges πŸ’«

Add new edge between existing nodes

SWIGTYPE_p_Agedge_t gv.edge (SWIGTYPE_p_Agnode_t t, SWIGTYPE_p_Agnode_t h);

connects existing tail node t to existing head node h, and you get the edge handle 🫢

Add a new edge between an existing tail node, and a named head node which will be induced in the graph if it doesn’t already exist

SWIGTYPE_p_Agedge_t gv.edge (SWIGTYPE_p_Agnode_t t, string hname);

tail node is already there, and the named head node gets induced into the graph if it’s not already a thing ✨

Add a new edge between an existing head node, and a named tail node which will be induced in the graph if it doesn’t already exist

SWIGTYPE_p_Agedge_t gv.edge (string tname, SWIGTYPE_p_Agnode_t h);

same energy, but flipped: named tail gets induced if needed, and the head node already exists πŸ’…

Add a new edge between named tail and head nodes which will be induced in the graph if they don’t already exist

SWIGTYPE_p_Agedge_t gv.edge (SWIGTYPE_p_Agraph_t g, string tname, string hname);

named tail and named head both get induced into graph g if they aren’t already there. main character edge energy for real 🌈

πŸŽ€ Setting attribute values πŸŽ€

Set value of named attribute of graph/node/edge β€” creating attribute if necessary

string gv.setv (SWIGTYPE_p_Agraph_t g, string attr, string val);
string gv.setv (SWIGTYPE_p_Agnode_t n, string attr, string val);
string gv.setv (SWIGTYPE_p_Agedge_t e, string attr, string val);

sets the value of a named attribute on a graph, node, or edge, and creates the attribute if it has to. returns a string πŸ“

Set value of existing attribute of graph/node/edge (using attribute handle)

string gv.setv (SWIGTYPE_p_Agraph_t g, SWIGTYPE_p_Agsym_t a, string val);
string gv.setv (SWIGTYPE_p_Agnode_t n, SWIGTYPE_p_Agsym_t a, string val);
string gv.setv (SWIGTYPE_p_Agedge_t e, SWIGTYPE_p_Agsym_t a, string val);

same setv era, but you’re passing an attribute handle a instead of a name. still returns a string πŸ’–

πŸ“ Getting attribute values πŸ“

Get value of named attribute of graph/node/edge

string gv.getv (SWIGTYPE_p_Agraph_t g, string attr);
string gv.getv (SWIGTYPE_p_Agnode_t n, string attr);
string gv.getv (SWIGTYPE_p_Agedge_t e, string attr);

grabs the value of a named attribute from a graph, node, or edge, and hands it back as a string ✨

Get value of attribute of graph/node/edge (using attribute handle)

string gv.getv (SWIGTYPE_p_Agraph_t g, SWIGTYPE_p_Agsym_t a);
string gv.getv (SWIGTYPE_p_Agnode_t n, SWIGTYPE_p_Agsym_t a);
string gv.getv (SWIGTYPE_p_Agedge_t e, SWIGTYPE_p_Agsym_t a);

same getv energy but with an attribute handle a instead of a name. returns a string πŸŽ€

🫢 Obtain names from handles 🫢

string gv.nameof (SWIGTYPE_p_Agraph_t g);
string gv.nameof (SWIGTYPE_p_Agnode_t n);
string gv.nameof (SWIGTYPE_p_Agsym_t a);

you’ve got a handle, you want the name β€” gv.nameof says β€œsay less” and returns a string πŸ’…

πŸ” Find handles from names πŸ”

SWIGTYPE_p_Agraph_t gv.findsubg (SWIGTYPE_p_Agraph_t g, string name);
SWIGTYPE_p_Agnode_t gv.findnode (SWIGTYPE_p_Agraph_t g, string name);
SWIGTYPE_p_Agedge_t gv.findedge (SWIGTYPE_p_Agnode_t t, SWIGTYPE_p_Agnode_t h);
SWIGTYPE_p_Agsym_t gv.findattr (SWIGTYPE_p_Agraph_t g, string name);
SWIGTYPE_p_Agsym_t gv.findattr (SWIGTYPE_p_Agnode_t n, string name);
SWIGTYPE_p_Agsym_t gv.findattr (SWIGTYPE_p_Agedge_t e, string name);

the β€œI know the name, now give me the handle” corner. subgraphs, nodes, edges, and attributes all get their finder moment πŸ”₯

🧭 Misc graph navigators returning handles 🧭

SWIGTYPE_p_Agnode_t gv.headof (SWIGTYPE_p_Agedge_t e);
SWIGTYPE_p_Agnode_t gv.tailof (SWIGTYPE_p_Agedge_t e);
SWIGTYPE_p_Agraph_t gv.graphof (SWIGTYPE_p_Agraph_t g);
SWIGTYPE_p_Agraph_t gv.graphof (SWIGTYPE_p_Agedge_t e);
SWIGTYPE_p_Agraph_t gv.graphof (SWIGTYPE_p_Agnode_t n);
SWIGTYPE_p_Agraph_t gv.rootof (SWIGTYPE_p_Agraph_t g);

little navigator besties that hand you back handles: head, tail, graph-of-this, graph-of-that, and root. iykyk 🌟

🧚 Obtain handles of proto node/edge for setting default attribute values 🧚

SWIGTYPE_p_Agnode_t gv.protonode (SWIGTYPE_p_Agraph_t g);
SWIGTYPE_p_Agedge_t gv.protoedge (SWIGTYPE_p_Agraph_t g);

grab the proto node or proto edge handle for graph g when you’re setting default attribute values. very β€œset the vibe for everyone” of them πŸ’œ

πŸ” Iterators πŸ”

Iteration termination tests

bool gv.ok (SWIGTYPE_p_Agraph_t g);
bool gv.ok (SWIGTYPE_p_Agnode_t n);
bool gv.ok (SWIGTYPE_p_Agedge_t e);
bool gv.ok (SWIGTYPE_p_Agsym_t a);

the bool check that tells you whether your iteration handle is still okay. graph, node, edge, attribute β€” all covered βœ…

Iterate over subgraphs of a graph

SWIGTYPE_p_Agraph_t gv.firstsubg (SWIGTYPE_p_Agraph_t g);
SWIGTYPE_p_Agraph_t gv.nextsubg (SWIGTYPE_p_Agraph_t g, SWIGTYPE_p_Agraph_t sg);

first subgraph, then keep calling nextsubg with the current subgraph handle. classic iteration slay πŸ¦‹

Iterate over supergraphs of a graph (obscure and rarely useful)

SWIGTYPE_p_Agraph_t gv.firstsupg (SWIGTYPE_p_Agraph_t g);
SWIGTYPE_p_Agraph_t gv.nextsupg (SWIGTYPE_p_Agraph_t g, SWIGTYPE_p_Agraph_t sg);

yes bestie, the original literally calls this obscure and rarely useful β€” so proceed with lowkey caution 😭

Iterate over edges of a graph

SWIGTYPE_p_Agedge_t gv.firstedge (SWIGTYPE_p_Agraph_t g);
SWIGTYPE_p_Agedge_t gv.nextedge (SWIGTYPE_p_Agraph_t g, SWIGTYPE_p_Agedge_t e);

walks the edges of graph g, first one then next one until you’re done πŸ”₯

Iterate over outedges of a graph

SWIGTYPE_p_Agedge_t gv.firstout (SWIGTYPE_p_Agraph_t g);
SWIGTYPE_p_Agedge_t gv.nextout (SWIGTYPE_p_Agraph_t g, SWIGTYPE_p_Agedge_t e);

same idea but for outedges of a graph. outedge era πŸ’«

Iterate over edges of a node

SWIGTYPE_p_Agedge_t gv.firstedge (SWIGTYPE_p_Agnode_t n);
SWIGTYPE_p_Agedge_t gv.nextedge (SWIGTYPE_p_Agnode_t n, SWIGTYPE_p_Agedge_t e);

edge iteration, but scoped to node n πŸŽ€

Iterate over out-edges of a node

SWIGTYPE_p_Agedge_t gv.firstout (SWIGTYPE_p_Agnode_t n);
SWIGTYPE_p_Agedge_t gv.nextout (SWIGTYPE_p_Agnode_t n, SWIGTYPE_p_Agedge_t e);

out-edge iteration for a single node. no cap, it’s giving β€œfollow the outgoing connections” 🌈

Iterate over head nodes reachable from out-edges of a node

SWIGTYPE_p_Agnode_t gv.firsthead (SWIGTYPE_p_Agnode_t n);
SWIGTYPE_p_Agnode_t gv.nexthead (SWIGTYPE_p_Agnode_t n, SWIGTYPE_p_Agnode_t h);

walks the head nodes you can reach from node n’s out-edges. head node hunting, but make it cute 🫢

Iterate over in-edges of a graph

SWIGTYPE_p_Agedge_t gv.firstin (SWIGTYPE_p_Agraph_t g);
SWIGTYPE_p_Agedge_t gv.nextin (SWIGTYPE_p_Agnode_t n, SWIGTYPE_p_Agedge_t e);

in-edge iteration for a graph. yes, the second signature is written exactly like that in the original β€” copy it as-is, bestie 😭

Iterate over in-edges of a node

SWIGTYPE_p_Agedge_t gv.firstin (SWIGTYPE_p_Agnode_t n);
SWIGTYPE_p_Agedge_t gv.nextin (SWIGTYPE_p_Agraph_t g, SWIGTYPE_p_Agedge_t e);

in-edge iteration for a node. again, the second line is exactly the original signature β€” no edits from me πŸ’…

Iterate over tail nodes reachable from in-edges of a node

SWIGTYPE_p_Agnode_t gv.firsttail (SWIGTYPE_p_Agnode_t n);
SWIGTYPE_p_Agnode_t gv.nexttail (SWIGTYPE_p_Agnode_t n, SWIGTYPE_p_Agnode_t t);

tail node iteration from node n’s in-edges. tail besties, assemble 🌸

Iterate over nodes of a graph

SWIGTYPE_p_Agnode_t gv.firstnode (SWIGTYPE_p_Agraph_t g);
SWIGTYPE_p_Agnode_t gv.nextnode (SWIGTYPE_p_Agraph_t g, SWIGTYPE_p_Agnode_t n);

walks every node in graph g. first node, next node, periodt πŸ‘‘

Iterate over nodes of an edge

SWIGTYPE_p_Agnode_t gv.firstnode (SWIGTYPE_p_Agedge_t e);
SWIGTYPE_p_Agnode_t gv.nextnode (SWIGTYPE_p_Agedge_t e, SWIGTYPE_p_Agnode_t n);

node iteration scoped to edge e. yes, edges have nodes, and they’re getting iterated πŸ’–

Iterate over attributes of a graph

SWIGTYPE_p_Agsym_t gv.firstattr (SWIGTYPE_p_Agraph_t g);
SWIGTYPE_p_Agsym_t gv.nextattr (SWIGTYPE_p_Agraph_t g, SWIGTYPE_p_Agsym_t a);

walks the attributes attached to graph g. attribute handle by attribute handle ✨

Iterate over attributes of an edge

SWIGTYPE_p_Agsym_t gv.firstattr (SWIGTYPE_p_Agedge_t e);
SWIGTYPE_p_Agsym_t gv.nextattr (SWIGTYPE_p_Agedge_t e, SWIGTYPE_p_Agsym_t a);

edge attribute iteration. every edge deserves its attribute moment πŸŽ€

Iterate over attributes of a node

SWIGTYPE_p_Agsym_t gv.firstattr (SWIGTYPE_p_Agnode_t n);
SWIGTYPE_p_Agsym_t gv.nextattr (SWIGTYPE_p_Agnode_t n, SWIGTYPE_p_Agsym_t a);

node attribute iteration, same energy. iconic πŸ¦‹

πŸ’€ Remove graph objects πŸ’€

bool gv.rm (SWIGTYPE_p_Agraph_t g);
bool gv.rm (SWIGTYPE_p_Agnode_t n);
bool gv.rm (SWIGTYPE_p_Agedge_t e);

removes a graph, node, or edge, and returns a bool. the β€œrespectfully, delete it” corner πŸ’…

πŸ“ Layout πŸ“

Annotate a graph with layout attributes and values using a specific layout engine

bool gv.layout (SWIGTYPE_p_Agraph_t g, string engine);

runs layout on graph g with the engine you name, annotating it with layout attributes and values. returns a bool 🌟

🎨 Render 🎨

Render a layout into attributes of the graph

bool gv.render (SWIGTYPE_p_Agraph_t g);

renders a layout into the graph’s own attributes and returns a bool 🫢

Render a layout to stdout

bool gv.render (SWIGTYPE_p_Agraph_t g, string format);

renders to stdout in the format you pass. yes bestie, straight to stdout πŸ’«

Render to an open file

bool gv.render (SWIGTYPE_p_Agraph_t g, string format, SWIGTYPE_p_FILE fout);

renders into the already-open file handle fout πŸŽ€

Render a layout to an unopened file by name

bool gv.render (SWIGTYPE_p_Agraph_t g, string format, string filename);

gives you the filename version β€” it renders to a file by filename instead of an open handle 🌈

Render to a string result

string gv.renderresult (SWIGTYPE_p_Agraph_t ing, string format);
gv.renderresult (SWIGTYPE_p_Agraph_t g, string format, string outdata);

the first one returns a string; the second is written exactly like that in the original β€” no return type, don’t @ me 😭 keep it exact, bestie.

Render to an open channel

bool gv.renderchannel (SWIGTYPE_p_Agraph_t g, string format, string channelname);

renders to the open channel named by channelname, and returns a bool πŸ”₯

Render a layout to a malloc’ed string, to be free’d by the caller

deprecated β€” too easy to leak memory 😭
still needed for "eval [gv::renderdata $G tk]" β€” yes, that exact quote is in the original.
string gv.renderdata (SWIGTYPE_p_Agraph_t g, string format);

returns a string that’s been malloc’ed and has to be free’d by the caller. deprecated because memory leaks are not the vibe, but still needed for that exact "eval [gv::renderdata $G tk]" situation πŸ’€

πŸ’Ύ Writing graph back to file πŸ’Ύ

bool gv.write (SWIGTYPE_p_Agraph_t g, string filename);
bool gv.write (SWIGTYPE_p_Agraph_t g, SWIGTYPE_p_FILE f);

writes graph g back out β€” either by filename or to an open FILE handle f. returns a bool πŸ“

πŸ”§ Graph transformation tools πŸ”§

bool gv.tred (SWIGTYPE_p_Agraph_t g);

the transformation-tools corner: gv.tred on graph g, returning a bool πŸ› οΈβœ¨


🌟 KEYWORDS 🌟

graph, dot, neato, fdp, circo, twopi, sharp. that’s the keyword lineup, no cap πŸ’œ


and that’s the whole page, bestie 🫢 shoutout to the footer energy: source/version 1792256243 and manual gv(3sharp) β€” periodt πŸ’…πŸŽ€

πŸ“¦ where this page comes from