1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-03 09:00:48 +00:00
plantuml/src/net/sourceforge/plantuml/svek/DotStringFactory.java

516 lines
17 KiB
Java
Raw Normal View History

2011-08-08 17:48:29 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2019-01-16 18:34:41 +00:00
* (C) Copyright 2009-2020, Arnaud Roques
2011-08-08 17:48:29 +00:00
*
2016-03-06 16:47:34 +00:00
* Project Info: http://plantuml.com
2011-08-08 17:48:29 +00:00
*
2017-03-15 19:13:31 +00:00
* If you like this project or if you find it useful, you can support us at:
*
* http://plantuml.com/patreon (only 1$ per month!)
* http://plantuml.com/paypal
*
2011-08-08 17:48:29 +00:00
* 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
2013-12-10 19:36:50 +00:00
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
2011-08-08 17:48:29 +00:00
* 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.svek;
import java.awt.geom.Point2D;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
2016-05-11 21:31:47 +00:00
import net.sourceforge.plantuml.BaseFile;
2016-03-06 16:47:34 +00:00
import net.sourceforge.plantuml.ISkinParam;
import net.sourceforge.plantuml.StringUtils;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.UmlDiagramType;
2016-03-06 16:47:34 +00:00
import net.sourceforge.plantuml.cucadiagram.CucaDiagram;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.cucadiagram.IGroup;
import net.sourceforge.plantuml.cucadiagram.Rankdir;
import net.sourceforge.plantuml.cucadiagram.dot.DotData;
2016-01-30 12:20:07 +00:00
import net.sourceforge.plantuml.cucadiagram.dot.DotSplines;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.cucadiagram.dot.Graphviz;
import net.sourceforge.plantuml.cucadiagram.dot.GraphvizUtils;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.cucadiagram.dot.GraphvizVersion;
import net.sourceforge.plantuml.cucadiagram.dot.GraphvizVersions;
import net.sourceforge.plantuml.cucadiagram.dot.ProcessState;
2020-02-18 21:24:31 +00:00
import net.sourceforge.plantuml.cucadiagram.entity.EntityFactory;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.graphic.TextBlock;
2011-09-08 10:42:27 +00:00
import net.sourceforge.plantuml.posimo.Moveable;
2020-05-30 15:20:23 +00:00
import net.sourceforge.plantuml.security.SFile;
2016-06-19 14:16:41 +00:00
import net.sourceforge.plantuml.vizjs.GraphvizJs;
import net.sourceforge.plantuml.vizjs.GraphvizJsRuntimeException;
2011-08-08 17:48:29 +00:00
2011-09-08 10:42:27 +00:00
public class DotStringFactory implements Moveable {
2011-08-08 17:48:29 +00:00
2013-12-10 19:36:50 +00:00
private final Bibliotekon bibliotekon = new Bibliotekon();
2011-08-08 17:48:29 +00:00
2021-05-14 08:42:57 +00:00
final private Set<String> rankMin = new HashSet<>();
2011-08-08 17:48:29 +00:00
private final ColorSequence colorSequence;
private final Cluster root;
2013-12-10 19:36:50 +00:00
2011-08-08 17:48:29 +00:00
private Cluster current;
2016-03-06 16:47:34 +00:00
private final UmlDiagramType umlDiagramType;
private final ISkinParam skinParam;
private final DotMode dotMode;
2021-08-30 17:13:54 +00:00
private DotSplines dotSplines;
2011-08-08 17:48:29 +00:00
private final StringBounder stringBounder;
2016-07-25 19:25:28 +00:00
public DotStringFactory(StringBounder stringBounder, DotData dotData) {
2016-03-06 16:47:34 +00:00
this.skinParam = dotData.getSkinParam();
this.umlDiagramType = dotData.getUmlDiagramType();
this.dotMode = dotData.getDotMode();
2016-07-25 19:25:28 +00:00
this.colorSequence = new ColorSequence();
2016-03-06 16:47:34 +00:00
this.stringBounder = stringBounder;
this.root = new Cluster(colorSequence, skinParam, dotData.getRootGroup());
this.current = root;
}
2016-07-25 19:25:28 +00:00
public DotStringFactory(StringBounder stringBounder, CucaDiagram diagram) {
2016-03-06 16:47:34 +00:00
this.skinParam = diagram.getSkinParam();
this.umlDiagramType = diagram.getUmlDiagramType();
this.dotMode = DotMode.NORMAL;
2016-07-25 19:25:28 +00:00
this.colorSequence = new ColorSequence();
2011-08-08 17:48:29 +00:00
this.stringBounder = stringBounder;
2016-03-06 16:47:34 +00:00
this.root = new Cluster(colorSequence, skinParam, diagram.getEntityFactory().getRootGroup());
2011-08-08 17:48:29 +00:00
this.current = root;
}
2021-02-02 10:12:15 +00:00
public void addNode(SvekNode node) {
2020-02-18 21:24:31 +00:00
current.addNode(node);
2011-08-08 17:48:29 +00:00
}
private void printMinRanking(StringBuilder sb) {
if (rankMin.size() == 0) {
return;
}
sb.append("{ rank = min;");
for (String id : rankMin) {
sb.append(id);
sb.append(";");
}
sb.append("}");
}
private double getHorizontalDzeta() {
double max = 0;
2021-04-20 20:19:49 +00:00
for (SvekLine l : bibliotekon.allLines()) {
2011-08-08 17:48:29 +00:00
final double c = l.getHorizontalDzeta(stringBounder);
if (c > max) {
max = c;
}
}
return max / 10;
}
private double getVerticalDzeta() {
double max = 0;
2021-04-20 20:19:49 +00:00
for (SvekLine l : bibliotekon.allLines()) {
2011-08-08 17:48:29 +00:00
final double c = l.getVerticalDzeta(stringBounder);
if (c > max) {
max = c;
}
}
return max / 10;
}
2013-12-10 19:36:50 +00:00
String createDotString(String... dotStrings) {
2011-08-08 17:48:29 +00:00
final StringBuilder sb = new StringBuilder();
double nodesep = getHorizontalDzeta();
if (nodesep < getMinNodeSep()) {
nodesep = getMinNodeSep();
}
2016-03-06 16:47:34 +00:00
if (skinParam.getNodesep() != 0) {
nodesep = skinParam.getNodesep();
2013-12-10 19:36:50 +00:00
}
2011-08-08 17:48:29 +00:00
final String nodesepInches = SvekUtils.pixelToInches(nodesep);
2013-12-10 19:36:50 +00:00
// Log.println("nodesep=" + nodesepInches);
2011-08-08 17:48:29 +00:00
double ranksep = getVerticalDzeta();
if (ranksep < getMinRankSep()) {
ranksep = getMinRankSep();
}
2016-03-06 16:47:34 +00:00
if (skinParam.getRanksep() != 0) {
ranksep = skinParam.getRanksep();
2013-12-10 19:36:50 +00:00
}
2011-08-08 17:48:29 +00:00
final String ranksepInches = SvekUtils.pixelToInches(ranksep);
2013-12-10 19:36:50 +00:00
// Log.println("ranksep=" + ranksepInches);
2011-08-08 17:48:29 +00:00
sb.append("digraph unix {");
SvekUtils.println(sb);
for (String s : dotStrings) {
if (s.startsWith("ranksep")) {
sb.append("ranksep=" + ranksepInches + ";");
} else if (s.startsWith("nodesep")) {
sb.append("nodesep=" + nodesepInches + ";");
} else {
sb.append(s);
}
SvekUtils.println(sb);
}
2015-04-07 18:18:37 +00:00
// sb.append("newrank=true;");
// SvekUtils.println(sb);
2011-08-08 17:48:29 +00:00
sb.append("remincross=true;");
SvekUtils.println(sb);
sb.append("searchsize=500;");
SvekUtils.println(sb);
2016-03-06 16:47:34 +00:00
// if (OptionFlags.USE_COMPOUND) {
// sb.append("compound=true;");
// SvekUtils.println(sb);
// }
2016-01-30 12:20:07 +00:00
2021-08-30 17:13:54 +00:00
dotSplines = skinParam.getDotSplines();
2016-01-30 12:20:07 +00:00
if (dotSplines == DotSplines.POLYLINE) {
sb.append("splines=polyline;");
SvekUtils.println(sb);
} else if (dotSplines == DotSplines.ORTHO) {
sb.append("splines=ortho;");
2021-08-30 17:13:54 +00:00
sb.append("forcelabels=true;");
2016-01-30 12:20:07 +00:00
SvekUtils.println(sb);
}
2016-03-06 16:47:34 +00:00
if (skinParam.getRankdir() == Rankdir.LEFT_TO_RIGHT) {
2013-12-10 19:36:50 +00:00
sb.append("rankdir=LR;");
SvekUtils.println(sb);
}
manageMinMaxCluster(sb);
2016-08-25 20:45:37 +00:00
root.printCluster1(sb, bibliotekon.allLines(), stringBounder);
2021-04-20 20:19:49 +00:00
for (SvekLine line : bibliotekon.lines0()) {
2021-08-30 17:13:54 +00:00
line.appendLine(getGraphvizVersion(), sb, dotMode, dotSplines);
2011-09-08 10:42:27 +00:00
}
2011-08-08 17:48:29 +00:00
root.fillRankMin(rankMin);
2016-03-06 16:47:34 +00:00
root.printCluster2(sb, bibliotekon.allLines(), stringBounder, dotMode, getGraphvizVersion(), umlDiagramType);
2011-08-08 17:48:29 +00:00
printMinRanking(sb);
2021-04-20 20:19:49 +00:00
for (SvekLine line : bibliotekon.lines1()) {
2021-08-30 17:13:54 +00:00
line.appendLine(getGraphvizVersion(), sb, dotMode, dotSplines);
2011-08-08 17:48:29 +00:00
}
SvekUtils.println(sb);
sb.append("}");
return sb.toString();
}
2013-12-10 19:36:50 +00:00
private void manageMinMaxCluster(final StringBuilder sb) {
2021-05-14 08:42:57 +00:00
final List<String> minPointCluster = new ArrayList<>();
final List<String> maxPointCluster = new ArrayList<>();
2013-12-10 19:36:50 +00:00
for (Cluster cluster : bibliotekon.allCluster()) {
2016-03-06 16:47:34 +00:00
final String minPoint = cluster.getMinPoint(umlDiagramType);
2013-12-10 19:36:50 +00:00
if (minPoint != null) {
minPointCluster.add(minPoint);
}
2016-03-06 16:47:34 +00:00
final String maxPoint = cluster.getMaxPoint(umlDiagramType);
2013-12-10 19:36:50 +00:00
if (maxPoint != null) {
maxPointCluster.add(maxPoint);
}
}
if (minPointCluster.size() > 0) {
sb.append("{rank=min;");
for (String s : minPointCluster) {
sb.append(s);
sb.append(" [shape=point,width=.01,label=\"\"]");
sb.append(";");
}
sb.append("}");
SvekUtils.println(sb);
}
if (maxPointCluster.size() > 0) {
sb.append("{rank=max;");
for (String s : maxPointCluster) {
sb.append(s);
sb.append(" [shape=point,width=.01,label=\"\"]");
sb.append(";");
}
sb.append("}");
SvekUtils.println(sb);
}
}
2011-08-08 17:48:29 +00:00
private int getMinRankSep() {
2016-03-06 16:47:34 +00:00
if (umlDiagramType == UmlDiagramType.ACTIVITY) {
2013-12-10 19:36:50 +00:00
// return 29;
return 40;
2011-08-08 17:48:29 +00:00
}
return 60;
}
private int getMinNodeSep() {
2016-03-06 16:47:34 +00:00
if (umlDiagramType == UmlDiagramType.ACTIVITY) {
2013-12-10 19:36:50 +00:00
// return 15;
return 20;
2011-08-08 17:48:29 +00:00
}
2013-12-10 19:36:50 +00:00
return 35;
}
2016-06-19 14:16:41 +00:00
private GraphvizVersion graphvizVersion;
2013-12-10 19:36:50 +00:00
public GraphvizVersion getGraphvizVersion() {
2016-06-19 14:16:41 +00:00
if (graphvizVersion == null) {
graphvizVersion = getGraphvizVersionInternal();
}
return graphvizVersion;
}
private GraphvizVersion getGraphvizVersionInternal() {
2016-04-04 19:05:10 +00:00
final Graphviz graphviz = GraphvizUtils.create(skinParam, "foo;", "svg");
2016-06-19 14:16:41 +00:00
if (graphviz instanceof GraphvizJs) {
return GraphvizJs.getGraphvizVersion(false);
}
2013-12-10 19:36:50 +00:00
final File f = graphviz.getDotExe();
return GraphvizVersions.getInstance().getVersion(f);
2011-08-08 17:48:29 +00:00
}
2016-06-19 14:16:41 +00:00
public String getSvg(BaseFile basefile, String[] dotOptions) throws IOException {
String dotString = createDotString(dotOptions);
2013-12-10 19:36:50 +00:00
2016-05-11 21:31:47 +00:00
if (basefile != null) {
2020-05-30 15:20:23 +00:00
final SFile f = basefile.getTraceFile("svek.dot");
2016-05-11 21:31:47 +00:00
SvekUtils.traceString(f, dotString);
2013-12-10 19:36:50 +00:00
}
2011-08-08 17:48:29 +00:00
2016-06-19 14:16:41 +00:00
Graphviz graphviz = GraphvizUtils.create(skinParam, dotString, "svg");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
final ProcessState state = graphviz.createFile3(baos);
baos.close();
if (state.differs(ProcessState.TERMINATED_OK())) {
throw new IllegalStateException("Timeout4 " + state, state.getCause());
}
} catch (GraphvizJsRuntimeException e) {
System.err.println("GraphvizJsRuntimeException");
graphvizVersion = GraphvizJs.getGraphvizVersion(true);
dotString = createDotString(dotOptions);
graphviz = GraphvizUtils.create(skinParam, dotString, "svg");
baos = new ByteArrayOutputStream();
final ProcessState state = graphviz.createFile3(baos);
baos.close();
if (state.differs(ProcessState.TERMINATED_OK())) {
throw new IllegalStateException("Timeout4 " + state, state.getCause());
}
2013-12-10 19:36:50 +00:00
}
2011-08-08 17:48:29 +00:00
final byte[] result = baos.toByteArray();
final String s = new String(result, "UTF-8");
2016-05-11 21:31:47 +00:00
if (basefile != null) {
2020-05-30 15:20:23 +00:00
final SFile f = basefile.getTraceFile("svek.svg");
2016-05-11 21:31:47 +00:00
SvekUtils.traceString(f, s);
2013-12-10 19:36:50 +00:00
}
2011-08-08 17:48:29 +00:00
return s;
}
public boolean illegalDotExe() {
2016-04-04 19:05:10 +00:00
final Graphviz graphviz = GraphvizUtils.create(skinParam, "svg");
2016-06-19 14:16:41 +00:00
if (graphviz instanceof GraphvizJs) {
return false;
}
2011-08-08 17:48:29 +00:00
final File dotExe = graphviz.getDotExe();
return dotExe == null || dotExe.isFile() == false || dotExe.canRead() == false;
}
public File getDotExe() {
2016-04-04 19:05:10 +00:00
final Graphviz graphviz = GraphvizUtils.create(skinParam, "svg");
2011-08-08 17:48:29 +00:00
return graphviz.getDotExe();
}
2020-06-07 10:03:18 +00:00
public void solve(boolean mergeIntricated, EntityFactory entityFactory, final String svg)
2020-02-18 21:24:31 +00:00
throws IOException, InterruptedException {
2013-12-10 19:36:50 +00:00
if (svg.length() == 0) {
throw new EmptySvgException();
}
2011-08-08 17:48:29 +00:00
final Pattern pGraph = Pattern.compile("(?m)\\<svg\\s+width=\"(\\d+)pt\"\\s+height=\"(\\d+)pt\"");
final Matcher mGraph = pGraph.matcher(svg);
if (mGraph.find() == false) {
throw new IllegalStateException();
}
2020-06-07 10:03:18 +00:00
// final int fullWidth = Integer.parseInt(mGraph.group(1));
2011-08-08 17:48:29 +00:00
final int fullHeight = Integer.parseInt(mGraph.group(2));
2020-06-07 10:03:18 +00:00
// final MinFinder corner1 = new MinFinder();
2013-12-10 19:36:50 +00:00
2018-03-09 21:37:34 +00:00
final Point2DFunction move = new YDelta(fullHeight);
final SvgResult svgResult = new SvgResult(svg, move);
2021-02-02 10:12:15 +00:00
for (SvekNode node : bibliotekon.allNodes()) {
2020-02-18 21:24:31 +00:00
int idx = svg.indexOf("<title>" + node.getUid() + "</title>");
if (node.getType() == ShapeType.RECTANGLE || node.getType() == ShapeType.RECTANGLE_HTML_FOR_PORTS
|| node.getType() == ShapeType.RECTANGLE_WITH_CIRCLE_INSIDE || node.getType() == ShapeType.FOLDER
|| node.getType() == ShapeType.DIAMOND) {
2018-03-09 21:37:34 +00:00
final List<Point2D.Double> points = svgResult.substring(idx).extractList(SvgResult.POINTS_EQUALS);
2011-08-08 17:48:29 +00:00
final double minY = SvekUtils.getMinY(points);
2020-02-18 21:24:31 +00:00
final double overscanX = node.getOverscanX(stringBounder);
2018-12-22 11:11:40 +00:00
final double minX = SvekUtils.getMinX(points);
2020-06-07 10:03:18 +00:00
// corner1.manage(minX - overscanX, minY);
2020-02-18 21:24:31 +00:00
node.moveSvek(minX, minY);
} else if (node.getType() == ShapeType.ROUND_RECTANGLE) {
2013-12-10 19:36:50 +00:00
final int idx2 = svg.indexOf("d=\"", idx + 1);
2011-08-08 17:48:29 +00:00
idx = svg.indexOf("points=\"", idx + 1);
2013-12-10 19:36:50 +00:00
final List<Point2D.Double> points;
2015-04-07 18:18:37 +00:00
if (idx2 != -1 && (idx == -1 || idx2 < idx)) {
2013-12-10 19:36:50 +00:00
// GraphViz 2.30
2018-03-09 21:37:34 +00:00
points = svgResult.substring(idx2).extractList(SvgResult.D_EQUALS);
2013-12-10 19:36:50 +00:00
} else {
2018-03-09 21:37:34 +00:00
points = svgResult.substring(idx).extractList(SvgResult.POINTS_EQUALS);
2013-12-10 19:36:50 +00:00
for (int i = 0; i < 3; i++) {
idx = svg.indexOf("points=\"", idx + 1);
2018-03-09 21:37:34 +00:00
points.addAll(svgResult.substring(idx).extractList(SvgResult.POINTS_EQUALS));
2013-12-10 19:36:50 +00:00
}
2011-08-08 17:48:29 +00:00
}
final double minX = SvekUtils.getMinX(points);
final double minY = SvekUtils.getMinY(points);
2020-06-07 10:03:18 +00:00
// corner1.manage(minX, minY);
2020-02-18 21:24:31 +00:00
node.moveSvek(minX, minY);
2021-02-02 10:12:15 +00:00
} else if (node.getType() == ShapeType.OCTAGON || node.getType() == ShapeType.HEXAGON) {
2015-04-07 18:18:37 +00:00
idx = svg.indexOf("points=\"", idx + 1);
2018-03-09 21:37:34 +00:00
final int starting = idx;
final List<Point2D.Double> points = svgResult.substring(starting).extractList(SvgResult.POINTS_EQUALS);
2015-04-07 18:18:37 +00:00
final double minX = SvekUtils.getMinX(points);
final double minY = SvekUtils.getMinY(points);
2020-06-07 10:03:18 +00:00
// corner1.manage(minX, minY);
2020-02-18 21:24:31 +00:00
node.moveSvek(minX, minY);
2021-02-02 10:12:15 +00:00
node.setPolygon(minX, minY, points);
2020-02-18 21:24:31 +00:00
} else if (node.getType() == ShapeType.CIRCLE || node.getType() == ShapeType.CIRCLE_IN_RECT
|| node.getType() == ShapeType.OVAL) {
2011-08-08 17:48:29 +00:00
final double cx = SvekUtils.getValue(svg, idx, "cx");
final double cy = SvekUtils.getValue(svg, idx, "cy") + fullHeight;
final double rx = SvekUtils.getValue(svg, idx, "rx");
final double ry = SvekUtils.getValue(svg, idx, "ry");
2020-02-18 21:24:31 +00:00
node.moveSvek(cx - rx, cy - ry);
2011-08-08 17:48:29 +00:00
} else {
2020-02-18 21:24:31 +00:00
throw new IllegalStateException(node.getType().toString() + " " + node.getUid());
2011-08-08 17:48:29 +00:00
}
}
2013-12-10 19:36:50 +00:00
for (Cluster cluster : bibliotekon.allCluster()) {
2020-02-18 21:24:31 +00:00
if (mergeIntricated) {
final IGroup group = cluster.getGroups().iterator().next();
if (entityFactory.isIntricated(group) != null) {
continue;
}
}
2013-12-10 19:36:50 +00:00
int idx = getClusterIndex(svg, cluster.getColor());
2018-03-09 21:37:34 +00:00
final int starting = idx;
final List<Point2D.Double> points = svgResult.substring(starting).extractList(SvgResult.POINTS_EQUALS);
2011-08-08 17:48:29 +00:00
final double minX = SvekUtils.getMinX(points);
final double minY = SvekUtils.getMinY(points);
final double maxX = SvekUtils.getMaxX(points);
final double maxY = SvekUtils.getMaxY(points);
cluster.setPosition(minX, minY, maxX, maxY);
2020-06-07 10:03:18 +00:00
// corner1.manage(minX, minY);
2011-08-08 17:48:29 +00:00
2013-12-10 19:36:50 +00:00
if (cluster.getTitleAndAttributeWidth() == 0 || cluster.getTitleAndAttributeHeight() == 0) {
2011-08-08 17:48:29 +00:00
continue;
}
2013-12-10 19:36:50 +00:00
idx = getClusterIndex(svg, cluster.getTitleColor());
2018-03-09 21:37:34 +00:00
final int starting1 = idx;
final List<Point2D.Double> pointsTitle = svgResult.substring(starting1)
.extractList(SvgResult.POINTS_EQUALS);
2011-08-08 17:48:29 +00:00
final double minXtitle = SvekUtils.getMinX(pointsTitle);
final double minYtitle = SvekUtils.getMinY(pointsTitle);
cluster.setTitlePosition(minXtitle, minYtitle);
}
2021-04-20 20:19:49 +00:00
for (SvekLine line : bibliotekon.allLines()) {
2020-06-07 10:03:18 +00:00
line.solveLine(svgResult);
2011-08-08 17:48:29 +00:00
}
2011-09-07 20:41:58 +00:00
2021-04-20 20:19:49 +00:00
for (SvekLine line : bibliotekon.allLines()) {
2020-02-18 21:24:31 +00:00
line.manageCollision(bibliotekon.allNodes());
2011-08-08 17:48:29 +00:00
}
2020-06-07 10:03:18 +00:00
// corner1.manage(0, 0);
// return new ClusterPosition(corner1.getMinX(), corner1.getMinY(), fullWidth, fullHeight);
// // return new ClusterPosition(0, 0, fullWidth, fullHeight);
2011-08-08 17:48:29 +00:00
}
2013-12-10 19:36:50 +00:00
private int getClusterIndex(final String svg, int colorInt) {
2020-04-26 18:31:41 +00:00
final String colorString = StringUtils.goLowerCase(DotStringFactory.sharp000000(colorInt));
2013-12-10 19:36:50 +00:00
final String keyTitle1 = "=\"" + colorString + "\"";
int idx = svg.indexOf(keyTitle1);
if (idx == -1) {
final String keyTitle2 = "stroke:" + colorString + ";";
idx = svg.indexOf(keyTitle2);
2011-09-08 10:42:27 +00:00
}
2013-12-10 19:36:50 +00:00
if (idx == -1) {
throw new IllegalStateException("Cannot find color " + colorString);
2011-09-08 10:42:27 +00:00
}
2013-12-10 19:36:50 +00:00
return idx;
2011-08-08 17:48:29 +00:00
}
2020-04-26 18:31:41 +00:00
public static String sharp000000(int color) {
final int v = 0xFFFFFF & color;
String s = "000000" + Integer.toHexString(v).toUpperCase();
s = s.substring(s.length() - 6);
return "#" + s;
}
2020-02-18 21:24:31 +00:00
public void openCluster(int titleAndAttributeWidth, int titleAndAttributeHeight, TextBlock title, TextBlock stereo,
IGroup g) {
this.current = current.createChild(titleAndAttributeWidth, titleAndAttributeHeight, title, stereo,
colorSequence, skinParam, g);
2013-12-10 19:36:50 +00:00
bibliotekon.addCluster(this.current);
2011-08-08 17:48:29 +00:00
}
public void closeCluster() {
2020-02-18 21:24:31 +00:00
if (current.getParentCluster() == null) {
2011-08-08 17:48:29 +00:00
throw new IllegalStateException();
}
2020-02-18 21:24:31 +00:00
this.current = current.getParentCluster();
2011-08-08 17:48:29 +00:00
}
2011-09-08 10:42:27 +00:00
public void moveSvek(double deltaX, double deltaY) {
2021-02-02 10:12:15 +00:00
for (SvekNode sh : bibliotekon.allNodes()) {
2011-09-08 10:42:27 +00:00
sh.moveSvek(deltaX, deltaY);
}
2021-04-20 20:19:49 +00:00
for (SvekLine line : bibliotekon.allLines()) {
2011-09-08 10:42:27 +00:00
line.moveSvek(deltaX, deltaY);
}
2013-12-10 19:36:50 +00:00
for (Cluster cl : bibliotekon.allCluster()) {
2011-09-08 10:42:27 +00:00
cl.moveSvek(deltaX, deltaY);
}
}
2013-12-10 19:36:50 +00:00
public final Bibliotekon getBibliotekon() {
return bibliotekon;
}
2016-04-04 19:05:10 +00:00
public ColorSequence getColorSequence() {
return colorSequence;
}
2011-08-08 17:48:29 +00:00
}