]> granicus.if.org Git - graphviz/commitdiff
Simplify script bindings a bit by introducing N=protonode(g) and E=protoedge(g) funct...
authorellson <devnull@localhost>
Fri, 6 Jan 2006 19:54:20 +0000 (19:54 +0000)
committerellson <devnull@localhost>
Fri, 6 Jan 2006 19:54:20 +0000 (19:54 +0000)
Now, common attribute manipulations can be used.

tclpkg/gv/demo/modgraph.lua
tclpkg/gv/demo/modgraph.pl
tclpkg/gv/demo/modgraph.py
tclpkg/gv/demo/modgraph.rb
tclpkg/gv/demo/modgraph.tcl
tclpkg/gv/gv.cpp
tclpkg/gv/gv.i

index 1c98a82baf0e48ce7e6d66d33da5d3dfca5a166f..7938ca54b5466735c3e9522b920494a3ae21cbf9 100755 (executable)
@@ -11,15 +11,17 @@ assert(lib)()
 modules = io.lines('/proc/modules') 
 
 G = gv.digraph("G")
+N = gv.protonode(G)
+E = gv.protoedge(G)
 gv.setv(G, 'rankdir', 'LR')
 gv.setv(G, 'nodesep', '0.05')
-gv.setv(G, 'node', 'shape', 'box')
-gv.setv(G, 'node', 'width', '0')
-gv.setv(G, 'node', 'height', '0')
-gv.setv(G, 'node', 'margin', '.03')
-gv.setv(G, 'node', 'fontsize', '8')
-gv.setv(G, 'node', 'fontname', 'helvetica')
-gv.setv(G, 'edge', 'arrowsize', '.4')
+gv.setv(N, 'shape', 'box')
+gv.setv(N, 'width', '0')
+gv.setv(N, 'height', '0')
+gv.setv(N, 'margin', '.03')
+gv.setv(N, 'fontsize', '8')
+gv.setv(N, 'fontname', 'helvetica')
+gv.setv(E, 'arrowsize', '.4')
 
 for rec in modules do
    for mod, usedbylist in string.gfind(rec, "([_%w]+) %w+ %w+ ([-,_%w]+)") do
index f134fc47d59ea65230242255321d8922d844a535..4958f01052dac111eed6ecefaa5d31cb1f5f98ad 100755 (executable)
@@ -7,16 +7,19 @@
 use lib "/usr/lib/graphviz/perl";
 use gv;
 
-$g = gv::digraph "G";
-gv::setv($g, "rankdir", "LR");
-gv::setv($g, "nodesep", "0.05");
-gv::setv($g, "node", "shape", "box");
-gv::setv($g, "node", "width", "0");
-gv::setv($g, "node", "height", "0");
-gv::setv($g, "node", "margin", ".03");
-gv::setv($g, "node", "fontsize", "8");
-gv::setv($g, "node", "fontname", "helvetica");
-gv::setv($g, "edge", "arrowsize", ".4");
+$G = gv::digraph("G");
+$N = gv::protonode($G);
+$E = gv::protoedge($G);
+
+gv::setv($G, "rankdir", "LR");
+gv::setv($G, "nodesep", "0.05");
+gv::setv($N, "shape", "box");
+gv::setv($N, "width", "0");
+gv::setv($N, "height", "0");
+gv::setv($N, "margin", ".03");
+gv::setv($N, "fontsize", "8");
+gv::setv($N, "fontname", "helvetica");
+gv::setv($E, "arrowsize", ".4");
 
 #FIXME - complete translation to perl
 
@@ -36,5 +39,5 @@ gv::setv($g, "edge", "arrowsize", ".4");
 #end   
 #f.close
 
-gv::layout($g, "dot");
-gv::render($g, "gtk");
+gv::layout($G, "dot");
+gv::render($G, "gtk");
index eaa50341d0a24f084678a37e0264bb333c8caf53..c09c455dadfb67b48da8c8e3a5348100ed0c975d 100755 (executable)
@@ -13,15 +13,18 @@ import gv
 modules = open("/proc/modules", 'r').readlines()
 
 G = gv.digraph("G")
