ui icon indicating copy to clipboard operation
ui copied to clipboard

Client-side automatic layout with Dagre doesn't work with filtered views

Open breaker78 opened this issue 2 years ago • 7 comments

Description

Using build tag 3196, the page or canvas size for my java generated diagrams automatically adjusted as the diagram increased in size. From build 3199 onwards, all my diagrams have the same canvas size. Diagrams which don't fit to this size are cropped.

The code change for the 3199 build seem to be removing the SafeMode property, so not sure why this would have caused the change in behaviour.

Steps to reproduce

  1. Run onpremises:3199 container
  2. Import json file
  3. Diagrams are all cropped to the same page/canvas size
  4. Run onpremises:3196 container
  5. Import json file
  6. Diagram sizes automatically adjust

Screenshot

No response

Code sample

No response

Configuration

com.structurizr-core:1.29.0 com.structurizr-client:1.29.9 onpremises:3199

Severity

Minor

Priority

I have no budget and there's no rush, please fix this for free

More information

No response

breaker78 avatar Feb 05 '24 16:02 breaker78

This is how the same diagram looks in the two different builds:

StructurizrUnCropped StructurizrCropped

breaker78 avatar Feb 05 '24 16:02 breaker78

I can't reproduce this unfortunately, and build 3199 works okay for me. Does the issue still persist in the latest build (2024.03.03)? If so, please add an example workspace. Thanks!

simonbrowndotje avatar Mar 04 '24 07:03 simonbrowndotje

Hi Simon, thanks for your reply. I've just tested it with the 2024.03.03 build and I get the same issue. I've attached a very simple component diagram, which has been clipped top and bottom: workspace.json structurizr

breaker78 avatar Mar 04 '24 14:03 breaker78

Thanks for the JSON file. I know what the problem is, but I don't know how to fix it. If you're using the Java library to create your workspace, the workaround is to use an alternative version of the enableAutomaticLayout() method that forces the UI to run Graphviz rather than Dagre; for example this one -> https://github.com/structurizr/java/blob/master/structurizr-core/src/main/java/com/structurizr/view/ModelView.java#L158

simonbrowndotje avatar Mar 04 '24 16:03 simonbrowndotje

Hi Simon, thanks for your response. Changing the layout from Dagre to Graphviz does fix this issue, but also introduces another issue. Using Graphviz, the layout of the SystemLandscape diagrams seem to be defined before the filter is applied (so all the components are drawn very far apart). To try and explain this better, using Graphviz I can see that all the components are drawn in the same location regardless of the filter applied, but using Dagre it moves the components based on the filter, which looks a lot better.

breaker78 avatar Mar 05 '24 10:03 breaker78

Using Graphviz, the layout of the SystemLandscape diagrams seem to be defined before the filter is applied

This is actually how it's supposed to work, with all filtered views sharing the same layout. From https://docs.structurizr.com/ui/diagrams/filtered-view:

The main benefit of using filtered views is that element and relationship positions are shared between the filtered views.

If this isn't what you're looking for, you'll need to define a regular view and add elements based upon their tags instead (this is what the DSL expression include element.tag==<tag> does, but it's easy to replicate with Java code).

simonbrowndotje avatar Mar 05 '24 11:03 simonbrowndotje

I've done what you suggested by just adding the relevant elements rather than applying a filter, and the diagrams look good. Thanks for your help

breaker78 avatar Mar 06 '24 15:03 breaker78