Graphviz 13.0.0~dev.20241220.2304
Loading...
Searching...
No Matches
unflatten.c
Go to the documentation of this file.
1
9/*
10 * Copyright (c) 2011 AT&T Intellectual Property
11 * All rights reserved. This program and the accompanying materials
12 * are made available under the terms of the Eclipse Public License v1.0
13 * which accompanies this distribution, and is available at
14 * https://www.eclipse.org/legal/epl-v10.html
15 *
16 * Authors: Stephen North, Emden Gansner
17 * Contributors: Details at https://graphviz.org
18 */
19
20#include <cgraph/cghdr.h>
21#include <stdbool.h>
22#include <stddef.h>
23#include <stdio.h>
24
25static int myindegree(Agnode_t *n) { return agdegree(n->root, n, 1, 0); }
26
27// need outdegree without selfarcs
28static int myoutdegree(Agnode_t *n) {
29 Agedge_t *e;
30 int rv = 0;
31
32 for (e = agfstout(n->root, n); e; e = agnxtout(n->root, e)) {
33 if (agtail(e) != aghead(e))
34 rv++;
35 }
36 return rv;
37}
38
39static bool isleaf(Agnode_t *n) { return myindegree(n) + myoutdegree(n) == 1; }
40
41static bool ischainnode(Agnode_t *n) {
42 return myindegree(n) == 1 && myoutdegree(n) == 1;
43}
44
45static void adjustlen(Agedge_t *e, Agsym_t *sym, int newlen) {
46 char buf[12];
47
48 snprintf(buf, sizeof(buf), "%d", newlen);
49 agxset(e, sym, buf);
50}
51
52static Agsym_t *bindedgeattr(Agraph_t *g, char *str) {
53 return agattr(g, AGEDGE, str, "");
54}
55
57 Agnode_t *n;
58 Agedge_t *e;
59 char *str;
60 Agsym_t *m_ix, *s_ix;
61 int cnt, d;
62 int ChainSize = 0;
63 Agnode_t *ChainNode = NULL;
64
65 m_ix = bindedgeattr(g, "minlen");
66 s_ix = bindedgeattr(g, "style");
67
68 for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
69 d = myindegree(n) + myoutdegree(n);
70 if (d == 0) {
71 if (opts->ChainLimit < 1)
72 continue;
73 if (ChainNode) {
74 e = agedge(g, ChainNode, n, "", 1);
75 agxset(e, s_ix, "invis");
76 ChainSize++;
77 if (ChainSize < opts->ChainLimit)
78 ChainNode = n;
79 else {
80 ChainNode = NULL;
81 ChainSize = 0;
82 }
83 } else
84 ChainNode = n;
85 } else if (d > 1) {
86 if (opts->MaxMinlen < 1)
87 continue;
88 cnt = 0;
89 for (e = agfstin(g, n); e; e = agnxtin(g, e)) {
90 if (isleaf(agtail(e))) {
91 str = agxget(e, m_ix);
92 if (str[0] == 0) {
93 adjustlen(e, m_ix, cnt % opts->MaxMinlen + 1);
94 cnt++;
95 }
96 }
97 }
98
99 cnt = 0;
100 for (e = agfstout(g, n); e; e = agnxtout(g, e)) {
101 if (isleaf(e->node) || (opts->Do_fans && ischainnode(e->node))) {
102 str = agxget(e, m_ix);
103 if (str[0] == 0)
104 adjustlen(e, m_ix, cnt % opts->MaxMinlen + 1);
105 cnt++;
106 }
107 }
108 }
109 }
110}
cgraph.h additions
node NULL
Definition grammar.y:163
static int cnt(Dict_t *d, Dtlink_t **set)
Definition graph.c:210
int agdegree(Agraph_t *g, Agnode_t *n, int in, int out)
Definition graph.c:237
void graphviz_unflatten(Agraph_t *g, const graphviz_unflatten_options_t *opts)
Definition unflatten.c:56
Agsym_t * agattr(Agraph_t *g, int kind, char *name, const char *value)
creates or looks up attributes of a graph
Definition attr.c:338
int agxset(void *obj, Agsym_t *sym, const char *value)
Definition attr.c:478
char * agxget(void *obj, Agsym_t *sym)
Definition attr.c:455
Agedge_t * agedge(Agraph_t *g, Agnode_t *t, Agnode_t *h, char *name, int createflag)
Definition edge.c:260
Agedge_t * agnxtin(Agraph_t *g, Agedge_t *e)
Definition edge.c:69
Agedge_t * agfstout(Agraph_t *g, Agnode_t *n)
Definition edge.c:24
#define agtail(e)
Definition cgraph.h:880
#define aghead(e)
Definition cgraph.h:881
Agedge_t * agnxtout(Agraph_t *g, Agedge_t *e)
Definition edge.c:39
Agedge_t * agfstin(Agraph_t *g, Agnode_t *n)
Definition edge.c:55
Agnode_t * agnxtnode(Agraph_t *g, Agnode_t *n)
Definition node.c:47
Agnode_t * agfstnode(Agraph_t *g)
Definition node.c:40
@ AGEDGE
Definition cgraph.h:207
static opts_t opts
Definition gvgen.c:394
textitem scanner parser str
Definition htmlparse.y:224
static void adjustlen(Agedge_t *e, Agsym_t *sym, int newlen)
Definition unflatten.c:45
static bool isleaf(Agnode_t *n)
Definition unflatten.c:39
static bool ischainnode(Agnode_t *n)
Definition unflatten.c:41
static Agsym_t * bindedgeattr(Agraph_t *g, char *str)
Definition unflatten.c:52
static int myindegree(Agnode_t *n)
Definition unflatten.c:25
static int myoutdegree(Agnode_t *n)
Definition unflatten.c:28
Agnode_t * node
Definition cgraph.h:272
Agraph_t * root
Definition cgraph.h:261
graph or subgraph
Definition cgraph.h:425
string attribute descriptor symbol in Agattr_s.dict
Definition cgraph.h:637
options for passing to graphviz_unflatten
Definition cgraph.h:955