Graphviz 13.0.0~dev.20250607.1528
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#include <util/itos.h>
25
26static int myindegree(Agnode_t *n) { return agdegree(n->root, n, 1, 0); }
27
28// need outdegree without selfarcs
29static int myoutdegree(Agnode_t *n) {
30 Agedge_t *e;
31 int rv = 0;
32
33 for (e = agfstout(n->root, n); e; e = agnxtout(n->root, e)) {
34 if (agtail(e) != aghead(e))
35 rv++;
36 }
37 return rv;
38}
39
40static bool isleaf(Agnode_t *n) { return myindegree(n) + myoutdegree(n) == 1; }
41
42static bool ischainnode(Agnode_t *n) {
43 return myindegree(n) == 1 && myoutdegree(n) == 1;
44}
45
46static void adjustlen(Agedge_t *e, Agsym_t *sym, int newlen) {
47 agxset(e, sym, ITOS(newlen));
48}
49
50static Agsym_t *bindedgeattr(Agraph_t *g, char *str) {
51 return agattr_text(g, AGEDGE, str, "");
52}
53
55 Agnode_t *n;
56 Agedge_t *e;
57 char *str;
58 Agsym_t *m_ix, *s_ix;
59 int cnt, d;
60 int ChainSize = 0;
61 Agnode_t *ChainNode = NULL;
62
63 m_ix = bindedgeattr(g, "minlen");
64 s_ix = bindedgeattr(g, "style");
65
66 for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
67 d = myindegree(n) + myoutdegree(n);
68 if (d == 0) {
69 if (opts->ChainLimit < 1)
70 continue;
71 if (ChainNode) {
72 e = agedge(g, ChainNode, n, "", 1);
73 agxset(e, s_ix, "invis");
74 ChainSize++;
75 if (ChainSize < opts->ChainLimit)
76 ChainNode = n;
77 else {
78 ChainNode = NULL;
79 ChainSize = 0;
80 }
81 } else
82 ChainNode = n;
83 } else if (d > 1) {
84 if (opts->MaxMinlen < 1)
85 continue;
86 cnt = 0;
87 for (e = agfstin(g, n); e; e = agnxtin(g, e)) {
88 if (isleaf(agtail(e))) {
89 str = agxget(e, m_ix);
90 if (str[0] == 0) {
91 adjustlen(e, m_ix, cnt % opts->MaxMinlen + 1);
92 cnt++;
93 }
94 }
95 }
96
97 cnt = 0;
98 for (e = agfstout(g, n); e; e = agnxtout(g, e)) {
99 if (isleaf(e->node) || (opts->Do_fans && ischainnode(e->node))) {
100 str = agxget(e, m_ix);
101 if (str[0] == 0)
102 adjustlen(e, m_ix, cnt % opts->MaxMinlen + 1);
103 cnt++;
104 }
105 }
106 }
107 }
108}
cgraph.h additions
node NULL
Definition grammar.y:180
static int cnt(Dict_t *d, Dtlink_t **set)
Definition graph.c:198
int agdegree(Agraph_t *g, Agnode_t *n, int in, int out)
Definition graph.c:225
void graphviz_unflatten(Agraph_t *g, const graphviz_unflatten_options_t *opts)
Definition unflatten.c:54
Agsym_t * agattr_text(Agraph_t *g, int kind, char *name, const char *value)
creates or looks up text attributes of a graph
Definition attr.c:348
int agxset(void *obj, Agsym_t *sym, const char *value)
Definition attr.c:536
char * agxget(void *obj, Agsym_t *sym)
Definition attr.c:472
Agedge_t * agedge(Agraph_t *g, Agnode_t *t, Agnode_t *h, char *name, int createflag)
Definition edge.c:253
Agedge_t * agnxtin(Agraph_t *g, Agedge_t *e)
Definition edge.c:71
Agedge_t * agfstout(Agraph_t *g, Agnode_t *n)
Definition edge.c:26
#define agtail(e)
Definition cgraph.h:988
#define aghead(e)
Definition cgraph.h:989
Agedge_t * agnxtout(Agraph_t *g, Agedge_t *e)
Definition edge.c:41
Agedge_t * agfstin(Agraph_t *g, Agnode_t *n)
Definition edge.c:57
Agnode_t * agnxtnode(Agraph_t *g, Agnode_t *n)
Definition node.c:48
Agnode_t * agfstnode(Agraph_t *g)
Definition node.c:41
@ AGEDGE
Definition cgraph.h:207
static opts_t opts
Definition gvgen.c:401
textitem scanner parser str
Definition htmlparse.y:224
#define ITOS(i)
Definition itos.h:43
static void adjustlen(Agedge_t *e, Agsym_t *sym, int newlen)
Definition unflatten.c:46
static bool isleaf(Agnode_t *n)
Definition unflatten.c:40
static bool ischainnode(Agnode_t *n)
Definition unflatten.c:42
static Agsym_t * bindedgeattr(Agraph_t *g, char *str)
Definition unflatten.c:50
static int myindegree(Agnode_t *n)
Definition unflatten.c:26
static int myoutdegree(Agnode_t *n)
Definition unflatten.c:29
Agnode_t * node
Definition cgraph.h:272
Agraph_t * root
Definition cgraph.h:261
graph or subgraph
Definition cgraph.h:424
string attribute descriptor symbol in Agattr_s.dict
Definition cgraph.h:651
options for passing to graphviz_unflatten
Definition cgraph.h:1059