Subject: [bug#50632] [PATCH] graph: Add '--max-depth'.

From: zimoun <[email-masked]>
Date: Mon, 20 Sep 2021 17:00:27 +0200

Hi,

On Fri, 17 Sept 2021 at 10:38, Ludovic Courtès <[email-masked]> wrote:

> * guix/graph.scm (export-graph): Add #:max-depth and honor it, adding
> 'depths' argument to 'loop'.
> * guix/scripts/graph.scm (%options, show-help): Add '--max-depth'.
> (%default-options): Add 'max-depth'.
> (guix-graph): Pass #:max-depth to 'export-graph'.
> * tests/graph.scm ("package DAG, limited depth"): New test.
> * doc/guix.texi (Invoking guix graph): Document it.
> ---
>  doc/guix.texi          | 14 +++++++++++++
>  guix/graph.scm         | 45 ++++++++++++++++++++++++++----------------
>  guix/scripts/graph.scm | 11 ++++++++++-
>  tests/graph.scm        | 21 +++++++++++++++++++-
>  4 files changed, 72 insertions(+), 19 deletions(-)

LGTM!

> Trimming of nodes beyond the max depth happens at export time.  The
> implementation is a bit naive (with a list containing the depth of
> each node) but performance is mostly unchanged.

Well, I do not see how it could be better. :-)
And export time is also walk time, IIUC. :-)

> diff --git a/doc/guix.texi b/doc/guix.texi
> index 2fc9687910..6c0a581463 100644
> --- a/doc/guix.texi
> +++ b/doc/guix.texi
> @@ -12598,6 +12598,20 @@ $ guix graph --path -t references emacs libunistring
>  /gnu/store/@dots{}-libunistring-0.9.10
>  @end example
>
> +Sometimes you still want to visualize the graph but would like to trim
> +it so it can actually be displayed.  One way to do it is via the
> +@option{--max-depth} (or @option{-M}) option, which lets you specify the
> +maximum depth of the graph.  In the example below, we visualize only
> +@code{libreoffice} and the nodes whose distance to @code{libreoffice} is
> +at most 2:
> +
> +@example
> +guix graph -M 2 libreoffice | xdot -f fdp -
> +@end example

I am not sure 'xdot' is part of the GraphViz toolsuite.  Instead,

+@example
+guix graph -M 2 libreoffice | fdp -Tsvg > libreoffice.svg
+@end example

Cheers,
simon