Skip to content

Commit

Permalink
Core: Add option to keep FixedLayoutProvider from enlarging graphs. #475
Browse files Browse the repository at this point in the history


Signed-off-by: Christoph Daniel Schulze <[email protected]>
  • Loading branch information
Christoph Daniel Schulze committed Dec 9, 2019
1 parent b091f72 commit 07952f9
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ algorithm fixed (FixedLayoutProvider) {
supports bendPoints
supports nodeSize.constraints
supports nodeSize.minimum
supports nodeSize.fixedGraphSize
}
algorithm box (BoxLayoutProvider) {
label "Box Layout"
Expand Down Expand Up @@ -454,6 +455,13 @@ group nodeSize {
default = new KVector(0, 0)
targets nodes
}
option fixedGraphSize: boolean {

This comment has been minimized.

Copy link
@uruuru

uruuru Dec 10, 2019

Contributor

Wouldn't fixedHierarchicalNodeSize suit our naming conventions better?

This comment has been minimized.

Copy link
@le-cds

le-cds Jan 6, 2020

Contributor

Certainly would. Sorry, totally overlooked this comment before the release. :(

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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2010, 2015 Kiel University and others.
* Copyright (c) 2010, 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
Expand Down Expand Up @@ -42,19 +42,17 @@
* <p>
* MIGRATE The fixed layout provider does not support hyperedges yet.
* </p>
*
* @author msp
*/
public class FixedLayoutProvider extends AbstractLayoutProvider {

/**
* {@inheritDoc}
*/
@Override
public void layout(final ElkNode layoutNode, final IElkProgressMonitor progressMonitor) {
progressMonitor.begin("Fixed Layout", 1);

EdgeRouting edgeRouting = layoutNode.getProperty(CoreOptions.EDGE_ROUTING);
double maxx = 0, maxy = 0;

double maxx = 0;
double maxy = 0;

for (ElkNode node : layoutNode.getChildren()) {
// set the fixed position of the node, or leave it as it is
Expand All @@ -63,7 +61,6 @@ public void layout(final ElkNode layoutNode, final IElkProgressMonitor progressM
node.setLocation(pos.x, pos.y);

// set the fixed size of the node
// TODO Think about whether this makes sense with the new size constraint options.
if (node.getProperty(FixedLayouterOptions.NODE_SIZE_CONSTRAINTS).contains(
SizeConstraint.MINIMUM_SIZE)) {

Expand Down Expand Up @@ -136,11 +133,13 @@ public void layout(final ElkNode layoutNode, final IElkProgressMonitor progressM
}
}

// set size of the parent node
ElkPadding padding = layoutNode.getProperty(FixedLayouterOptions.PADDING);
double newWidth = maxx + padding.getLeft() + padding.getRight();
double newHeight = maxy + padding.getTop() + padding.getBottom();
ElkUtil.resizeNode(layoutNode, newWidth, newHeight, true, true);
// set size of the parent node unless its size should be fixed as well
if (!layoutNode.getProperty(FixedLayouterOptions.NODE_SIZE_FIXED_GRAPH_SIZE)) {
ElkPadding padding = layoutNode.getProperty(FixedLayouterOptions.PADDING);
double newWidth = maxx + padding.getLeft() + padding.getRight();
double newHeight = maxy + padding.getTop() + padding.getBottom();
ElkUtil.resizeNode(layoutNode, newWidth, newHeight, true, true);
}
progressMonitor.done();
}

Expand Down
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);
}
}

}

0 comments on commit 07952f9

Please sign in to comment.