+N = gv.protonode(G)
+E = gv.protoedge(G)
+
 gv.setv(G, 'rankdir', 'LR')
 gv.setv(G, 'nodesep', '0.05')
-gv.setv(G, 'node', 'shape', 'box')
-gv.setv(G, 'node', 'width', '0')
-gv.setv(G, 'node', 'height', '0')
-gv.setv(G, 'node', 'margin', '.03')
-gv.setv(G, 'node', 'fontsize', '8')
-gv.setv(G, 'node', 'fontname', 'helvetica')
-gv.setv(G, 'edge', 'arrowsize', '.4')
+gv.setv(N, 'shape', 'box')
+gv.setv(N, 'width', '0')
+gv.setv(N, 'height', '0')
+gv.setv(N, 'margin', '.03')
+gv.setv(N, 'fontsize', '8')
+gv.setv(N, 'fontname', 'helvetica')
+gv.setv(E, 'arrowsize', '.4')
 
 for rec in modules:
    fields = rec.split(' ')
index 05cd096a1ccf881249cce27802458e12ca494114..bd841a4d04bd9040b4d97e5e92075061dced0925 100755 (executable)
@@ -7,15 +7,18 @@
 require 'gv'
 
 G = Gv.digraph("G")
+N = Gv.protonode(G)
+E = Gv.protoedge(G)
+
 Gv.setv(G, 'rankdir', 'LR')
 Gv.setv(G, 'nodesep', '0.05')
-Gv.setv(G, 'node', 'shape', 'box')
-Gv.setv(G, 'node', 'width', '0')
-Gv.setv(G, 'node', 'height', '0')
-Gv.setv(G, 'node', 'margin', '.03')
-Gv.setv(G, 'node', 'fontsize', '8')
-Gv.setv(G, 'node', 'fontname', 'helvetica')
-Gv.setv(G, 'edge', 'arrowsize', '.4')
+Gv.setv(N, 'shape', 'box')
+Gv.setv(N, 'width', '0')
+Gv.setv(N, 'height', '0')
+Gv.setv(N, 'margin', '.03')
+Gv.setv(N, 'fontsize', '8')
+Gv.setv(N, 'fontname', 'helvetica')
+Gv.setv(E, 'arrowsize', '.4')
 
 f = File.open('/proc/modules', mode="r")
 while ! f.eof do
index f04d85c27a72de2327396d7d24906d23c5eaa926..640397c73eeba8eeef7d42db64d3b20c012cc4db 100755 (executable)
@@ -10,26 +10,27 @@ set f [open /proc/modules r]
 set modules [read -nonewline $f]
 close $f
 
-set g [gv::digraph G]
-gv::setv $g rankdir LR
-gv::setv $g nodesep .05
-
-gv::setv $g node shape box
-gv::setv $g node width 0
-gv::setv $g node height 0
-gv::setv $g node margin .03
-gv::setv $g node fontsize 8
-gv::setv $g node fontname helvetica
-
-gv::setv $g edge arrowsize .4
+set G [gv::digraph G]
+set N [gv::protonode $G]
+set E [gv::protoedge $G]
+
+gv::setv $G rankdir LR
+gv::setv $G nodesep .05
+gv::setv $N shape box
+gv::setv $N width 0
+gv::setv $N height 0
+gv::setv $N margin .03
+gv::setv $N fontsize 8
+gv::setv $N fontname helvetica
+gv::setv $E arrowsize .4
 
 foreach rec [split $modules \n] {
-  set n [gv::node $g [lindex $rec 0]]
+  set n [gv::node $G [lindex $rec 0]]
   foreach usedby [split [lindex $rec 3] ,] {
     if {[string equal $usedby -] || [string equal $usedby {}]} {continue}
-    set e [gv::edge $n [gv::node $g $usedby]]
+    set e [gv::edge $n [gv::node $G $usedby]]
   }
 }
 
