structurizr / dsl

Structurizr DSL
https://docs.structurizr.com/dsl
Apache License 2.0
1.41k stars 265 forks source link

Excluding elements without relationships #123

Closed juanrferia closed 2 years ago

juanrferia commented 2 years ago

When defining a view I usually include and exclude elements and relationships based on tags. I observed some cases in which I end with some isolated elements in the view. When that happens, I identified them and exclude them explicitally.

As an example:

workspace "Getting Started" "This is a model of my software system." {

    model {
        softwareSystem1 = softwareSystem "Software System 1" 

        softwareSystem2 = softwareSystem "Software System 2" 
        softwareSystem3 = softwareSystem "Software System 3"

        softwareSystem1 -> softwareSystem2 "" "" "context_1"
        softwareSystem1 -> softwareSystem3 "" "" "context_2"
    }

    views {
        systemContext softwareSystem1 "SystemContext" "An example of a System Context diagram." {
            include *
            exclude "relationship.tag==context_2"
            autoLayout
        }

    }

}

In that view, software system 3 will be presented in the diagram as an isolated element. In that case, I usually add it manually exclude softwareSystem3 to exclude that element from the view.

It would be great to have a way to exclude all elements in the view without any relationship. Maybe using an expression which allows it.

simonbrowndotje commented 2 years ago

You should be able to use a script/plugin to call the removeElementsWithNoRelationships() method on the view instance; see https://github.com/structurizr/java/blob/master/structurizr-core/src/com/structurizr/view/View.java#L394 for more.

juanrferia commented 2 years ago

Working like a charm! Thank you Simon.