]> granicus.if.org Git - graphviz/commitdiff
Allow empty clusters;
authorerg <devnull@localhost>
Wed, 20 Apr 2011 22:10:10 +0000 (22:10 +0000)
committererg <devnull@localhost>
Wed, 20 Apr 2011 22:10:10 +0000 (22:10 +0000)
change main attribute from size to area to avoid conflict with size for graphs

lib/patchwork/patchwork.c
lib/patchwork/patchworkinit.c

index bc40f96437d0c497bcf2dae1d06d2e7007a48a59..1afac820990c9a3815695fff1cd9b90f612babef 100644 (file)
@@ -30,18 +30,24 @@ struct treenode_t {
     int n_children;
 };
 
-#define DFTL_SZ 1.0
+#define DFLT_SZ 1.0
 #define SCALE 1000.0      /* scale up so that 1 is a reasonable default size */
 
+static double getArea (void* obj, attrsym_t* ap)
+{
+    double area = late_double (obj, ap, DFLT_SZ, 0);
+    if (area == 0) area = DFLT_SZ;
+    area *= SCALE;
+    return area;
+}
+
 /* mkTreeNode:
  */
 static treenode_t* mkTreeNode (Agnode_t* n, attrsym_t* ap)
 {
     treenode_t *p = NEW(treenode_t);
 
-    p->area = late_double (n, ap, DFTL_SZ, 0);
-    if (p->area == 0) p->area = DFTL_SZ;
-    p->area *= SCALE;
+    p->area = getArea (n, ap);
     p->kind = AGNODE;
     p->u.n = n;
 
@@ -54,7 +60,7 @@ static treenode_t* mkTreeNode (Agnode_t* n, attrsym_t* ap)
  * Recursively build tree from graph
  * Pre-condition: agnnodes(g) != 0
  */
-static treenode_t *mkTree (Agraph_t * g,  attrsym_t* ap)
+static treenode_t *mkTree (Agraph_t * g, attrsym_t* gp, attrsym_t* ap)
 {
     treenode_t *p = NEW(treenode_t);
     Agraph_t *subg;
@@ -70,9 +76,7 @@ static treenode_t *mkTree (Agraph_t * g,  attrsym_t* ap)
 
     for (i = 1; i <= GD_n_cluster(g); i++) {
        subg = GD_clust(g)[i];
-       if (agnnodes(subg) == 0)
-           continue;
-       cp = mkTree (subg, ap);
+       cp = mkTree (subg, gp, ap);
        n_children++;
        area += cp->area;
        INSERT(cp);
@@ -89,7 +93,11 @@ static treenode_t *mkTree (Agraph_t * g,  attrsym_t* ap)
     }
 
     p->n_children = n_children;
-    p->area = area;
+    if (n_children)
+       p->area = area;
+    else {
+       p->area = getArea (g, gp);
+    }
     p->leftchild = first;
 
     return p;
@@ -230,10 +238,11 @@ static void freeTree (treenode_t* tp)
 void patchworkLayout(Agraph_t * g)
 {
     treenode_t* root;
-    attrsym_t * ap = agfindnodeattr(g, "size");
+    attrsym_t * ap = agfindnodeattr(g, "area");
+    attrsym_t * gp = agfindgraphattr(g, "area");
     double total;
 
-    root = mkTree (g,ap);
+    root = mkTree (g,gp,ap);
     total = root->area;
     root->r = rectangle_new(0, 0, sqrt(total + 0.1), sqrt(total + 0.1));
     layoutTree(root);
index 8dc29871b6a8fa1f93574fe3376520b7a02d7c75..316f52095e8d77486084ed266d8513211503de66 100644 (file)
@@ -156,10 +156,10 @@ static void patchwork_init_graph(graph_t * g)
  */
 void patchwork_layout(Agraph_t *g)
 {
-    if (agnnodes(g) == 0) return;
-
     patchwork_init_graph(g);
 
+    if ((agnnodes(g) == 0) && (GD_n_cluster(g) == 0)) return;
+
     patchworkLayout (g);
 
     dotneato_postprocess(g);