thebjorn / pydeps

Python Module Dependency graphs
https://pydeps.readthedocs.io/en/latest/
BSD 2-Clause "Simplified" License
1.79k stars 114 forks source link

Constrain output geometry / size #220

Open ruzko opened 6 months ago

ruzko commented 6 months ago

Hi, and thanks for making this great tool!

Background

I'm writing a thesis about developing a software project, and would like to display a graph of internal and external dependencies in the report.

What's the current status?

I struggle with finding a good method of making the graph fit a single page while still displaying relevant information in a legible manner. I couldn't find an option in the docs that would split the graph visually into multiple parts either, to allow manual chopping. This is the graph of my project using pydeps predalert --max-bacon=2 --cluster --exclude-exact predalert.desktop --exclude-exact predalert.web -T svg:

dependency_graph

It's about twice too wide to fit naturally in the LaTeX document, but has a lot of vertical space left unused. Regular text underneath, for size comparison: predalert_pydeps_in_pdf

What I'd like

An option in pydeps to constrain output to some geometry. Some method to make sure that the graph fits on the page of a PDF or book, or a slide of a presentation; without requiring shrinking of output (giving tiny, non-legible text) or reducing the number of modules taken into account (giving a less informative graph).

Pydeps could then potentially use more vertical space if only constrained horizontally and vice versa if constrained only vertically, and would reduce the "air" between modules if necessary when constrained in both directions.

thebjorn commented 6 months ago

Hei Jacob og takk for interessen i pydeps :-)

(switching to English for archival purposes..) Pydeps uses the graphviz package's dot command to display the graph (with only minor modifications to highlight the paths when hovering over them). The --show-dot and --dot-output <filename> flags give you access to the graph in this intermediate step.

Re-ordering the input to dot will give different graphs, and there are several "knobs" you can adjust when calling dot manually, but dot is already doing a heroic effort to draw the graph so maybe do this as a last resort..?

The --cluster --collapse-target-cluster combination of flags will give you the smallest possible graph (in combination with a sensible --max-bacon value). --cluster --keep-target-cluster will draw a box around your modules. --only predalert.web will limit the graph to just that branch of your import graph, and -x predalert.web.* will prune the graph.

Displaying the full graph in reduced size with exploded views of the area you are discussing is often useful to orient the reader, and providing a link to the full graph is also often useful (do people still read paper versions of LaTeX documents?)

Hopefully this gives you some ideas..?

I'm more than happy to merge if anyone wants to create a PR for this (you'll probably need to make changes in pydeps/render_context.py).

ruzko commented 5 months ago

Takk så mye for svaret, Bjorn! In the end I used two different dependency graphs, one with --max-bacon=2 --cluster --collapse-target-cluster --rankdir LR to show general external deps, and one with --only predalert --rmprefix predalert. --exclude-exact predalert.desktop predalert.web for internal deps :)

Will keep this issue open, since someone else might want this feature