Class Diagram Layout

+2 votes
asked Jun 19, 2013 in To be sorted by anonymous

We have a class diagram that renders a set of classes. This diagram has many classes but few relationships. As a consequence, PlantUML layouts the diagram with essentially every class next to each other:

    [Class1]   [Class2]   [Class3]   [Class4]   [Class5]   

This leads to a very wide diagram. If we embed it in a document, as a consequence of the size, the boxes and text in the boxes become very small.

Is there a way to tell PlantUML to use a different arrangement, for example, by limiting the number of elements in a row or by specifying a "grid" layout, so it results in something like this:

    [Class1]   [Class2]   [Class3]

    [Class4]   [Class5]   [Class6]

    [Class7]   [Class8]   [Class9]

THank you,

Markus

voelter@acm.org

 

 

1 Answer

0 votes
answered Jun 21, 2013 by plantuml (294,960 points)

Hello,

Today, there is no way of forcing PlantUML to do so.
However, the default behaviour is to put classes that have no relation in grid, rather than in line.

Example:
 
@startuml
class class1
class class2
class class3
class class4
class class5
class class6
class class7
class class8
class class9
@enduml


http://www.plantuml.com/plantuml/img/Iyv9B2vMI0QHXbp928uHCiSOcME2p355vfWXSyoHEHR874ik0000

This is not implemented in all cases (especially when there are some packages).
Could you provide a non-working example ?

Thanks,
 

commented Oct 1, 2013 by scooper (440 points)
I can say that Component diagrams do not layout this way in certain cases.
I'm using packages to represent data centers, nodes to represent servers and components to represent services running in them.
So if I have:
package datacenter1 {
 node server1 {
   [service1]
   [service2]
 }
}
And I have a lot of servers listed, then the servers all lay out in a line, instead of in a grid.
A grid would be much more helpful.
commented Apr 15, 2014 by anonymous
non-work example:
@startuml
Class Event{
    name:String
}
Enum ResultType{
    + BOOLEAN
    + STRING
    + INTEGER
}
Enum RuleStyle{
    + AVIATOR
    + NATURAL
    + JPOOL
}
class Rule{
    ruleId:String
    name:String
    expression:String
    resultType:ResultType
    ruleStyle:RuleStyle
    available:Boolean
   
}

class RuleBinding{
    + appid:String
    + event:Event
    + ruleId:String
}

RuleBinding - Rule: ruleid >

Rule - Event:event >
Rule - ResultType:resultType >
Rule - RuleStyle:ruleStyle >
interface QueryRules{
    List<Rule> getRules(String ApplicationID, String Event)
}
interface EnforceRules{
    String eval(Rule rule, Context ctx)
    Boolean eval(Rule rule, Context ctx)
    Boolean eval(List<Rule> rules, Context ctx)
}
note right
    For 3rd method, all rules in list shall return boolean
    all results shall combined with "AND" operation.
end note
class AvaitorRuleEngine{
}
AvaitorRuleEngine-|>EnforceRules
class RuleEngineFactory{
    ~ getRuleEngineInstance()   
}
RuleEngineFactory ..> AvaitorRuleEngine:create
class RuleUtil -|>QueryRules
@enduml
commented Oct 24, 2014 by anonymous
I see the same issue as the OP.

I am using class diagrams to model a database.  There are lots of entities and lots of relationships.

The layout always tends to be in a horizontal line, resulting in very wide and narrow diagrams.

I've not found any way of avoiding this.
commented Dec 10, 2015 by jaap.dehaan (100 points)
I also face the issue. Here is an example. I tried to put elements in a package to see if it improves but this still leads to a poor one line layout...

Best regards.

@startuml
interface IProjectEngine
interface IEngine
interface IProjectEngineState
class BaseEngine
class ProjectEngine
class ProjectEngineState

IProjectEngine -|> IEngine
BaseEngine -|> IEngine
ProjectEngine -|> BaseEngine
ProjectEngineState -|> IProjectEngineState
ProjectEngine -> ProjectEngineState : <<maintains>>

package Configuration {
  interface IProjectItem
  class ProjectItem
  class ProjectConfiguration
  class JobConfiguration
  class ScriptProjectItem
  class GroupProjectItem
  class IterationProjectItem
  class VariableScopeProjectItem

  ProjectItem -|> IProjectItem
  ProjectConfiguration -|> ProjectItem
  JobConfiguration -|> ProjectItem
  ScriptProjectItem -|> ProjectItem
  GroupProjectItem -|> ProjectItem
  IterationProjectItem -|> ProjectItem
  VariableScopeProjectItem -|> ProjectItem

  IProjectItem -> IProjectItem  : parent >
  IProjectItem *-- IProjectItem : children >
}
@enduml
commented Dec 10, 2015 by plantuml (294,960 points)
You should change -|> to --|> and -> to -->.

@startuml
interface IProjectEngine
interface IEngine
interface IProjectEngineState
class BaseEngine
class ProjectEngine
class ProjectEngineState

IProjectEngine --|> IEngine
BaseEngine --|> IEngine
ProjectEngine --|> BaseEngine
ProjectEngineState --|> IProjectEngineState
ProjectEngine --> ProjectEngineState : <<maintains>>

package Configuration {
  interface IProjectItem
  class ProjectItem
  class ProjectConfiguration
  class JobConfiguration
  class ScriptProjectItem
  class GroupProjectItem
  class IterationProjectItem
  class VariableScopeProjectItem

  ProjectItem --|> IProjectItem
  ProjectConfiguration --|> ProjectItem
  JobConfiguration --|> ProjectItem
  ScriptProjectItem --|> ProjectItem
  GroupProjectItem --|> ProjectItem
  IterationProjectItem --|> ProjectItem
  VariableScopeProjectItem --|> ProjectItem

  IProjectItem --> IProjectItem  : parent >
  IProjectItem *-- IProjectItem : children >
}
@enduml

Result : http://plantuml.com/plantuml/png/TPAnZi8m44HxVyNMIFa1X5nmGWWgf4ZqYsy9Xc1RZgdW_lsC4eLil1GfFFCywrd5kaJnZ8PWTuZ-IYPjN6CTAVinIeMXTS94ohJOTR36ZWQy5tYeeFMt5O-4gdhfSV0dbEl2bSdySifmMnW_JzB26s49gzKTynRorscjL41pmuRWnxkpRHuHa_KEdWgWNDKkqJqRR06Inh96S-zFib6RQ4EIyhRHFu9av4CV8fb7Z1PFBTN61ve2cPWS-IQ71Ab13t9kNaPYYbuIDAyeCL9RYVjMl6JVeHpWcu3yemICv1BeERkeAYuimLni-vlf3F_z0m00
commented Dec 11, 2015 by jaap.dehaan (100 points)
reshown Dec 11, 2015 by plantuml
Oh I feel sorry. Thanks for the hint it works actually perfectly of course! :-)
...