graphviz, show Inherited attributes of a class

38 views Asked by At

I would like to solve the following problem in Graphviz.

I have two classes A and B. Both have some attributes. When I combine class A and B to class C, I want a list of all (in this case all attributes of class A and B). If I then add class D, I also want attributes of the source classes of D.

CLASS A

  • ATTR1
  • ATTR2

CLASS B

  • ATTR 3
  • ATTR 4

CLASS C

  • ATTR1
  • ATTR2
  • ATTR3
  • ATTR4

How can I achieve this with Graphviz?

The result should look like this. at the moment this is done manually.

digraph {
    graph [pad="0.5", nodesep="0.5", ranksep="2"];
    node [shape=plain]
    rankdir=LR;


Foo [label=<
<table border="0" cellborder="1" cellspacing="0">
  <tr><td><i>Input Foo</i></td></tr>
  <tr><td port="1">one</td></tr>
  <tr><td port="2">two</td></tr> 
</table>>];


Bar [label=<
<table border="0" cellborder="1" cellspacing="0">
  <tr><td><i>Input Bar</i></td></tr>
  <tr><td>three</td></tr>
  <tr><td>four</td></tr>
  </table>>];


Baz [label=<
<table border="0" cellborder="1" cellspacing="0">
  <tr><td><i>Output Baz</i></td></tr>
  <tr><td >one</td></tr>
  <tr><td >two</td></tr>
  <tr><td >three</td></tr>
  <tr><td >four</td></tr>
</table>>];

Foo -> Baz;
Bar -> Baz;
}
1

There are 1 answers

1
sroush On

Graphviz does not have a layout program/engine that will do this automatically. One problem is that Graphviz nodes must have unique names (e.g. there can only be a single two node). But multiple nodes can have the same label, so this is easy to work around.
Depending on you complete requirements, it would probably be pretty easy to create the desired graphs with a preprocessor written in a scripting or general-purpose programming language.
Here is an example of an alternative way to represent your graph. Not better or worse, just different. Also manually created.

digraph {
  rankdir=LR

subgraph clusterFoo {
  label="input Foo"
  aOne [label=one]
  aTwo [label=two]
}
subgraph clusterBar {
  label="input Foo"
  bThree [label=three]
  bFour  [label=four]
}
subgraph clusterBaz {
  label="Output Baz"
  cOne   [label=one]
  cTwo   [label=two]
  cThree [label=three]
  cFour  [label=four]  
}
aOne -> cOne
aTwo -> cTwo
bThree -> cThree
bFour -> cFour
}

Giving:
enter image description here