[prev in list] [next in list] [prev in thread] [next in thread]
List: graphviz-interest
Subject: [graphviz-interest] how would I copy node/edge attributes into
From: erg () research ! att ! com (Emden R ! Gansner)
Date: 2005-10-31 14:21:51
Message-ID: 43666ECD.5030003 () research ! att ! com
[Download RAW message or body]
Wolfgang H?felinger wrote:
> I'm using 'gvpr' to manipulate a graph. My "manipultion" is simpy to get rid
> of edges/nodes not of interest (this part works fine).
>
> My input graph (i.e. dot file) contains also attributes. For example:
>
> == input.dot ==
> digraph G {
> graph [overlap = false];
> node [color = red];
>
> ..
> }
>
> After having processed my input.dot file using 'gvpr', I'm getting
>
> digraph H {
> graph [overlap = false];
>
> ..
> }
>
Without seeing the script you are using, I can't say precisely what to change. \
However, as an example, suppose you want to get rid of all nodes with color=blue. \
This can be done using the script 'N[color == "blue"]{delete($G,$)}' and running gvpr \
-c. The -c flag says use the input graph as the output graph.
The basic model used by gvpr is that of awk. That is, if a node or object satisfies
a certain condition, add it to the output graph. If you supply an explicit action, \
this action overrides the default one. So, if you want the node or edge to be in the \
output graph, the action needs to add it explicitly.
For example, suppose you want to get rid of all nodes with color=blue, and make all \
other nodes have color=red. This is done by the script 'N[color != \
"blue"]{color="red"; subnode($T,$)}'. This changes the non-blue nodes to red and adds \
them to the target subgraph, which is the default output graph.
Note that the target graph will have the nodes you want, but no edges. You could add \
a rule for edges but the edges you want are the ones induced by the nodes you've \
selected. This is a frequent enough occurrence that gvpr provide the -i option add \
precisely these edges on output.
Finally, the model of in-place editing of the input graph arose frequently enough \
that the -c flag was added to gvpr. With this, the subnode and subedge commands can \
be dropped. One just uses the actions to modify the input graph, knowing that the \
changed graph will be output at the end.
> Note that node attributes are gone.
>
> So far I have been able to "rescue" graph attributes by using builtin function
> 'copyA':
> H = subg($G,"H");
> ..
> copy(H,some_current_node);
> ..
> copyA($G,H);
> induce(H);
> write(H);
>
For many (most?) uses, you probably don't need one of the copy functions, since you \
can work with the relevant nodes directly, either by moving them to the output graph \
or using gvpr -c.
> P.S.: 'gvpr's documentation contains
>
> > > copy(g : graph_t, x : obj_t) : obj_t
> > > creates a copy of object x in graph g, [..]
>
>
> As a non-native I have some trouble to understand. Does it mean that
> a. a copy of x (no matter to which graph it belongs) will be created in graph 'g' \
> ; or does it mean that b. a copy of 'x in graph g' is created and returned?
>
> After having analyzed my gvpr's output I firmly believe that a.) is correct.
Yes, copy means make an object in graph g that looks like object x, no matter what \
graph x belongs to. Note that for edges, this is a shallow copy. This means the new \
edge will look like x, but the endpoints may not look like the endpoints of x. This \
is done using clone, which does a deep copy.
< However, in
> such a case one would expect that 'copy' has this signature:
>
> copy(x : obj_t, g : graph_t)
>
> to comply to the well established copy(src,dst) convention (and also to the way \
> it's written - "creates a copy of object x in ..".
>
You mean as with C functions:
SYNOPSIS
#include <string.h>
char *strcpy(char *dest, const char *src);
? :)
Emden
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic