]> granicus.if.org Git - graphviz/commitdiff
Add X and Y attributes to nodes
authorEmden R. Gansner <erg@alum.mit.edu>
Wed, 23 Apr 2014 21:02:53 +0000 (17:02 -0400)
committerEmden R. Gansner <erg@alum.mit.edu>
Wed, 23 Apr 2014 21:02:53 +0000 (17:02 -0400)
cmd/gvpr/gvpr.1
lib/gvpr/compile.c
lib/gvpr/gprdata

index 6209007f1d713863a843c114eda7632ddb182450..e830bc6ae275dd3ae984e49a7a180b3dcdd1e1fe 100644 (file)
@@ -309,6 +309,12 @@ the outdegree of a node.
 \fBdegree\fR : \fBint\fR
 the degree of a node.
 .TP
+\fBX\fR : \fBdouible\fR
+the X coordinate of a node. (Assumes the node has a \fIpos\fP attribute.)
+.TP
+\fBY\fR : \fBdouible\fR
+the Y coordinate of a node. (Assumes the node has a \fIpos\fP attribute.)
+.TP
 \fBroot\fR : \fBgraph_t\fR
 the root graph of an object. The root of a root graph
 is itself.
index f8cb70becdd385ce59036a6837ad064fe67537a0..cc128213c8398ae5d604765de760fa6e89cee6bd 100644 (file)
@@ -166,6 +166,32 @@ static char *xyOf(Expr_t * pgm, char *pt, int getx)
     return v;
 }
 
+/* posOf:
+ * Get pos data from node; store x or y into v if successful and return  0;
+ * else return -1
+ */
+static int posOf(Agnode_t* np, int idx, double* v)
+{
+    static Agraph_t* root;
+    static Agsym_t* pos;
+    Agraph_t* nroot = agroot(np);
+    char* ps;
+    double p[2];
+
+    if (root != nroot) {
+       root = nroot;
+       pos = agattr(root, AGNODE, "pos", 0);
+    } 
+    if (!pos) return -1;
+    ps = agxget(np, pos);
+    if (sscanf(ps, "%lf,%lf", &p[0], &p[1]) == 2) {
+       *v = p[idx];
+       return 0;
+    }
+    else return -1;
+    
+}
+
 #ifdef DEBUG
 static char *symName(Expr_t * ex, int op)
 {
@@ -456,6 +482,24 @@ static int lookup(Expr_t * pgm, Agobj_t * objp, Exid_t * sym, Extype_t * v,
                return -1;
            }
            break;
+       case M_X:
+           if (AGTYPE(objp) == AGNODE) {
+               if (posOf ((Agnode_t *) objp, 0, &(v->floating)))
+                   exerror("no x coordinate for node \"%s\"", agnameof(objp));
+           } else {
+               exerror("x coordinate of non-node");
+               return -1;
+           }
+           break;
+       case M_Y:
+           if (AGTYPE(objp) == AGNODE) {
+               if (posOf ((Agnode_t *) objp, 1, &(v->floating)))
+                   exerror("no y coordinate for node \"%s\"", agnameof(objp));
+           } else {
+               exerror("x coordinate of non-node");
+               return -1;
+           }
+           break;
        case M_parent:
            if (AGTYPE(objp) == AGRAPH)
                v->integer = PTR2INT(agparent((Agraph_t *) objp));
index b02fc39f472c9882589386bdd7e0742cd8934450..f4465675e1a1dc7a73c8196caba5bb2ac372b27d 100644 (file)
@@ -11,6 +11,8 @@ V_travedge  "$tvedge"      ID       T_edge             0           Y(E)
 V_travtype  "$tvtype"      ID       T_tvtyp            0           Y(TV)
 V_ARGC      "ARGC"         ID       INTEGER            0           Y(I)
 M_degree    "degree"       ID       INTEGER            Y(V)        Y(I)
+M_X         "X"                           ID       FLOATING           Y(V)        Y(F)
+M_Y         "Y"                           ID       FLOATING           Y(V)        Y(F)
 M_head      "head"         ID       T_node             Y(E)        Y(V)
 M_tail      "tail"         ID       T_node             Y(E)        Y(V)
 M_name      "name"         ID       STRING             YALL        Y(S)