-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Core: Add option to keep FixedLayoutProvider from enlarging graphs. #475
Signed-off-by: Christoph Daniel Schulze <[email protected]>
- Loading branch information
Christoph Daniel Schulze
committed
Dec 9, 2019
1 parent
b091f72
commit 07952f9
Showing
3 changed files
with
117 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,6 +89,7 @@ algorithm fixed (FixedLayoutProvider) { | |
supports bendPoints | ||
supports nodeSize.constraints | ||
supports nodeSize.minimum | ||
supports nodeSize.fixedGraphSize | ||
} | ||
algorithm box (BoxLayoutProvider) { | ||
label "Box Layout" | ||
|
@@ -454,6 +455,13 @@ group nodeSize { | |
default = new KVector(0, 0) | ||
targets nodes | ||
} | ||
option fixedGraphSize: boolean { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
le-cds
Contributor
|
||
label "Fixed Graph Size" | ||
description "By default, the fixed layout provider will enlarge a graph until it is large enough to contain | ||
its children. If this option is set, it won't do so." | ||
default = false | ||
targets parents | ||
} | ||
} | ||
//------- PROGRAMMATIC OPTIONS | ||
output option junctionPoints: KVectorChain { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
test/org.eclipse.elk.alg.common.test/src/org/eclipse/elk/alg/common/issues/Issue475Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2019 Kiel University and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*******************************************************************************/ | ||
package org.eclipse.elk.alg.common.issues; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.util.List; | ||
|
||
import org.eclipse.elk.alg.test.framework.LayoutTestRunner; | ||
import org.eclipse.elk.alg.test.framework.annotations.Algorithm; | ||
import org.eclipse.elk.alg.test.framework.annotations.Configurator; | ||
import org.eclipse.elk.alg.test.framework.annotations.DefaultConfiguration; | ||
import org.eclipse.elk.alg.test.framework.annotations.GraphResourceProvider; | ||
import org.eclipse.elk.alg.test.framework.io.AbstractResourcePath; | ||
import org.eclipse.elk.alg.test.framework.io.ModelResourcePath; | ||
import org.eclipse.elk.core.options.FixedLayouterOptions; | ||
import org.eclipse.elk.graph.ElkNode; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import com.google.common.collect.Lists; | ||
|
||
/** | ||
* Test for issue 475. | ||
*/ | ||
@RunWith(LayoutTestRunner.class) | ||
@Algorithm(FixedLayouterOptions.ALGORITHM_ID) | ||
@DefaultConfiguration | ||
public class Issue475Test { | ||
|
||
////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
// Sources | ||
|
||
@GraphResourceProvider | ||
public List<AbstractResourcePath> testGraphs() { | ||
return Lists.newArrayList(new ModelResourcePath("tickets/core/475_fixedLayoutWithLongLabels.elkt")); | ||
} | ||
|
||
////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
// Configuration | ||
|
||
/** Default compound node size. */ | ||
private static final double SIZE = 20; | ||
|
||
@Configurator | ||
public void configureFixedGraphSize(final ElkNode graph) { | ||
for (ElkNode child : graph.getChildren()) { | ||
// Make sure we know the size the node shall have | ||
child.setProperty(FixedLayouterOptions.NODE_SIZE_FIXED_GRAPH_SIZE, true); | ||
child.setHeight(SIZE); | ||
child.setWidth(SIZE); | ||
} | ||
} | ||
|
||
@Configurator | ||
public void configureNoFixedGraphSize(final ElkNode graph) { | ||
graph.getChildren().stream() | ||
.forEach(node -> node.setProperty(FixedLayouterOptions.NODE_SIZE_FIXED_GRAPH_SIZE, false)); | ||
} | ||
|
||
////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
// Tests | ||
|
||
@Test | ||
public void testCompoundNodeSize(final ElkNode graph) { | ||
graph.getChildren().stream().forEach(node -> doTestCompoundNodeSize(node)); | ||
} | ||
|
||
public void doTestCompoundNodeSize(final ElkNode node) { | ||
if (node.getProperty(FixedLayouterOptions.NODE_SIZE_FIXED_GRAPH_SIZE)) { | ||
// The node's size should not have changed | ||
assertEquals(SIZE, node.getWidth(), 0); | ||
assertEquals(SIZE, node.getHeight(), 0); | ||
|
||
} else { | ||
double maxX = 0; | ||
double maxY = 0; | ||
|
||
for (ElkNode child : node.getChildren()) { | ||
maxX = Math.max(maxX, child.getX() + child.getWidth()); | ||
maxY = Math.max(maxY, child.getY() + child.getHeight()); | ||
} | ||
|
||
assertTrue(node.getWidth() >= maxX); | ||
assertTrue(node.getHeight() >= maxY); | ||
} | ||
} | ||
|
||
} |
Wouldn't
fixedHierarchicalNodeSize
suit our naming conventions better?