1
0
mirror of https://github.com/octoleo/plantuml.git synced 2025-04-02 00:01:52 +00:00

Fix various mindmap and WBS style issues

This commit is contained in:
Arnaud Roques 2022-07-22 16:12:55 +02:00
parent 3bff5329c7
commit ed8ad4bf69
8 changed files with 138 additions and 105 deletions

View File

@ -68,7 +68,6 @@ import net.sourceforge.plantuml.style.ClockwiseTopRightBottomLeft;
import net.sourceforge.plantuml.style.PName; import net.sourceforge.plantuml.style.PName;
import net.sourceforge.plantuml.style.SName; import net.sourceforge.plantuml.style.SName;
import net.sourceforge.plantuml.style.Style; import net.sourceforge.plantuml.style.Style;
import net.sourceforge.plantuml.style.StyleBuilder;
import net.sourceforge.plantuml.style.StyleSignatureBasic; import net.sourceforge.plantuml.style.StyleSignatureBasic;
import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.UStroke; import net.sourceforge.plantuml.ugraphic.UStroke;
@ -139,11 +138,8 @@ public class FtileBoxOld extends AbstractFtile {
return new FtileBoxOld(skinParam, label, null, BoxStyle.PLAIN, style, styleArrow); return new FtileBoxOld(skinParam, label, null, BoxStyle.PLAIN, style, styleArrow);
} }
public static TextBlock createMindMap(StyleBuilder styleBuilder, ISkinParam skinParam, Display label, public static TextBlock createMindMap(Style style, ISkinParam skinParam, Display label) {
StyleSignatureBasic styleDefinition) { return new FtileBoxOld(skinParam, label, null, BoxStyle.PLAIN, style, style);
final Style style = styleDefinition.getMergedStyle(styleBuilder);
final Style styleArrow = style;
return new FtileBoxOld(skinParam, label, null, BoxStyle.PLAIN, style, styleArrow);
} }
private FtileBoxOld(ISkinParam skinParam, Display label, Swimlane swimlane, BoxStyle boxStyle, Style style, private FtileBoxOld(ISkinParam skinParam, Display label, Swimlane swimlane, BoxStyle boxStyle, Style style,

View File

@ -35,7 +35,6 @@
*/ */
package net.sourceforge.plantuml.mindmap; package net.sourceforge.plantuml.mindmap;
import net.sourceforge.plantuml.awt.geom.Dimension2D;
import java.awt.geom.Point2D; import java.awt.geom.Point2D;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -44,19 +43,17 @@ import net.sourceforge.plantuml.Direction;
import net.sourceforge.plantuml.ISkinParam; import net.sourceforge.plantuml.ISkinParam;
import net.sourceforge.plantuml.SkinParamColors; import net.sourceforge.plantuml.SkinParamColors;
import net.sourceforge.plantuml.activitydiagram3.ftile.vertical.FtileBoxOld; import net.sourceforge.plantuml.activitydiagram3.ftile.vertical.FtileBoxOld;
import net.sourceforge.plantuml.awt.geom.Dimension2D;
import net.sourceforge.plantuml.creole.CreoleMode; import net.sourceforge.plantuml.creole.CreoleMode;
import net.sourceforge.plantuml.cucadiagram.Display;
import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.graphic.TextBlock; import net.sourceforge.plantuml.graphic.TextBlock;
import net.sourceforge.plantuml.graphic.TextBlockUtils; import net.sourceforge.plantuml.graphic.TextBlockUtils;
import net.sourceforge.plantuml.graphic.UDrawable; import net.sourceforge.plantuml.graphic.UDrawable;
import net.sourceforge.plantuml.graphic.color.ColorType; import net.sourceforge.plantuml.graphic.color.ColorType;
import net.sourceforge.plantuml.graphic.color.Colors; import net.sourceforge.plantuml.graphic.color.Colors;
import net.sourceforge.plantuml.style.ClockwiseTopRightBottomLeft;
import net.sourceforge.plantuml.style.PName; import net.sourceforge.plantuml.style.PName;
import net.sourceforge.plantuml.style.SName;
import net.sourceforge.plantuml.style.Style; import net.sourceforge.plantuml.style.Style;
import net.sourceforge.plantuml.style.StyleBuilder;
import net.sourceforge.plantuml.style.StyleSignatureBasic;
import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.UPath; import net.sourceforge.plantuml.ugraphic.UPath;
import net.sourceforge.plantuml.ugraphic.UStroke; import net.sourceforge.plantuml.ugraphic.UStroke;
@ -65,55 +62,16 @@ import net.sourceforge.plantuml.ugraphic.color.HColor;
public class FingerImpl implements Finger, UDrawable { public class FingerImpl implements Finger, UDrawable {
private final Display label; private final Idea idea;
private final HColor backColor;
private final String stereotype;
private final ISkinParam skinParam; private final ISkinParam skinParam;
private final StyleBuilder styleBuilder;
private final IdeaShape shape;
private final Direction direction; private final Direction direction;
private final int level;
private boolean drawPhalanx = true; private boolean drawPhalanx = true;
private double marginLeft = 10;
private double marginRight = 10;
private double marginTop = 10;
private double marginBottom = 10;
private final List<FingerImpl> nail = new ArrayList<>(); private final List<FingerImpl> nail = new ArrayList<>();
private Tetris tetris = null; private Tetris tetris = null;
private StyleSignatureBasic getDefaultStyleDefinitionNode() {
final String depth = SName.depth(level);
if (level == 0) {
return StyleSignatureBasic.of(SName.root, SName.element, SName.mindmapDiagram, SName.node, SName.rootNode)
.add(stereotype).add(depth);
}
if (shape == IdeaShape.NONE && nail.size() == 0) {
return StyleSignatureBasic
.of(SName.root, SName.element, SName.mindmapDiagram, SName.node, SName.leafNode, SName.boxless)
.add(stereotype).add(depth);
}
if (shape == IdeaShape.NONE) {
return StyleSignatureBasic.of(SName.root, SName.element, SName.mindmapDiagram, SName.node, SName.boxless)
.add(stereotype).add(depth);
}
if (nail.size() == 0) {
return StyleSignatureBasic.of(SName.root, SName.element, SName.mindmapDiagram, SName.node, SName.leafNode)
.add(stereotype).add(depth);
}
return StyleSignatureBasic.of(SName.root, SName.element, SName.mindmapDiagram, SName.node).add(stereotype)
.add(depth);
}
public StyleSignatureBasic getDefaultStyleDefinitionArrow() {
final String depth = SName.depth(level);
return StyleSignatureBasic.of(SName.root, SName.element, SName.mindmapDiagram, SName.arrow).add(stereotype)
.add(depth);
}
public static FingerImpl build(Idea idea, ISkinParam skinParam, Direction direction) { public static FingerImpl build(Idea idea, ISkinParam skinParam, Direction direction) {
final FingerImpl result = new FingerImpl(idea.getStyleBuilder(), idea.getBackColor(), idea.getLabel(), final FingerImpl result = new FingerImpl(idea, skinParam, direction);
skinParam, idea.getShape(), direction, idea.getLevel(), idea.getStereotype());
for (Idea child : idea.getChildren()) for (Idea child : idea.getChildren())
result.addInNail(build(child, skinParam, direction)); result.addInNail(build(child, skinParam, direction));
@ -124,21 +82,14 @@ public class FingerImpl implements Finger, UDrawable {
nail.add(child); nail.add(child);
} }
private FingerImpl(StyleBuilder styleBuilder, HColor backColor, Display label, ISkinParam skinParam, private FingerImpl(Idea idea, ISkinParam skinParam, Direction direction) {
IdeaShape shape, Direction direction, int level, String stereotype) { this.idea = idea;
this.backColor = backColor;
this.stereotype = stereotype;
this.level = level;
this.label = label;
this.skinParam = skinParam; this.skinParam = skinParam;
this.shape = shape;
this.styleBuilder = styleBuilder;
this.direction = direction; this.direction = direction;
final Style styleNode = getDefaultStyleDefinitionNode().getMergedStyle(styleBuilder); }
this.marginLeft = styleNode.getMargin().getLeft();
this.marginRight = styleNode.getMargin().getRight(); private ClockwiseTopRightBottomLeft getMargin() {
this.marginTop = styleNode.getMargin().getTop(); return getStyle().getMargin();
this.marginBottom = styleNode.getMargin().getBottom();
} }
public void drawU(final UGraphic ug) { public void drawU(final UGraphic ug) {
@ -166,12 +117,12 @@ public class FingerImpl implements Finger, UDrawable {
} }
private HColor getLinkColor() { private HColor getLinkColor() {
final Style styleArrow = getDefaultStyleDefinitionArrow().getMergedStyle(styleBuilder); final Style styleArrow = getStyleArrow();
return styleArrow.value(PName.LineColor).asColor(skinParam.getThemeStyle(), skinParam.getIHtmlColorSet()); return styleArrow.value(PName.LineColor).asColor(skinParam.getThemeStyle(), skinParam.getIHtmlColorSet());
} }
private UStroke getUStroke() { private UStroke getUStroke() {
final Style styleArrow = getDefaultStyleDefinitionArrow().getMergedStyle(styleBuilder); final Style styleArrow = getStyleArrow();
return styleArrow.getStroke(); return styleArrow.getStroke();
} }
@ -190,7 +141,7 @@ public class FingerImpl implements Finger, UDrawable {
private Tetris getTetris(StringBounder stringBounder) { private Tetris getTetris(StringBounder stringBounder) {
if (tetris == null) { if (tetris == null) {
tetris = new Tetris(label.toString()); tetris = new Tetris(idea.getLabel().toString());
for (FingerImpl child : nail) for (FingerImpl child : nail)
tetris.add(child.asSymetricalTee(stringBounder)); tetris.add(child.asSymetricalTee(stringBounder));
@ -211,11 +162,11 @@ public class FingerImpl implements Finger, UDrawable {
} }
private double getX1() { private double getX1() {
return marginLeft; return getMargin().getLeft();
} }
private double getX2() { private double getX2() {
return marginRight + 30; return getMargin().getRight() + 30;
} }
public double getX12() { public double getX12() {
@ -234,23 +185,37 @@ public class FingerImpl implements Finger, UDrawable {
if (drawPhalanx == false) if (drawPhalanx == false)
return TextBlockUtils.empty(0, 0); return TextBlockUtils.empty(0, 0);
if (shape == IdeaShape.BOX) { final Style style = getStyle();
final ISkinParam foo = new SkinParamColors(skinParam, Colors.empty().add(ColorType.BACK, backColor));
final TextBlock box = FtileBoxOld.createMindMap(styleBuilder, foo, label, getDefaultStyleDefinitionNode()); if (idea.getShape() == IdeaShape.BOX) {
return TextBlockUtils.withMargin(box, 0, 0, marginTop, marginBottom); final ISkinParam foo = new SkinParamColors(skinParam,
Colors.empty().add(ColorType.BACK, idea.getBackColor()));
final TextBlock box = FtileBoxOld.createMindMap(style, foo, idea.getLabel());
final ClockwiseTopRightBottomLeft margin = getMargin();
return TextBlockUtils.withMargin(box, 0, 0, margin.getTop(), margin.getBottom());
} }
assert shape == IdeaShape.NONE; assert idea.getShape() == IdeaShape.NONE;
final Style styleNode = getDefaultStyleDefinitionNode().getMergedStyle(styleBuilder); final TextBlock text = idea.getLabel().create0(
final TextBlock text = label.create0( style.getFontConfiguration(skinParam.getThemeStyle(), skinParam.getIHtmlColorSet()),
styleNode.getFontConfiguration(skinParam.getThemeStyle(), skinParam.getIHtmlColorSet()), style.getHorizontalAlignment(), skinParam, style.wrapWidth(), CreoleMode.FULL, null, null);
styleNode.getHorizontalAlignment(), skinParam, styleNode.wrapWidth(), CreoleMode.FULL, null, null);
if (direction == Direction.RIGHT) if (direction == Direction.RIGHT)
return TextBlockUtils.withMargin(text, 3, 0, 1, 1); return TextBlockUtils.withMargin(text, 3, 0, 1, 1);
return TextBlockUtils.withMargin(text, 0, 3, 1, 1); return TextBlockUtils.withMargin(text, 0, 3, 1, 1);
} }
private Style getStyle() {
if (nail.size() != idea.getChildren().size())
throw new IllegalStateException();
return idea.getStyle();
}
private Style getStyleArrow() {
return idea.getStyleArrow();
}
public double getNailThickness(StringBounder stringBounder) { public double getNailThickness(StringBounder stringBounder) {
return getTetris(stringBounder).getHeight(); return getTetris(stringBounder).getHeight();
} }

View File

@ -41,8 +41,13 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import net.sourceforge.plantuml.cucadiagram.Display; import net.sourceforge.plantuml.cucadiagram.Display;
import net.sourceforge.plantuml.style.MergeStrategy;
import net.sourceforge.plantuml.style.SName;
import net.sourceforge.plantuml.style.Style;
import net.sourceforge.plantuml.style.StyleBuilder; import net.sourceforge.plantuml.style.StyleBuilder;
import net.sourceforge.plantuml.style.StyleSignatureBasic;
import net.sourceforge.plantuml.ugraphic.color.HColor; import net.sourceforge.plantuml.ugraphic.color.HColor;
import net.sourceforge.plantuml.wbs.WElement;
class Idea { class Idea {
@ -55,6 +60,50 @@ class Idea {
private final StyleBuilder styleBuilder; private final StyleBuilder styleBuilder;
private final String stereotype; private final String stereotype;
private StyleSignatureBasic getDefaultStyleDefinitionNode(int level) {
final String depth = SName.depth(level);
if (level == 0) {
return StyleSignatureBasic.of(SName.root, SName.element, SName.mindmapDiagram, SName.node, SName.rootNode)
.add(stereotype).add(depth);
}
if (shape == IdeaShape.NONE && children.size() == 0) {
return StyleSignatureBasic
.of(SName.root, SName.element, SName.mindmapDiagram, SName.node, SName.leafNode, SName.boxless)
.add(stereotype).add(depth);
}
if (shape == IdeaShape.NONE) {
return StyleSignatureBasic.of(SName.root, SName.element, SName.mindmapDiagram, SName.node, SName.boxless)
.add(stereotype).add(depth);
}
if (children.size() == 0) {
return StyleSignatureBasic.of(SName.root, SName.element, SName.mindmapDiagram, SName.node, SName.leafNode)
.add(stereotype).add(depth);
}
return StyleSignatureBasic.of(SName.root, SName.element, SName.mindmapDiagram, SName.node).add(stereotype)
.add(depth);
}
private static final int STEP_BY_PARENT = WElement.STEP_BY_PARENT;
public Style getStyle() {
int deltaPriority = STEP_BY_PARENT * 1000;
Style result = styleBuilder.getMergedStyleSpecial(getDefaultStyleDefinitionNode(level), deltaPriority);
for (Idea up = parent; up != null; up = up.parent) {
final StyleSignatureBasic ss = up.getDefaultStyleDefinitionNode(level).addStar();
deltaPriority -= STEP_BY_PARENT;
final Style styleParent = styleBuilder.getMergedStyleSpecial(ss, deltaPriority);
result = result.mergeWith(styleParent, MergeStrategy.OVERWRITE_EXISTING_VALUE);
}
return result;
}
public Style getStyleArrow() {
final String depth = SName.depth(level);
final StyleSignatureBasic defaultStyleDefinitionArrow = StyleSignatureBasic
.of(SName.root, SName.element, SName.mindmapDiagram, SName.arrow).add(stereotype).add(depth);
return defaultStyleDefinitionArrow.getMergedStyle(styleBuilder);
}
public static Idea createIdeaSimple(StyleBuilder styleBuilder, HColor backColor, Display label, IdeaShape shape, public static Idea createIdeaSimple(StyleBuilder styleBuilder, HColor backColor, Display label, IdeaShape shape,
String stereotype) { String stereotype) {
return new Idea(styleBuilder, backColor, 0, null, label, shape, stereotype); return new Idea(styleBuilder, backColor, 0, null, label, shape, stereotype);

View File

@ -132,20 +132,45 @@ public class StyleSignatureBasic implements StyleSignature {
} }
public boolean matchAll(StyleSignatureBasic other) { public boolean matchAll(StyleSignatureBasic other) {
if (other.isStarred() && names.contains("*") == false) final boolean namesContainsStar = names.contains("*");
if (other.isStarred() && namesContainsStar == false)
return false; return false;
final int depthInNames = depthFromTokens(other.names);
for (String token : names) { for (String token : names) {
if (token.equals("*")) if (token.equals("*"))
continue; continue;
if (other.names.contains(token) == false) if (namesContainsStar && depthInNames != -1 && depthFromToken(token) != -1) {
return false; // depth comparaison
if (depthInNames < depthFromToken(token))
return false;
} else {
if (other.names.contains(token) == false)
return false;
}
} }
return true; return true;
} }
private static int depthFromToken(String token) {
if (token.startsWith("depth("))
return Integer.parseInt(token.substring("depth(".length(), token.length() - 1));
return -1;
}
private static int depthFromTokens(Collection<String> tokens) {
for (String token : tokens) {
final int depth = depthFromToken(token);
if (depth != -1)
return depth;
}
return -1;
}
public final Set<String> getNames() { public final Set<String> getNames() {
return Collections.unmodifiableSet(names); return Collections.unmodifiableSet(names);
} }
@ -159,7 +184,7 @@ public class StyleSignatureBasic implements StyleSignature {
} }
public StyleSignature forStereotypeItself(Stereotype stereotype) { public StyleSignature forStereotypeItself(Stereotype stereotype) {
if (stereotype == null || stereotype.getStyleNames().size()==0) if (stereotype == null || stereotype.getStyleNames().size() == 0)
return this; return this;
final StyleSignatures result = new StyleSignatures(); final StyleSignatures result = new StyleSignatures();
@ -175,7 +200,7 @@ public class StyleSignatureBasic implements StyleSignature {
@Override @Override
public StyleSignature withTOBECHANGED(Stereotype stereotype) { public StyleSignature withTOBECHANGED(Stereotype stereotype) {
if (stereotype == null || stereotype.getStyleNames().size()==0) if (stereotype == null || stereotype.getStyleNames().size() == 0)
return this; return this;
final StyleSignatures result = new StyleSignatures(); final StyleSignatures result = new StyleSignatures();

View File

@ -80,7 +80,7 @@ public class Version {
} }
public static int beta() { public static int beta() {
final int beta = 5; final int beta = 6;
return beta; return beta;
} }

View File

@ -71,18 +71,16 @@ public class CommandWBSItem extends SingleLineCommand2<WBSDiagram> {
final String label = arg.get("LABEL", 0); final String label = arg.get("LABEL", 0);
final String stringColor = arg.get("BACKCOLOR", 0); final String stringColor = arg.get("BACKCOLOR", 0);
HColor backColor = null; HColor backColor = null;
if (stringColor != null) { if (stringColor != null)
backColor = diagram.getSkinParam().getIHtmlColorSet().getColor(diagram.getSkinParam().getThemeStyle(), backColor = diagram.getSkinParam().getIHtmlColorSet().getColor(diagram.getSkinParam().getThemeStyle(),
stringColor); stringColor);
}
Direction dir = type.contains("-") ? Direction.LEFT : Direction.RIGHT; Direction dir = type.contains("-") ? Direction.LEFT : Direction.RIGHT;
final String direction = arg.get("DIRECTION", 0); final String direction = arg.get("DIRECTION", 0);
if ("<".equals(direction)) { if ("<".equals(direction))
dir = Direction.LEFT; dir = Direction.LEFT;
} else if (">".equals(direction)) { else if (">".equals(direction))
dir = Direction.RIGHT; dir = Direction.RIGHT;
}
return diagram.addIdea(backColor, diagram.getSmartLevel(type), label, dir, return diagram.addIdea(backColor, diagram.getSmartLevel(type), label, dir,
IdeaShape.fromDesc(arg.get("SHAPE", 0))); IdeaShape.fromDesc(arg.get("SHAPE", 0)));

View File

@ -35,7 +35,6 @@
*/ */
package net.sourceforge.plantuml.wbs; package net.sourceforge.plantuml.wbs;
import net.sourceforge.plantuml.awt.geom.Dimension2D;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
@ -45,6 +44,7 @@ import net.sourceforge.plantuml.FileFormatOption;
import net.sourceforge.plantuml.UmlDiagram; import net.sourceforge.plantuml.UmlDiagram;
import net.sourceforge.plantuml.UmlDiagramType; import net.sourceforge.plantuml.UmlDiagramType;
import net.sourceforge.plantuml.api.ThemeStyle; import net.sourceforge.plantuml.api.ThemeStyle;
import net.sourceforge.plantuml.awt.geom.Dimension2D;
import net.sourceforge.plantuml.command.CommandExecutionResult; import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.command.regex.Matcher2; import net.sourceforge.plantuml.command.regex.Matcher2;
import net.sourceforge.plantuml.command.regex.MyPattern; import net.sourceforge.plantuml.command.regex.MyPattern;
@ -134,9 +134,9 @@ public class WBSDiagram extends UmlDiagram {
Direction direction, IdeaShape shape) { Direction direction, IdeaShape shape) {
try { try {
if (level == 0) { if (level == 0) {
if (root != null) { if (root != null)
return CommandExecutionResult.error("Error 44"); return CommandExecutionResult.error("Error 44");
}
initRoot(backColor, display, stereotype, shape); initRoot(backColor, display, stereotype, shape);
return CommandExecutionResult.ok(); return CommandExecutionResult.ok();
} }
@ -158,9 +158,9 @@ public class WBSDiagram extends UmlDiagram {
private WElement getParentOfLast(int nb) { private WElement getParentOfLast(int nb) {
WElement result = last; WElement result = last;
for (int i = 0; i < nb; i++) { for (int i = 0; i < nb; i++)
result = result.getParent(); result = result.getParent();
}
return result; return result;
} }
@ -171,18 +171,18 @@ public class WBSDiagram extends UmlDiagram {
return 0; return 0;
} }
type = type.replace('\t', ' '); type = type.replace('\t', ' ');
if (type.contains(" ") == false) { if (type.contains(" ") == false)
return type.length() - 1; return type.length() - 1;
}
if (type.endsWith(first)) { if (type.endsWith(first))
return type.length() - first.length(); return type.length() - first.length();
}
if (type.trim().length() == 1) { if (type.trim().length() == 1)
return type.length() - 1; return type.length() - 1;
}
if (type.startsWith(first)) { if (type.startsWith(first))
return type.length() - first.length(); return type.length() - first.length();
}
throw new UnsupportedOperationException("type=<" + type + ">[" + first + "]"); throw new UnsupportedOperationException("type=<" + type + ">[" + first + "]");
} }

View File

@ -54,7 +54,7 @@ import net.sourceforge.plantuml.style.StyleBuilder;
import net.sourceforge.plantuml.style.StyleSignatureBasic; import net.sourceforge.plantuml.style.StyleSignatureBasic;
import net.sourceforge.plantuml.ugraphic.color.HColor; import net.sourceforge.plantuml.ugraphic.color.HColor;
final class WElement { final public class WElement {
private final HColor backColor; private final HColor backColor;
private final Display label; private final Display label;
@ -95,7 +95,7 @@ final class WElement {
return new SkinParamColors(skinParam, Colors.empty().add(ColorType.BACK, backColor)); return new SkinParamColors(skinParam, Colors.empty().add(ColorType.BACK, backColor));
} }
private static final int STEP_BY_PARENT = 1000_1000; public static final int STEP_BY_PARENT = 1000_1000;
public Style getStyle() { public Style getStyle() {
int deltaPriority = STEP_BY_PARENT * 1000; int deltaPriority = STEP_BY_PARENT * 1000;