MOTHBALLED-graphviz
MOTHBALLED-graphviz copied to clipboard
[cgraph, dot] How to turn a subgraph into a cluster?
In C code, how can I turn an existing subgraph into a cluster? I haven't found a function in cgraph.h
that renames subgraphs. The latter would allow you to prepend a subgraph with 'cluster', effectively turning it into a cluster. Are there other ways to accomplish this?
At present, there is no way to do this with a simple library call. You would basically do a clone, but use a new name. (I should add this as a feature when I add agclone.) In general, the library relies on a certain stability in the subgraph structure, including names. In retrospect, using a "cluster" prefix to denote subgraphs that are clusters is convenient, it might have been better to make this an explicit attribute. It would not be difficult to actually support both mechanism; the only worry would be if someone has a non-cluster subgraph with cluster=true set.
There is a function int agrename(Agobj_t * obj, char *newname) in obj.c I don't remember anymore why this is not exposed in cgraph.h and there are no comments from my past self to explain this. I believe it is safe for simple cases. (I'm not sure if all the side-effect machinery, like client callbacks, are working, but I suspect you don't rely on this.) I would recommend some basic tests like duplicate subgraph names, anonymous vs. non-anonymous subgraphs, callbacks, maybe other issues to consider.
On Tue, Feb 21, 2017 at 10:15 AM, emden [email protected] wrote:
At present, there is no way to do this with a simple library call. You would basically do a clone, but use a new name. (I should add this as a feature when I add agclone.) In general, the library relies on a certain stability in the subgraph structure, including names. In retrospect, using a "cluster" prefix to denote subgraphs that are clusters is convenient, it might have been better to make this an explicit attribute. It would not be difficult to actually support both mechanism; the only worry would be if someone has a non-cluster subgraph with cluster=true set.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ellson/graphviz/issues/1211#issuecomment-281372901, or mute the thread https://github.com/notifications/unsubscribe-auth/ACtWzxODNpJvuy7Tnisbf_utiRHeypz3ks5rev-agaJpZM4MHaVO .
Should the function agrename
be exposed in a PR, or is it considered too unsafe?
I forgot about that. Wasn't that something John asked for?
Yes - I believe it works for simple cases, but we never decided which client callbacks should be made. At present, there are none. For example should renaming a node trigger a callback for modifying the node? The graph(s) that contain it? Probably.
There’s little arg checking, but can’t think of any unusual cases to consider, like having to generate “anonymous” names for subgraphs since that mainly happens at the graph parser level.
On Feb 21, 2017, at 10:58 AM, emden [email protected] wrote:
I forgot about that. Wasn't that something John asked for?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ellson/graphviz/issues/1211#issuecomment-281386534, or mute the thread https://github.com/notifications/unsubscribe-auth/ACtWz4P9Q4NW3eECoTjm4W_u1SJKEj9rks5rewmlgaJpZM4MHaVO.
I don't recall ... I may have done to support GUI operations -- but I doubt that I expected rename to effect a structural change like subgraph --> cluster.
On February 21, 2017 at 10:58 AM emden [email protected] wrote:
I forgot about that. Wasn't that something John asked for? — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ellson/graphviz/issues/1211#issuecomment-281386534 , or mute the thread https://github.com/notifications/unsubscribe-auth/ABcTPUHpC2OhG3Js8r35WHBDEVxObsd-ks5rewmlgaJpZM4MHaVO .