-gv::layout $g dot
-gv::render $g gtk
+gv::layout $G dot
+gv::render $G gtk
index f333cee155872e978c49aa2043b25f169996a940..bd28c764a41be1783976e80f7c2f04f5ccd82c09 100644 (file)
@@ -92,22 +92,26 @@ Agnode_t *node(Agraph_t *g, char *name)
 
 Agedge_t *edge(Agnode_t *t, Agnode_t *h)
 {
+    // edges from/to the protonode are not permitted
+    if ((t->name[0] == '\001' && strcmp (t->name, "\001proto") == 0)
+     || (h->name[0] == '\001' && strcmp (h->name, "\001proto") == 0))
+       return NULL;
     return agedge(t->graph, t, h);
 }
 
 Agedge_t *edge(char *tname, Agnode_t *h)
 {
-    return agedge(h->graph, agnode(h->graph, tname), h);
+    return edge(agnode(h->graph, tname), h);
 }
 
 Agedge_t *edge(Agnode_t *t, char *hname)
 {
-    return agedge(t->graph, t, agnode(t->graph, hname));
+    return edge(t, agnode(t->graph, hname));
 }
 
 Agedge_t *edge(Agraph_t *g, char *tname, char *hname)
 {
-    return agedge(g, agnode(g, tname), agnode(g, hname));
+    return edge(agnode(g, tname), agnode(g, hname));
 }
 
 //-------------------------------------------------
@@ -122,26 +126,6 @@ char *getv(Agraph_t *g, Agsym_t *a)
        return empty_string;
     return val;
 }
-char *getv(Agraph_t *g, char *gne, Agsym_t *a)
-{
-    char *val;
-    int len;
-
-    if (!g || !gne || !gne[0] || !a)
-       return NULL;
-    len = strlen(gne);
-    if (strncmp(gne,"graph",len) == 0)
-        val = agxget(g, a->index);
-    else if (strncmp(gne,"node",len) == 0)
-        val = agxget(g->proto->n, a->index);
-    else if (strncmp(gne,"edge",len) == 0)
-        val = agxget(g->proto->e, a->index);
-    else
-        return NULL;
-    if (!val)
-       return empty_string;
-    return val;
-}
 char *getv(Agraph_t *g, char *attr)
 {
     Agsym_t *a;
@@ -157,39 +141,6 @@ char *getv(Agraph_t *g, char *attr)
        return empty_string;
     return val;
 }
-char *getv(Agraph_t *g, char *gne, char *attr)
-{
-    Agsym_t *a;
-    char *val;
-    int len;
-
-    if (!g || !gne || !gne[0] || !attr)
-       return NULL;
-    len = strlen(gne);
-    if (strncmp(gne,"graph",len) == 0) {
-        a = agfindattr(g->root, attr);
-        if (!a)
-           return empty_string;
-        val = agxget(g, a->index);
-    }
-    else if (strncmp(gne,"node",len) == 0) {
-        a = agfindattr(g->proto->n, attr);
-        if (!a)
-           return empty_string;
-        val = agxget(g->proto->n, a->index);
-    }
-    else if (strncmp(gne,"edge",len) == 0) {
-        a = agfindattr(g->proto->e, attr);
-        if (!a)
-           return empty_string;
-        val = agxget(g->proto->e, a->index);
-    }
-    else
-        return NULL;
-    if (!val)
-       return empty_string;
-    return val;
-}
 char *setv(Agraph_t *g, Agsym_t *a, char *val)
 {
     if (!g || !a || !val)
@@ -197,23 +148,6 @@ char *setv(Agraph_t *g, Agsym_t *a, char *val)
     agxset(g, a->index, val);
     return val;
 }
-char *setv(Agraph_t *g, char *gne, Agsym_t *a, char *val)
-{
-    int len;
-
-    if (!g || !gne || !gne[0] || !a || !val)
-       return NULL;
-    len = strlen(gne);
-    if (strncmp(gne,"graph",len) == 0)
-        agxset(g, a->index, val);
-    else if (strncmp(gne,"node",len) == 0)
-        agxset(g->proto->n, a->index, val);
-    else if (strncmp(gne,"edge",len) == 0)
-        agxset(g->proto->e, a->index, val);
-    else
-        return NULL;
-    return val;
-}
 char *setv(Agraph_t *g, char *attr, char *val)
 {
     Agsym_t *a;
@@ -226,36 +160,6 @@ char *setv(Agraph_t *g, char *attr, char *val)
     agxset(g, a->index, val);
     return val;
 }
-char *setv(Agraph_t *g, char *gne, char *attr, char *val)
-{
-    Agsym_t *a;
-    int len;
-
-    if (!g || !gne || !gne[0] || !attr || !val)
-       return NULL;
-    len = strlen(gne);
-    if (strncmp(gne,"graph",len) == 0) {
-        a = agfindattr(g->root, attr);
-        if (!a)
-           a = agraphattr(g->root, attr, empty_string);
-        agxset(g, a->index, val);
-    }
-    else if (strncmp(gne,"node",len) == 0) {
-        a = agfindattr(g->proto->n, attr);
-        if (!a)
-           a = agnodeattr(g->root, attr, empty_string);
-        agxset(g->proto->n, a->index, val);
-    }
-    else if (strncmp(gne,"edge",len) == 0) {
-        a = agfindattr(g->proto->e, attr);
-        if (!a)
-           a = agedgeattr(g->root, attr, empty_string);
-        agxset(g->proto->e, a->index, val);
-    }
-    else
-        return NULL;
-    return val;
-}
 //-------------------------------------------------
 char *getv(Agnode_t *n, Agsym_t *a)
 {
@@ -443,6 +347,21 @@ Agraph_t *rootof(Agraph_t *g)
     return g->root;
 }
 
+//-------------------------------------------------
+Agnode_t *protonode(Agraph_t *g)
+{
+    if (!g)
+        return NULL;
+    return g->proto->n;
+}
+
+Agedge_t *protoedge(Agraph_t *g)
+{
+    if (!g)
+        return NULL;
+    return g->proto->e;
+}
+
 //-------------------------------------------------
 char *nameof(Agraph_t *g)
 {
@@ -806,69 +725,6 @@ Agsym_t *nextattr(Agraph_t *g, Agsym_t *a)
         return NULL;
     return g->univ->globattr->list[i];
 }
