Skip to content

Commit

Permalink
fix: better support for package with ELK layout
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudroques committed Nov 16, 2023
1 parent f91a194 commit 546174d
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 20 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Warning, "version" should be the same in gradle.properties and Version.java
# Any idea anyone how to magically synchronize those :-) ?
version = 1.2023.13beta1
version = 1.2023.13beta2
org.gradle.workers.max = 3
30 changes: 14 additions & 16 deletions src/net/sourceforge/plantuml/elk/CucaDiagramFileMakerElk.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
import net.sourceforge.plantuml.svek.Bibliotekon;
import net.sourceforge.plantuml.svek.Cluster;
import net.sourceforge.plantuml.svek.ClusterDecoration;
import net.sourceforge.plantuml.svek.ClusterHeader;
import net.sourceforge.plantuml.svek.CucaDiagramFileMaker;
import net.sourceforge.plantuml.svek.DotStringFactory;
import net.sourceforge.plantuml.svek.GeneralImageBuilder;
Expand Down Expand Up @@ -298,12 +299,12 @@ private void drawSingleCluster(UGraphic ug, Entity group, ElkNode elkNode) {
// final double roundCorner = group.getUSymbol() == null ? 0
// : group.getUSymbol().getSkinParameter().getRoundCorner(skinParam, group.getStereotype());

final TextBlock ztitle = getTitleBlock(group);
final TextBlock zstereo = TextBlockUtils.empty(0, 0);

final RectangleArea rectangleArea = new RectangleArea(0, 0, elkNode.getWidth(), elkNode.getHeight());
final ClusterDecoration decoration = new ClusterDecoration(packageStyle, group.getUSymbol(), ztitle,
zstereo, rectangleArea, stroke);
final ClusterHeader clusterHeader = new ClusterHeader(group, diagram.getSkinParam(), diagram,
stringBounder);

final ClusterDecoration decoration = new ClusterDecoration(packageStyle, group.getUSymbol(),
clusterHeader.getTitle(), clusterHeader.getStereo(), rectangleArea, stroke);

final HColor borderColor = HColors.BLACK;
decoration.drawU(ug.apply(UTranslate.point(corner)), backColor, borderColor, shadowing, roundCorner,
Expand All @@ -314,16 +315,6 @@ private void drawSingleCluster(UGraphic ug, Entity group, ElkNode elkNode) {
// ug.apply(HColorUtils.BLACK).apply(UStroke.withThickness(1.5)).apply(new UTranslate(corner)).draw(rect);
}

private TextBlock getTitleBlock(Entity g) {
final Display label = g.getDisplay();
if (label == null)
return TextBlockUtils.empty(0, 0);

final ISkinParam skinParam = diagram.getSkinParam();
final FontConfiguration fontConfiguration = g.getFontConfigurationForTitle(skinParam);
return label.create(fontConfiguration, HorizontalAlignment.CENTER, skinParam);
}

private HColor getBackColor(UmlDiagramType umlDiagramType) {
return null;
}
Expand Down Expand Up @@ -429,7 +420,14 @@ private void printAllSubgroups(ElkNode cluster, Entity group) {
// We create the "cluster" in ELK for this group
final ElkNode elkCluster = ElkGraphUtil.createNode(cluster);
elkCluster.setProperty(CoreOptions.DIRECTION, Direction.DOWN);
elkCluster.setProperty(CoreOptions.PADDING, new ElkPadding(40, 15, 15, 15));

final ClusterHeader clusterHeader = new ClusterHeader(g, diagram.getSkinParam(), diagram,
stringBounder);

final int titleAndAttributeHeight = clusterHeader.getTitleAndAttributeHeight();

final double topPadding = Math.max(25, titleAndAttributeHeight) + 15;
elkCluster.setProperty(CoreOptions.PADDING, new ElkPadding(topPadding, 15, 15, 15));

// Not sure this is usefull to put a label on a "cluster"
final ElkLabel label = ElkGraphUtil.createLabel(elkCluster);
Expand Down
5 changes: 4 additions & 1 deletion src/net/sourceforge/plantuml/stats/FormatCounter.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ public void reload(String prefix, Preferences prefs) throws BackingStoreExceptio
final String name = removeDotSaved(key);
final NumberAnalyzed value = NumberAnalyzed.load(name, prefs);
if (value != null) {
final FileFormat format = FileFormat.valueOf(name.substring(prefix.length()));
final String subname = name.substring(prefix.length());
if (subname.equals("ANIMATED_GIF"))
continue;
final FileFormat format = FileFormat.valueOf(subname);
data.put(format, value);
}
} catch (Exception e) {
Expand Down
2 changes: 1 addition & 1 deletion src/net/sourceforge/plantuml/svek/GeneralImageBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ private void printGroup(DotStringFactory dotStringFactory, Entity g) {
if (g.getGroupType() == GroupType.CONCURRENT_STATE)
return;

final ClusterHeader clusterHeader = new ClusterHeader((Entity) g, dotData.getSkinParam(), dotData,
final ClusterHeader clusterHeader = new ClusterHeader(g, dotData.getSkinParam(), dotData,
stringBounder);
dotStringFactory.openCluster(g, clusterHeader);
this.printEntities(dotStringFactory, g.leafs());
Expand Down
150 changes: 150 additions & 0 deletions src/net/sourceforge/plantuml/syntax/SyntaxChecker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009-2024, Arnaud Roques
*
* Project Info: https://plantuml.com
*
* If you like this project or if you find it useful, you can support us at:
*
* https://plantuml.com/patreon (only 1$ per month!)
* https://plantuml.com/paypal
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
*
* Original Author: Arnaud Roques
*
*
*/
package net.sourceforge.plantuml.syntax;

import java.util.Collections;
import java.util.List;

import net.sourceforge.plantuml.BlockUml;
import net.sourceforge.plantuml.ErrorUml;
import net.sourceforge.plantuml.OptionFlags;
import net.sourceforge.plantuml.SourceStringReader;
import net.sourceforge.plantuml.UmlDiagram;
import net.sourceforge.plantuml.core.Diagram;
import net.sourceforge.plantuml.error.PSystemError;
import net.sourceforge.plantuml.preproc.Defines;
import net.sourceforge.plantuml.text.BackSlash;
import net.sourceforge.plantuml.utils.LineLocation;
import net.sourceforge.plantuml.utils.LineLocationImpl;

public class SyntaxChecker {
// ::remove folder when __HAXE__
// ::remove file when __CORE__

public static SyntaxResult checkSyntax(List<String> source) {
final StringBuilder sb = new StringBuilder();
for (String s : source) {
sb.append(s);
sb.append(BackSlash.NEWLINE);
}
return checkSyntax(sb.toString());
}

public static SyntaxResult checkSyntax(String source) {
OptionFlags.getInstance().setQuiet(true);
final SyntaxResult result = new SyntaxResult();

if (source.startsWith("@startuml\n") == false) {
result.setError(true);
result.setLineLocation(new LineLocationImpl("", null).oneLineRead());
result.addErrorText("No @startuml/@enduml found");
return result;
}
if (source.endsWith("@enduml\n") == false && source.endsWith("@enduml") == false) {
result.setError(true);
result.setLineLocation(lastLineNumber(source));
result.addErrorText("No @enduml found");
return result;
}
final SourceStringReader sourceStringReader = new SourceStringReader(Defines.createEmpty(), source,
Collections.<String>emptyList());

final List<BlockUml> blocks = sourceStringReader.getBlocks();
if (blocks.size() == 0) {
result.setError(true);
result.setLineLocation(lastLineNumber(source));
result.addErrorText("No @enduml found");
return result;
}
final Diagram system = blocks.get(0).getDiagram();
result.setCmapData(system.hasUrl());
if (system instanceof UmlDiagram) {
result.setUmlDiagramType(((UmlDiagram) system).getUmlDiagramType());
result.setDescription(system.getDescription().getDescription());
} else if (system instanceof PSystemError) {
result.setError(true);
final PSystemError sys = (PSystemError) system;
result.setLineLocation(sys.getLineLocation());
result.setSystemError(sys);
for (ErrorUml er : sys.getErrorsUml())
result.addErrorText(er.getError());
} else {
result.setDescription(system.getDescription().getDescription());
}
return result;
}

public static SyntaxResult checkSyntaxFair(String source) {
final SyntaxResult result = new SyntaxResult();
final SourceStringReader sourceStringReader = new SourceStringReader(Defines.createEmpty(), source,
Collections.<String>emptyList());

final List<BlockUml> blocks = sourceStringReader.getBlocks();
if (blocks.size() == 0) {
result.setError(true);
result.setLineLocation(lastLineNumber(source));
result.addErrorText("No @enduml found");
return result;
}

final Diagram system = blocks.get(0).getDiagram();
result.setCmapData(system.hasUrl());
if (system instanceof UmlDiagram) {
result.setUmlDiagramType(((UmlDiagram) system).getUmlDiagramType());
result.setDescription(system.getDescription().getDescription());
} else if (system instanceof PSystemError) {
result.setError(true);
final PSystemError sys = (PSystemError) system;
result.setLineLocation(sys.getLineLocation());
for (ErrorUml er : sys.getErrorsUml()) {
result.addErrorText(er.getError());
}
result.setSystemError(sys);
} else {
result.setDescription(system.getDescription().getDescription());
}
return result;
}

private static LineLocation lastLineNumber(String source) {
LineLocationImpl result = new LineLocationImpl("", null).oneLineRead();
for (int i = 0; i < source.length(); i++)
if (source.charAt(i) == '\n')
result = result.oneLineRead();

return result;
}
}
2 changes: 1 addition & 1 deletion src/net/sourceforge/plantuml/version/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class Version {

// Warning, "version" should be the same in gradle.properties and Version.java
// Any idea anyone how to magically synchronize those :-) ?
private static final String version = "1.2023.13beta1";
private static final String version = "1.2023.13beta2";

public static String versionString() {
return version;
Expand Down

0 comments on commit 546174d

Please sign in to comment.