From: Emden R. Gansner Date: Wed, 23 Apr 2014 21:02:53 +0000 (-0400) Subject: Add X and Y attributes to nodes X-Git-Tag: TRAVIS_CI_BUILD_EXPERIMENTAL~221 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1eca100f977c305f4a48eb78830cb5b208a164b3;p=graphviz Add X and Y attributes to nodes --- diff --git a/cmd/gvpr/gvpr.1 b/cmd/gvpr/gvpr.1 index 6209007f1..e830bc6ae 100644 --- a/cmd/gvpr/gvpr.1 +++ b/cmd/gvpr/gvpr.1 @@ -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. diff --git a/lib/gvpr/compile.c b/lib/gvpr/compile.c index f8cb70bec..cc128213c 100644 --- a/lib/gvpr/compile.c +++ b/lib/gvpr/compile.c @@ -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)); diff --git a/lib/gvpr/gprdata b/lib/gvpr/gprdata index b02fc39f4..f4465675e 100644 --- a/lib/gvpr/gprdata +++ b/lib/gvpr/gprdata @@ -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)