-Agsym_t *firstattr(Agraph_t *g, char *gne)
-{
-    int len;
-
-    if (!g || !gne || !gne[0])
-       return NULL;
-    g = g->root;
-    len = strlen(gne);
-    if (strncmp(gne,"graph",len) == 0) {
-        if (dtsize(g->univ->globattr->dict) == 0)
-           return NULL;
-        return g->univ->globattr->list[0];
-    }
-    else if (strncmp(gne,"node",len) == 0) {
-        if (dtsize(g->univ->nodeattr->dict) == 0)
-           return NULL;
-        return g->univ->nodeattr->list[0];
-    }
-    else if (strncmp(gne,"edge",len) == 0) {
-        if (dtsize(g->univ->edgeattr->dict) == 0)
-           return NULL;
-        return g->univ->edgeattr->list[0];
-    }
-    return NULL;
-}
-
-Agsym_t *nextattr(Agraph_t *g, char *gne, Agsym_t *a)
-{
-    int i, len;
-
-    if (!g || !gne || !gne[0] || !a)
-        return NULL;
-    g = g->root;
-    len = strlen(gne);
-    if (strncmp(gne,"graph",len) == 0) {
-        for (i = 0; i < dtsize(g->univ->globattr->dict); i++)
-           if (a == g->univ->globattr->list[i])
-               break;
-        i++;
-        if (i > dtsize(g->univ->globattr->dict))
-            return NULL;
-        return g->univ->globattr->list[i];
-    }
-    else if (strncmp(gne,"node",len) == 0) {
-        for (i = 0; i < dtsize(g->univ->nodeattr->dict); i++)
-           if (a == g->univ->nodeattr->list[i])
-               break;
-        i++;
-        if (i > dtsize(g->univ->nodeattr->dict))
-            return NULL;
-        return g->univ->nodeattr->list[i];
-    }
-    else if (strncmp(gne,"edge",len) == 0) {
-        for (i = 0; i < dtsize(g->univ->edgeattr->dict); i++)
-           if (a == g->univ->edgeattr->list[i])
-               break;
-        i++;
-        if (i > dtsize(g->univ->edgeattr->dict))
-            return NULL;
-        return g->univ->edgeattr->list[i];
-    }
-    return NULL;
-}
 
 Agsym_t *firstattr(Agnode_t *n)
 {
@@ -949,11 +805,18 @@ void rm(Agraph_t *g)
 
 void rm(Agnode_t *n)
 {
+    // removal of the protonode is not permitted
+    if (n->name[0] == '\001' && strcmp (n->name, "\001proto") ==0)
+       return;
     agdelete(n->graph, n);
 }
 
 void rm(Agedge_t *e)
 {
+    // removal of the protoedge is not permitted
+    if ((e->head->name[0] == '\001' && strcmp (e->head->name, "\001proto") == 0)
+     || (e->tail->name[0] == '\001' && strcmp (e->tail->name, "\001proto") == 0))
+       return;
     agdelete(e->head->graph->root, e);
 }
 
index 41cdb62051a66b67997e802510e144727f43e2ad..529c1ed7f71755a4b53db69941063924ede2f767 100644 (file)
@@ -60,34 +60,22 @@ extern char *setv(Agraph_t *g, char *attr, char *val);
 extern char *setv(Agnode_t *n, char *attr, char *val);
 extern char *setv(Agedge_t *e, char *attr, char *val);
 
-/*** Set default value of graph/node/edge named attribute - creating attribute if necessary */
-extern char *setv(Agraph_t *g, char *gne, char *attr, char *val);
-
 /*** Set value of existing attribute of graph/node/edge (using attribute handle) */
 extern char *setv(Agraph_t *g, Agsym_t *a, char *val);
 extern char *setv(Agnode_t *n, Agsym_t *a, char *val);
 extern char *setv(Agedge_t *e, Agsym_t *a, char *val);
 
-/*** Set default value of existing graph/node/edge attribute (using attribute handle) */
-extern char *setv(Agraph_t *g, char *gne, Agsym_t *a, char *val);
-
 /** Getting attribute values */
 /*** Get value of named attribute of graph/node/edge */
 extern char *getv(Agraph_t *g, char *attr);
 extern char *getv(Agnode_t *n, char *attr);
 extern char *getv(Agedge_t *e, char *attr);
 
-/*** Get default value of graph/node/edge named attribute */
-extern char *getv(Agraph_t *g, char *gne, char *attr);
-
 /*** Get value of attribute of graph/node/edge (using attribute handle) */
 extern char *getv(Agraph_t *g, Agsym_t *a);
 extern char *getv(Agnode_t *n, Agsym_t *a);
 extern char *getv(Agedge_t *e, Agsym_t *a);
 
-/*** Get default value of attribute of graph/node/edge (using attribute handle) */
-extern char *getv(Agraph_t *g, char *gne, Agsym_t *a);
-
 /** Obtain names from handles */
 extern char *nameof(Agraph_t *g);
 extern char *nameof(Agnode_t *n);
@@ -112,6 +100,10 @@ extern Agraph_t *graphof(Agedge_t *e);
 extern Agraph_t *graphof(Agnode_t *n);
 extern Agraph_t *rootof(Agraph_t *g);
 
+/** Obtain handles of proto node/edge for setting default attribute values */
+extern Agnode_t *protonode(Agraph_t *g);
+extern Agedge_t *protoedge(Agraph_t *g);
+
 /** Iterators */
 /*** Iteration termination tests */
 extern bool ok(Agraph_t *g);
@@ -171,10 +163,6 @@ extern Agnode_t *nextnode(Agedge_t *e, Agnode_t *n);
 extern Agsym_t *firstattr(Agraph_t *g);
 extern Agsym_t *nextattr(Agraph_t *g, Agsym_t *a);
 
-/*** Iterate over default graph/node/edge attributes of a graph */
-extern Agsym_t *firstattr(Agraph_t *g, char *gne);
-extern Agsym_t *nextattr(Agraph_t *g, char *gne, Agsym_t *a);
-
 /*** Iterate over attributes of an edge */
 extern Agsym_t *firstattr(Agedge_t *e);
 extern Agsym_t *nextattr(Agedge_t *e, Agsym_t *a);