Graphviz 12.0.1~dev.20240715.2254
Loading...
Searching...
No Matches
patchworkinit.c
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (c) 2011 AT&T Intellectual Property
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * https://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors: Details at https://graphviz.org
9 *************************************************************************/
10
11#include <assert.h>
12#include <cgraph/list.h>
13#include <cgraph/startswith.h>
14#include <patchwork/patchwork.h>
15#include <limits.h>
16#include <neatogen/adjust.h>
17#include <pack/pack.h>
18#include <neatogen/neatoprocs.h>
19#include <stdbool.h>
20
21/* the following code shamelessly copied from lib/fdpgen/layout.c
22and should be extracted and made into a common function */
23
24DEFINE_LIST(clist, graph_t*)
25
26/* mkClusters:
27 * Attach list of immediate child clusters.
28 * NB: By convention, the indexing starts at 1.
29 * If pclist is NULL, the graph is the root graph or a cluster
30 * If pclist is non-NULL, we are recursively scanning a non-cluster
31 * subgraph for cluster children.
32 */
33static void
34mkClusters (graph_t * g, clist_t* pclist, graph_t* parent)
35{
36 graph_t* subg;
37 clist_t list = {0};
38 clist_t* clist;
39
40 if (pclist == NULL) {
41 // [0] is empty. The clusters are in [1..cnt].
42 clist_append(&list, NULL);
43 clist = &list;
44 }
45 else
46 clist = pclist;
47
48 for (subg = agfstsubg(g); subg; subg = agnxtsubg(subg)) {
49 if (startswith(agnameof(subg), "cluster")) {
50 agbindrec(subg, "Agraphinfo_t", sizeof(Agraphinfo_t), true);
51#ifdef FDP_GEN
52 GD_alg(subg) = gv_alloc(sizeof(gdata)); /* freed in cleanup_subgs */
53 GD_ndim(subg) = GD_ndim(parent);
54 LEVEL(subg) = LEVEL(parent) + 1;
55 GPARENT(subg) = parent;
56#endif
57 clist_append(clist, subg);
58 mkClusters(subg, NULL, subg);
59 }
60 else {
61 mkClusters(subg, clist, parent);
62 }
63 }
64 if (pclist == NULL) {
65 assert(clist_size(&list) - 1 <= INT_MAX);
66 GD_n_cluster(g) = (int)(clist_size(&list) - 1);
67 if (clist_size(&list) > 1) {
68 clist_shrink_to_fit(&list);
69 GD_clust(g) = clist_detach(&list);
70 } else {
71 clist_free(&list);
72 }
73 }
74}
75
77{
78 agset(n,"shape","box");
79 /* common_init_node_opt(n,FALSE); */
80}
81
83{
84 agbindrec(e, "Agedgeinfo_t", sizeof(Agnodeinfo_t), true); // edge custom data
85 /* common_init_edge(e); */
86}
87
89{
90 node_t *n;
91 edge_t *e;
92 int i = 0;
93 rdata* alg = gv_calloc(agnnodes(g), sizeof(rdata));
94
95 GD_neato_nlist(g) = gv_calloc(agnnodes(g) + 1, sizeof(node_t*));
96 for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
97 agbindrec(n, "Agnodeinfo_t", sizeof(Agnodeinfo_t), true); // node custom data
98 ND_alg(n) = alg + i;
99 GD_neato_nlist(g)[i++] = n;
101
102 for (e = agfstout(g, n); e; e = agnxtout(g, e)) {
104 }
105 }
106}
107
109{
110 N_shape = agattr(g, AGNODE, "shape","box");
112 /* GD_ndim(g) = late_int(g,agfindattr(g,"dim"),2,2); */
113 Ndim = GD_ndim(g) = 2; /* The algorithm only makes sense in 2D */
114 mkClusters(g, NULL, g);
116}
117
118/* patchwork_layout:
119 * The current version makes no use of edges, neither for a notion of connectivity
120 * nor during drawing.
121 */
123{
125
126 if ((agnnodes(g) == 0) && (GD_n_cluster(g) == 0)) return;
127
128 patchworkLayout (g);
129
131}
132
134{
136 free(GD_clust(g));
137}
138
140{
141 node_t *n;
142 edge_t *e;
143
144 n = agfstnode(g);
145 if (!n) return;
146 free (ND_alg(n));
147 for (; n; n = agnxtnode(g, n)) {
148 for (e = agfstout(g, n); e; e = agnxtout(g, e)) {
150 }
152 }
154}
155
static void * gv_calloc(size_t nmemb, size_t size)
Definition alloc.h:26
static void * gv_alloc(size_t size)
Definition alloc.h:47
#define parent(i)
Definition closest.c:78
void setEdgeType(graph_t *g, int defaultValue)
Definition utils.c:1443
#define EDGETYPE_LINE
Definition const.h:249
Agsym_t * N_shape
Definition globals.h:79
unsigned short Ndim
Definition globals.h:64
void free(void *)
node NULL
Definition grammar.y:149
int agnnodes(Agraph_t *g)
Definition graph.c:158
Agsym_t * agattr(Agraph_t *g, int kind, char *name, const char *value)
creates or looks up attributes of a graph
Definition attr.c:341
int agset(void *obj, char *name, const char *value)
Definition attr.c:469
Agedge_t * agfstout(Agraph_t *g, Agnode_t *n)
Definition edge.c:23
Agedge_t * agnxtout(Agraph_t *g, Agedge_t *e)
Definition edge.c:38
#define GD_clust(g)
Definition types.h:360
#define GD_alg(g)
Definition types.h:358
#define GD_n_cluster(g)
Definition types.h:389
#define GD_ndim(g)
Definition types.h:390
#define GD_neato_nlist(g)
Definition types.h:392
Agnode_t * agnxtnode(Agraph_t *g, Agnode_t *n)
Definition node.c:47
Agnode_t * agfstnode(Agraph_t *g)
Definition node.c:40
#define ND_alg(n)
Definition types.h:484
char * agnameof(void *)
returns a string descriptor for the object.
Definition id.c:158
@ AGNODE
Definition cgraph.h:207
void * agbindrec(void *obj, const char *name, unsigned int recsize, int move_to_front)
attaches a new record of the given size to the object
Definition rec.c:88
Agraph_t * agfstsubg(Agraph_t *g)
Definition subg.c:77
Agraph_t * agnxtsubg(Agraph_t *subg)
Definition subg.c:82
#define DEFINE_LIST(name, type)
Definition list.h:26
support for connected components
void patchworkLayout(Agraph_t *g)
Definition patchwork.c:273
void patchwork_cleanup(graph_t *g)
static void patchwork_init_graph(graph_t *g)
static void patchwork_init_node(node_t *n)
static void patchwork_init_node_edge(graph_t *g)
static void patchwork_init_edge(edge_t *e)
static void patchwork_cleanup_graph(graph_t *g)
static void mkClusters(graph_t *g, clist_t *pclist, graph_t *parent)
void patchwork_layout(Agraph_t *g)
void dotneato_postprocess(Agraph_t *g)
Definition postproc.c:693
void gv_cleanup_edge(Agedge_t *e)
Definition utils.c:1533
void gv_cleanup_node(Agnode_t *n)
Definition utils.c:1545
static bool startswith(const char *s, const char *prefix)
does the string s begin with the string prefix?
Definition startswith.h:11
graph or subgraph
Definition cgraph.h:425