Graphviz 14.1.3~dev.20260124.0732
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 "config.h"
21
22#include <cgraph/cghdr.h>
23#include <stdbool.h>
24#include <stddef.h>
25#include <stdio.h>
26#include <util/itos.h>
27
28static int myindegree(Agnode_t *n) { return agdegree(n->root, n, 1, 0); }
29
30// need outdegree without selfarcs
31static int myoutdegree(Agnode_t *n) {
32 Agedge_t *e;
33 int rv = 0;
34
35 for (e = agfstout(n->root, n); e; e = agnxtout(n->root, e)) {
36 if (agtail(e) != aghead(e))
37 rv++;
38 }
39 return rv;
40}
41
42static bool isleaf(Agnode_t *n) { return myindegree(n) + myoutdegree(n) == 1; }
43
44static bool ischainnode(Agnode_t *n) {
45 return myindegree(n) == 1 && myoutdegree(n) == 1;
46}
47
48static void adjustlen(Agedge_t *e, Agsym_t *sym, int newlen) {
49 agxset(e, sym, ITOS(newlen));
50}
51
52static Agsym_t *bindedgeattr(Agraph_t *g, char *str) {
53 return agattr_text(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:181
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:56
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:336
int agxset(void *obj, Agsym_t *sym, const char *value)
Definition attr.c:524
char * agxget(void *obj, Agsym_t *sym)
Definition attr.c:460
Agedge_t * agedge(Agraph_t *g, Agnode_t *t, Agnode_t *h, char *name, int createflag)
Definition edge.c:255
Agedge_t * agnxtin(Agraph_t *g, Agedge_t *e)
Definition edge.c:73
Agedge_t * agfstout(Agraph_t *g, Agnode_t *n)
Definition edge.c:28
#define agtail(e)
Definition cgraph.h:977
#define aghead(e)
Definition cgraph.h:978
Agedge_t * agnxtout(Agraph_t *g, Agedge_t *e)
Definition edge.c:43
Agedge_t * agfstin(Agraph_t *g, Agnode_t *n)
Definition edge.c:59
Agnode_t * agnxtnode(Agraph_t *g, Agnode_t *n)
Definition node.c:50
Agnode_t * agfstnode(Agraph_t *g)
Definition node.c:43
@ AGEDGE
Definition cgraph.h:207
static opts_t opts
Definition gvgen.c:415
textitem scanner parser str
Definition htmlparse.y:218
#define ITOS(i)
Definition itos.h:43
static void adjustlen(Agedge_t *e, Agsym_t *sym, int newlen)
Definition unflatten.c:48
static bool isleaf(Agnode_t *n)
Definition unflatten.c:42
static bool ischainnode(Agnode_t *n)
Definition unflatten.c:44
static Agsym_t * bindedgeattr(Agraph_t *g, char *str)
Definition unflatten.c:52
static int myindegree(Agnode_t *n)
Definition unflatten.c:28
static int myoutdegree(Agnode_t *n)
Definition unflatten.c:31
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:640
options for passing to graphviz_unflatten
Definition cgraph.h:1048