-
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.
Add OrderBySize Rectpacking preprocessor (#1095)
* Add OrderBySize Rectpacking preprocessor Setting OrderBySize to true will order nodes by the sizes of their areas while preserving any prior ordering in case of ties. * put node size orderer before interactive orderer
- Loading branch information
Showing
5 changed files
with
92 additions
and
0 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
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
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
33 changes: 33 additions & 0 deletions
33
....alg.rectpacking/src/org/eclipse/elk/alg/rectpacking/intermediate/NodeSizeComparator.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,33 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 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.rectpacking.intermediate; | ||
|
||
import java.util.Comparator; | ||
|
||
import org.eclipse.elk.graph.ElkNode; | ||
|
||
/** | ||
* Node size comparator to compare nodes by their size | ||
* | ||
*/ | ||
public class NodeSizeComparator implements Comparator<ElkNode> { | ||
|
||
/* (non-Javadoc) | ||
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) | ||
*/ | ||
@Override | ||
public int compare(ElkNode node0, ElkNode node1) { | ||
double area0 = node0.getWidth() * node0.getHeight(); | ||
double area1 = node1.getWidth() * node1.getHeight(); | ||
|
||
return Double.compare(area1, area0); | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
...k.alg.rectpacking/src/org/eclipse/elk/alg/rectpacking/intermediate/NodeSizeReorderer.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,41 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 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.rectpacking.intermediate; | ||
|
||
import org.eclipse.elk.core.alg.ILayoutProcessor; | ||
import org.eclipse.elk.core.util.IElkProgressMonitor; | ||
import org.eclipse.elk.graph.ElkNode; | ||
import org.eclipse.emf.common.util.ECollections; | ||
|
||
/** | ||
* Sorts all child nodes by their sizes from largest to smallest while preserving any existing ordering. | ||
* | ||
* <dl> | ||
* <dt>Precondition:</dt> | ||
* <dt>Postcondition:</dt> | ||
* <dd>Children are sorted in descending order from largest to smallest.</dd> | ||
* <dt>Slots:</dt> | ||
* <dd>Before phase 1.</dd> | ||
* <dt>Same-slot dependencies:</dt> | ||
* <dd>Before Interactive Node Reorderer</dd> | ||
* </dl> | ||
*/ | ||
public class NodeSizeReorderer implements ILayoutProcessor<ElkNode> { | ||
|
||
/* (non-Javadoc) | ||
* @see org.eclipse.elk.core.alg.ILayoutProcessor#process(java.lang.Object, org.eclipse.elk.core.util.IElkProgressMonitor) | ||
*/ | ||
@Override | ||
public void process(ElkNode graph, IElkProgressMonitor progressMonitor) { | ||
|
||
ECollections.sort(graph.getChildren(), new NodeSizeComparator()); | ||
} | ||
|
||
} |