From d5e2fd1dd6947264a037449994984414a1a54806 Mon Sep 17 00:00:00 2001 From: erg Date: Thu, 27 May 2010 18:56:39 +0000 Subject: [PATCH] Allow the user to specify alignment when packing graphs as arrays --- cmd/tools/gvpack.1 | 21 ++++++++++++++++++++- doc/info/attrs.html | 4 ++++ doc/infosrc/types | 4 ++++ lib/pack/pack.c | 30 ++++++++++++++++++++++++++++-- lib/pack/pack.h | 8 ++++++-- 5 files changed, 62 insertions(+), 5 deletions(-) diff --git a/cmd/tools/gvpack.1 b/cmd/tools/gvpack.1 index 9ab64c60f..7e715b411 100644 --- a/cmd/tools/gvpack.1 +++ b/cmd/tools/gvpack.1 @@ -1,4 +1,4 @@ -.TH GVPACK 1 "8 April 2003" +.TH GVPACK 1 "27 May 2010" .SH NAME gvpack \- merge and pack disjoint graphs .SH SYNOPSIS @@ -10,6 +10,9 @@ gvpack \- merge and pack disjoint graphs .BI \-m margin ] [ +.B \-array\fI[_flags][n]\fP +] +[ .BI \-o outfile ] [ @@ -40,6 +43,22 @@ The following options are supported: Combines the graphs at the graph level. This uses more space, but prevents parts of one graph from occurring between parts of another. .TP +.BI \-array\fI[_flags][n]\fP +Combines the graphs at the graph level, placing them in an array. +By default, the layout is done in row-major order. The number of columns +used is roughly the square root of the number of graphs. If the optional +integer \fIn\fP is supplied, this indicates the number of columns to use. +.TP + +If optional flags are supplied, these consist of an underscore followed +by any of the letters "c", "t", "b", "l", "r" or "u". +If "c" is supplied, the graphs are packed in column-major order, in which +case a final integer specifies the number of rows. +The flags "t", "b", "l", "r" indicate that components are aligned +along the top, bottom, left or right, respectively. +The "u" flag indicates that the insertion order is based on the +\fIsortv\fP attribute attached to each graph. +.TP .BI \-G "name\fB=\fPvalue" Specifies attributes to be added to the resulting union graph. For example, this can be used to specify a graph label. diff --git a/doc/info/attrs.html b/doc/info/attrs.html index 63e2d2abb..135c21748 100644 --- a/doc/info/attrs.html +++ b/doc/info/attrs.html @@ -1957,6 +1957,10 @@ the given types. starting in the upper left and going down the first column, then down the second column, etc., until all components are used.

+ If a graph is smaller than the array cell it occupies, it is centered by default. + The optional flags may contain "t", "b", "l", or "r", indicating that the graphs + should be aligned along the top, bottom, left or right, respectively. +

If the optional flags contains "u", this causes the insertion order of elements in the array to be determined by user-supplied values. Each component can specify its sort value by a diff --git a/doc/infosrc/types b/doc/infosrc/types index baf10971a..c21eb9b65 100644 --- a/doc/infosrc/types +++ b/doc/infosrc/types @@ -193,6 +193,10 @@ Thus, the mode "array_c4" indicates array packing, with 4 rows, starting in the upper left and going down the first column, then down the second column, etc., until all components are used.

+If a graph is smaller than the array cell it occupies, it is centered by default. +The optional flags may contain "t", "b", "l", or "r", indicating that the graphs +should be aligned along the top, bottom, left or right, respectively. +

If the optional flags contains "u", this causes the insertion order of elements in the array to be determined by user-supplied values. Each component can specify its sort value by a diff --git a/lib/pack/pack.c b/lib/pack/pack.c index 25c07d650..28934b8dc 100644 --- a/lib/pack/pack.c +++ b/lib/pack/pack.c @@ -705,8 +705,18 @@ arrayRects (int ng, boxf* gs, pack_info* pinfo) ip = sinfo[i]; idx = ip->index; bb = gs[idx]; - places[idx].x = (widths[c] + widths[c+1] - bb.UR.x - bb.LL.x)/2.0; - places[idx].y = (heights[r] + heights[r+1] - bb.UR.y - bb.LL.y)/2.0; + if (pinfo->flags & PK_LEFT_ALIGN) + places[idx].x = widths[c]; + else if (pinfo->flags & PK_RIGHT_ALIGN) + places[idx].x = widths[c+1] - (bb.UR.x - bb.LL.x); + else + places[idx].x = (widths[c] + widths[c+1] - bb.UR.x - bb.LL.x)/2.0; + if (pinfo->flags & PK_TOP_ALIGN) + places[idx].y = heights[r] - (bb.UR.y - bb.LL.y); + else if (pinfo->flags & PK_BOT_ALIGN) + places[idx].y = heights[r+1]; + else + places[idx].y = (heights[r] + heights[r+1] - bb.UR.y - bb.LL.y)/2.0; INC(rowMajor,c,r); } @@ -1208,6 +1218,22 @@ chkFlags (char* p, pack_info* pinfo) pinfo->flags |= PK_USER_VALS; p++; break; + case 't' : + pinfo->flags |= PK_TOP_ALIGN; + p++; + break; + case 'b' : + pinfo->flags |= PK_BOT_ALIGN; + p++; + break; + case 'l' : + pinfo->flags |= PK_LEFT_ALIGN; + p++; + break; + case 'r' : + pinfo->flags |= PK_RIGHT_ALIGN; + p++; + break; default : more = 0; break; diff --git a/lib/pack/pack.h b/lib/pack/pack.h index 229e4fa44..8d4c1fa2d 100644 --- a/lib/pack/pack.h +++ b/lib/pack/pack.h @@ -39,8 +39,12 @@ extern "C" { */ typedef enum { l_undef, l_clust, l_node, l_graph, l_array, l_aspect } pack_mode; -#define PK_COL_MAJOR 1 -#define PK_USER_VALS 2 +#define PK_COL_MAJOR (1 << 0) +#define PK_USER_VALS (1 << 1) +#define PK_LEFT_ALIGN (1 << 2) +#define PK_RIGHT_ALIGN (1 << 3) +#define PK_TOP_ALIGN (1 << 4) +#define PK_BOT_ALIGN (1 << 5) typedef unsigned char packval_t; -- 2.40.0