Skip to content

Commit

Permalink
Force layout fixes (#579)
Browse files Browse the repository at this point in the history
* Change default time step
* Change default max iteration steps
* Update unit tests references
* Fix bug for negative coordinates
* Fix unit tests references
* Initial positions on an interval depending of unknown positions
* Fix unit tests references
* Fix remaining unit tests references

---------

Signed-off-by: Florian Dupuy <[email protected]>
Co-authored-by: Luma <[email protected]>
  • Loading branch information
flo-dup and zamarrenolm authored Jan 25, 2024
1 parent 6dc27b4 commit ed24436
Show file tree
Hide file tree
Showing 47 changed files with 7,749 additions and 7,751 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ public class ForceLayout<V, E> {
/** Deterministic randomness */
private final Random random = new Random(3L);

private static final int DEFAULT_MAX_STEPS = 1000;
private static final int DEFAULT_MAX_STEPS = 400;
private static final double DEFAULT_MIN_ENERGY_THRESHOLD = 0.001;
private static final double DEFAULT_DELTA_TIME = 1;
private static final double DEFAULT_DELTA_TIME = 0.1;
private static final double DEFAULT_REPULSION = 800.0;
private static final double DEFAULT_FRICTION = 500;
private static final double DEFAULT_MAX_SPEED = 100;
Expand Down Expand Up @@ -146,14 +146,12 @@ public ForceLayout<V, E> setFixedNodes(Set<V> fixedNodes) {
}

private void initializePoints() {
int nbUnknownPositions = graph.vertexSet().size() - initialPoints.size();

// instead of generating initial points in the [0,1] interval apply a scale depending on the number of unknown positions
double scale = Math.sqrt(nbUnknownPositions) * 5;
for (V vertex : graph.vertexSet()) {
Point p;
if (initialPoints.containsKey(vertex)) {
p = initialPoints.get(vertex);
} else {
p = new Point(random.nextDouble(), random.nextDouble());
}
points.put(vertex, p);
points.put(vertex, initialPoints.getOrDefault(vertex, new Point(scale * random.nextDouble(), scale * random.nextDouble())));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private void setEdgeVisibility(Node node, BranchEdge branchEdge, BranchEdge.Side
}

private void computeSize(Graph graph) {
double[] dims = new double[4];
double[] dims = new double[] {Double.MAX_VALUE, -Double.MAX_VALUE, Double.MAX_VALUE, -Double.MAX_VALUE};
Stream.concat(graph.getTextNodesStream(), graph.getNodesStream()).forEach(node -> {
dims[0] = Math.min(dims[0], node.getX());
dims[1] = Math.max(dims[1], node.getX());
Expand Down
60 changes: 30 additions & 30 deletions network-area-diagram/src/test/resources/3wt.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
60 changes: 30 additions & 30 deletions network-area-diagram/src/test/resources/3wt_disconnected.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit ed24436

Please sign in to comment.