1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-11-25 22:37:33 +00:00

Fixed nested togethers not working

This commit is contained in:
Kálmán Vince 2023-08-02 19:43:17 +02:00
parent a9f4ea985d
commit 719927895b
3 changed files with 28 additions and 14 deletions

View File

@ -485,7 +485,7 @@ public class Cluster implements Moveable {
private int togetherCounter = 0; private int togetherCounter = 0;
private void printTogether(Together together, StringBuilder sb, List<SvekNode> nodesOrderedWithoutTop, private void printTogether(Together together, Collection<Together> otherTogethers, StringBuilder sb, List<SvekNode> nodesOrderedWithoutTop,
StringBounder stringBounder, Collection<SvekLine> lines, DotMode dotMode, GraphvizVersion graphvizVersion, StringBounder stringBounder, Collection<SvekLine> lines, DotMode dotMode, GraphvizVersion graphvizVersion,
UmlDiagramType type) { UmlDiagramType type) {
sb.append("subgraph " + getClusterId() + "t" + togetherCounter + " {\n"); sb.append("subgraph " + getClusterId() + "t" + togetherCounter + " {\n");
@ -495,7 +495,11 @@ public class Cluster implements Moveable {
for (Cluster child : children) for (Cluster child : children)
if (child.group.getTogether() == together) if (child.group.getTogether() == together)
child.printInternal(sb, lines, stringBounder, dotMode, graphvizVersion, type); child.printInternal(sb, lines, stringBounder, dotMode, graphvizVersion, type, together);
for (Together otherTogether : otherTogethers)
if (otherTogether.getParent() == together)
printTogether(otherTogether, otherTogethers, sb, nodesOrderedWithoutTop, stringBounder, lines, dotMode, graphvizVersion, type);
sb.append("}\n"); sb.append("}\n");
togetherCounter++; togetherCounter++;
@ -503,7 +507,7 @@ public class Cluster implements Moveable {
} }
public SvekNode printCluster2(StringBuilder sb, Collection<SvekLine> lines, StringBounder stringBounder, public SvekNode printCluster2(StringBuilder sb, Collection<SvekLine> lines, StringBounder stringBounder,
DotMode dotMode, GraphvizVersion graphvizVersion, UmlDiagramType type) { DotMode dotMode, GraphvizVersion graphvizVersion, UmlDiagramType type, Together parentTogether) {
SvekNode added = null; SvekNode added = null;
final Collection<Together> togethers = new LinkedHashSet<>(); final Collection<Together> togethers = new LinkedHashSet<>();
@ -513,16 +517,17 @@ public class Cluster implements Moveable {
if (together == null) if (together == null)
node.appendShape(sb, stringBounder); node.appendShape(sb, stringBounder);
else else
togethers.add(together); addTogetherWithParents(togethers, together);
added = node; added = node;
} }
for (Cluster child : children) for (Cluster child : children)
if (child.group.getTogether() != null) if (child.group.getTogether() != null)
togethers.add(child.group.getTogether()); addTogetherWithParents(togethers, child.group.getTogether());
for (Together together : togethers) for (Together together : togethers)
printTogether(together, sb, nodesOrderedWithoutTop, stringBounder, lines, dotMode, graphvizVersion, type); if (together.getParent() == parentTogether)
printTogether(together, togethers, sb, nodesOrderedWithoutTop, stringBounder, lines, dotMode, graphvizVersion, type);
if (skinParam.useRankSame() && dotMode != DotMode.NO_LEFT_RIGHT_AND_XLABEL if (skinParam.useRankSame() && dotMode != DotMode.NO_LEFT_RIGHT_AND_XLABEL
&& graphvizVersion.ignoreHorizontalLinks() == false) && graphvizVersion.ignoreHorizontalLinks() == false)
@ -530,11 +535,19 @@ public class Cluster implements Moveable {
for (Cluster child : children) for (Cluster child : children)
if (child.group.getTogether() == null) if (child.group.getTogether() == null)
child.printInternal(sb, lines, stringBounder, dotMode, graphvizVersion, type); child.printInternal(sb, lines, stringBounder, dotMode, graphvizVersion, type, parentTogether);
return added; return added;
} }
private static void addTogetherWithParents(Collection<Together> collection, Together together) {
Together t = together;
while (t != null) {
collection.add(t);
t = t.getParent();
}
}
public void printCluster3_forKermor(StringBuilder sb, Collection<SvekLine> lines, StringBounder stringBounder, public void printCluster3_forKermor(StringBuilder sb, Collection<SvekLine> lines, StringBounder stringBounder,
DotMode dotMode, GraphvizVersion graphvizVersion, UmlDiagramType type) { DotMode dotMode, GraphvizVersion graphvizVersion, UmlDiagramType type) {
final List<SvekNode> tmp = getNodes(EntityPosition.getNormals()); final List<SvekNode> tmp = getNodes(EntityPosition.getNormals());
@ -548,12 +561,12 @@ public class Cluster implements Moveable {
} }
for (Cluster child : getChildren()) for (Cluster child : getChildren())
child.printInternal(sb, lines, stringBounder, dotMode, graphvizVersion, type); child.printInternal(sb, lines, stringBounder, dotMode, graphvizVersion, type, null);
} }
private void printInternal(StringBuilder sb, Collection<SvekLine> lines, StringBounder stringBounder, private void printInternal(StringBuilder sb, Collection<SvekLine> lines, StringBounder stringBounder,
DotMode dotMode, GraphvizVersion graphvizVersion, UmlDiagramType type) { DotMode dotMode, GraphvizVersion graphvizVersion, UmlDiagramType type, Together parentTogether) {
new ClusterDotString(this, skinParam).printInternal(sb, lines, stringBounder, dotMode, graphvizVersion, type); new ClusterDotString(this, skinParam).printInternal(sb, lines, stringBounder, dotMode, graphvizVersion, type, parentTogether);
} }
private void appendRankSame(StringBuilder sb, Collection<SvekLine> lines) { private void appendRankSame(StringBuilder sb, Collection<SvekLine> lines) {

View File

@ -46,6 +46,7 @@ import java.util.Set;
import net.sourceforge.plantuml.StringUtils; import net.sourceforge.plantuml.StringUtils;
import net.sourceforge.plantuml.abel.EntityPosition; import net.sourceforge.plantuml.abel.EntityPosition;
import net.sourceforge.plantuml.abel.Together;
import net.sourceforge.plantuml.decoration.symbol.USymbols; import net.sourceforge.plantuml.decoration.symbol.USymbols;
import net.sourceforge.plantuml.dot.GraphvizVersion; import net.sourceforge.plantuml.dot.GraphvizVersion;
import net.sourceforge.plantuml.klimt.font.StringBounder; import net.sourceforge.plantuml.klimt.font.StringBounder;
@ -71,7 +72,7 @@ public class ClusterDotString {
} }
void printInternal(StringBuilder sb, Collection<SvekLine> lines, StringBounder stringBounder, DotMode dotMode, void printInternal(StringBuilder sb, Collection<SvekLine> lines, StringBounder stringBounder, DotMode dotMode,
GraphvizVersion graphvizVersion, UmlDiagramType type) { GraphvizVersion graphvizVersion, UmlDiagramType type, Together parentTogether) {
if (cluster.diagram.getPragma().useKermor()) { if (cluster.diagram.getPragma().useKermor()) {
new ClusterDotStringKermor(cluster, skinParam).printInternal(sb, lines, stringBounder, dotMode, new ClusterDotStringKermor(cluster, skinParam).printInternal(sb, lines, stringBounder, dotMode,
graphvizVersion, type); graphvizVersion, type);
@ -81,7 +82,7 @@ public class ClusterDotString {
if (packed) { if (packed) {
cluster.printCluster1(sb, lines, stringBounder); cluster.printCluster1(sb, lines, stringBounder);
final SvekNode added = cluster.printCluster2(sb, lines, stringBounder, dotMode, graphvizVersion, type); final SvekNode added = cluster.printCluster2(sb, lines, stringBounder, dotMode, graphvizVersion, type, parentTogether);
return; return;
} }
@ -170,7 +171,7 @@ public class ClusterDotString {
// ----------- // -----------
cluster.printCluster1(sb, lines, stringBounder); cluster.printCluster1(sb, lines, stringBounder);
final SvekNode added = cluster.printCluster2(sb, lines, stringBounder, dotMode, graphvizVersion, type); final SvekNode added = cluster.printCluster2(sb, lines, stringBounder, dotMode, graphvizVersion, type, parentTogether);
if (entityPositionsExceptNormal.size() > 0) if (entityPositionsExceptNormal.size() > 0)
if (hasPort()) { if (hasPort()) {
sb.append(empty() + " [shape=rect,width=.01,height=.01,label="); sb.append(empty() + " [shape=rect,width=.01,height=.01,label=");

View File

@ -214,7 +214,7 @@ public class DotStringFactory implements Moveable {
line.appendLine(getGraphvizVersion(), sb, dotMode, dotSplines); line.appendLine(getGraphvizVersion(), sb, dotMode, dotSplines);
root.printCluster2(sb, bibliotekon.allLines(), stringBounder, dotMode, getGraphvizVersion(), root.printCluster2(sb, bibliotekon.allLines(), stringBounder, dotMode, getGraphvizVersion(),
umlDiagramType); umlDiagramType, null);
for (SvekLine line : bibliotekon.lines1()) for (SvekLine line : bibliotekon.lines1())
line.appendLine(getGraphvizVersion(), sb, dotMode, dotSplines); line.appendLine(getGraphvizVersion(), sb, dotMode, dotSplines);