-
Notifications
You must be signed in to change notification settings - Fork 92
Add the fixed integer size approximator #1144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Eddykasp
merged 5 commits into
eclipse-elk:master
from
Eddykasp:fixed-integer-size-approximator
May 23, 2025
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7e45dfa
Add the fixed integer size approximator
Eddykasp d5f5197
Make size categories range end depend on number of categories again
Eddykasp d936002
Add fallback handling and robustness to LAYOUT_NEXT_LEVEL approximator
Eddykasp 9d0440c
align calculation to be closer to equations given by log
Eddykasp bdbd9fb
Add javadoc for public methods
Eddykasp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
28 changes: 28 additions & 0 deletions
28
plugins/org.eclipse.elk.core/src/org/eclipse/elk/core/options/ITopdownSizeApproximator.java
This file contains hidden or 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,28 @@ | ||
| /******************************************************************************* | ||
| * 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.core.options; | ||
|
|
||
| import org.eclipse.elk.core.math.KVector; | ||
| import org.eclipse.elk.graph.ElkNode; | ||
|
|
||
| /** | ||
| * A topdown size approximator returns an estimated size of the graph drawing after performing layout using some | ||
| * heuristic. | ||
| * | ||
| */ | ||
| public interface ITopdownSizeApproximator { | ||
|
|
||
| /** | ||
| * Returns an approximated required size for a given node. | ||
| * @param node the node | ||
| * @return the size as a vector | ||
| */ | ||
| public KVector getSize(ElkNode node); | ||
| } |
This file contains hidden or 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
106 changes: 106 additions & 0 deletions
106
...ns/org.eclipse.elk.core/src/org/eclipse/elk/core/options/TopdownSizeApproximatorUtil.java
This file contains hidden or 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,106 @@ | ||
| /******************************************************************************* | ||
| * 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.core.options; | ||
|
|
||
| import org.eclipse.elk.graph.ElkNode; | ||
|
|
||
| /** | ||
| * Utility functions for reuse across different size approximators. | ||
| * | ||
| */ | ||
| public class TopdownSizeApproximatorUtil { | ||
|
|
||
| /** | ||
| * Dynamically calculate the multiplier to be applied for the side length of the input node based on the number | ||
| * of children (with and without hierarchy) it and its siblings have. The distribution is mapped to a log scale, | ||
| * which is divided into a number of categories that determine the multiplier. | ||
| * | ||
| * Category i => 2^i | ||
| * | ||
| * @param originalGraph | ||
| * @return | ||
| */ | ||
| public static double getSizeCategoryMultiplier(final ElkNode originalGraph) { | ||
| ElkNode parent = originalGraph.getParent(); | ||
| int thisGraphsSize = getGraphSize(originalGraph); | ||
|
|
||
| int CATEGORIES = originalGraph.getProperty(CoreOptions.TOPDOWN_SIZE_CATEGORIES); | ||
|
|
||
|
|
||
| if (parent != null) { | ||
| // 1. compute distribution of node sizes | ||
| int sizeMinFound = Integer.MAX_VALUE; | ||
| int sizeMaxFound = Integer.MIN_VALUE; | ||
|
|
||
| for (ElkNode child : parent.getChildren()) { | ||
| int size = getGraphSize(child); | ||
|
|
||
| if (size > sizeMaxFound) { | ||
| sizeMaxFound = size; | ||
| } | ||
| if (size < sizeMinFound) { | ||
| sizeMinFound = size; | ||
| } | ||
| } | ||
|
|
||
|
|
||
| double sizeMin = 1; | ||
| double sizeMax = originalGraph.getProperty(CoreOptions.TOPDOWN_SIZE_CATEGORIES_RANGE_MAX); | ||
| // shift the range to encompass the largest graph in the local neighbourhood | ||
| if (sizeMaxFound > sizeMax) { | ||
| sizeMax = sizeMaxFound; | ||
| } | ||
|
|
||
| // 2. set cutoffs at quarter percentiles on logarithmic scale | ||
| double x = (Math.log(sizeMax) - Math.log(sizeMin)) / CATEGORIES; | ||
| double factor = Math.exp(x); | ||
|
|
||
| // 3. assign node size according to dynamic cutoffs | ||
| double cutoff = sizeMin * factor; | ||
| for (int i = 0; i < CATEGORIES; i++) { | ||
| if (thisGraphsSize <= cutoff) { | ||
| return Math.pow(2, i); | ||
| } else { | ||
| cutoff *= factor; | ||
| } | ||
| } | ||
| // largest category | ||
| return Math.pow(2, CATEGORIES-1); | ||
|
|
||
| } else { | ||
| return 1.0; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * Returns the "size" of the graph defined as the sum of the children's weights. | ||
| * Each simple node containing no children is counted with a weight of 1. | ||
| * Each node with further children is counted with a weight defined in | ||
| * `CoreOptions.TOPDOWN_SIZE_CATEGORIES_HIERARCHICAL_NODE_WEIGHT` | ||
| * @param originalGraph the graph | ||
| * @return the size of the graph | ||
| */ | ||
| public static int getGraphSize(final ElkNode originalGraph) { | ||
|
|
||
| int sum = 0; | ||
|
|
||
| final int HIERARCHICAL_NODE_WEIGHT = originalGraph.getProperty(CoreOptions.TOPDOWN_SIZE_CATEGORIES_HIERARCHICAL_NODE_WEIGHT); | ||
| for (ElkNode child : originalGraph.getChildren()) { | ||
| if (child.getChildren() != null && child.getChildren().size() > 0) { | ||
| sum += HIERARCHICAL_NODE_WEIGHT; | ||
| } else { | ||
| sum += 1; | ||
| } | ||
| } | ||
| return sum; | ||
| } | ||
|
|
||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.